blob: 7c176ef2028925cf34452e91245b155b640fea1d [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080053import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Looper;
55import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080057import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070058import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070059import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080060import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080061import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070062import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070063import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080064import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070066import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070068import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070069import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080070import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070071import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090072import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080073import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080074import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070075import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080076import android.telephony.AccessNetworkConstants;
77import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070078import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070079import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080080import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070081import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080082import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070083import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080084import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070085import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080086import android.telephony.CellIdentityCdma;
87import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070089import android.telephony.CellInfoGsm;
90import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070091import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080092import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070093import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070094import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070095import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080096import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070097import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080098import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070099import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800100import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800101import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700102import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800103import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800105import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800106import android.telephony.SignalStrengthUpdateRequest;
107import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800108import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800109import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800110import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700111import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700112import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800113import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800114import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800115import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000116import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000117import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000118import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700119import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700120import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800121import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800122import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700123import android.telephony.gba.GbaAuthRequest;
124import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700125import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800126import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000127import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000128import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700129import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000130import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700131import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800132import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700133import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800134import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700135import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000136import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700137import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800138import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800139import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700142import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800144import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800145
Andrew Lee312e8172014-10-23 17:01:36 -0700146import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800147import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800148import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800149import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800150import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700152import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700153import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800154import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800155import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700156import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800158import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700159import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800160import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800161import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800162import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700163import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000164import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800166import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800169import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700170import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700171import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700174import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800175import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700176import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700177import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700178import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700179import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800180import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800181import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700182import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700183import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800185import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800186import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800187import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700188import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700190import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800191import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700192import com.android.internal.telephony.imsphone.ImsPhone;
193import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000194import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800195import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700196import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.IccIoResult;
198import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700200import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000203import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800206import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700207import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700208import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800209import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800210import com.android.phone.callcomposer.CallComposerPictureManager;
211import com.android.phone.callcomposer.CallComposerPictureTransfer;
212import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700213import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700214import com.android.phone.slicestore.SliceStore;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800216import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700217import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700218import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800219import com.android.services.telephony.TelecomAccountRegistry;
220import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800221import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800222
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.io.IOException;
226import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700227import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800229import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000230import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800231import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800232import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800233import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800234import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100235import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700237import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800239import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700240import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800241import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800242import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800243import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244
245/**
246 * Implementation of the ITelephony interface.
247 */
Santos Cordon117fee72014-05-16 17:56:12 -0700248public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 private static final String LOG_TAG = "PhoneInterfaceManager";
250 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
251 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800252 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253
254 // Message codes used with mMainThreadHandler
255 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700256 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
257 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700258 private static final int CMD_OPEN_CHANNEL = 9;
259 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
260 private static final int CMD_CLOSE_CHANNEL = 11;
261 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800262 private static final int CMD_NV_READ_ITEM = 13;
263 private static final int EVENT_NV_READ_ITEM_DONE = 14;
264 private static final int CMD_NV_WRITE_ITEM = 15;
265 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
266 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
267 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700268 private static final int CMD_RESET_MODEM_CONFIG = 19;
269 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800270 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
271 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800272 private static final int CMD_SEND_ENVELOPE = 25;
273 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000274 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
275 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700276 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
277 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
278 private static final int CMD_EXCHANGE_SIM_IO = 31;
279 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800280 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
281 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700282 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
283 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700284 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
285 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700286 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
287 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
288 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
289 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700290 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
291 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
292 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
293 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700294 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800295 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
296 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000297 private static final int CMD_SWITCH_SLOTS = 50;
298 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700299 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
300 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
301 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
302 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
303 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
304 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
305 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
306 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700307 private static final int CMD_GET_ALL_CELL_INFO = 60;
308 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
309 private static final int CMD_GET_CELL_LOCATION = 62;
310 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700311 private static final int CMD_MODEM_REBOOT = 64;
312 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700313 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
314 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800315 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
316 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700317 private static final int CMD_GET_MODEM_STATUS = 70;
318 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700319 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
320 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700321 private static final int CMD_ERASE_MODEM_CONFIG = 74;
322 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800323 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
324 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
325 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
326 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800327 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
328 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800329 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800330 private static final int CMD_GET_CALL_FORWARDING = 83;
331 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
332 private static final int CMD_SET_CALL_FORWARDING = 85;
333 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
334 private static final int CMD_GET_CALL_WAITING = 87;
335 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
336 private static final int CMD_SET_CALL_WAITING = 89;
337 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700338 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
339 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
340 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
341 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700342 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
343 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800344 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
345 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800346 private static final int CMD_SET_DATA_THROTTLING = 99;
347 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800348 private static final int CMD_SET_SIM_POWER = 101;
349 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800350 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
351 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
352 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
353 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800354 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
355 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000356 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800357 private static final int CMD_GET_SLICING_CONFIG = 110;
358 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800359 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700360 private static final int CMD_ENABLE_VONR = 113;
361 private static final int EVENT_ENABLE_VONR_DONE = 114;
362 private static final int CMD_IS_VONR_ENABLED = 115;
363 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700364 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
365 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800367 // Parameters of select command.
368 private static final int SELECT_COMMAND = 0xA4;
369 private static final int SELECT_P1 = 0x04;
370 private static final int SELECT_P2 = 0;
371 private static final int SELECT_P3 = 0x10;
372
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 /** The singleton instance. */
374 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800375 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800379 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700380 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700382 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800383 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800384 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800385 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700386 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800387 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
Peter Wangdafb9ac2020-01-15 14:13:38 -0800389 /** User Activity */
390 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800391 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
392
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700393 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
394
Derek Tan97ebb422014-09-05 16:55:38 -0700395 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
396 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800397 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800398 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700399
Michelecea4cf22018-12-21 15:00:11 -0800400 // String to store multi SIM allowed
401 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
402
Derek Tan740e1672017-06-27 14:56:27 -0700403 // The AID of ISD-R.
404 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
405
yinxub1bed742017-04-17 11:45:04 -0700406 private NetworkScanRequestTracker mNetworkScanRequestTracker;
407
David Kelly5e06a7f2018-03-12 14:10:59 +0000408 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
409 private static final int MANUFACTURER_CODE_LENGTH = 8;
410
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800411 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800412 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800413
Sarah Chin2ec39f62022-08-31 17:03:26 -0700414 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
415 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
416
Derek Tan89e89d42014-07-08 17:00:10 -0700417 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700418 * Experiment flag to enable erase modem config on reset network, default value is false
419 */
420 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
421 "reset_network_erase_modem_config_enabled";
422
Rambo Wang0f050d82021-02-12 11:43:36 -0800423 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800424
sandeepjsb6c87872021-09-27 15:34:44 +0000425 /**
426 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
427 * one ICCID active at the same time.
428 * Apps should use below API signatures if targeting SDK is T and beyond.
429 *
430 * @hide
431 */
432 @ChangeId
433 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
434 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800435
Naina Nallurid63128d2019-09-17 14:10:30 -0700436 /**
Chen Xu540470b2021-12-14 17:15:47 -0800437 * Apps targeting on Android T and beyond will get exception whenever icc close channel
438 * operation fails.
439 */
440 @ChangeId
441 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
442 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
443
444 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 * A request object to use for transmitting data to an ICC.
446 */
447 private static final class IccAPDUArgument {
448 public int channel, cla, command, p1, p2, p3;
449 public String data;
450
451 public IccAPDUArgument(int channel, int cla, int command,
452 int p1, int p2, int p3, String data) {
453 this.channel = channel;
454 this.cla = cla;
455 this.command = command;
456 this.p1 = p1;
457 this.p2 = p2;
458 this.p3 = p3;
459 this.data = data;
460 }
461 }
462
463 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700464 * A request object to use for transmitting data to an ICC.
465 */
466 private static final class ManualNetworkSelectionArgument {
467 public OperatorInfo operatorInfo;
468 public boolean persistSelection;
469
470 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
471 this.operatorInfo = operatorInfo;
472 this.persistSelection = persistSelection;
473 }
474 }
475
Sarah Chin71b3a852022-09-28 15:54:19 -0700476 private static final class PurchasePremiumCapabilityArgument {
477 public @TelephonyManager.PremiumCapability int capability;
478 public @NonNull String appName;
479 public @NonNull IIntegerConsumer callback;
480
481 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
482 @NonNull String appName, @NonNull IIntegerConsumer callback) {
483 this.capability = capability;
484 this.appName = appName;
485 this.callback = callback;
486 }
487 }
488
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700489 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
491 * request after sending. The main thread will notify the request when it is complete.
492 */
493 private static final class MainThreadRequest {
494 /** The argument to use for the request */
495 public Object argument;
496 /** The result of the request that is run on the main thread */
497 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800498 // The subscriber id that this request applies to. Defaults to
499 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
500 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700501
Nathan Harold92bed182018-10-12 18:16:49 -0700502 // In cases where subId is unavailable, the caller needs to specify the phone.
503 public Phone phone;
504
vagdeviaf9a5b92018-08-15 16:01:53 -0700505 public WorkSource workSource;
506
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 public MainThreadRequest(Object argument) {
508 this.argument = argument;
509 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800510
Nathan Harold92bed182018-10-12 18:16:49 -0700511 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
512 this.argument = argument;
513 if (phone != null) {
514 this.phone = phone;
515 }
516 this.workSource = workSource;
517 }
518
vagdeviaf9a5b92018-08-15 16:01:53 -0700519 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800520 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800521 if (subId != null) {
522 this.subId = subId;
523 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700524 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 }
527
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800528 private static final class IncomingThirdPartyCallArgs {
529 public final ComponentName component;
530 public final String callId;
531 public final String callerDisplayName;
532
533 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
534 String callerDisplayName) {
535 this.component = component;
536 this.callId = callId;
537 this.callerDisplayName = callerDisplayName;
538 }
539 }
540
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541 /**
542 * A handler that processes messages on the main thread in the phone process. Since many
543 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
544 * inbound binder threads to the main thread in the phone process. The Binder thread
545 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
546 * on, which will be notified when the operation completes and will contain the result of the
547 * request.
548 *
549 * <p>If a MainThreadRequest object is provided in the msg.obj field,
550 * note that request.result must be set to something non-null for the calling thread to
551 * unblock.
552 */
553 private final class MainThreadHandler extends Handler {
554 @Override
555 public void handleMessage(Message msg) {
556 MainThreadRequest request;
557 Message onCompleted;
558 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000559 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800561 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562
563 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 case CMD_HANDLE_USSD_REQUEST: {
565 request = (MainThreadRequest) msg.obj;
566 final Phone phone = getPhoneFromRequest(request);
567 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800568 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700570
Pengquan Menga1bb6272018-09-06 09:59:22 -0700571 if (!isUssdApiAllowed(request.subId)) {
572 // Carrier does not support use of this API, return failure.
573 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
574 UssdResponse response = new UssdResponse(ussdRequest, null);
575 Bundle returnData = new Bundle();
576 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
577 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700578
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 request.result = true;
580 notifyRequester(request);
581 return;
582 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700583
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 try {
585 request.result = phone != null
586 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
587 } catch (CallStateException cse) {
588 request.result = false;
589 }
590 // Wake up the requesting thread
591 notifyRequester(request);
592 break;
pkanwar32d516d2016-10-14 19:37:38 -0700593 }
594
Yorke Lee716f67e2015-06-17 15:39:16 -0700595 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700596 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700597 final Phone phone = getPhoneFromRequest(request);
598 request.result = phone != null ?
599 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
600 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700601 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700603 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700605
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000609 uiccPort = getUiccPortFromRequest(request);
610 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800612 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700614 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800616 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000617 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800618 iccArgument.channel, iccArgument.cla, iccArgument.command,
619 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
620 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 ar = (AsyncResult) msg.obj;
626 request = (MainThreadRequest) ar.userObj;
627 if (ar.exception == null && ar.result != null) {
628 request.result = ar.result;
629 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800630 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 if (ar.result == null) {
632 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800633 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800635 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 } else {
637 loge("iccTransmitApduLogicalChannel: Unknown exception");
638 }
639 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 break;
642
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
644 request = (MainThreadRequest) msg.obj;
645 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000646 uiccPort = getUiccPortFromRequest(request);
647 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800649 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700650 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 } else {
652 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800653 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000654 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800655 iccArgument.cla, iccArgument.command, iccArgument.p1,
656 iccArgument.p2,
657 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 }
659 break;
660
661 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
664 if (ar.exception == null && ar.result != null) {
665 request.result = ar.result;
666 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 if (ar.result == null) {
669 loge("iccTransmitApduBasicChannel: Empty response");
670 } else if (ar.exception instanceof CommandException) {
671 loge("iccTransmitApduBasicChannel: CommandException: " +
672 ar.exception);
673 } else {
674 loge("iccTransmitApduBasicChannel: Unknown exception");
675 }
676 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 break;
679
680 case CMD_EXCHANGE_SIM_IO:
681 request = (MainThreadRequest) msg.obj;
682 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort = getUiccPortFromRequest(request);
684 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800686 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 } else {
689 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
690 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000691 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
693 iccArgument.data, onCompleted);
694 }
695 break;
696
697 case EVENT_EXCHANGE_SIM_IO_DONE:
698 ar = (AsyncResult) msg.obj;
699 request = (MainThreadRequest) ar.userObj;
700 if (ar.exception == null && ar.result != null) {
701 request.result = ar.result;
702 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800703 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 break;
707
Derek Tan4d5e5c12014-02-04 11:54:58 -0800708 case CMD_SEND_ENVELOPE:
709 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000710 uiccPort = getUiccPortFromRequest(request);
711 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700712 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800713 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 } else {
716 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800717 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800719 break;
720
721 case EVENT_SEND_ENVELOPE_DONE:
722 ar = (AsyncResult) msg.obj;
723 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700724 if (ar.exception == null && ar.result != null) {
725 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800726 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800727 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700728 if (ar.result == null) {
729 loge("sendEnvelopeWithStatus: Empty response");
730 } else if (ar.exception instanceof CommandException) {
731 loge("sendEnvelopeWithStatus: CommandException: " +
732 ar.exception);
733 } else {
734 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
735 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800736 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800738 break;
739
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 case CMD_OPEN_CHANNEL:
741 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000742 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800743 IccLogicalChannelRequest openChannelRequest =
744 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000745 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800747 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800748 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 } else {
751 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800752 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
753 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700754 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 break;
756
757 case EVENT_OPEN_CHANNEL_DONE:
758 ar = (AsyncResult) msg.obj;
759 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700760 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 int[] result = (int[]) ar.result;
763 int channelId = result[0];
764 byte[] selectResponse = null;
765 if (result.length > 1) {
766 selectResponse = new byte[result.length - 1];
767 for (int i = 1; i < result.length; ++i) {
768 selectResponse[i - 1] = (byte) result[i];
769 }
770 }
771 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800772 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800773
774 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700775 if (uiccPort == null) {
776 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
777 } else {
778 IccLogicalChannelRequest channelRequest =
779 (IccLogicalChannelRequest) request.argument;
780 channelRequest.channel = channelId;
781 uiccPort.onLogicalChannelOpened(channelRequest);
782 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 if (ar.result == null) {
785 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700787 if (ar.exception != null) {
788 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
789 }
790
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700791 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700792 if (ar.exception instanceof CommandException) {
793 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800794 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700795 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700796 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700797 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700798 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700799 }
800 }
801 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800802 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700804 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700805 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700806 break;
807
808 case CMD_CLOSE_CHANNEL:
809 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000810 uiccPort = getUiccPortFromRequest(request);
811 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700812 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800813 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800814 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800815 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700816 } else {
817 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000818 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700819 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700820 break;
821
822 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
825 if (ar.exception == null) {
826 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800827 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700828 if (uiccPort == null) {
829 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
830 } else {
831 final int channelId = (Integer) request.argument;
832 uiccPort.onLogicalChannelClosed(channelId);
833 }
Chen Xu540470b2021-12-14 17:15:47 -0800834 } else {
835 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800836 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800837 if (ar.exception instanceof CommandException) {
838 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
839 CommandException.Error error =
840 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800841 if (error == CommandException.Error.INVALID_ARGUMENTS) {
842 // should only throw exceptions from the binder threads.
843 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800844 "iccCloseLogicalChannel: invalid argument ");
845 }
846 } else {
847 loge("iccCloseLogicalChannel: Unknown exception");
848 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800849 request.result = (exception != null) ? exception :
850 new IllegalStateException(
851 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800852 }
853 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800854 break;
855
856 case CMD_NV_READ_ITEM:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800859 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
860 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800861 break;
862
863 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700868 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800869 request.result = "";
870 if (ar.result == null) {
871 loge("nvReadItem: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("nvReadItem: CommandException: " +
874 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700875 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800876 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700877 }
878 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700879 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700880 break;
881
Jake Hambye994d462014-02-03 13:10:13 -0800882 case CMD_NV_WRITE_ITEM:
883 request = (MainThreadRequest) msg.obj;
884 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
885 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700887 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800888 break;
889
890 case EVENT_NV_WRITE_ITEM_DONE:
891 handleNullReturnEvent(msg, "nvWriteItem");
892 break;
893
894 case CMD_NV_WRITE_CDMA_PRL:
895 request = (MainThreadRequest) msg.obj;
896 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800897 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800898 break;
899
900 case EVENT_NV_WRITE_CDMA_PRL_DONE:
901 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
902 break;
903
chen xu6dac5ab2018-10-26 17:39:23 -0700904 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800905 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700906 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800907 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800908 break;
909
chen xu6dac5ab2018-10-26 17:39:23 -0700910 case EVENT_RESET_MODEM_CONFIG_DONE:
911 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800912 break;
913
Sooraj Sasindran37444802020-08-11 10:40:43 -0700914 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
915 request = (MainThreadRequest) msg.obj;
916 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
917 request);
918 Phone phone = getPhoneFromRequest(request);
919 if (phone != null) {
920 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
921 } else {
922 loge("isNRDualConnectivityEnabled: No phone object");
923 request.result = false;
924 notifyRequester(request);
925 }
926 break;
927 }
928
929 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
932 if (ar.exception == null && ar.result != null) {
933 request.result = ar.result;
934 } else {
935 // request.result must be set to something non-null
936 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700937 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700938 request.result = ar.result;
939 } else {
940 request.result = false;
941 }
942 if (ar.result == null) {
943 loge("isNRDualConnectivityEnabled: Empty response");
944 } else if (ar.exception instanceof CommandException) {
945 loge("isNRDualConnectivityEnabled: CommandException: "
946 + ar.exception);
947 } else {
948 loge("isNRDualConnectivityEnabled: Unknown exception");
949 }
950 }
951 notifyRequester(request);
952 break;
953
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700954 case CMD_IS_VONR_ENABLED: {
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
957 request);
958 Phone phone = getPhoneFromRequest(request);
959 if (phone != null) {
960 phone.isVoNrEnabled(onCompleted, request.workSource);
961 } else {
962 loge("isVoNrEnabled: No phone object");
963 request.result = false;
964 notifyRequester(request);
965 }
966 break;
967 }
968
969 case EVENT_IS_VONR_ENABLED_DONE:
970 ar = (AsyncResult) msg.obj;
971 request = (MainThreadRequest) ar.userObj;
972 if (ar.exception == null && ar.result != null) {
973 request.result = ar.result;
974 } else {
975 // request.result must be set to something non-null
976 // for the calling thread to unblock
977 if (ar.result != null) {
978 request.result = ar.result;
979 } else {
980 request.result = false;
981 }
982 if (ar.result == null) {
983 loge("isVoNrEnabled: Empty response");
984 } else if (ar.exception instanceof CommandException) {
985 loge("isVoNrEnabled: CommandException: "
986 + ar.exception);
987 } else {
988 loge("isVoNrEnabled: Unknown exception");
989 }
990 }
991 notifyRequester(request);
992 break;
993
Sooraj Sasindran37444802020-08-11 10:40:43 -0700994 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
995 request = (MainThreadRequest) msg.obj;
996 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
997 Phone phone = getPhoneFromRequest(request);
998 if (phone != null) {
999 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1000 request.workSource);
1001 } else {
1002 loge("enableNrDualConnectivity: No phone object");
1003 request.result =
1004 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1005 notifyRequester(request);
1006 }
1007 break;
1008 }
1009
1010 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 if (ar.exception == null) {
1014 request.result =
1015 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1016 } else {
1017 request.result =
1018 TelephonyManager
1019 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1020 if (ar.exception instanceof CommandException) {
1021 CommandException.Error error =
1022 ((CommandException) (ar.exception)).getCommandError();
1023 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1024 request.result =
1025 TelephonyManager
1026 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001027 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1028 request.result =
1029 TelephonyManager
1030 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001031 }
1032 loge("enableNrDualConnectivity" + ": CommandException: "
1033 + ar.exception);
1034 } else {
1035 loge("enableNrDualConnectivity" + ": Unknown exception");
1036 }
1037 }
1038 notifyRequester(request);
1039 break;
1040 }
1041
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001042 case CMD_ENABLE_VONR: {
1043 request = (MainThreadRequest) msg.obj;
1044 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1045 Phone phone = getPhoneFromRequest(request);
1046 if (phone != null) {
1047 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1048 request.workSource);
1049 } else {
1050 loge("setVoNrEnabled: No phone object");
1051 request.result =
1052 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1053 notifyRequester(request);
1054 }
1055 break;
1056 }
1057
1058 case EVENT_ENABLE_VONR_DONE: {
1059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
1061 if (ar.exception == null) {
1062 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1063 } else {
1064 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1065 if (ar.exception instanceof CommandException) {
1066 CommandException.Error error =
1067 ((CommandException) (ar.exception)).getCommandError();
1068 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1069 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1070 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1071 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1072 } else {
1073 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1074 }
1075 loge("setVoNrEnabled" + ": CommandException: "
1076 + ar.exception);
1077 } else {
1078 loge("setVoNrEnabled" + ": Unknown exception");
1079 }
1080 }
1081 notifyRequester(request);
1082 break;
1083 }
1084
SongFerngWang3ef3e072020-12-21 16:41:52 +08001085 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001086 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1088 request);
1089 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 break;
1091
SongFerngWang3ef3e072020-12-21 16:41:52 +08001092 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 if (ar.exception == null && ar.result != null) {
1096 request.result = ar.result; // Integer
1097 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301098 // request.result must be set to something non-null
1099 // for the calling thread to unblock
1100 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001101 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001102 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001103 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001104 loge("getAllowedNetworkTypesBitmask: CommandException: "
1105 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001107 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001108 }
1109 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001110 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001111 break;
1112
SongFerngWang3ef3e072020-12-21 16:41:52 +08001113 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001114 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001115 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1116 request);
1117 Pair<Integer, Long> reasonWithNetworkTypes =
1118 (Pair<Integer, Long>) request.argument;
1119 getPhoneFromRequest(request).setAllowedNetworkTypes(
1120 reasonWithNetworkTypes.first,
1121 reasonWithNetworkTypes.second,
1122 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 break;
1124
SongFerngWang3ef3e072020-12-21 16:41:52 +08001125 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1126 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001127 break;
1128
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001129 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1130 request = (MainThreadRequest)msg.obj;
1131 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001132 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001133 break;
1134
1135 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1136 ar = (AsyncResult)msg.obj;
1137 request = (MainThreadRequest)ar.userObj;
1138 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001139 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001140 break;
1141
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001142 case CMD_SET_VOICEMAIL_NUMBER:
1143 request = (MainThreadRequest) msg.obj;
1144 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1145 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001146 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1147 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001148 break;
1149
1150 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1151 handleNullReturnEvent(msg, "setVoicemailNumber");
1152 break;
1153
Stuart Scott54788802015-03-30 13:18:01 -07001154 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1155 request = (MainThreadRequest) msg.obj;
1156 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1157 request);
1158 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1159 break;
1160
1161 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1162 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1163 break;
1164
Shishir Agrawal302c8692015-06-19 13:49:39 -07001165 case CMD_PERFORM_NETWORK_SCAN:
1166 request = (MainThreadRequest) msg.obj;
1167 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1168 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1169 break;
1170
Hall Liu27d24262020-09-18 19:04:59 -07001171 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001172 request = (MainThreadRequest) msg.obj;
1173 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001174 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1175 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1176 request.argument;
1177 int callForwardingReason = args.first;
1178 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001179 break;
Hall Liu27d24262020-09-18 19:04:59 -07001180 }
1181 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001182 ar = (AsyncResult) msg.obj;
1183 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001184 TelephonyManager.CallForwardingInfoCallback callback =
1185 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1186 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001187 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001188 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001189 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1190 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1191 // Service Class is a bit mask per 3gpp 27.007. Search for
1192 // any service for voice call.
1193 if ((callForwardInfo.serviceClass
1194 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001195 callForwardingInfo = new CallForwardingInfo(
1196 callForwardInfo.status
1197 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001198 callForwardInfo.reason,
1199 callForwardInfo.number,
1200 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001201 break;
1202 }
1203 }
1204 // Didn't find a call forward info for voice call.
1205 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001206 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1207 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001208 }
Hall Liu27d24262020-09-18 19:04:59 -07001209 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001210 } else {
1211 if (ar.result == null) {
1212 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1213 }
1214 if (ar.exception != null) {
1215 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1216 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001217 int errorCode = TelephonyManager
1218 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 if (ar.exception instanceof CommandException) {
1220 CommandException.Error error =
1221 ((CommandException) (ar.exception)).getCommandError();
1222 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001223 errorCode = TelephonyManager
1224 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001225 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001226 errorCode = TelephonyManager
1227 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001228 }
1229 }
Hall Liu27d24262020-09-18 19:04:59 -07001230 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001231 }
Shuo Qian4a594052020-01-23 11:59:30 -08001232 break;
Hall Liu27d24262020-09-18 19:04:59 -07001233 }
Shuo Qian4a594052020-01-23 11:59:30 -08001234
Hall Liu27d24262020-09-18 19:04:59 -07001235 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001236 request = (MainThreadRequest) msg.obj;
1237 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001238 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001239 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001240 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1241 request.argument).first;
1242 request.phone.setCallForwardingOption(
1243 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001244 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001245 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001246 callForwardingInfoToSet.getReason(),
1247 callForwardingInfoToSet.getNumber(),
1248 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1249 break;
Hall Liu27d24262020-09-18 19:04:59 -07001250 }
Shuo Qian4a594052020-01-23 11:59:30 -08001251
Hall Liu27d24262020-09-18 19:04:59 -07001252 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001253 ar = (AsyncResult) msg.obj;
1254 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001255 Consumer<Integer> callback =
1256 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1257 request.argument).second;
1258 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001260 int errorCode = TelephonyManager.CallForwardingInfoCallback
1261 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001262 if (ar.exception instanceof CommandException) {
1263 CommandException.Error error =
1264 ((CommandException) (ar.exception)).getCommandError();
1265 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001266 errorCode = TelephonyManager.CallForwardingInfoCallback
1267 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001268 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001269 errorCode = TelephonyManager.CallForwardingInfoCallback
1270 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001271 }
1272 }
1273 callback.accept(errorCode);
1274 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001275 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001276 }
Shuo Qian4a594052020-01-23 11:59:30 -08001277 break;
Hall Liu27d24262020-09-18 19:04:59 -07001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279
Hall Liu27d24262020-09-18 19:04:59 -07001280 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001281 request = (MainThreadRequest) msg.obj;
1282 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1283 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1284 break;
Hall Liu27d24262020-09-18 19:04:59 -07001285 }
Shuo Qian4a594052020-01-23 11:59:30 -08001286
Hall Liu27d24262020-09-18 19:04:59 -07001287 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001288 ar = (AsyncResult) msg.obj;
1289 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001290 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001291 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001292 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001293 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001294 // Service Class is a bit mask per 3gpp 27.007.
1295 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001296 if (callForwardResults.length > 1
1297 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001298 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001299 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001300 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1301 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001302 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001303 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001304 }
1305 } else {
1306 if (ar.result == null) {
1307 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1308 }
1309 if (ar.exception != null) {
1310 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1311 }
1312 if (ar.exception instanceof CommandException) {
1313 CommandException.Error error =
1314 ((CommandException) (ar.exception)).getCommandError();
1315 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001316 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001317 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001318 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1319 callWaitingStatus =
1320 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001321 }
1322 }
1323 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001324 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001325 break;
Hall Liu27d24262020-09-18 19:04:59 -07001326 }
Shuo Qian4a594052020-01-23 11:59:30 -08001327
Hall Liu27d24262020-09-18 19:04:59 -07001328 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001329 request = (MainThreadRequest) msg.obj;
1330 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001331 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1332 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001333 break;
Hall Liu27d24262020-09-18 19:04:59 -07001334 }
Shuo Qian4a594052020-01-23 11:59:30 -08001335
Hall Liu27d24262020-09-18 19:04:59 -07001336 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001337 ar = (AsyncResult) msg.obj;
1338 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001339 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1340 Consumer<Integer> callback =
1341 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1342 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001343 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001344 if (ar.exception instanceof CommandException) {
1345 CommandException.Error error =
1346 ((CommandException) (ar.exception)).getCommandError();
1347 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1348 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001349 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1350 callback.accept(
1351 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001352 } else {
1353 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1354 }
1355 } else {
1356 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1357 }
1358 } else {
1359 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1360 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001361 }
Shuo Qian4a594052020-01-23 11:59:30 -08001362 break;
Hall Liu27d24262020-09-18 19:04:59 -07001363 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001364 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1365 ar = (AsyncResult) msg.obj;
1366 request = (MainThreadRequest) ar.userObj;
1367 CellNetworkScanResult cellScanResult;
1368 if (ar.exception == null && ar.result != null) {
1369 cellScanResult = new CellNetworkScanResult(
1370 CellNetworkScanResult.STATUS_SUCCESS,
1371 (List<OperatorInfo>) ar.result);
1372 } else {
1373 if (ar.result == null) {
1374 loge("getCellNetworkScanResults: Empty response");
1375 }
1376 if (ar.exception != null) {
1377 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1378 }
1379 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1380 if (ar.exception instanceof CommandException) {
1381 CommandException.Error error =
1382 ((CommandException) (ar.exception)).getCommandError();
1383 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1384 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1385 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1386 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1387 }
1388 }
1389 cellScanResult = new CellNetworkScanResult(errorCode, null);
1390 }
1391 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001392 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001393 break;
1394
1395 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1396 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001397 ManualNetworkSelectionArgument selArg =
1398 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001399 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1400 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001401 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1402 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001403 break;
1404
1405 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001406 ar = (AsyncResult) msg.obj;
1407 request = (MainThreadRequest) ar.userObj;
1408 if (ar.exception == null) {
1409 request.result = true;
1410 } else {
1411 request.result = false;
1412 loge("setNetworkSelectionModeManual " + ar.exception);
1413 }
1414 notifyRequester(request);
1415 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001416 break;
1417
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001418 case CMD_GET_MODEM_ACTIVITY_INFO:
1419 request = (MainThreadRequest) msg.obj;
1420 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001421 if (defaultPhone != null) {
1422 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001423 } else {
1424 ResultReceiver result = (ResultReceiver) request.argument;
1425 Bundle bundle = new Bundle();
1426 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001427 new ModemActivityInfo(0, 0, 0,
1428 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001429 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001430 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001431 break;
1432
Hall Liud0f208c2020-10-14 16:54:44 -07001433 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001434 ar = (AsyncResult) msg.obj;
1435 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001436 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001437 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001438 if (mLastModemActivityInfo == null) {
1439 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1440 mLastModemActivitySpecificInfo[0] =
1441 new ActivityStatsTechSpecificInfo(
1442 0,
1443 0,
1444 new int[ModemActivityInfo.getNumTxPowerLevels()],
1445 0);
1446 mLastModemActivityInfo =
1447 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1448 }
1449
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001451 // Update the last modem activity info and the result of the request.
1452 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1453 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001454 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001455 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001456 mLastModemActivityInfo =
1457 new ModemActivityInfo(
1458 mLastModemActivityInfo.getTimestampMillis(),
1459 mLastModemActivityInfo.getSleepTimeMillis(),
1460 mLastModemActivityInfo.getIdleTimeMillis(),
1461 mLastModemActivitySpecificInfo);
1462
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 } else {
1464 if (ar.result == null) {
1465 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001466 error = TelephonyManager.ModemActivityInfoException
1467 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001469 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001470 error = TelephonyManager.ModemActivityInfoException
1471 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001472 } else {
1473 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001474 error = TelephonyManager.ModemActivityInfoException
1475 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001476 }
1477 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001478 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001479 if (mLastModemActivityInfo != null) {
1480 bundle.putParcelable(
1481 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1482 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001483 } else {
1484 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1485 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001486 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001487 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001489 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001490
Meng Wang1a7c35a2016-05-05 20:56:15 -07001491 case CMD_SET_ALLOWED_CARRIERS:
1492 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001493 CarrierRestrictionRules argument =
1494 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001495 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001496 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001497 break;
1498
1499 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1500 ar = (AsyncResult) msg.obj;
1501 request = (MainThreadRequest) ar.userObj;
1502 if (ar.exception == null && ar.result != null) {
1503 request.result = ar.result;
1504 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001505 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1506 if (ar.exception instanceof CommandException) {
1507 loge("setAllowedCarriers: CommandException: " + ar.exception);
1508 CommandException.Error error =
1509 ((CommandException) (ar.exception)).getCommandError();
1510 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1511 request.result =
1512 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1513 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001514 } else {
1515 loge("setAllowedCarriers: Unknown exception");
1516 }
1517 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001518 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001519 break;
1520
1521 case CMD_GET_ALLOWED_CARRIERS:
1522 request = (MainThreadRequest) msg.obj;
1523 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001524 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001525 break;
1526
1527 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 if (ar.exception == null && ar.result != null) {
1531 request.result = ar.result;
1532 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001533 request.result = new IllegalStateException(
1534 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001535 if (ar.result == null) {
1536 loge("getAllowedCarriers: Empty response");
1537 } else if (ar.exception instanceof CommandException) {
1538 loge("getAllowedCarriers: CommandException: " +
1539 ar.exception);
1540 } else {
1541 loge("getAllowedCarriers: Unknown exception");
1542 }
1543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 break;
1546
Nathan Haroldb3014052017-01-25 15:57:32 -08001547 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 if (ar.exception == null && ar.result != null) {
1551 request.result = ar.result;
1552 } else {
1553 request.result = new IllegalArgumentException(
1554 "Failed to retrieve Forbidden Plmns");
1555 if (ar.result == null) {
1556 loge("getForbiddenPlmns: Empty response");
1557 } else {
1558 loge("getForbiddenPlmns: Unknown exception");
1559 }
1560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001561 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001562 break;
1563
1564 case CMD_GET_FORBIDDEN_PLMNS:
1565 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001566 uiccPort = getUiccPortFromRequest(request);
1567 if (uiccPort == null) {
1568 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001569 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001570 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001571 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001572 break;
1573 }
1574 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001575 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001576 if (uiccApp == null) {
1577 loge("getForbiddenPlmns() no app with specified type -- "
1578 + appType);
1579 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001580 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001581 break;
1582 } else {
1583 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1584 + " specified type -- " + appType);
1585 }
1586 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1587 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1588 onCompleted);
1589 break;
1590
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001591 case CMD_SWITCH_SLOTS:
1592 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001593 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001594 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001595 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001596 break;
1597
1598 case EVENT_SWITCH_SLOTS_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001602 notifyRequester(request);
1603 break;
1604 case CMD_GET_NETWORK_SELECTION_MODE:
1605 request = (MainThreadRequest) msg.obj;
1606 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1607 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1608 break;
1609
1610 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 if (ar.exception != null) {
1614 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1615 } else {
1616 int mode = ((int[]) ar.result)[0];
1617 if (mode == 0) {
1618 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1619 } else {
1620 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1621 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001623 notifyRequester(request);
1624 break;
1625 case CMD_GET_CDMA_ROAMING_MODE:
1626 request = (MainThreadRequest) msg.obj;
1627 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1628 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1629 break;
1630 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception != null) {
1634 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1635 } else {
1636 request.result = ((int[]) ar.result)[0];
1637 }
1638 notifyRequester(request);
1639 break;
1640 case CMD_SET_CDMA_ROAMING_MODE:
1641 request = (MainThreadRequest) msg.obj;
1642 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1643 int mode = (int) request.argument;
1644 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1645 break;
1646 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1647 ar = (AsyncResult) msg.obj;
1648 request = (MainThreadRequest) ar.userObj;
1649 request.result = ar.exception == null;
1650 notifyRequester(request);
1651 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001652 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1653 request = (MainThreadRequest) msg.obj;
1654 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1655 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1656 break;
1657 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1658 ar = (AsyncResult) msg.obj;
1659 request = (MainThreadRequest) ar.userObj;
1660 if (ar.exception != null) {
1661 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1662 } else {
1663 request.result = ((int[]) ar.result)[0];
1664 }
1665 notifyRequester(request);
1666 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001667 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1668 request = (MainThreadRequest) msg.obj;
1669 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1670 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001671 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1672 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001673 break;
1674 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1675 ar = (AsyncResult) msg.obj;
1676 request = (MainThreadRequest) ar.userObj;
1677 request.result = ar.exception == null;
1678 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001679 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001680 case CMD_GET_ALL_CELL_INFO:
1681 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001682 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001683 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001684 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001685 case EVENT_GET_ALL_CELL_INFO_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001688 // If a timeout occurs, the response will be null
1689 request.result = (ar.exception == null && ar.result != null)
1690 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001691 synchronized (request) {
1692 request.notifyAll();
1693 }
1694 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001695 case CMD_REQUEST_CELL_INFO_UPDATE:
1696 request = (MainThreadRequest) msg.obj;
1697 request.phone.requestCellInfoUpdate(request.workSource,
1698 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1699 break;
1700 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1701 ar = (AsyncResult) msg.obj;
1702 request = (MainThreadRequest) ar.userObj;
1703 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1704 try {
1705 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001706 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001707 cb.onError(
1708 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1709 ar.exception.getClass().getName(),
1710 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001711 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001712 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001713 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001714 } else {
1715 // use the result as returned
1716 cb.onCellInfo((List<CellInfo>) ar.result);
1717 }
1718 } catch (RemoteException re) {
1719 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1720 }
1721 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001722 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001723 request = (MainThreadRequest) msg.obj;
1724 WorkSource ws = (WorkSource) request.argument;
1725 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001726 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001727 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001728 }
1729 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001730 ar = (AsyncResult) msg.obj;
1731 request = (MainThreadRequest) ar.userObj;
1732 if (ar.exception == null) {
1733 request.result = ar.result;
1734 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001735 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001736 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001737 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 }
1739
1740 synchronized (request) {
1741 request.notifyAll();
1742 }
1743 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001744 }
chen xu6dac5ab2018-10-26 17:39:23 -07001745 case CMD_MODEM_REBOOT:
1746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001748 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001749 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001750 case EVENT_CMD_MODEM_REBOOT_DONE:
1751 handleNullReturnEvent(msg, "rebootModem");
1752 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001753 case CMD_REQUEST_ENABLE_MODEM:
1754 request = (MainThreadRequest) msg.obj;
1755 boolean enable = (boolean) request.argument;
1756 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001757 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001758 PhoneConfigurationManager.getInstance()
1759 .enablePhone(request.phone, enable, onCompleted);
1760 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001761 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001762 ar = (AsyncResult) msg.obj;
1763 request = (MainThreadRequest) ar.userObj;
1764 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001765 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001766 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001767 if ((boolean) request.result) {
1768 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1769 updateModemStateMetrics();
1770 } else {
1771 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1772 + ar.exception);
1773 }
1774 notifyRequester(request);
1775 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001776 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001777 case CMD_GET_MODEM_STATUS:
1778 request = (MainThreadRequest) msg.obj;
1779 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1780 PhoneConfigurationManager.getInstance()
1781 .getPhoneStatusFromModem(request.phone, onCompleted);
1782 break;
1783 case EVENT_GET_MODEM_STATUS_DONE:
1784 ar = (AsyncResult) msg.obj;
1785 request = (MainThreadRequest) ar.userObj;
1786 int id = request.phone.getPhoneId();
1787 if (ar.exception == null && ar.result != null) {
1788 request.result = ar.result;
1789 //update the cache as modem status has changed
1790 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1791 (boolean) request.result);
1792 } else {
1793 // Return true if modem status cannot be retrieved. For most cases,
1794 // modem status is on. And for older version modems, GET_MODEM_STATUS
1795 // and disable modem are not supported. Modem is always on.
1796 // TODO: this should be fixed in R to support a third
1797 // status UNKNOWN b/131631629
1798 request.result = true;
1799 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1800 + ar.exception);
1801 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001802 notifyRequester(request);
1803 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001804 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1805 request = (MainThreadRequest) msg.obj;
1806 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1807 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1808 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1809 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1810 break;
1811 }
1812 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1813 ar = (AsyncResult) msg.obj;
1814 request = (MainThreadRequest) ar.userObj;
1815 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1816 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1817 args.second.accept(ar.exception == null);
1818 notifyRequester(request);
1819 break;
1820 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001821 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1822 request = (MainThreadRequest) msg.obj;
1823 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1824 Phone phone = getPhoneFromRequest(request);
1825 if (phone != null) {
1826 phone.getSystemSelectionChannels(onCompleted);
1827 } else {
1828 loge("getSystemSelectionChannels: No phone object");
1829 request.result = new ArrayList<RadioAccessSpecifier>();
1830 notifyRequester(request);
1831 }
1832 break;
1833 }
1834 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1835 ar = (AsyncResult) msg.obj;
1836 request = (MainThreadRequest) ar.userObj;
1837 if (ar.exception == null && ar.result != null) {
1838 request.result = ar.result;
1839 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001840 request.result = new IllegalStateException(
1841 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001842 if (ar.result == null) {
1843 loge("getSystemSelectionChannels: Empty response");
1844 } else {
1845 loge("getSystemSelectionChannels: Unknown exception");
1846 }
1847 }
1848 notifyRequester(request);
1849 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001850 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1851 ar = (AsyncResult) msg.obj;
1852 request = (MainThreadRequest) ar.userObj;
1853 if (ar.exception == null && ar.result != null) {
1854 request.result = ar.result;
1855 } else {
1856 request.result = -1;
1857 loge("Failed to set Forbidden Plmns");
1858 if (ar.result == null) {
1859 loge("setForbidenPlmns: Empty response");
1860 } else if (ar.exception != null) {
1861 loge("setForbiddenPlmns: Exception: " + ar.exception);
1862 request.result = -1;
1863 } else {
1864 loge("setForbiddenPlmns: Unknown exception");
1865 }
1866 }
1867 notifyRequester(request);
1868 break;
1869 case CMD_SET_FORBIDDEN_PLMNS:
1870 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001871 uiccPort = getUiccPortFromRequest(request);
1872 if (uiccPort == null) {
1873 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001874 request.result = -1;
1875 notifyRequester(request);
1876 break;
1877 }
1878 Pair<Integer, List<String>> setFplmnsArgs =
1879 (Pair<Integer, List<String>>) request.argument;
1880 appType = setFplmnsArgs.first;
1881 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001882 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001883 if (uiccApp == null) {
1884 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1885 request.result = -1;
1886 loge("Failed to get UICC App");
1887 notifyRequester(request);
1888 } else {
1889 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1890 ((SIMRecords) uiccApp.getIccRecords())
1891 .setForbiddenPlmns(onCompleted, fplmns);
1892 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001893 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001894 case CMD_ERASE_MODEM_CONFIG:
1895 request = (MainThreadRequest) msg.obj;
1896 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1897 defaultPhone.eraseModemConfig(onCompleted);
1898 break;
1899 case EVENT_ERASE_MODEM_CONFIG_DONE:
1900 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001901 break;
zoey chene02881a2019-12-30 16:11:23 +08001902
Kai Shif70f46f2021-03-03 13:59:46 -08001903 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1904 request = (MainThreadRequest) msg.obj;
1905 request.result = defaultPhone.eraseDataInSharedPreferences();
1906 notifyRequester(request);
1907 break;
1908
zoey chene02881a2019-12-30 16:11:23 +08001909 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1910 request = (MainThreadRequest) msg.obj;
1911 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1912 Pair<String, String> changed = (Pair<String, String>) request.argument;
1913 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1914 changed.first, changed.second, onCompleted);
1915 break;
1916 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1917 ar = (AsyncResult) msg.obj;
1918 request = (MainThreadRequest) ar.userObj;
1919 if (ar.exception == null) {
1920 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001921 // If the operation is successful, update the PIN storage
1922 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1923 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001924 UiccController.getInstance().getPinStorage()
1925 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001926 } else {
1927 request.result = msg.arg1;
1928 }
1929 notifyRequester(request);
1930 break;
1931
Michele Berionne5e411512020-11-13 02:36:59 +00001932 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001933 request = (MainThreadRequest) msg.obj;
1934 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1935 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1936 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1937 enabled.first, enabled.second, onCompleted);
1938 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001939 }
zoey chene02881a2019-12-30 16:11:23 +08001940 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1941 ar = (AsyncResult) msg.obj;
1942 request = (MainThreadRequest) ar.userObj;
1943 if (ar.exception == null) {
1944 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001945 // If the operation is successful, update the PIN storage
1946 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1947 int phoneId = getPhoneFromRequest(request).getPhoneId();
1948 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001949 UiccController.getInstance().getPinStorage()
1950 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001951 } else {
1952 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1953 }
zoey chene02881a2019-12-30 16:11:23 +08001954 } else {
1955 request.result = msg.arg1;
1956 }
Michele Berionne5e411512020-11-13 02:36:59 +00001957
1958
zoey chene02881a2019-12-30 16:11:23 +08001959 notifyRequester(request);
1960 break;
1961
Peter Wangdafb9ac2020-01-15 14:13:38 -08001962 case MSG_NOTIFY_USER_ACTIVITY:
1963 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001964 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001965 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1966 getDefaultPhone().getContext().sendBroadcastAsUser(
1967 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1968 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001969
1970 case CMD_SET_DATA_THROTTLING: {
1971 request = (MainThreadRequest) msg.obj;
1972 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1973 DataThrottlingRequest dataThrottlingRequest =
1974 (DataThrottlingRequest) request.argument;
1975 Phone phone = getPhoneFromRequest(request);
1976 if (phone != null) {
1977 phone.setDataThrottling(onCompleted,
1978 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1979 dataThrottlingRequest.getCompletionDurationMillis());
1980 } else {
1981 loge("setDataThrottling: No phone object");
1982 request.result =
1983 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1984 notifyRequester(request);
1985 }
1986
1987 break;
1988 }
1989 case EVENT_SET_DATA_THROTTLING_DONE:
1990 ar = (AsyncResult) msg.obj;
1991 request = (MainThreadRequest) ar.userObj;
1992
1993 if (ar.exception == null) {
1994 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1995 } else if (ar.exception instanceof CommandException) {
1996 loge("setDataThrottling: CommandException: " + ar.exception);
1997 CommandException.Error error =
1998 ((CommandException) (ar.exception)).getCommandError();
1999
2000 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2001 request.result = TelephonyManager
2002 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2003 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2004 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002005 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2006 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002007 } else {
2008 request.result =
2009 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2010 }
2011 } else {
2012 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2013 }
2014 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2015 notifyRequester(request);
2016 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002017
2018 case CMD_SET_SIM_POWER: {
2019 request = (MainThreadRequest) msg.obj;
2020 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2021 request = (MainThreadRequest) msg.obj;
2022 int stateToSet =
2023 ((Pair<Integer, IIntegerConsumer>)
2024 request.argument).first;
2025 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2026 break;
2027 }
2028 case EVENT_SET_SIM_POWER_DONE: {
2029 ar = (AsyncResult) msg.obj;
2030 request = (MainThreadRequest) ar.userObj;
2031 IIntegerConsumer callback =
2032 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2033 if (ar.exception != null) {
2034 loge("setSimPower exception: " + ar.exception);
2035 int errorCode = TelephonyManager.CallForwardingInfoCallback
2036 .RESULT_ERROR_UNKNOWN;
2037 if (ar.exception instanceof CommandException) {
2038 CommandException.Error error =
2039 ((CommandException) (ar.exception)).getCommandError();
2040 if (error == CommandException.Error.SIM_ERR) {
2041 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2042 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2043 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2044 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2045 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2046 } else {
2047 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2048 }
2049 }
2050 try {
2051 callback.accept(errorCode);
2052 } catch (RemoteException e) {
2053 // Ignore if the remote process is no longer available to call back.
2054 Log.w(LOG_TAG, "setSimPower: callback not available.");
2055 }
2056 } else {
2057 try {
2058 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2059 } catch (RemoteException e) {
2060 // Ignore if the remote process is no longer available to call back.
2061 Log.w(LOG_TAG, "setSimPower: callback not available.");
2062 }
2063 }
2064 break;
2065 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002066 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2067 request = (MainThreadRequest) msg.obj;
2068
2069 final Phone phone = getPhoneFromRequest(request);
2070 if (phone == null || phone.getServiceStateTracker() == null) {
2071 request.result = new IllegalStateException("Phone or SST is null");
2072 notifyRequester(request);
2073 break;
2074 }
2075
2076 Pair<Integer, SignalStrengthUpdateRequest> pair =
2077 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2078 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2079 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002080 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002081 request.subId, pair.first /*callingUid*/,
2082 pair.second /*request*/, onCompleted);
2083 break;
2084 }
2085 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2086 ar = (AsyncResult) msg.obj;
2087 request = (MainThreadRequest) ar.userObj;
2088 // request.result will be the exception of ar if present, true otherwise.
2089 // Be cautious not to leave result null which will wait() forever
2090 request.result = ar.exception != null ? ar.exception : true;
2091 notifyRequester(request);
2092 break;
2093 }
2094 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2095 request = (MainThreadRequest) msg.obj;
2096
2097 Phone phone = getPhoneFromRequest(request);
2098 if (phone == null || phone.getServiceStateTracker() == null) {
2099 request.result = new IllegalStateException("Phone or SST is null");
2100 notifyRequester(request);
2101 break;
2102 }
2103
2104 Pair<Integer, SignalStrengthUpdateRequest> pair =
2105 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2106 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2107 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002108 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002109 request.subId, pair.first /*callingUid*/,
2110 pair.second /*request*/, onCompleted);
2111 break;
2112 }
2113 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2114 ar = (AsyncResult) msg.obj;
2115 request = (MainThreadRequest) ar.userObj;
2116 request.result = ar.exception != null ? ar.exception : true;
2117 notifyRequester(request);
2118 break;
2119 }
Jordan Liu109698e2020-11-24 14:50:34 -08002120
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002121 case CMD_GET_SLICING_CONFIG: {
2122 request = (MainThreadRequest) msg.obj;
2123 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2124 request.phone.getSlicingConfig(onCompleted);
2125 break;
2126 }
2127 case EVENT_GET_SLICING_CONFIG_DONE: {
2128 ar = (AsyncResult) msg.obj;
2129 request = (MainThreadRequest) ar.userObj;
2130 ResultReceiver result = (ResultReceiver) request.argument;
2131
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002132 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002133 Bundle bundle = new Bundle();
2134 int resultCode = 0;
2135 if (ar.exception != null) {
2136 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2137 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002138 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002139 } else if (ar.result == null) {
2140 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002141 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002142 } else {
2143 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002144 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2145 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002146 }
2147
2148 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002149 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002150 }
2151 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2152 result.send(resultCode, bundle);
2153 notifyRequester(request);
2154 break;
2155 }
2156
Sarah Chin71b3a852022-09-28 15:54:19 -07002157 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002158 request = (MainThreadRequest) msg.obj;
2159 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002160 PurchasePremiumCapabilityArgument arg =
2161 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002162 SliceStore.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002163 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002164 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002165 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002166
Sarah Chin71b3a852022-09-28 15:54:19 -07002167 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002168 ar = (AsyncResult) msg.obj;
2169 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002170 PurchasePremiumCapabilityArgument arg =
2171 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002172 try {
2173 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002174 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002175 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002176 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002177 + ", result= "
2178 + TelephonyManager.convertPurchaseResultToString(result));
2179 } catch (RemoteException e) {
2180 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002181 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002182 + " failed: " + e;
2183 if (DBG) log(logStr);
2184 AnomalyReporter.reportAnomaly(
2185 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2186 }
2187 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002188 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002189
Michele Berionne5e411512020-11-13 02:36:59 +00002190 case CMD_PREPARE_UNATTENDED_REBOOT:
2191 request = (MainThreadRequest) msg.obj;
2192 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002193 UiccController.getInstance().getPinStorage()
2194 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002195 notifyRequester(request);
2196 break;
2197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 default:
2199 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2200 break;
2201 }
2202 }
Jake Hambye994d462014-02-03 13:10:13 -08002203
Pengquan Menga1bb6272018-09-06 09:59:22 -07002204 private void notifyRequester(MainThreadRequest request) {
2205 synchronized (request) {
2206 request.notifyAll();
2207 }
2208 }
2209
Jake Hambye994d462014-02-03 13:10:13 -08002210 private void handleNullReturnEvent(Message msg, String command) {
2211 AsyncResult ar = (AsyncResult) msg.obj;
2212 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2213 if (ar.exception == null) {
2214 request.result = true;
2215 } else {
2216 request.result = false;
2217 if (ar.exception instanceof CommandException) {
2218 loge(command + ": CommandException: " + ar.exception);
2219 } else {
2220 loge(command + ": Unknown exception");
2221 }
2222 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002223 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 }
2226
2227 /**
2228 * Posts the specified command to be executed on the main thread,
2229 * waits for the request to complete, and returns the result.
2230 * @see #sendRequestAsync
2231 */
2232 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002233 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2234 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002235 }
2236
2237 /**
2238 * Posts the specified command to be executed on the main thread,
2239 * waits for the request to complete, and returns the result.
2240 * @see #sendRequestAsync
2241 */
2242 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2243 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002244 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002245 }
2246
2247 /**
2248 * Posts the specified command to be executed on the main thread,
2249 * waits for the request to complete, and returns the result.
2250 * @see #sendRequestAsync
2251 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002252 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002253 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2254 }
2255
2256 /**
2257 * Posts the specified command to be executed on the main thread,
2258 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2259 * if not timeout or null otherwise.
2260 * @see #sendRequestAsync
2261 */
2262 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2263 long timeoutInMs) {
2264 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002265 }
2266
2267 /**
2268 * Posts the specified command to be executed on the main thread,
2269 * waits for the request to complete, and returns the result.
2270 * @see #sendRequestAsync
2271 */
Nathan Harold92bed182018-10-12 18:16:49 -07002272 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002273 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002274 }
2275
2276 /**
2277 * Posts the specified command to be executed on the main thread,
2278 * waits for the request to complete, and returns the result.
2279 * @see #sendRequestAsync
2280 */
2281 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002282 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2283 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002284 }
2285
2286 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002287 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2288 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2289 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002290 * @see #sendRequestAsync
2291 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002292 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2293 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2295 throw new RuntimeException("This method will deadlock if called from the main thread.");
2296 }
2297
Nathan Harold92bed182018-10-12 18:16:49 -07002298 MainThreadRequest request = null;
2299 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2300 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2301 } else if (phone != null) {
2302 request = new MainThreadRequest(argument, phone, workSource);
2303 } else {
2304 request = new MainThreadRequest(argument, subId, workSource);
2305 }
2306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 Message msg = mMainThreadHandler.obtainMessage(command, request);
2308 msg.sendToTarget();
2309
Rambo Wang0f050d82021-02-12 11:43:36 -08002310
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002312 if (timeoutInMs >= 0) {
2313 // Wait for at least timeoutInMs before returning null request result
2314 long now = SystemClock.elapsedRealtime();
2315 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002316 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002317 try {
2318 request.wait(deadline - now);
2319 } catch (InterruptedException e) {
2320 // Do nothing, go back and check if request is completed or timeout
2321 } finally {
2322 now = SystemClock.elapsedRealtime();
2323 }
2324 }
2325 } else {
2326 // Wait for the request to complete
2327 while (request.result == null) {
2328 try {
2329 request.wait();
2330 } catch (InterruptedException e) {
2331 // Do nothing, go back and wait until the request is complete
2332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334 }
2335 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002336 if (request.result == null) {
2337 Log.wtf(LOG_TAG,
2338 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 return request.result;
2341 }
2342
2343 /**
2344 * Asynchronous ("fire and forget") version of sendRequest():
2345 * Posts the specified command to be executed on the main thread, and
2346 * returns immediately.
2347 * @see #sendRequest
2348 */
2349 private void sendRequestAsync(int command) {
2350 mMainThreadHandler.sendEmptyMessage(command);
2351 }
2352
2353 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002354 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002355 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002356 */
2357 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002358 sendRequestAsync(command, argument, null, null);
2359 }
2360
2361 /**
2362 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2363 * @see {@link #sendRequest(int,Object)}
2364 */
2365 private void sendRequestAsync(
2366 int command, Object argument, Phone phone, WorkSource workSource) {
2367 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002368 Message msg = mMainThreadHandler.obtainMessage(command, request);
2369 msg.sendToTarget();
2370 }
2371
2372 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 * Initialize the singleton PhoneInterfaceManager instance.
2374 * This is only done once, at startup, from PhoneApp.onCreate().
2375 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002376 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 synchronized (PhoneInterfaceManager.class) {
2378 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002379 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 } else {
2381 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2382 }
2383 return sInstance;
2384 }
2385 }
2386
2387 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002388 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002391 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002392 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002394 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002396 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002397 mTelephonySharedPreferences =
2398 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002399 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002400 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002401 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002402 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002403 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 publish();
2405 }
2406
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002407 private Phone getDefaultPhone() {
2408 Phone thePhone = getPhone(getDefaultSubscription());
2409 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2410 }
2411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 private void publish() {
2413 if (DBG) log("publish: " + this);
2414
Peter Wangc035ce42020-01-08 21:00:22 -08002415 TelephonyFrameworkInitializer
2416 .getTelephonyServiceManager()
2417 .getTelephonyServiceRegisterer()
2418 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
2420
Stuart Scott584921c2015-01-15 17:10:34 -08002421 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002422 if (request.phone != null) {
2423 return request.phone;
2424 } else {
2425 return getPhoneFromSubId(request.subId);
2426 }
2427 }
2428
2429 private Phone getPhoneFromSubId(int subId) {
2430 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2431 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002432 }
2433
Rambo Wange53e07d2022-05-10 13:01:13 -07002434 @Nullable
2435 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002436 Phone phone = getPhoneFromRequest(request);
2437 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002438 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002439 }
2440
Wink Saville36469e72014-06-11 15:17:00 -07002441 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002442 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002443 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445
Kai Shif70f46f2021-03-03 13:59:46 -08002446 private void sendEraseModemConfig(@NonNull Phone phone) {
2447 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2448 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2449 }
2450
2451 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2452 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2453 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002454 }
2455
Peter Wang44b186e2020-01-13 23:33:09 -08002456 private boolean isImsAvailableOnDevice() {
2457 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2458 if (pm == null) {
2459 // For some reason package manger is not available.. This will fail internally anyway,
2460 // so do not throw error and allow.
2461 return true;
2462 }
2463 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2464 }
2465
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002467 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002468 }
2469
Wink Savilleb564aae2014-10-23 10:18:09 -07002470 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 if (DBG) log("dial: " + number);
2472 // No permission check needed here: This is just a wrapper around the
2473 // ACTION_DIAL intent, which is available to any app since it puts up
2474 // the UI before it does anything.
2475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 String url = createTelUrl(number);
2479 if (url == null) {
2480 return;
2481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 // PENDING: should we just silently fail if phone is offhook or ringing?
2484 PhoneConstants.State state = mCM.getState(subId);
2485 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2486 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2487 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2488 mApp.startActivity(intent);
2489 }
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 }
2493 }
2494
2495 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002496 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002497 }
2498
Wink Savilleb564aae2014-10-23 10:18:09 -07002499 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 if (DBG) log("call: " + number);
2501
2502 // This is just a wrapper around the ACTION_CALL intent, but we still
2503 // need to do a permission check since we're calling startActivity()
2504 // from the context of the phone app.
2505 enforceCallPermission();
2506
Jordan Liu1617b712019-07-10 15:06:26 -07002507 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 != AppOpsManager.MODE_ALLOWED) {
2509 return;
2510 }
2511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 String url = createTelUrl(number);
2515 if (url == null) {
2516 return;
2517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519 boolean isValid = false;
2520 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2521 if (slist != null) {
2522 for (SubscriptionInfo subInfoRecord : slist) {
2523 if (subInfoRecord.getSubscriptionId() == subId) {
2524 isValid = true;
2525 break;
2526 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002527 }
Wink Saville08874612014-08-31 19:19:58 -07002528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529 if (!isValid) {
2530 return;
2531 }
Wink Saville08874612014-08-31 19:19:58 -07002532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2534 intent.putExtra(SUBSCRIPTION_KEY, subId);
2535 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2536 mApp.startActivity(intent);
2537 } finally {
2538 Binder.restoreCallingIdentity(identity);
2539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540 }
2541
Wink Savilleb564aae2014-10-23 10:18:09 -07002542 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002543 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002544 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2545 }
2546
Wink Savilleb564aae2014-10-23 10:18:09 -07002547 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002548 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002549 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2550 }
2551
Wink Savilleb564aae2014-10-23 10:18:09 -07002552 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554
2555 final long identity = Binder.clearCallingIdentity();
2556 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002557 Phone phone = getPhone(subId);
2558 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 checkSimPin.start();
2560 return checkSimPin.unlockSim(null, pin);
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
2563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
Wink Savilleb564aae2014-10-23 10:18:09 -07002566 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002571 Phone phone = getPhone(subId);
2572 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573 checkSimPuk.start();
2574 return checkSimPuk.unlockSim(puk, pin);
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 }
2579
2580 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002581 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 * a synchronous one.
2583 */
2584 private static class UnlockSim extends Thread {
2585
2586 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002587 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588
2589 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002590 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2591 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592
2593 // For replies from SimCard interface
2594 private Handler mHandler;
2595
2596 // For async handler to identify request type
2597 private static final int SUPPLY_PIN_COMPLETE = 100;
2598
Michele Berionne5e411512020-11-13 02:36:59 +00002599 UnlockSim(int phoneId, IccCard simCard) {
2600 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 mSimCard = simCard;
2602 }
2603
2604 @Override
2605 public void run() {
2606 Looper.prepare();
2607 synchronized (UnlockSim.this) {
2608 mHandler = new Handler() {
2609 @Override
2610 public void handleMessage(Message msg) {
2611 AsyncResult ar = (AsyncResult) msg.obj;
2612 switch (msg.what) {
2613 case SUPPLY_PIN_COMPLETE:
2614 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2615 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002616 mRetryCount = msg.arg1;
2617 if (ar.exception != null) {
2618 if (ar.exception instanceof CommandException &&
2619 ((CommandException)(ar.exception)).getCommandError()
2620 == CommandException.Error.PASSWORD_INCORRECT) {
2621 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002622 } //When UiccCardApp dispose,handle message and return exception
2623 else if (ar.exception instanceof CommandException &&
2624 ((CommandException) (ar.exception)).getCommandError()
2625 == CommandException.Error.ABORTED) {
2626 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002627 } else {
2628 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2629 }
2630 } else {
2631 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 mDone = true;
2634 UnlockSim.this.notifyAll();
2635 }
2636 break;
2637 }
2638 }
2639 };
2640 UnlockSim.this.notifyAll();
2641 }
2642 Looper.loop();
2643 }
2644
2645 /*
2646 * Use PIN or PUK to unlock SIM card
2647 *
2648 * If PUK is null, unlock SIM card with PIN
2649 *
2650 * If PUK is not null, unlock SIM card with PUK and set PIN code
2651 */
Wink Saville9de0f752013-10-22 19:04:03 -07002652 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653
2654 while (mHandler == null) {
2655 try {
2656 wait();
2657 } catch (InterruptedException e) {
2658 Thread.currentThread().interrupt();
2659 }
2660 }
2661 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2662
2663 if (puk == null) {
2664 mSimCard.supplyPin(pin, callback);
2665 } else {
2666 mSimCard.supplyPuk(puk, pin, callback);
2667 }
2668
2669 while (!mDone) {
2670 try {
2671 Log.d(LOG_TAG, "wait for done");
2672 wait();
2673 } catch (InterruptedException e) {
2674 // Restore the interrupted status
2675 Thread.currentThread().interrupt();
2676 }
2677 }
2678 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002679 int[] resultArray = new int[2];
2680 resultArray[0] = mResult;
2681 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002682
2683 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002684 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002685 }
2686
Wink Saville9de0f752013-10-22 19:04:03 -07002687 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 }
2689 }
2690
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002691 /**
2692 * This method has been removed due to privacy and stability concerns.
2693 */
2694 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002696 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2697 return;
Wink Saville36469e72014-06-11 15:17:00 -07002698 }
2699
Nathan Harold1f889d82020-06-04 17:05:26 -07002700 @Override
2701 public void updateServiceLocationWithPackageName(String callingPackage) {
2702 mApp.getSystemService(AppOpsManager.class)
2703 .checkPackage(Binder.getCallingUid(), callingPackage);
2704
Nathan Haroldf096d982020-11-18 17:18:06 -08002705 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002706 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2707 // Callers targeting S have no business invoking this method.
2708 return;
2709 }
2710
2711 LocationAccessPolicy.LocationPermissionResult locationResult =
2712 LocationAccessPolicy.checkLocationPermission(mApp,
2713 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2714 .setCallingPackage(callingPackage)
2715 .setCallingFeatureId(null)
2716 .setCallingPid(Binder.getCallingPid())
2717 .setCallingUid(Binder.getCallingUid())
2718 .setMethod("updateServiceLocation")
2719 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2720 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2721 .build());
2722 // Apps that lack location permission have no business calling this method;
2723 // however, because no permission was declared in the public API, denials must
2724 // all be "soft".
2725 switch (locationResult) {
2726 case DENIED_HARD: /* fall through */
2727 case DENIED_SOFT:
2728 return;
2729 }
2730
2731 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 final long identity = Binder.clearCallingIdentity();
2733 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002734 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002736 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 }
2742
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002743 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002744 @Override
2745 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002746 return isRadioOnWithFeature(callingPackage, null);
2747 }
2748
2749
2750 @Override
2751 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2752 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2753 callingFeatureId);
2754 }
2755
2756 @Deprecated
2757 @Override
2758 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2759 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002760 }
2761
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002763 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2764 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002766 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002767 return false;
2768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 return isRadioOnForSubscriber(subId);
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
2775 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002776 }
2777
2778 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 final Phone phone = getPhone(subId);
2782 if (phone != null) {
2783 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2784 } else {
2785 return false;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
2792 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002793 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 }
Wink Saville36469e72014-06-11 15:17:00 -07002795
Wink Savilleb564aae2014-10-23 10:18:09 -07002796 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 final Phone phone = getPhone(subId);
2802 if (phone != null) {
2803 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2804 }
2805 } finally {
2806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002807 }
Wink Saville36469e72014-06-11 15:17:00 -07002808 }
2809
2810 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002811 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002812 }
2813
Wink Savilleb564aae2014-10-23 10:18:09 -07002814 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002815 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816
2817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 final Phone phone = getPhone(subId);
2820 if (phone == null) {
2821 return false;
2822 }
2823 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2824 toggleRadioOnOffForSubscriber(subId);
2825 }
2826 return true;
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 }
Wink Saville36469e72014-06-11 15:17:00 -07002831
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002832 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002833 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002834 /*
2835 * If any of the Radios are available, it will need to be
2836 * shutdown. So return true if any Radio is available.
2837 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2841 Phone phone = PhoneFactory.getPhone(i);
2842 if (phone != null && phone.isRadioAvailable()) return true;
2843 }
2844 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2845 return false;
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002848 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002849 }
2850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002852 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 enforceModifyPermission();
2854
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2858 logv("Shutting down Phone " + i);
2859 shutdownRadioUsingPhoneId(i);
2860 }
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002863 }
2864 }
2865
2866 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002867 Phone phone = PhoneFactory.getPhone(phoneId);
2868 if (phone != null && phone.isRadioAvailable()) {
2869 phone.shutdownRadio();
2870 }
2871 }
2872
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875
2876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2879 if (defaultPhone != null) {
2880 defaultPhone.setRadioPower(turnOn);
2881 return true;
2882 } else {
2883 loge("There's no default phone.");
2884 return false;
2885 }
2886 } finally {
2887 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002888 }
Wink Saville36469e72014-06-11 15:17:00 -07002889 }
2890
Wink Savilleb564aae2014-10-23 10:18:09 -07002891 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893
2894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 final Phone phone = getPhone(subId);
2897 if (phone != null) {
2898 phone.setRadioPower(turnOn);
2899 return true;
2900 } else {
2901 return false;
2902 }
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 }
2907
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002908 /**
2909 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2910 * no reason to power it off. When any of the voters want to power it off, it will be turned
2911 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2912 * powering it off, and these radio off votes will be cleared.
2913 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2914 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2915 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2916 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2917 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2918 * check its vote.
2919 *
2920 * @param subId The subscription ID.
2921 * @param reason The reason for powering off radio.
2922 * @return true on success and false on failure.
2923 */
2924 public boolean requestRadioPowerOffForReason(int subId,
2925 @TelephonyManager.RadioPowerReason int reason) {
2926 enforceModifyPermission();
2927
2928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 final Phone phone = getPhone(subId);
2931 if (phone != null) {
2932 phone.setRadioPowerForReason(false, reason);
2933 return true;
2934 } else {
2935 return false;
2936 }
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
2940 }
2941
2942 /**
2943 * Remove the vote on powering off the radio for a reason, as requested by
2944 * {@link requestRadioPowerOffForReason}.
2945 *
2946 * @param subId The subscription ID.
2947 * @param reason The reason for powering off radio.
2948 * @return true on success and false on failure.
2949 */
2950 public boolean clearRadioPowerOffForReason(int subId,
2951 @TelephonyManager.RadioPowerReason int reason) {
2952 enforceModifyPermission();
2953
2954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 final Phone phone = getPhone(subId);
2957 if (phone != null) {
2958 phone.setRadioPowerForReason(true, reason);
2959 return true;
2960 } else {
2961 return false;
2962 }
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
2965 }
2966 }
2967
2968 /**
2969 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2970 *
2971 * @param subId The subscription ID.
2972 * @param callingPackage The package making the call.
2973 * @param callingFeatureId The feature in the package.
2974 * @return List of reasons for powering off radio.
2975 */
2976 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2977 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2978
2979 final long identity = Binder.clearCallingIdentity();
2980 List result = new ArrayList();
2981 try {
2982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2983 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2984 return result;
2985 }
2986
2987 final Phone phone = getPhone(subId);
2988 if (phone != null) {
2989 result.addAll(phone.getRadioPowerOffReasons());
2990 }
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
2994 return result;
2995 }
2996
Wink Saville36469e72014-06-11 15:17:00 -07002997 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002998 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002999 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003000 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001
3002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 int subId = mSubscriptionController.getDefaultDataSubId();
3005 final Phone phone = getPhone(subId);
3006 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003007 phone.getDataSettingsManager().setDataEnabled(
3008 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009 return true;
3010 } else {
3011 return false;
3012 }
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 }
3017
Wink Saville36469e72014-06-11 15:17:00 -07003018 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003019 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003020 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022
3023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 int subId = mSubscriptionController.getDefaultDataSubId();
3026 final Phone phone = getPhone(subId);
3027 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003028 phone.getDataSettingsManager().setDataEnabled(
3029 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030 return true;
3031 } else {
3032 return false;
3033 }
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 }
3038
Sanket Padawe356d7632015-06-22 14:03:32 -07003039 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003040 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 final Phone phone = getPhone(subId);
3044 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003045 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046 } else {
3047 return false;
3048 }
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003052 }
3053
3054 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003055 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003056 }
3057
pkanwarae03a6b2016-11-06 20:37:09 -08003058 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059 enforceCallPermission();
3060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3064 return;
3065 }
3066 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3067 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
pkanwar32d516d2016-10-14 19:37:38 -07003071 };
3072
Wink Savilleb564aae2014-10-23 10:18:09 -07003073 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003075
3076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3079 return false;
3080 }
3081 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003085 }
3086
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003087 /**
3088 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3089 * tag on getCallState Binder call.
3090 */
3091 @Deprecated
3092 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003094 if (CompatChanges.isChangeEnabled(
3095 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3096 Binder.getCallingUid())) {
3097 // Do not allow this API to be called on API version 31+, it should only be
3098 // called on old apps using this Binder call directly.
3099 throw new SecurityException("This method can only be used for applications "
3100 + "targeting API version 30 or less.");
3101 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 final long identity = Binder.clearCallingIdentity();
3103 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003104 Phone phone = getPhone(getDefaultSubscription());
3105 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3106 PhoneConstantConversions.convertCallState(phone.getState());
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
3110 }
3111
3112 @Override
3113 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3114 if (CompatChanges.isChangeEnabled(
3115 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3116 Binder.getCallingUid())) {
3117 // Check READ_PHONE_STATE for API version 31+
3118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3119 featureId, "getCallStateForSubscription")) {
3120 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3121 + "targeting API level 31+.");
3122 }
3123 }
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3128 PhoneConstantConversions.convertCallState(phone.getState());
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
3133
Sanket Padawe356d7632015-06-22 14:03:32 -07003134 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003135 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003136 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3137 }
3138
3139 @Override
3140 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141 final long identity = Binder.clearCallingIdentity();
3142 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003143 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003145 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 } else {
3147 return PhoneConstantConversions.convertDataState(
3148 PhoneConstants.DataState.DISCONNECTED);
3149 }
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 }
3154
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003156 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003157 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3158 }
3159
3160 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003161 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162 final long identity = Binder.clearCallingIdentity();
3163 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003164 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003166 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 } else {
3168 return TelephonyManager.DATA_ACTIVITY_NONE;
3169 }
3170 } finally {
3171 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 }
3174
3175 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003176 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003177 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003178 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003179
3180 LocationAccessPolicy.LocationPermissionResult locationResult =
3181 LocationAccessPolicy.checkLocationPermission(mApp,
3182 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3183 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003184 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003185 .setCallingPid(Binder.getCallingPid())
3186 .setCallingUid(Binder.getCallingUid())
3187 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003188 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003189 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3190 .build());
3191 switch (locationResult) {
3192 case DENIED_HARD:
3193 throw new SecurityException("Not allowed to access cell location");
3194 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003195 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3196 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003199 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003203 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003204 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 } finally {
3206 Binder.restoreCallingIdentity(identity);
3207 }
Svetoslav64fad262015-04-14 14:35:21 -07003208 }
3209
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003211 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003212 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3213 // registered cell info, so return a NULL country instead.
3214 final long identity = Binder.clearCallingIdentity();
3215 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003216 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3217 // Get default phone in this case.
3218 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3219 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003220 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003222 if (phone == null) return "";
3223 ServiceStateTracker sst = phone.getServiceStateTracker();
3224 if (sst == null) return "";
3225 LocaleTracker lt = sst.getLocaleTracker();
3226 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003227 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003231 }
3232
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003233 /**
3234 * This method was removed due to potential issues caused by performing partial
3235 * updates of service state, and lack of a credible use case.
3236 *
3237 * This has the ability to break the telephony implementation by disabling notification of
3238 * changes in device connectivity. DO NOT USE THIS!
3239 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003240 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003241 public void enableLocationUpdates() {
3242 mApp.enforceCallingOrSelfPermission(
3243 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003244 }
3245
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003246 /**
3247 * This method was removed due to potential issues caused by performing partial
3248 * updates of service state, and lack of a credible use case.
3249 *
3250 * This has the ability to break the telephony implementation by disabling notification of
3251 * changes in device connectivity. DO NOT USE THIS!
3252 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 @Override
3254 public void disableLocationUpdates() {
3255 mApp.enforceCallingOrSelfPermission(
3256 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 }
3258
3259 @Override
3260 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003261 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3262 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003263 try {
3264 mApp.getSystemService(AppOpsManager.class)
3265 .checkPackage(Binder.getCallingUid(), callingPackage);
3266 } catch (SecurityException e) {
3267 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3268 throw e;
3269 }
3270
Nathan Haroldf096d982020-11-18 17:18:06 -08003271 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003272 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3273 throw new SecurityException(
3274 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3275 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003276
Jordan Liu1617b712019-07-10 15:06:26 -07003277 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3279 return null;
3280 }
Svetoslav64fad262015-04-14 14:35:21 -07003281
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003282 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003284 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003285 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286
Nathan Haroldf180aac2018-06-01 18:43:55 -07003287 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3288 for (CellInfo ci : info) {
3289 if (ci instanceof CellInfoGsm) {
3290 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3291 } else if (ci instanceof CellInfoWcdma) {
3292 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003294 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003295 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003296 }
3297
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003298 private List<CellInfo> getCachedCellInfo() {
3299 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3300 for (Phone phone : PhoneFactory.getPhones()) {
3301 List<CellInfo> info = phone.getAllCellInfo();
3302 if (info != null) cellInfos.addAll(info);
3303 }
3304 return cellInfos;
3305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003306
3307 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003308 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003309 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003310 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003311
3312 LocationAccessPolicy.LocationPermissionResult locationResult =
3313 LocationAccessPolicy.checkLocationPermission(mApp,
3314 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3315 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003316 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003317 .setCallingPid(Binder.getCallingPid())
3318 .setCallingUid(Binder.getCallingUid())
3319 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003320 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003321 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3322 .build());
3323 switch (locationResult) {
3324 case DENIED_HARD:
3325 throw new SecurityException("Not allowed to access cell info");
3326 case DENIED_SOFT:
3327 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003328 }
3329
Nathan Haroldf096d982020-11-18 17:18:06 -08003330 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003331 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3332 return getCachedCellInfo();
3333 }
3334
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003335 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003336 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3340 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003341 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003342 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 if (info != null) cellInfos.addAll(info);
3344 }
3345 return cellInfos;
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 }
3349 }
3350
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003351 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003352 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3353 String callingFeatureId) {
3354 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3355 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003356 }
3357
3358 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003359 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3360 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003361 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003362 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003363 }
3364
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003365 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3366 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003367 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003368 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003369
3370 LocationAccessPolicy.LocationPermissionResult locationResult =
3371 LocationAccessPolicy.checkLocationPermission(mApp,
3372 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3373 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003374 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003375 .setCallingPid(Binder.getCallingPid())
3376 .setCallingUid(Binder.getCallingUid())
3377 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003378 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3379 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003380 .build());
3381 switch (locationResult) {
3382 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003383 if (TelephonyPermissions
3384 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003385 // Safetynet logging for b/154934934
3386 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3387 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003388 throw new SecurityException("Not allowed to access cell info");
3389 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003390 if (TelephonyPermissions
3391 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003392 // Safetynet logging for b/154934934
3393 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3394 }
Nathan Harold5320c422019-05-09 10:26:08 -07003395 try {
3396 cb.onCellInfo(new ArrayList<CellInfo>());
3397 } catch (RemoteException re) {
3398 // Drop without consequences
3399 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003400 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003401 }
3402
Nathan Harolda939a962019-05-09 10:13:47 -07003403
3404 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003405 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3406
3407 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3408 }
3409
3410 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003411 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003412 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003413 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003414
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003417 Phone phone = getPhone(subId);
3418 if (phone == null) {
3419 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3420 } else {
3421 phone.setCellInfoListRate(rateInMillis, workSource);
3422 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003426 }
3427
Shishir Agrawala9f32182016-04-12 12:00:16 -07003428 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003429 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003430 Phone phone = PhoneFactory.getPhone(slotIndex);
3431 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003432 return null;
3433 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003434 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003435 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003436 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003437 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003438 return null;
3439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 return phone.getImei();
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003447 }
3448
3449 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003450 public String getTypeAllocationCodeForSlot(int slotIndex) {
3451 Phone phone = PhoneFactory.getPhone(slotIndex);
3452 String tac = null;
3453 if (phone != null) {
3454 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003455 try {
3456 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3457 } catch (IndexOutOfBoundsException e) {
3458 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3459 return null;
3460 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003461 }
3462 return tac;
3463 }
3464
3465 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003466 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003467 try {
3468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3469 } catch (SecurityException se) {
3470 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3471 throw new SecurityException("Package " + callingPackage + " does not belong to "
3472 + Binder.getCallingUid());
3473 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003474 Phone phone = PhoneFactory.getPhone(slotIndex);
3475 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003476 return null;
3477 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478
Jeff Davidson913390f2018-02-23 17:11:49 -08003479 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003480 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003481 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003482 return null;
3483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003484
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 return phone.getMeid();
3488 } finally {
3489 Binder.restoreCallingIdentity(identity);
3490 }
Jack Yu2af8d712017-03-15 17:14:14 -07003491 }
3492
3493 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003494 public String getManufacturerCodeForSlot(int slotIndex) {
3495 Phone phone = PhoneFactory.getPhone(slotIndex);
3496 String manufacturerCode = null;
3497 if (phone != null) {
3498 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003499 try {
3500 manufacturerCode =
3501 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3502 } catch (IndexOutOfBoundsException e) {
3503 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3504 return null;
3505 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003506 }
3507 return manufacturerCode;
3508 }
3509
3510 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003511 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3512 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003513 Phone phone = PhoneFactory.getPhone(slotIndex);
3514 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003515 return null;
3516 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003517 int subId = phone.getSubId();
3518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003519 mApp, subId, callingPackage, callingFeatureId,
3520 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003521 return null;
3522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523
3524 final long identity = Binder.clearCallingIdentity();
3525 try {
3526 return phone.getDeviceSvn();
3527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003530 }
3531
fionaxu43304da2017-11-27 22:51:16 -08003532 @Override
3533 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 final Phone phone = getPhone(subId);
3537 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
fionaxu43304da2017-11-27 22:51:16 -08003541 }
3542
3543 @Override
3544 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 final Phone phone = getPhone(subId);
3548 return phone == null ? null : phone.getCarrierName();
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
3551 }
fionaxu43304da2017-11-27 22:51:16 -08003552 }
3553
calvinpanffe225e2018-11-01 19:43:06 +08003554 @Override
chen xu0026ca62019-03-06 15:28:50 -08003555 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003556 final long identity = Binder.clearCallingIdentity();
3557 try {
3558 final Phone phone = getPhone(subId);
3559 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003560 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
3564 }
3565
3566 @Override
chen xu0026ca62019-03-06 15:28:50 -08003567 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003571 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003572 } finally {
3573 Binder.restoreCallingIdentity(identity);
3574 }
3575 }
3576
chen xu651eec72018-11-11 19:03:44 -08003577 @Override
chen xu864e11c2018-12-06 22:10:03 -08003578 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3579 if (!isSubscriptionMccMnc) {
3580 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3581 }
chen xu651eec72018-11-11 19:03:44 -08003582 final Phone phone = PhoneFactory.getPhone(slotIndex);
3583 if (phone == null) {
3584 return TelephonyManager.UNKNOWN_CARRIER_ID;
3585 }
3586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
3592 }
3593
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003594 //
3595 // Internal helper methods.
3596 //
3597
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003598 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003599 * Make sure the caller is the calling package itself
3600 *
3601 * @throws SecurityException if the caller is not the calling package
3602 */
3603 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3604 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003605 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3606 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003607 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003608 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003609 } catch (PackageManager.NameNotFoundException e) {
3610 // packageUid is -1
3611 }
3612 if (packageUid != callingUid) {
3613 throw new SecurityException(message + ": Package " + callingPackage
3614 + " does not belong to " + callingUid);
3615 }
3616 }
3617
3618 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003619 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3620 *
3621 * @throws SecurityException if the caller does not have the required permission
3622 */
3623 private void enforceModifyPermission() {
3624 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3625 }
3626
Shuo Qian3b6ee772019-11-13 17:43:31 -08003627 private void enforceActiveEmergencySessionPermission() {
3628 mApp.enforceCallingOrSelfPermission(
3629 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3630 }
3631
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003632 /**
3633 * Make sure the caller has the CALL_PHONE permission.
3634 *
3635 * @throws SecurityException if the caller does not have the required permission
3636 */
3637 private void enforceCallPermission() {
3638 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3639 }
3640
paulhu5a773602019-08-23 19:17:33 +08003641 private void enforceSettingsPermission() {
3642 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003643 }
3644
Michele Berionne5e411512020-11-13 02:36:59 +00003645 private void enforceRebootPermission() {
3646 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3647 }
3648
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 private String createTelUrl(String number) {
3650 if (TextUtils.isEmpty(number)) {
3651 return null;
3652 }
3653
Jake Hambye994d462014-02-03 13:10:13 -08003654 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003655 }
3656
Ihab Awadf9e92732013-12-05 18:02:52 -08003657 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003658 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3659 }
3660
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003661 private static void logv(String msg) {
3662 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3663 }
3664
Ihab Awadf9e92732013-12-05 18:02:52 -08003665 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003666 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3667 }
3668
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003669 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003670 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003671 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003672 }
3673
Sanket Padawe356d7632015-06-22 14:03:32 -07003674 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003675 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 final Phone phone = PhoneFactory.getPhone(slotIndex);
3679 if (phone == null) {
3680 return PhoneConstants.PHONE_TYPE_NONE;
3681 } else {
3682 return phone.getPhoneType();
3683 }
3684 } finally {
3685 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003686 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003687 }
3688
3689 /**
3690 * Returns the CDMA ERI icon index to display
3691 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003692 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003693 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3694 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3695 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003696 }
3697
Sanket Padawe356d7632015-06-22 14:03:32 -07003698 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003699 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3700 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003702 mApp, subId, callingPackage, callingFeatureId,
3703 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003704 return -1;
3705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706
3707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 final Phone phone = getPhone(subId);
3710 if (phone != null) {
3711 return phone.getCdmaEriIconIndex();
3712 } else {
3713 return -1;
3714 }
3715 } finally {
3716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003718 }
3719
3720 /**
3721 * Returns the CDMA ERI icon mode,
3722 * 0 - ON
3723 * 1 - FLASHING
3724 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003725 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003726 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3727 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3728 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003729 }
3730
Sanket Padawe356d7632015-06-22 14:03:32 -07003731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003732 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3733 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003735 mApp, subId, callingPackage, callingFeatureId,
3736 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003737 return -1;
3738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739
3740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 final Phone phone = getPhone(subId);
3743 if (phone != null) {
3744 return phone.getCdmaEriIconMode();
3745 } else {
3746 return -1;
3747 }
3748 } finally {
3749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003751 }
3752
3753 /**
3754 * Returns the CDMA ERI text,
3755 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003756 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003757 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3758 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3759 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003760 }
3761
Sanket Padawe356d7632015-06-22 14:03:32 -07003762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3764 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003766 mApp, subId, callingPackage, callingFeatureId,
3767 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003768 return null;
3769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770
3771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 final Phone phone = getPhone(subId);
3774 if (phone != null) {
3775 return phone.getCdmaEriText();
3776 } else {
3777 return null;
3778 }
3779 } finally {
3780 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003782 }
3783
3784 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003785 * Returns the CDMA MDN.
3786 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003787 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003788 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3790 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003795 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 return phone.getLine1Number();
3797 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003798 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 return null;
3800 }
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003803 }
3804 }
3805
3806 /**
3807 * Returns the CDMA MIN.
3808 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003809 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003810 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3812 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813
3814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 final Phone phone = getPhone(subId);
3817 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3818 return phone.getCdmaMin();
3819 } else {
3820 return null;
3821 }
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003824 }
3825 }
3826
Hall Liud892bec2018-11-30 14:51:45 -08003827 @Override
3828 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3829 INumberVerificationCallback callback, String callingPackage) {
3830 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3831 != PERMISSION_GRANTED) {
3832 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3833 }
3834 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3835
3836 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3837 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003838 throw new SecurityException("Calling package must be configured in the device config: "
3839 + "calling package: " + callingPackage
3840 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003841 }
3842
3843 if (range == null) {
3844 throw new NullPointerException("Range must be non-null");
3845 }
3846
3847 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003848 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003849
3850 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3851 }
3852
Junda Liuca05d5d2014-08-14 22:36:34 -07003853 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003854 * Returns true if CDMA provisioning needs to run.
3855 */
3856 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003859 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860 } finally {
3861 Binder.restoreCallingIdentity(identity);
3862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003863 }
3864
3865 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003866 * Sets the voice mail number of a given subId.
3867 */
3868 @Override
3869 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003870 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3871 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872
3873 final long identity = Binder.clearCallingIdentity();
3874 try {
3875 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3876 new Pair<String, String>(alphaTag, number), new Integer(subId));
3877 return success;
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
3880 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003881 }
3882
Ta-wei Yen87c49842016-05-13 21:19:52 -07003883 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003884 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3885 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003886 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3887 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003888 if (!TextUtils.equals(callingPackage, systemDialer)) {
3889 throw new SecurityException("caller must be system dialer");
3890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891
3892 final long identity = Binder.clearCallingIdentity();
3893 try {
3894 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3895 if (phoneAccountHandle == null) {
3896 return null;
3897 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003898 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899 } finally {
3900 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003901 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003902 }
3903
3904 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003905 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3906 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003907 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003909 mApp, subId, callingPackage, callingFeatureId,
3910 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003911 return null;
3912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003914 final long identity = Binder.clearCallingIdentity();
3915 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003916 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003920 }
3921
3922 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003923 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3924 VisualVoicemailSmsFilterSettings settings) {
3925 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003926
3927 final long identity = Binder.clearCallingIdentity();
3928 try {
3929 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003930 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003931 } finally {
3932 Binder.restoreCallingIdentity(identity);
3933 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003934 }
3935
3936 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003937 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3938 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939
3940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003943 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003947 }
3948
3949 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003950 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3951 String callingPackage, int subId) {
3952 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953
3954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958 } finally {
3959 Binder.restoreCallingIdentity(identity);
3960 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003961 }
3962
3963 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003964 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003966
3967 final long identity = Binder.clearCallingIdentity();
3968 try {
3969 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003970 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003971 } finally {
3972 Binder.restoreCallingIdentity(identity);
3973 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003974 }
3975
3976 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003977 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3978 String callingAttributionTag, int subId, String number, int port, String text,
3979 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003980 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003981 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003982 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003983 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003984 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3985 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003986 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003987
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003988 /**
fionaxu0152e512016-11-14 13:36:14 -08003989 * Sets the voice activation state of a given subId.
3990 */
3991 @Override
3992 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3994 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995
3996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 final Phone phone = getPhone(subId);
3999 if (phone != null) {
4000 phone.setVoiceActivationState(activationState);
4001 } else {
4002 loge("setVoiceActivationState fails with invalid subId: " + subId);
4003 }
4004 } finally {
4005 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004006 }
4007 }
4008
4009 /**
4010 * Sets the data activation state of a given subId.
4011 */
4012 @Override
4013 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4015 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016
4017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 final Phone phone = getPhone(subId);
4020 if (phone != null) {
4021 phone.setDataActivationState(activationState);
4022 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004023 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004024 }
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004027 }
4028 }
4029
4030 /**
4031 * Returns the voice activation state of a given subId.
4032 */
4033 @Override
4034 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004036
fionaxu0152e512016-11-14 13:36:14 -08004037 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004038 final long identity = Binder.clearCallingIdentity();
4039 try {
4040 if (phone != null) {
4041 return phone.getVoiceActivationState();
4042 } else {
4043 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4044 }
4045 } finally {
4046 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004047 }
4048 }
4049
4050 /**
4051 * Returns the data activation state of a given subId.
4052 */
4053 @Override
4054 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056
fionaxu0152e512016-11-14 13:36:14 -08004057 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 final long identity = Binder.clearCallingIdentity();
4059 try {
4060 if (phone != null) {
4061 return phone.getDataActivationState();
4062 } else {
4063 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4064 }
4065 } finally {
4066 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004067 }
4068 }
4069
4070 /**
Wink Saville36469e72014-06-11 15:17:00 -07004071 * Returns the unread count of voicemails for a subId
4072 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004073 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004074 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4075 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004077 mApp, subId, callingPackage, callingFeatureId,
4078 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004079 return 0;
4080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081 final long identity = Binder.clearCallingIdentity();
4082 try {
4083 final Phone phone = getPhone(subId);
4084 if (phone != null) {
4085 return phone.getVoiceMessageCount();
4086 } else {
4087 return 0;
4088 }
4089 } finally {
4090 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004092 }
4093
4094 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004095 * returns true, if the device is in a state where both voice and data
4096 * are supported simultaneously. This can change based on location or network condition.
4097 */
4098 @Override
4099 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 final Phone phone = getPhone(subId);
4103 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004107 }
4108
4109 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004110 * Send the dialer code if called from the current default dialer or the caller has
4111 * carrier privilege.
4112 * @param inputCode The dialer code to send
4113 */
4114 @Override
4115 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004116 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004117 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004118 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4119 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004120 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004121 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004122 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124
4125 final long identity = Binder.clearCallingIdentity();
4126 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004127 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
fionaxu235cc5e2017-03-06 22:25:57 -08004131 }
4132
Pengquan Menga1bb6272018-09-06 09:59:22 -07004133 @Override
4134 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004135 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004136 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004137 mApp, subId, "getNetworkSelectionMode");
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 if (!isActiveSubscription(subId)) {
4141 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4142 }
4143 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4144 } finally {
4145 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004146 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004147 }
4148
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004150 public boolean isInEmergencySmsMode() {
4151 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 for (Phone phone : PhoneFactory.getPhones()) {
4155 if (phone.isInEmergencySmsMode()) {
4156 return true;
4157 }
4158 }
4159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
4162 return false;
4163 }
4164
shilu366312e2019-12-17 09:28:10 -08004165 /**
4166 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4167 * @param subId The subscription to use to check the configuration.
4168 * @param c The callback that will be used to send the result.
4169 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004170 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004171 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4172 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004173 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004174 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004175
4176 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4177 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4178 "IMS not available on device.");
4179 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 final long token = Binder.clearCallingIdentity();
4181 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004182 int slotId = getSlotIndexOrException(subId);
4183 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004184
4185 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4186 if (controller != null) {
4187 ImsManager imsManager = controller.getImsManager(subId);
4188 if (imsManager != null) {
4189 imsManager.addRegistrationCallbackForSubscription(c, subId);
4190 } else {
4191 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4192 }
4193 } else {
4194 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4195 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004196 } catch (ImsException e) {
4197 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 } finally {
4199 Binder.restoreCallingIdentity(token);
4200 }
4201 }
4202
shilu366312e2019-12-17 09:28:10 -08004203 /**
4204 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4205 * @param subId The subscription to use to check the configuration.
4206 * @param c The callback that will be used to send the result.
4207 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004209 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004210 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004211 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004212 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4213 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4214 }
Meng Wangafbc5852019-09-19 17:37:13 -07004215 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004216
Meng Wangafbc5852019-09-19 17:37:13 -07004217 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004218 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4219 if (controller != null) {
4220 ImsManager imsManager = controller.getImsManager(subId);
4221 if (imsManager != null) {
4222 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4223 } else {
4224 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4225 + "is inactive, ignoring unregister.");
4226 // If the ImsManager is not valid, just return, since the callback
4227 // will already have been removed internally.
4228 }
4229 }
Meng Wangafbc5852019-09-19 17:37:13 -07004230 } finally {
4231 Binder.restoreCallingIdentity(token);
4232 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 }
4234
Brad Ebingera34a6c22019-10-22 17:36:18 -07004235 /**
4236 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4237 */
4238 @Override
4239 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4240 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4241 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4242 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4243 "IMS not available on device.");
4244 }
4245 final long token = Binder.clearCallingIdentity();
4246 try {
4247 Phone phone = getPhone(subId);
4248 if (phone == null) {
4249 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4250 + subId + "'");
4251 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4252 }
4253 phone.getImsRegistrationState(regState -> {
4254 try {
4255 consumer.accept((regState == null)
4256 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4257 } catch (RemoteException e) {
4258 // Ignore if the remote process is no longer available to call back.
4259 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4260 }
4261 });
4262 } finally {
4263 Binder.restoreCallingIdentity(token);
4264 }
4265 }
4266
4267 /**
4268 * Get the transport type for the IMS service registration state.
4269 */
4270 @Override
4271 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004272 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004273 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004274 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4275 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4276 "IMS not available on device.");
4277 }
4278 final long token = Binder.clearCallingIdentity();
4279 try {
4280 Phone phone = getPhone(subId);
4281 if (phone == null) {
4282 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4283 + subId + "'");
4284 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4285 }
4286 phone.getImsRegistrationTech(regTech -> {
4287 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4288 int regTechConverted = (regTech == null)
4289 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4290 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4291 regTechConverted);
4292 try {
4293 consumer.accept(regTechConverted);
4294 } catch (RemoteException e) {
4295 // Ignore if the remote process is no longer available to call back.
4296 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4297 }
4298 });
4299 } finally {
4300 Binder.restoreCallingIdentity(token);
4301 }
4302 }
4303
shilu366312e2019-12-17 09:28:10 -08004304 /**
4305 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4306 * @param subId The subscription to use to check the configuration.
4307 * @param c The callback that will be used to send the result.
4308 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004310 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4311 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004312 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004313 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004314 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4316 "IMS not available on device.");
4317 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 final long token = Binder.clearCallingIdentity();
4319 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004320 int slotId = getSlotIndexOrException(subId);
4321 verifyImsMmTelConfiguredOrThrow(slotId);
4322 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004323 } catch (ImsException e) {
4324 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004325 } finally {
4326 Binder.restoreCallingIdentity(token);
4327 }
4328 }
4329
shilu366312e2019-12-17 09:28:10 -08004330 /**
4331 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4332 * @param subId The subscription to use to check the configuration.
4333 * @param c The callback that will be used to send the result.
4334 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004336 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004337 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004338 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004339 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4340 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4341 }
Meng Wangafbc5852019-09-19 17:37:13 -07004342
4343 final long token = Binder.clearCallingIdentity();
4344 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004345 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004346 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004347 } catch (ImsException e) {
4348 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4349 + "is inactive, ignoring unregister.");
4350 // If the subscription is no longer active, just return, since the callback
4351 // will already have been removed internally.
4352 } finally {
4353 Binder.restoreCallingIdentity(token);
4354 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 }
4356
4357 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004358 public boolean isCapable(int subId, int capability, int regTech) {
4359 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 final long token = Binder.clearCallingIdentity();
4361 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004362 int slotId = getSlotIndexOrException(subId);
4363 verifyImsMmTelConfiguredOrThrow(slotId);
4364 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4365 } catch (com.android.ims.ImsException e) {
4366 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4367 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004368 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004369 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4370 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 } finally {
4372 Binder.restoreCallingIdentity(token);
4373 }
4374 }
4375
4376 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004377 public boolean isAvailable(int subId, int capability, int regTech) {
4378 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 final long token = Binder.clearCallingIdentity();
4380 try {
4381 Phone phone = getPhone(subId);
4382 if (phone == null) return false;
4383 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004384 } catch (com.android.ims.ImsException e) {
4385 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4386 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 } finally {
4388 Binder.restoreCallingIdentity(token);
4389 }
4390 }
4391
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004392 /**
4393 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4394 * subscription.
4395 * @param subId The subscription to use to check the configuration.
4396 * @param callback The callback that will be used to send the result.
4397 * @param capability The MmTelFeature capability that will be used to send the result.
4398 * @param transportType The transport type of the MmTelFeature capability.
4399 */
4400 @Override
4401 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4402 int transportType) {
4403 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004404 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4405 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4406 "IMS not available on device.");
4407 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004408 final long token = Binder.clearCallingIdentity();
4409 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004410 int slotId = getSlotIndex(subId);
4411 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4412 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4413 + subId + "'");
4414 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4415 }
4416 verifyImsMmTelConfiguredOrThrow(slotId);
4417 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4418 transportType, aBoolean -> {
4419 try {
4420 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4421 } catch (RemoteException e) {
4422 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4423 + "running. Ignore");
4424 }
4425 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004426 } catch (ImsException e) {
4427 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004428 } finally {
4429 Binder.restoreCallingIdentity(token);
4430 }
4431 }
4432
shilu366312e2019-12-17 09:28:10 -08004433 /**
4434 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4435 * @param subId The subscription to use to check the configuration.
4436 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 @Override
4438 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004439 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004440 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004441
Brad Ebinger35c841c2018-10-01 10:40:55 -07004442 final long token = Binder.clearCallingIdentity();
4443 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004444 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004445 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004446 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004447 } catch (ImsException e) {
4448 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 } finally {
4450 Binder.restoreCallingIdentity(token);
4451 }
4452 }
4453
4454 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004455 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004457 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004458 final long identity = Binder.clearCallingIdentity();
4459 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004461 // This setting doesn't require an active ImsService connection, so do not verify. The
4462 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004463 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004464 } catch (ImsException e) {
4465 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
shilu366312e2019-12-17 09:28:10 -08004471 /**
4472 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4473 * @param subId The subscription to use to check the configuration.
4474 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004476 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004477 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004478 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 final long identity = Binder.clearCallingIdentity();
4480 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004482 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004484 } catch (ImsException e) {
4485 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
4489 }
4490
4491 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004492 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004494 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004495 final long identity = Binder.clearCallingIdentity();
4496 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004498 // This setting doesn't require an active ImsService connection, so do not verify. The
4499 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004501 } catch (ImsException e) {
4502 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506 }
4507
shilu366312e2019-12-17 09:28:10 -08004508 /**
4509 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4510 * @param subId The subscription to use to check the configuration.
4511 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004512 @Override
4513 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004514 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004515 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 final long identity = Binder.clearCallingIdentity();
4517 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004519 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004520 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004521 } catch (ImsException e) {
4522 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
4526 }
4527
4528 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004529 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004531 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004532 final long identity = Binder.clearCallingIdentity();
4533 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004534 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004535 // This setting doesn't require an active ImsService connection, so do not verify. The
4536 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004537 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004538 } catch (ImsException e) {
4539 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
4543 }
4544
shilu366312e2019-12-17 09:28:10 -08004545 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004546 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4547 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4548 * @param subId The subscription to use to check the configuration.
4549 */
4550 @Override
4551 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004552 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004553 mApp, subId, "isCrossSimCallingEnabledByUser");
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004557 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004559 } catch (ImsException e) {
4560 throw new ServiceSpecificException(e.getCode());
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
4564 }
4565
4566 /**
4567 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4568 * Requires MODIFY_PHONE_STATE permission.
4569 * @param subId The subscription to use to check the configuration.
4570 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4571 * false otherwise
4572 */
4573 @Override
4574 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4576 "setCrossSimCallingEnabled");
4577 final long identity = Binder.clearCallingIdentity();
4578 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004579 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004580 // This setting doesn't require an active ImsService connection, so do not verify. The
4581 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004582 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004583 } catch (ImsException e) {
4584 throw new ServiceSpecificException(e.getCode());
4585 } finally {
4586 Binder.restoreCallingIdentity(identity);
4587 }
4588 }
4589
4590 /**
shilu366312e2019-12-17 09:28:10 -08004591 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4592 * @param subId The subscription to use to check the configuration.
4593 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004594 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004595
Brad Ebinger35c841c2018-10-01 10:40:55 -07004596 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004597 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004598 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004599 final long identity = Binder.clearCallingIdentity();
4600 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004601 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004602 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004603 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004604 } catch (ImsException e) {
4605 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 } finally {
4607 Binder.restoreCallingIdentity(identity);
4608 }
4609 }
4610
4611 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004612 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004614 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004615 final long identity = Binder.clearCallingIdentity();
4616 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004617 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004618 // This setting doesn't require an active ImsService connection, so do not verify. The
4619 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004620 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004621 } catch (ImsException e) {
4622 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 } finally {
4624 Binder.restoreCallingIdentity(identity);
4625 }
4626 }
4627
4628 @Override
4629 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4631 "setVoWiFiNonPersistent");
4632 final long identity = Binder.clearCallingIdentity();
4633 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004634 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004635 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004636 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004637 } catch (ImsException e) {
4638 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004639 } finally {
4640 Binder.restoreCallingIdentity(identity);
4641 }
4642 }
4643
shilu366312e2019-12-17 09:28:10 -08004644 /**
4645 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4646 * @param subId The subscription to use to check the configuration.
4647 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004648 @Override
4649 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004650 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004651 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004652 final long identity = Binder.clearCallingIdentity();
4653 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004654 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004655 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004656 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004657 } catch (ImsException e) {
4658 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
4662 }
4663
4664 @Override
4665 public void setVoWiFiModeSetting(int subId, int mode) {
4666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4667 "setVoWiFiModeSetting");
4668 final long identity = Binder.clearCallingIdentity();
4669 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004670 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004671 // This setting doesn't require an active ImsService connection, so do not verify. The
4672 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004673 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004674 } catch (ImsException e) {
4675 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004676 } finally {
4677 Binder.restoreCallingIdentity(identity);
4678 }
4679 }
4680
4681 @Override
4682 public int getVoWiFiRoamingModeSetting(int subId) {
4683 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4684 final long identity = Binder.clearCallingIdentity();
4685 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004686 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004687 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004688 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004689 } catch (ImsException e) {
4690 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
4694 }
4695
4696 @Override
4697 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4699 "setVoWiFiRoamingModeSetting");
4700 final long identity = Binder.clearCallingIdentity();
4701 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004702 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004703 // This setting doesn't require an active ImsService connection, so do not verify. The
4704 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004705 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004706 } catch (ImsException e) {
4707 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004708 } finally {
4709 Binder.restoreCallingIdentity(identity);
4710 }
4711 }
4712
4713 @Override
4714 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4716 "setRttCapabilityEnabled");
4717 final long identity = Binder.clearCallingIdentity();
4718 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004719 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004720 // This setting doesn't require an active ImsService connection, so do not verify. The
4721 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004722 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004723 } catch (ImsException e) {
4724 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
4728 }
4729
shilu366312e2019-12-17 09:28:10 -08004730 /**
4731 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4732 * @param subId The subscription to use to check the configuration.
4733 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004734 @Override
4735 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004736 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004737 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004738 final long identity = Binder.clearCallingIdentity();
4739 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004740 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004741 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004742 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004743 } catch (ImsException e) {
4744 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
4748 }
4749
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004750 @Override
4751 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4752 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004753
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004754 final long identity = Binder.clearCallingIdentity();
4755 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004756 if (!isImsAvailableOnDevice()) {
4757 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4758 "IMS not available on device.");
4759 }
4760 int slotId = getSlotIndexOrException(subId);
4761 verifyImsMmTelConfiguredOrThrow(slotId);
4762 ImsManager.getInstance(mApp, slotId)
4763 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004764 } catch (ImsException e) {
4765 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004766 } finally {
4767 Binder.restoreCallingIdentity(identity);
4768 }
4769 }
4770
4771 @Override
4772 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4773 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004774
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004775 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004776 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4777 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4778 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004779 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004780 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004781 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004782 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004783 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4784 + "is inactive, ignoring unregister.");
4785 // If the subscription is no longer active, just return, since the callback will already
4786 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004787 } finally {
4788 Binder.restoreCallingIdentity(identity);
4789 }
4790 }
4791
joonhunshincffb7fc2021-11-28 07:32:01 +00004792 @Override
4793 public void registerFeatureProvisioningChangedCallback(int subId,
4794 IFeatureProvisioningCallback callback) {
4795 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4796 mApp, subId, "registerFeatureProvisioningChangedCallback");
4797
4798 final long identity = Binder.clearCallingIdentity();
4799 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4800 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4801 }
4802
joonhunshin91bc1952022-04-29 08:47:15 +00004803 try {
4804 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4805 if (controller == null) {
4806 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4807 "Device does not support IMS");
4808 }
4809 controller.addFeatureProvisioningChangedCallback(subId, callback);
4810 } finally {
4811 Binder.restoreCallingIdentity(identity);
4812 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004813 }
4814
4815 @Override
4816 public void unregisterFeatureProvisioningChangedCallback(int subId,
4817 IFeatureProvisioningCallback callback) {
4818 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4819 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4820
4821 final long identity = Binder.clearCallingIdentity();
4822 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4823 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4824 }
4825
joonhunshin91bc1952022-04-29 08:47:15 +00004826 try {
4827 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4828 if (controller == null) {
4829 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4830 return;
4831 }
4832 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4833 } finally {
4834 Binder.restoreCallingIdentity(identity);
4835 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004836 }
allenwtsu99c623b2020-01-03 18:24:23 +08004837
4838 private void checkModifyPhoneStatePermission(int subId, String message) {
4839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4840 message);
4841 }
4842
allenwtsu99c623b2020-01-03 18:24:23 +08004843 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004844 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004845 boolean isProvisioned) {
4846 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4847
4848 final long identity = Binder.clearCallingIdentity();
4849 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004850 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4851 if (controller == null) {
4852 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4853 return;
4854 }
4855 controller.setRcsProvisioningStatusForCapability(
4856 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
allenwtsu99c623b2020-01-03 18:24:23 +08004860 }
4861
4862
4863 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004864 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4865 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4866 mApp, subId, "getRcsProvisioningStatusForCapability");
4867
allenwtsu99c623b2020-01-03 18:24:23 +08004868 final long identity = Binder.clearCallingIdentity();
4869 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004870 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4871 if (controller == null) {
4872 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4873
4874 // device does not support IMS, this method will return true always.
4875 return true;
4876 }
4877 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
4881 }
4882
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004883 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004884 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4885 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004886 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004887
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004890 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4891 if (controller == null) {
4892 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4893 return;
4894 }
4895 controller.setImsProvisioningStatusForCapability(
4896 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
4900 }
4901
4902 @Override
4903 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004904 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4905 mApp, subId, "getProvisioningStatusForCapability");
4906
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 final long identity = Binder.clearCallingIdentity();
4908 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004909 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4910 if (controller == null) {
4911 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004912
joonhunshin91bc1952022-04-29 08:47:15 +00004913 // device does not support IMS, this method will return true always.
4914 return true;
4915 }
4916 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 } finally {
4918 Binder.restoreCallingIdentity(identity);
4919 }
4920 }
4921
4922 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004923 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4924 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4925 mApp, subId, "isProvisioningRequiredForCapability");
4926
4927 final long identity = Binder.clearCallingIdentity();
4928 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004929 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4930 if (controller == null) {
4931 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4932
4933 // device does not support IMS, this method will return false
4934 return false;
4935 }
4936 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004937 } finally {
4938 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004939 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004940 }
4941
4942 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004943 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4944 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4945 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004946
joonhunshincffb7fc2021-11-28 07:32:01 +00004947 final long identity = Binder.clearCallingIdentity();
4948 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004949 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4950 if (controller == null) {
4951 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4952
4953 // device does not support IMS, this method will return false
4954 return false;
4955 }
4956 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 }
4961
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004962 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004963 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004964 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4965 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4966 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004967 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4968 mApp, subId, "getImsProvisioningInt");
4969
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004973 int slotId = getSlotIndex(subId);
4974 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4975 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4976 + subId + "' for key:" + key);
4977 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4978 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004979
joonhunshin91bc1952022-04-29 08:47:15 +00004980 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4981 if (controller == null) {
4982 loge("getImsProvisioningInt: Device does not support IMS");
4983
4984 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4985 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4986 }
4987 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004988 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4989 return retVal;
4990 }
4991
calvinpanb5a34062021-02-08 19:59:36 +08004992 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004993 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004994 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4995 + subId + "' for key:" + key);
4996 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
5000 }
5001
5002 @Override
5003 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005004 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5005 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5006 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005007 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5008 mApp, subId, "getImsProvisioningString");
5009
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005010 final long identity = Binder.clearCallingIdentity();
5011 try {
5012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005013 int slotId = getSlotIndex(subId);
5014 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5015 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5016 + subId + "' for key:" + key);
5017 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5018 }
calvinpanb5a34062021-02-08 19:59:36 +08005019 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005020 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005021 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5022 + subId + "' for key:" + key);
5023 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
5026 }
5027 }
5028
5029 @Override
5030 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005031 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5032 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5033 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5035 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005036
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005040 int slotId = getSlotIndex(subId);
5041 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5042 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5043 + subId + "' for key:" + key);
5044 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5045 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005046
joonhunshin91bc1952022-04-29 08:47:15 +00005047 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5048 if (controller == null) {
5049 loge("setImsProvisioningInt: Device does not support IMS");
5050
5051 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5052 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5053 }
5054 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005055 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5056 return retVal;
5057 }
5058
calvinpanb5a34062021-02-08 19:59:36 +08005059 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5060 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005061 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005062 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005063 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
5067 }
5068
5069 @Override
5070 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005071 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5072 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5073 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5075 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005079 int slotId = getSlotIndex(subId);
5080 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5081 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5082 + subId + "' for key:" + key);
5083 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5084 }
calvinpanb5a34062021-02-08 19:59:36 +08005085 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5086 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005087 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005088 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005089 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005090 } finally {
5091 Binder.restoreCallingIdentity(identity);
5092 }
5093 }
5094
Brad Ebinger919631e2021-06-02 17:46:35 -07005095 /**
5096 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5097 * for the given slot ID or no ImsResolver instance has been created.
5098 * @param slotId The slot ID that the IMS service is created for.
5099 * @throws ImsException If there is no ImsService configured for this slot.
5100 */
5101 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5102 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5103 ImsFeature.FEATURE_MMTEL)) {
5104 throw new ImsException("This subscription does not support MMTEL over IMS",
5105 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5106 }
5107 }
5108
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005109 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005110 int slotId = SubscriptionManager.getSlotIndex(subId);
5111 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005112 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5113 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005114 }
5115 return slotId;
5116 }
5117
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005118 private int getSlotIndex(int subId) {
5119 int slotId = SubscriptionManager.getSlotIndex(subId);
5120 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5121 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5122 }
5123 return slotId;
5124 }
5125
Wink Saville36469e72014-06-11 15:17:00 -07005126 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005127 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005128 */
5129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005130 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5131 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005132 try {
5133 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5134 } catch (SecurityException se) {
5135 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5136 throw new SecurityException("Package " + callingPackage + " does not belong to "
5137 + Binder.getCallingUid());
5138 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005139 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005140 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005141 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005142 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005143 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005144 mApp, subId, callingPackage, callingFeatureId,
5145 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005146 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5147 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 final long identity = Binder.clearCallingIdentity();
5150 try {
5151 final Phone phone = getPhone(subId);
5152 if (phone != null) {
5153 return phone.getServiceState().getDataNetworkType();
5154 } else {
5155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5156 }
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005160 }
5161
5162 /**
5163 * Returns the data network type
5164 */
5165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005166 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005167 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5168 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005169 }
5170
5171 /**
5172 * Returns the data network type for a subId
5173 */
5174 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005175 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5176 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005177 String functionName = "getDataNetworkTypeForSubscriber";
5178 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5179 mApp, functionName)) {
5180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5181 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5182 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5183 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005184 }
5185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186 final long identity = Binder.clearCallingIdentity();
5187 try {
5188 final Phone phone = getPhone(subId);
5189 if (phone != null) {
5190 return phone.getServiceState().getDataNetworkType();
5191 } else {
5192 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5193 }
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005197 }
5198
5199 /**
Wink Saville36469e72014-06-11 15:17:00 -07005200 * Returns the Voice network type for a subId
5201 */
5202 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005203 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5204 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005205 String functionName = "getVoiceNetworkTypeForSubscriber";
5206 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5207 mApp, functionName)) {
5208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5209 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5210 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5211 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005212 }
5213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 final long identity = Binder.clearCallingIdentity();
5215 try {
5216 final Phone phone = getPhone(subId);
5217 if (phone != null) {
5218 return phone.getServiceState().getVoiceNetworkType();
5219 } else {
5220 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5221 }
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005225 }
5226
5227 /**
5228 * @return true if a ICC card is present
5229 */
5230 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005231 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005232 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5233 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005234 }
5235
5236 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005237 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005238 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005239 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005240 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 final long identity = Binder.clearCallingIdentity();
5242 try {
5243 final Phone phone = PhoneFactory.getPhone(slotIndex);
5244 if (phone != null) {
5245 return phone.getIccCard().hasIccCard();
5246 } else {
5247 return false;
5248 }
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005252 }
5253
5254 /**
5255 * Return if the current radio is LTE on CDMA. This
5256 * is a tri-state return value as for a period of time
5257 * the mode may be unknown.
5258 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005259 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005260 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005261 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005262 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005263 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005264 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5265 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5266 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005267 }
5268
Sanket Padawe356d7632015-06-22 14:03:32 -07005269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005270 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5271 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005272 try {
5273 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5274 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005275 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5276 }
5277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 final long identity = Binder.clearCallingIdentity();
5279 try {
5280 final Phone phone = getPhone(subId);
5281 if (phone == null) {
5282 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5283 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005284 return TelephonyProperties.lte_on_cdma_device()
5285 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 }
5287 } finally {
5288 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005289 }
Wink Saville36469e72014-06-11 15:17:00 -07005290 }
5291
Wink Saville36469e72014-06-11 15:17:00 -07005292 /**
5293 * {@hide}
5294 * Returns Default subId, 0 in the case of single standby.
5295 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005296 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005297 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005298 }
5299
Shishir Agrawala9f32182016-04-12 12:00:16 -07005300 private int getSlotForDefaultSubscription() {
5301 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5302 }
5303
Wink Savilleb564aae2014-10-23 10:18:09 -07005304 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005305 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005306 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005307
Pengquan Menge92a50d2018-09-21 15:54:48 -07005308 private boolean isActiveSubscription(int subId) {
5309 return mSubscriptionController.isActiveSubId(subId);
5310 }
5311
Ihab Awadf2177b72013-11-25 13:33:23 -08005312 /**
5313 * @see android.telephony.TelephonyManager.WifiCallingChoices
5314 */
5315 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 final long identity = Binder.clearCallingIdentity();
5317 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005318 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5320 getWhenToMakeWifiCallsDefaultPreference());
5321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005324 }
5325
5326 /**
5327 * @see android.telephony.TelephonyManager.WifiCallingChoices
5328 */
5329 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 final long identity = Binder.clearCallingIdentity();
5331 try {
5332 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005333 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005338 }
5339
Sailesh Nepald1e68152013-12-12 19:08:02 -08005340 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005341 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005342 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005343 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005344
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005345 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5346 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5347 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005348 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005349 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5350 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005351 }
5352 return PhoneFactory.getPhone(phoneId);
5353 }
5354
Shishir Agrawal566b7612013-10-28 14:41:00 -07005355 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005356 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005357 @NonNull IccLogicalChannelRequest request) {
5358 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5359 /*message=*/ "iccOpenLogicalChannel");
5360
5361 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5362 // Verify that the callingPackage in the request belongs to the calling UID
5363 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5364
5365 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005366 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005367
Rambo Wanga1782702021-11-10 20:15:19 -08005368 private Phone getPhoneFromValidIccLogicalChannelRequest(
5369 @NonNull IccLogicalChannelRequest request, String message) {
5370 Phone phone;
5371 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5373 mApp, request.subId, message);
5374 phone = getPhoneFromSubId(request.subId);
5375 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5376 enforceModifyPermission();
5377 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5378 } else {
5379 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005380 }
Rambo Wanga1782702021-11-10 20:15:19 -08005381 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005382 }
5383
5384 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005385 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005388 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005390 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5391 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005392 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5393 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 loge("The calling package is not allowed to access ISD-R.");
5395 throw new SecurityException(
5396 "The calling package is not allowed to access ISD-R.");
5397 }
Derek Tan740e1672017-06-27 14:56:27 -07005398 }
Derek Tan740e1672017-06-27 14:56:27 -07005399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005401 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5402 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 return response;
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
5406 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005407 }
5408
5409 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005410 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5411 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5412 /*message=*/"iccCloseLogicalChannel");
5413
5414 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5415
5416 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005418
Rambo Wanga1782702021-11-10 20:15:19 -08005419 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5420 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005421 // before this feature is enabled, this API should only return false if
5422 // the operation fails instead of throwing runtime exception for
5423 // backward-compatibility.
5424 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5425 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005428 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005429 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 }
Chen Xue9d737e2022-01-01 23:41:31 -08005431 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005432 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005433 Boolean success = false;
5434 if (result instanceof RuntimeException) {
5435 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005436 if (shouldThrowExceptionOnFailure) {
5437 throw (RuntimeException) result;
5438 } else {
5439 return false;
5440 }
Chen Xue9d737e2022-01-01 23:41:31 -08005441 } else if (result instanceof Boolean) {
5442 success = (Boolean) result;
5443 } else {
5444 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5445 }
Rambo Wanga1782702021-11-10 20:15:19 -08005446 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 return success;
5448 } finally {
5449 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005450 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005451 }
5452
5453 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005454 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005455 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5457 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005458 if (DBG) {
5459 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5460 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5461 + p3 + " data=" + data);
5462 }
5463 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5464 command, p1, p2, p3, data);
5465 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005466
Jordan Liu4c733742019-02-28 12:03:40 -08005467 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005468 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5469 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005470 enforceModifyPermission();
5471 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005472 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5473 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5474 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005475 }
5476 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005477 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5478 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005479 }
5480
5481 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5482 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 final long identity = Binder.clearCallingIdentity();
5484 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005485 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 return "";
5487 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005490 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5491 null /* workSource */);
5492 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 // Append the returned status code to the end of the response payload.
5495 String s = Integer.toHexString(
5496 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5497 if (response.payload != null) {
5498 s = IccUtils.bytesToHexString(response.payload) + s;
5499 }
5500 return s;
5501 } finally {
5502 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005503 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005504 }
Jake Hambye994d462014-02-03 13:10:13 -08005505
Evan Charltonc66da362014-05-16 14:06:40 -07005506 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005507 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5508 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005509 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5510 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005512 if (DBG) {
5513 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5514 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5515 }
5516 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5517 cla, command, p1, p2, p3, data);
5518 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005519
Jordan Liu4c733742019-02-28 12:03:40 -08005520 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005521 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5522 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005523 enforceModifyPermission();
5524 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5525 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005526 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5527 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5528 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005529 }
5530
5531 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005532 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5533 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005534 }
5535
5536 // open APDU basic channel assuming the caller has sufficient permissions
5537 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5538 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 final long identity = Binder.clearCallingIdentity();
5540 try {
5541 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5542 && TextUtils.equals(ISDR_AID, data)) {
5543 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005544 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5545 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 if (bestComponent == null
5547 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5548 loge("The calling package is not allowed to select ISD-R.");
5549 throw new SecurityException(
5550 "The calling package is not allowed to select ISD-R.");
5551 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005552 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005555 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5556 null /* workSource */);
5557 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 // Append the returned status code to the end of the response payload.
5560 String s = Integer.toHexString(
5561 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5562 if (response.payload != null) {
5563 s = IccUtils.bytesToHexString(response.payload) + s;
5564 }
5565 return s;
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005568 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005569 }
5570
5571 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005572 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005573 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5575 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 final long identity = Binder.clearCallingIdentity();
5578 try {
5579 if (DBG) {
5580 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5581 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5582 }
5583
5584 IccIoResult response =
5585 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5586 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5587 subId);
5588
5589 if (DBG) {
5590 log("Exchange SIM_IO [R]" + response);
5591 }
5592
5593 byte[] result = null;
5594 int length = 2;
5595 if (response.payload != null) {
5596 length = 2 + response.payload.length;
5597 result = new byte[length];
5598 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5599 } else {
5600 result = new byte[length];
5601 }
5602
5603 result[length - 1] = (byte) response.sw2;
5604 result[length - 2] = (byte) response.sw1;
5605 return result;
5606 } finally {
5607 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005608 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005609 }
5610
Nathan Haroldb3014052017-01-25 15:57:32 -08005611 /**
5612 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5613 * on a particular subscription
5614 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005615 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5616 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005618 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005619 return null;
5620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621
5622 final long identity = Binder.clearCallingIdentity();
5623 try {
5624 if (appType != TelephonyManager.APPTYPE_USIM
5625 && appType != TelephonyManager.APPTYPE_SIM) {
5626 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5627 return null;
5628 }
5629 Object response = sendRequest(
5630 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5631 if (response instanceof String[]) {
5632 return (String[]) response;
5633 }
yincheng zhao2737e882019-09-06 17:06:54 -07005634 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005636 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 } finally {
5638 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005639 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005640 }
5641
yincheng zhao2737e882019-09-06 17:06:54 -07005642 /**
5643 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5644 * subscription.
5645 *
5646 * @param subId the id of the subscription.
5647 * @param appType the uicc app type, must be USIM or SIM.
5648 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5649 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005650 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005651 * @return number of fplmns that is successfully written to the SIM.
5652 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005653 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5654 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5656 mApp, subId, "setForbiddenPlmns");
5657
yincheng zhao2737e882019-09-06 17:06:54 -07005658 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5659 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5660 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5661 }
5662 if (fplmns == null) {
5663 throw new IllegalArgumentException("Fplmn List provided is null");
5664 }
5665 for (String fplmn : fplmns) {
5666 if (!CellIdentity.isValidPlmn(fplmn)) {
5667 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5668 }
5669 }
5670 final long identity = Binder.clearCallingIdentity();
5671 try {
5672 Object response = sendRequest(
5673 CMD_SET_FORBIDDEN_PLMNS,
5674 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5675 subId);
5676 return (int) response;
5677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
5680 }
5681
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005682 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005683 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5685 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5690 if (response.payload == null) {
5691 return "";
5692 }
Evan Charltonc66da362014-05-16 14:06:40 -07005693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 // Append the returned status code to the end of the response payload.
5695 String s = Integer.toHexString(
5696 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5697 s = IccUtils.bytesToHexString(response.payload) + s;
5698 return s;
5699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
Evan Charltonc66da362014-05-16 14:06:40 -07005702 }
5703
Jake Hambye994d462014-02-03 13:10:13 -08005704 /**
5705 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5706 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5707 *
5708 * @param itemID the ID of the item to read
5709 * @return the NV item as a String, or null on error.
5710 */
5711 @Override
5712 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005713 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5715 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716
5717 final long identity = Binder.clearCallingIdentity();
5718 try {
5719 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005720 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5722 return value;
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Jake Hambye994d462014-02-03 13:10:13 -08005726 }
5727
5728 /**
5729 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5730 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5731 *
5732 * @param itemID the ID of the item to read
5733 * @param itemValue the value to write, as a String
5734 * @return true on success; false on any failure
5735 */
5736 @Override
5737 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005738 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5740 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
5744 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5745 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005746 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5748 return success;
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Jake Hambye994d462014-02-03 13:10:13 -08005752 }
5753
5754 /**
5755 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5756 * Used for device configuration by some CDMA operators.
5757 *
5758 * @param preferredRoamingList byte array containing the new PRL
5759 * @return true on success; false on any failure
5760 */
5761 @Override
5762 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5764 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765
5766 final long identity = Binder.clearCallingIdentity();
5767 try {
5768 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5769 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5770 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5771 return success;
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
Jake Hambye994d462014-02-03 13:10:13 -08005775 }
5776
5777 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005778 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005779 * Used for device configuration by some CDMA operators.
5780 *
chen xu6dac5ab2018-10-26 17:39:23 -07005781 * @param slotIndex - device slot.
5782 *
Jake Hambye994d462014-02-03 13:10:13 -08005783 * @return true on success; false on any failure
5784 */
5785 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005786 public boolean resetModemConfig(int slotIndex) {
5787 Phone phone = PhoneFactory.getPhone(slotIndex);
5788 if (phone != null) {
5789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5790 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791
chen xu6dac5ab2018-10-26 17:39:23 -07005792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5795 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5796 return success;
5797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 }
chen xu6dac5ab2018-10-26 17:39:23 -07005801 return false;
5802 }
5803
5804 /**
5805 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5806 *
5807 * @param slotIndex - device slot.
5808 *
5809 * @return true on success; false on any failure
5810 */
5811 @Override
5812 public boolean rebootModem(int slotIndex) {
5813 Phone phone = PhoneFactory.getPhone(slotIndex);
5814 if (phone != null) {
5815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5816 mApp, phone.getSubId(), "rebootModem");
5817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5821 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5822 return success;
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
5826 }
5827 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005828 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005829
Brad Ebinger51f743a2017-01-23 13:50:20 -08005830 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005831 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5832 * {@link #disableIms(int)}.
5833 * @param slotIndex device slot.
5834 */
5835 public void resetIms(int slotIndex) {
5836 enforceModifyPermission();
5837
5838 final long identity = Binder.clearCallingIdentity();
5839 try {
5840 if (mImsResolver == null) {
5841 // may happen if the does not support IMS.
5842 return;
5843 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005844 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
5848 }
5849
5850 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005851 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5852 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005853 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005854 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005859 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005860 // may happen if the device does not support IMS.
5861 return;
5862 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005867 }
5868
5869 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005870 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5871 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005872 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005873 public void disableIms(int slotId) {
5874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875
5876 final long identity = Binder.clearCallingIdentity();
5877 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005878 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005879 // may happen if the device does not support IMS.
5880 return;
5881 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005882 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005886 }
5887
5888 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005889 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5890 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005891 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005892 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005893 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005894 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895
5896 final long identity = Binder.clearCallingIdentity();
5897 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005898 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005899 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5900 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005901 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005902 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005906 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005907 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005908 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5909 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005910 @Override
5911 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005912 enforceModifyPermission();
5913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005917 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005918 } finally {
5919 Binder.restoreCallingIdentity(identity);
5920 }
5921 }
5922
5923 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005924 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005925 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005926 */
5927 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929
5930 final long identity = Binder.clearCallingIdentity();
5931 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005932 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005933 // may happen if the device does not support IMS.
5934 return null;
5935 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005940 }
5941
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005942 /**
5943 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005944 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005945 */
5946 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948
5949 final long identity = Binder.clearCallingIdentity();
5950 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005951 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005952 // may happen if the device does not support IMS.
5953 return null;
5954 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005955 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005959 }
5960
Brad Ebinger884c07b2018-02-15 16:17:40 -08005961 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005962 * Sets the ImsService Package Name that Telephony will bind to.
5963 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005964 * @param slotIndex the slot ID that the ImsService should bind for.
5965 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005966 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005967 * @param featureTypes An integer array of feature types associated with a packageName.
5968 * @param packageName The name of the package that the current configuration will be replaced
5969 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005970 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005971 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005972 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5973 int[] featureTypes, String packageName) {
5974 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5975 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5977 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005978 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 final long identity = Binder.clearCallingIdentity();
5981 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005982 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005983 // may happen if the device does not support IMS.
5984 return false;
5985 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005986 Map<Integer, String> featureConfig = new HashMap<>();
5987 for (int featureType : featureTypes) {
5988 featureConfig.put(featureType, packageName);
5989 }
5990 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5991 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 } finally {
5993 Binder.restoreCallingIdentity(identity);
5994 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005995 }
5996
5997 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005998 * Clears any carrier ImsService overrides for the slot index specified that were previously
5999 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6000 *
6001 * This should only be used for testing.
6002 *
6003 * @param slotIndex the slot ID that the ImsService should bind for.
6004 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6005 */
6006 @Override
6007 public boolean clearCarrierImsServiceOverride(int slotIndex) {
6008 int[] subIds = SubscriptionManager.getSubId(slotIndex);
6009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6010 "clearCarrierImsServiceOverride");
6011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
6012 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6013 "clearCarrierImsServiceOverride");
6014
6015 final long identity = Binder.clearCallingIdentity();
6016 try {
6017 if (mImsResolver == null) {
6018 // may happen if the device does not support IMS.
6019 return false;
6020 }
6021 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
6025 }
6026
6027 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006028 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006029 *
6030 * @param slotId The slot that the ImsService is associated with.
6031 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6032 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006033 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006034 * @return the package name of the ImsService configuration.
6035 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006036 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6037 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006038 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006039 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006040 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006041 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6042 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 final long identity = Binder.clearCallingIdentity();
6045 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006046 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006047 // may happen if the device does not support IMS.
6048 return "";
6049 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006050 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006051 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6052 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006056 }
6057
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006058 /**
6059 * Get the MmTelFeature state associated with the requested subscription id.
6060 * @param subId The subscription that the MmTelFeature is associated with.
6061 * @param callback A callback with an integer containing the
6062 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6063 */
6064 @Override
6065 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6066 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006067 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6068 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6069 "IMS not available on device.");
6070 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006071 final long token = Binder.clearCallingIdentity();
6072 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006073 int slotId = getSlotIndex(subId);
6074 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6075 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6076 + subId + "'");
6077 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6078 }
6079 verifyImsMmTelConfiguredOrThrow(slotId);
6080 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6081 try {
6082 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6083 } catch (RemoteException e) {
6084 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6085 + "Ignore");
6086 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006087 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006088 } catch (ImsException e) {
6089 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006090 } finally {
6091 Binder.restoreCallingIdentity(token);
6092 }
6093 }
6094
Daniel Brightbb5840b2021-01-12 15:48:18 -08006095 /**
6096 * Sets the ims registration state on all valid {@link Phone}s.
6097 */
6098 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006099 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006103 // NOTE: Before S, this method only set the default phone.
6104 for (final Phone phone : PhoneFactory.getPhones()) {
6105 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6106 phone.setImsRegistrationState(registered);
6107 }
6108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 } finally {
6110 Binder.restoreCallingIdentity(identity);
6111 }
Wink Saville36469e72014-06-11 15:17:00 -07006112 }
6113
6114 /**
Stuart Scott54788802015-03-30 13:18:01 -07006115 * Set the network selection mode to automatic.
6116 *
6117 */
6118 @Override
6119 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6121 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122
6123 final long identity = Binder.clearCallingIdentity();
6124 try {
shilufc958392020-01-20 11:36:01 -08006125 if (!isActiveSubscription(subId)) {
6126 return;
6127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006129 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6130 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 } finally {
6132 Binder.restoreCallingIdentity(identity);
6133 }
Stuart Scott54788802015-03-30 13:18:01 -07006134 }
6135
Jack Yud10cdd42020-09-28 20:28:01 -07006136 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006137 * Ask the radio to connect to the input network and change selection mode to manual.
6138 *
6139 * @param subId the id of the subscription.
6140 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6141 * the operator to attach to.
6142 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6143 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6144 * normal network selection next time.
6145 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006146 */
6147 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006148 public boolean setNetworkSelectionModeManual(
6149 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6151 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006152
6153 if (!isActiveSubscription(subId)) {
6154 return false;
6155 }
6156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 final long identity = Binder.clearCallingIdentity();
6158 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006159 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006161 if (DBG) {
6162 log("setNetworkSelectionModeManual: subId: " + subId
6163 + " operator: " + operatorInfo);
6164 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6166 } finally {
6167 Binder.restoreCallingIdentity(identity);
6168 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006169 }
shilu84f6e8b2019-12-19 13:58:01 -08006170 /**
6171 * Get the manual network selection
6172 *
6173 * @param subId the id of the subscription.
6174 *
6175 * @return the previously saved user selected PLMN
6176 */
6177 @Override
6178 public String getManualNetworkSelectionPlmn(int subId) {
6179 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006180 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006181 mApp, subId, "getManualNetworkSelectionPlmn");
6182
6183 final long identity = Binder.clearCallingIdentity();
6184 try {
6185 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006186 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006187 }
6188
6189 final Phone phone = getPhone(subId);
6190 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006191 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006192 }
6193 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6194 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6195 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
6199 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006200
6201 /**
6202 * Scans for available networks.
6203 */
6204 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006205 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6206 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6208 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006209 LocationAccessPolicy.LocationPermissionResult locationResult =
6210 LocationAccessPolicy.checkLocationPermission(mApp,
6211 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6212 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006213 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006214 .setCallingPid(Binder.getCallingPid())
6215 .setCallingUid(Binder.getCallingUid())
6216 .setMethod("getCellNetworkScanResults")
6217 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006218 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6219 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006220 .build());
6221 switch (locationResult) {
6222 case DENIED_HARD:
6223 throw new SecurityException("Not allowed to access scan results -- location");
6224 case DENIED_SOFT:
6225 return null;
6226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227
Pengquan Menga1bb6272018-09-06 09:59:22 -07006228 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 try {
6230 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006231 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 } finally {
6234 Binder.restoreCallingIdentity(identity);
6235 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006236 }
6237
6238 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006239 * Get the call forwarding info, given the call forwarding reason.
6240 */
6241 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006242 public void getCallForwarding(int subId, int callForwardingReason,
6243 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006244 enforceReadPrivilegedPermission("getCallForwarding");
6245 long identity = Binder.clearCallingIdentity();
6246 try {
6247 if (DBG) {
6248 log("getCallForwarding: subId " + subId
6249 + " callForwardingReason" + callForwardingReason);
6250 }
Hall Liu27d24262020-09-18 19:04:59 -07006251
6252 Phone phone = getPhone(subId);
6253 if (phone == null) {
6254 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006255 callback.onError(
6256 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006257 } catch (RemoteException e) {
6258 // ignore
6259 }
6260 return;
6261 }
6262
6263 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6264 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6265 @Override
6266 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6267 try {
6268 callback.onCallForwardingInfoAvailable(info);
6269 } catch (RemoteException e) {
6270 // ignore
6271 }
6272 }
6273
6274 @Override
6275 public void onError(int error) {
6276 try {
6277 callback.onError(error);
6278 } catch (RemoteException e) {
6279 // ignore
6280 }
6281 }
6282 });
6283 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006284 } finally {
6285 Binder.restoreCallingIdentity(identity);
6286 }
6287 }
6288
6289 /**
6290 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6291 * reason, the number to forward, and the timeout before the forwarding is attempted.
6292 */
6293 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006294 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6295 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006296 enforceModifyPermission();
6297 long identity = Binder.clearCallingIdentity();
6298 try {
6299 if (DBG) {
6300 log("setCallForwarding: subId " + subId
6301 + " callForwardingInfo" + callForwardingInfo);
6302 }
Hall Liu27d24262020-09-18 19:04:59 -07006303
6304 Phone phone = getPhone(subId);
6305 if (phone == null) {
6306 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006307 callback.accept(
6308 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006309 } catch (RemoteException e) {
6310 // ignore
6311 }
6312 return;
6313 }
6314
6315 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6316 FunctionalUtils.ignoreRemoteException(callback::accept));
6317
6318 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006319 } finally {
6320 Binder.restoreCallingIdentity(identity);
6321 }
6322 }
6323
6324 /**
Hall Liu27d24262020-09-18 19:04:59 -07006325 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006326 */
6327 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006328 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006329 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006330 long identity = Binder.clearCallingIdentity();
6331 try {
Hall Liu27d24262020-09-18 19:04:59 -07006332 Phone phone = getPhone(subId);
6333 if (phone == null) {
6334 try {
6335 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6336 } catch (RemoteException e) {
6337 // ignore
6338 }
6339 return;
6340 }
SongFerngWang0e767992021-03-31 22:08:45 +08006341 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6342 PersistableBundle c = configManager.getConfigForSubId(subId);
6343 boolean requireUssd = c.getBoolean(
6344 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006345
Shuo Qian4a594052020-01-23 11:59:30 -08006346 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006347 if (requireUssd) {
6348 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6349 getSubscriptionCarrierId(subId));
6350 String newUssdCommand = "";
6351 try {
6352 newUssdCommand = carrierXmlParser.getFeature(
6353 CarrierXmlParser.FEATURE_CALL_WAITING)
6354 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6355 } catch (NullPointerException e) {
6356 loge("Failed to generate USSD number" + e);
6357 }
6358 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6359 mMainThreadHandler, callback, carrierXmlParser,
6360 CarrierXmlParser.SsEntry.SSAction.QUERY);
6361 final String ussdCommand = newUssdCommand;
6362 Executors.newSingleThreadExecutor().execute(() -> {
6363 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6364 });
6365 } else {
6366 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6367 callback::accept);
6368 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6369 }
Shuo Qian4a594052020-01-23 11:59:30 -08006370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
6373 }
6374
6375 /**
Hall Liu27d24262020-09-18 19:04:59 -07006376 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006377 */
6378 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006379 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006380 enforceModifyPermission();
6381 long identity = Binder.clearCallingIdentity();
6382 try {
Hall Liu27d24262020-09-18 19:04:59 -07006383 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6384
6385 Phone phone = getPhone(subId);
6386 if (phone == null) {
6387 try {
6388 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6389 } catch (RemoteException e) {
6390 // ignore
6391 }
6392 return;
6393 }
6394
SongFerngWang0e767992021-03-31 22:08:45 +08006395 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6396 PersistableBundle c = configManager.getConfigForSubId(subId);
6397 boolean requireUssd = c.getBoolean(
6398 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006399
SongFerngWang0e767992021-03-31 22:08:45 +08006400 if (DBG) log("getCallWaitingStatus: subId " + subId);
6401 if (requireUssd) {
6402 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6403 getSubscriptionCarrierId(subId));
6404 CarrierXmlParser.SsEntry.SSAction ssAction =
6405 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6406 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6407 String newUssdCommand = "";
6408 try {
6409 newUssdCommand = carrierXmlParser.getFeature(
6410 CarrierXmlParser.FEATURE_CALL_WAITING)
6411 .makeCommand(ssAction, null);
6412 } catch (NullPointerException e) {
6413 loge("Failed to generate USSD number" + e);
6414 }
6415 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6416 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6417 final String ussdCommand = newUssdCommand;
6418 Executors.newSingleThreadExecutor().execute(() -> {
6419 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6420 });
6421 } else {
6422 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6423 FunctionalUtils.ignoreRemoteException(callback::accept));
6424
6425 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6426 }
Shuo Qian4a594052020-01-23 11:59:30 -08006427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
6430 }
6431
6432 /**
yinxub1bed742017-04-17 11:45:04 -07006433 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006434 *
yinxub1bed742017-04-17 11:45:04 -07006435 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006436 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6437 * location related information which will be sent if the caller already possess
6438 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006439 * @param request contains the radio access networks with bands/channels to scan
6440 * @param messenger callback messenger for scan results or errors
6441 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006442 * @return the id of the requested scan which can be used to stop the scan.
6443 */
6444 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006445 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6446 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006447 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6449 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006450 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006451 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6452 if (!renounceFineLocationAccess) {
6453 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6454 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6455 .setCallingPackage(callingPackage)
6456 .setCallingFeatureId(callingFeatureId)
6457 .setCallingPid(Binder.getCallingPid())
6458 .setCallingUid(Binder.getCallingUid())
6459 .setMethod("requestNetworkScan")
6460 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6461 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6462 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6463 .build());
6464 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006465 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006466 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6467 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006468 if (e != null) {
6469 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6470 throw e;
6471 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006472 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006473 return TelephonyScanManager.INVALID_SCAN_ID;
6474 }
6475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006476 }
Hall Liu912dfd32019-04-25 14:02:26 -07006477 int callingUid = Binder.getCallingUid();
6478 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006479 final long identity = Binder.clearCallingIdentity();
6480 try {
6481 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006482 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006483 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006484 } finally {
6485 Binder.restoreCallingIdentity(identity);
6486 }
yinxu504e1392017-04-12 16:03:22 -07006487 }
6488
Hall Liub2ac8ef2019-02-28 15:56:23 -08006489 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006490 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006491 boolean hasCarrierPriv;
6492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6495 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
Hall Liu558027f2019-05-15 19:14:05 -07006499 boolean hasNetworkScanPermission =
6500 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6501 == PERMISSION_GRANTED;
6502
6503 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6504 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6505 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006506 }
6507
6508 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6509 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006510 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6511 return new SecurityException("Specific channels must not be"
6512 + " scanned without location access.");
6513 }
6514 }
6515 }
6516
Hall Liub2ac8ef2019-02-28 15:56:23 -08006517 return null;
6518 }
6519
yinxu504e1392017-04-12 16:03:22 -07006520 /**
6521 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006522 *
6523 * @param subId id of the subscription
6524 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006525 */
6526 @Override
6527 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6529 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530
Hall Liu912dfd32019-04-25 14:02:26 -07006531 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532 final long identity = Binder.clearCallingIdentity();
6533 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006534 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535 } finally {
6536 Binder.restoreCallingIdentity(identity);
6537 }
yinxu504e1392017-04-12 16:03:22 -07006538 }
6539
6540 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006542 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006543 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006544 */
6545 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006546 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006547 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006548 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006549 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550
6551 final long identity = Binder.clearCallingIdentity();
6552 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 if (DBG) log("getAllowedNetworkTypesBitmask");
6554 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6555 int networkTypesBitmask = (result != null ? result[0] : -1);
6556 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6557 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 } finally {
6559 Binder.restoreCallingIdentity(identity);
6560 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006561 }
6562
6563 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006564 * Get the allowed network types for certain reason.
6565 *
6566 * @param subId the id of the subscription.
6567 * @param reason the reason the allowed network type change is taking place
6568 * @return the allowed network types.
6569 */
6570 @Override
6571 public long getAllowedNetworkTypesForReason(int subId,
6572 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006573 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006574 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006575 final long identity = Binder.clearCallingIdentity();
6576 try {
6577 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6578 } finally {
6579 Binder.restoreCallingIdentity(identity);
6580 }
6581 }
6582
6583 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006584 * Enable/Disable E-UTRA-NR Dual Connectivity
6585 * @param subId subscription id of the sim card
6586 * @param nrDualConnectivityState expected NR dual connectivity state
6587 * This can be passed following states
6588 * <ol>
6589 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6590 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6591 * <li>Disable NR dual connectivity and force secondary cell to be released
6592 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6593 * </ol>
6594 * @return operation result.
6595 */
6596 @Override
6597 public int setNrDualConnectivityState(int subId,
6598 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6600 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006601 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006602 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6603 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6604 }
6605
Sooraj Sasindran37444802020-08-11 10:40:43 -07006606 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
6609 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6610 nrDualConnectivityState, subId,
6611 workSource);
6612 if (DBG) log("enableNRDualConnectivity result: " + result);
6613 return result;
6614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
6617 }
6618
6619 /**
6620 * Is E-UTRA-NR Dual Connectivity enabled
6621 * @return true if dual connectivity is enabled else false
6622 */
6623 @Override
6624 public boolean isNrDualConnectivityEnabled(int subId) {
6625 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006626 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006627 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006628 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006629 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6630 return false;
6631 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006632 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6636 null, subId, workSource);
6637 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6638 return isEnabled;
6639 } finally {
6640 Binder.restoreCallingIdentity(identity);
6641 }
6642 }
6643
6644 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006645 * Set the allowed network types of the device and
6646 * provide the reason triggering the allowed network change.
6647 *
6648 * @param subId the id of the subscription.
6649 * @param reason the reason the allowed network type change is taking place
6650 * @param allowedNetworkTypes the allowed network types.
6651 * @return true on success; false on any failure.
6652 */
6653 @Override
6654 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006655 @TelephonyManager.AllowedNetworkTypesReason int reason,
6656 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6658 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006659 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006660 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6661 return false;
6662 }
6663 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6664 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006665 return false;
6666 }
6667
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006668 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6669 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6670
6671
6672 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6673 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6674 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006675 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006676
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006677 final long identity = Binder.clearCallingIdentity();
6678 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006679 Boolean success = (Boolean) sendRequest(
6680 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6681 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6682
6683 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6684 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
6688 }
6689
6690 /**
Miaoa84611c2019-03-15 09:21:10 +08006691 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006692 *
Miaoa84611c2019-03-15 09:21:10 +08006693 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006694 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006695 * @hide
6696 */
6697 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006698 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006701 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702 try {
Miaoa84611c2019-03-15 09:21:10 +08006703 if (phone != null) {
6704 return phone.hasMatchedTetherApnSetting();
6705 } else {
6706 return false;
6707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 } finally {
6709 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006710 }
Junda Liu475951f2014-11-07 16:45:03 -08006711 }
6712
6713 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006714 * Get the user enabled state of Mobile Data.
6715 *
6716 * TODO: remove and use isUserDataEnabled.
6717 * This can't be removed now because some vendor codes
6718 * calls through ITelephony directly while they should
6719 * use TelephonyManager.
6720 *
6721 * @return true on enabled
6722 */
6723 @Override
6724 public boolean getDataEnabled(int subId) {
6725 return isUserDataEnabled(subId);
6726 }
6727
6728 /**
6729 * Get whether mobile data is enabled per user setting.
6730 *
6731 * There are other factors deciding whether mobile data is actually enabled, but they are
6732 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006733 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006734 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6735 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006736 *
6737 * @return {@code true} if data is enabled else {@code false}
6738 */
6739 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006740 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006741 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006742 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006743 try {
6744 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6745 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006746 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006747 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6748 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006749 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006751 mApp, subId, functionName);
6752
Robert Greenwalt646120a2014-05-23 11:54:03 -07006753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006754
6755 final long identity = Binder.clearCallingIdentity();
6756 try {
6757 int phoneId = mSubscriptionController.getPhoneId(subId);
6758 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6759 Phone phone = PhoneFactory.getPhone(phoneId);
6760 if (phone != null) {
6761 boolean retVal = phone.isUserDataEnabled();
6762 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6763 return retVal;
6764 } else {
6765 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6766 return false;
6767 }
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006770 }
6771 }
6772
6773 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006774 * Checks if the device is capable of mobile data by considering whether whether the
6775 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6776 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006777 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006778 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006779 */
6780 @Override
6781 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006782 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006783 try {
6784 try {
6785 mApp.enforceCallingOrSelfPermission(
6786 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006787 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006788 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006789 try {
6790 mApp.enforceCallingOrSelfPermission(
6791 android.Manifest.permission.READ_PHONE_STATE,
6792 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006793 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006794 mApp.enforceCallingOrSelfPermission(
6795 permission.READ_BASIC_PHONE_STATE, functionName);
6796 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006797 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006798 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006799 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
6804 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 Phone phone = PhoneFactory.getPhone(phoneId);
6806 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006807 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006808 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 return retVal;
6810 } else {
6811 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6812 return false;
6813 }
6814 } finally {
6815 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006816 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006817 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006818
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006819 /**
6820 * Check if data is enabled for a specific reason
6821 * @param subId Subscription index
6822 * @param reason the reason the data enable change is taking place
6823 * @return {@code true} if the overall data is enabled; {@code false} if not.
6824 */
6825 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006826 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006827 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006828 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006829 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006830 try {
6831 mApp.enforceCallingOrSelfPermission(
6832 android.Manifest.permission.ACCESS_NETWORK_STATE,
6833 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006834 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006835 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6836 functionName);
6837 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006838 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006839 try {
6840 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006841 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006842 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006844 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006845 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006846 }
6847
6848
6849 final long identity = Binder.clearCallingIdentity();
6850 try {
6851 int phoneId = mSubscriptionController.getPhoneId(subId);
6852 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006853 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006854 + " reason=" + reason);
6855 }
6856 Phone phone = PhoneFactory.getPhone(phoneId);
6857 if (phone != null) {
6858 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006859 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006860 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006861 return retVal;
6862 } else {
6863 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006864 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006865 + subId + " retVal=false");
6866 }
6867 return false;
6868 }
6869 } finally {
6870 Binder.restoreCallingIdentity(identity);
6871 }
6872 }
6873
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006874 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006875 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006876 // No permission needed; this only lets the caller inspect their own status.
6877 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006878 }
Junda Liu29340342014-07-10 15:23:27 -07006879
6880 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006881 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006882 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006883 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6884 }
6885
6886 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6887 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006888 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006889 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006890 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6891 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006892 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6893 if (cpt == null) {
6894 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6896 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006897 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006898 }
6899
6900 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006901 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006902 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006903 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006904 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006905 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006906 Phone phone = getPhone(subId);
6907 if (phone == null) {
6908 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6909 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6910 }
6911 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6912 if (cpt == null) {
6913 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006914 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6915 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006916 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006917 }
6918
6919 @Override
6920 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006921 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006922 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6923 }
6924
6925 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006926 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006927 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006928 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006929 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006930 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6931 Phone phone = PhoneFactory.getPhone(phoneId);
6932 if (phone == null) {
6933 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006934 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006935 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6936 if (cpt == null) {
6937 continue;
6938 }
6939 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006940 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6941 break;
6942 }
6943 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006944 return result;
Junda Liu29340342014-07-10 15:23:27 -07006945 }
Derek Tan89e89d42014-07-08 17:00:10 -07006946
6947 @Override
Junda Liue64de782015-04-16 17:19:16 -07006948 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006949 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006950 Phone phone = PhoneFactory.getPhone(phoneId);
6951 if (phone == null) {
6952 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006953 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006954 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6955 if (cpt == null) {
6956 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006957 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006958 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006959 }
6960
Amith Yamasani6e118872016-02-19 12:53:51 -08006961 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006962 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006963 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006964 Phone phone = PhoneFactory.getPhone(phoneId);
6965 if (phone == null) {
6966 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006967 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006968 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6969 if (cpt == null) {
6970 return Collections.emptyList();
6971 }
6972 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006973 }
6974
chen xuf7e9fe82019-05-09 19:31:02 -07006975 @Override
6976 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006977 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006978 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006979 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006980 try {
6981 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6982 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6983 }
6984 } finally {
6985 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006986 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006987 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006988 }
6989
Rambo Wang6812ffb2022-03-15 16:54:17 -07006990 @Override
6991 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6992 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6993
6994 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6995 if (phone == null) {
6996 return null;
6997 }
6998 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6999 if (cpt == null) {
7000 return null;
7001 }
7002 return cpt.getCarrierServicePackageName();
7003 }
7004
Wink Savilleb564aae2014-10-23 10:18:09 -07007005 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007006 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007007 UiccPort port = phone == null ? null : phone.getUiccPort();
7008 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007009 return null;
7010 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007011 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007012 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007013 return null;
7014 }
7015 return iccId;
7016 }
7017
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007018 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007019 public void setCallComposerStatus(int subId, int status) {
7020 enforceModifyPermission();
7021
7022 final long identity = Binder.clearCallingIdentity();
7023 try {
7024 Phone phone = getPhone(subId);
7025 if (phone != null) {
7026 Phone defaultPhone = phone.getImsPhone();
7027 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7028 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7029 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007030 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7031 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007032 }
7033 }
Shuo Qian284ae752020-12-22 19:10:14 -08007034 } catch (ImsException e) {
7035 throw new ServiceSpecificException(e.getCode());
7036 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007037 Binder.restoreCallingIdentity(identity);
7038 }
7039 }
7040
7041 @Override
7042 public int getCallComposerStatus(int subId) {
7043 enforceReadPrivilegedPermission("getCallComposerStatus");
7044
7045 final long identity = Binder.clearCallingIdentity();
7046 try {
7047 Phone phone = getPhone(subId);
7048 if (phone != null) {
7049 Phone defaultPhone = phone.getImsPhone();
7050 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7051 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7052 return imsPhone.getCallComposerStatus();
7053 }
7054 }
7055 } finally {
7056 Binder.restoreCallingIdentity(identity);
7057 }
7058 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7059 }
7060
7061 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007062 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7063 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007064 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007065 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067 final long identity = Binder.clearCallingIdentity();
7068 try {
7069 final String iccId = getIccId(subId);
7070 final Phone phone = getPhone(subId);
7071 if (phone == null) {
7072 return false;
7073 }
7074 final String subscriberId = phone.getSubscriberId();
7075
7076 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007077 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078 + subscriberId + " to " + number);
7079 }
7080
7081 if (TextUtils.isEmpty(iccId)) {
7082 return false;
7083 }
7084
7085 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7086
7087 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7088 if (alphaTag == null) {
7089 editor.remove(alphaTagPrefKey);
7090 } else {
7091 editor.putString(alphaTagPrefKey, alphaTag);
7092 }
7093
7094 // Record both the line number and IMSI for this ICCID, since we need to
7095 // track all merged IMSIs based on line number
7096 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7097 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7098 if (number == null) {
7099 editor.remove(numberPrefKey);
7100 editor.remove(subscriberPrefKey);
7101 } else {
7102 editor.putString(numberPrefKey, number);
7103 editor.putString(subscriberPrefKey, subscriberId);
7104 }
7105
7106 editor.commit();
7107 return true;
7108 } finally {
7109 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007110 }
Derek Tan7226c842014-07-02 17:42:23 -07007111 }
7112
7113 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007114 public String getLine1NumberForDisplay(int subId, String callingPackage,
7115 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007116 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007118 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007119 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007120 return null;
7121 }
Derek Tan97ebb422014-09-05 16:55:38 -07007122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123 final long identity = Binder.clearCallingIdentity();
7124 try {
7125 String iccId = getIccId(subId);
7126 if (iccId != null) {
7127 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7128 if (DBG_MERGE) {
7129 log("getLine1NumberForDisplay returning "
7130 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7131 }
7132 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7135 return null;
7136 } finally {
7137 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007138 }
Derek Tan7226c842014-07-02 17:42:23 -07007139 }
7140
7141 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007142 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7143 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007145 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007146 return null;
7147 }
Derek Tan97ebb422014-09-05 16:55:38 -07007148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 String iccId = getIccId(subId);
7152 if (iccId != null) {
7153 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7154 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7155 }
7156 return null;
7157 } finally {
7158 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007159 }
Derek Tan7226c842014-07-02 17:42:23 -07007160 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007161
7162 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007163 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7164 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007165 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7166 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007168 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007169 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007170 return null;
7171 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007172
Jordan Liub49b04b2019-05-06 14:45:15 -07007173 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7174 // the process, where TelephonyManager was instantiated.
7175 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007176 final long identity = Binder.clearCallingIdentity();
7177 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007178 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 final TelephonyManager tele = TelephonyManager.from(context);
7180 final SubscriptionManager sub = SubscriptionManager.from(context);
7181
7182 // Figure out what subscribers are currently active
7183 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184
Jordan Liub49b04b2019-05-06 14:45:15 -07007185 // Only consider subs which match the current subId
7186 // This logic can be simplified. See b/131189269 for progress.
7187 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007188 activeSubscriberIds.add(tele.getSubscriberId(subId));
7189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190
7191 // First pass, find a number override for an active subscriber
7192 String mergeNumber = null;
7193 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7194 for (String key : prefs.keySet()) {
7195 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7196 final String subscriberId = (String) prefs.get(key);
7197 if (activeSubscriberIds.contains(subscriberId)) {
7198 final String iccId = key.substring(
7199 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7200 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7201 mergeNumber = (String) prefs.get(numberKey);
7202 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007203 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 + " for active subscriber " + subscriberId);
7205 }
7206 if (!TextUtils.isEmpty(mergeNumber)) {
7207 break;
7208 }
7209 }
7210 }
7211 }
7212
7213 // Shortcut when no active merged subscribers
7214 if (TextUtils.isEmpty(mergeNumber)) {
7215 return null;
7216 }
7217
7218 // Second pass, find all subscribers under that line override
7219 final ArraySet<String> result = new ArraySet<>();
7220 for (String key : prefs.keySet()) {
7221 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7222 final String number = (String) prefs.get(key);
7223 if (mergeNumber.equals(number)) {
7224 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7225 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7226 final String subscriberId = (String) prefs.get(subscriberKey);
7227 if (!TextUtils.isEmpty(subscriberId)) {
7228 result.add(subscriberId);
7229 }
7230 }
7231 }
7232 }
7233
7234 final String[] resultArray = result.toArray(new String[result.size()]);
7235 Arrays.sort(resultArray);
7236 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007237 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007238 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7239 }
7240 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007241 } finally {
7242 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007243 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007244 }
7245
7246 @Override
zoey chen38003472019-12-13 17:16:31 +08007247 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7248 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007249
7250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 final TelephonyManager telephonyManager = mApp.getSystemService(
7253 TelephonyManager.class);
7254 String subscriberId = telephonyManager.getSubscriberId(subId);
7255 if (subscriberId == null) {
7256 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007257 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007258 + subId);
7259 }
7260 return null;
7261 }
7262
7263 final SubscriptionInfo info = SubscriptionController.getInstance()
7264 .getSubscriptionInfo(subId);
7265 final ParcelUuid groupUuid = info.getGroupUuid();
7266 // If it doesn't belong to any group, return just subscriberId of itself.
7267 if (groupUuid == null) {
7268 return new String[]{subscriberId};
7269 }
7270
7271 // Get all subscriberIds from the group.
7272 final List<String> mergedSubscriberIds = new ArrayList<>();
7273 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007274 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007275 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007276 for (SubscriptionInfo subInfo : groupInfos) {
7277 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7278 if (subscriberId != null) {
7279 mergedSubscriberIds.add(subscriberId);
7280 }
7281 }
7282
7283 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7284 } finally {
7285 Binder.restoreCallingIdentity(identity);
7286
7287 }
7288 }
7289
7290 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007291 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007292 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007293 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007294
7295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 final Phone phone = getPhone(subId);
7298 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007302 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007303
7304 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007305 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007306 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7307 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007308 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7309 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310
7311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 final Phone phone = getPhone(subId);
7314 if (phone == null) {
7315 return false;
7316 }
7317 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7318 cdmaNonRoamingList);
7319 } finally {
7320 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007321 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007322 }
7323
7324 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007325 @Deprecated
7326 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7327 enforceModifyPermission();
7328
7329 int returnValue = 0;
7330 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007331 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007332 if(result.exception == null) {
7333 if (result.result != null) {
7334 byte[] responseData = (byte[])(result.result);
7335 if(responseData.length > oemResp.length) {
7336 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7337 responseData.length + "bytes. Buffer Size is " +
7338 oemResp.length + "bytes.");
7339 }
7340 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7341 returnValue = responseData.length;
7342 }
7343 } else {
7344 CommandException ex = (CommandException) result.exception;
7345 returnValue = ex.getCommandError().ordinal();
7346 if(returnValue > 0) returnValue *= -1;
7347 }
7348 } catch (RuntimeException e) {
7349 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7350 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7351 if(returnValue > 0) returnValue *= -1;
7352 }
7353
7354 return returnValue;
7355 }
7356
7357 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007358 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007359 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007360 try {
7361 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007362 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007363 mApp, phone.getSubId(), "getRadioAccessFamily");
7364 } catch (SecurityException e) {
7365 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7366 throw e;
7367 }
chen xub97461a2018-10-26 14:17:57 -07007368 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007369 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007370 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 final long identity = Binder.clearCallingIdentity();
7373 try {
chen xub97461a2018-10-26 14:17:57 -07007374 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007375 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007376 mApp, phone.getSubId(), "getRadioAccessFamily");
7377 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378 } finally {
7379 Binder.restoreCallingIdentity(identity);
7380 }
chen xub97461a2018-10-26 14:17:57 -07007381 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007382 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007383
7384 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007385 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007386 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007387 try {
7388 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7389 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007390 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007391 }
7392 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007393 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007394 }
7395 RoleManager rm = mApp.getSystemService(RoleManager.class);
7396 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7397 if (!dialerRoleHolders.contains(callingPackage)) {
7398 throw new SecurityException("App must be the dialer role holder to"
7399 + " upload a call composer pic");
7400 }
7401
7402 Executors.newSingleThreadExecutor().execute(() -> {
7403 ByteArrayOutputStream output = new ByteArrayOutputStream(
7404 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7405 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7406 boolean readUntilEnd = false;
7407 int totalBytesRead = 0;
7408 byte[] buffer = new byte[16 * 1024];
7409 while (true) {
7410 int numRead;
7411 try {
7412 numRead = input.read(buffer);
7413 } catch (IOException e) {
7414 try {
7415 fd.checkError();
7416 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7417 null);
7418 } catch (IOException e1) {
7419 // This means that the other side closed explicitly with an error. If this
7420 // happens, log and ignore.
7421 loge("Remote end of call composer picture pipe closed: " + e1);
7422 }
7423 break;
7424 }
7425 if (numRead == -1) {
7426 readUntilEnd = true;
7427 break;
7428 }
7429 totalBytesRead += numRead;
7430 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7431 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7432 try {
7433 input.close();
7434 } catch (IOException e) {
7435 // ignore
7436 }
7437 break;
7438 }
7439 output.write(buffer, 0, numRead);
7440 }
7441 // Generally, the remote end will close the file descriptors. The only case where we
7442 // close is above, where the picture size is too big.
7443
7444 try {
7445 fd.checkError();
7446 } catch (IOException e) {
7447 loge("Remote end for call composer closed with an error: " + e);
7448 return;
7449 }
7450
Hall Liuaa4211e2021-01-20 15:43:39 -08007451 if (!readUntilEnd) {
7452 loge("Did not finish reading entire image; aborting");
7453 return;
7454 }
Hall Liu82694d52020-12-11 18:22:04 -08007455
Hall Liuaa4211e2021-01-20 15:43:39 -08007456 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7457 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7458 new CallComposerPictureTransfer.Factory() {},
7459 imageData,
7460 (result) -> {
7461 if (result.first != null) {
7462 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7463 Bundle outputResult = new Bundle();
7464 outputResult.putParcelable(
7465 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7466 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7467 outputResult);
7468 } else {
7469 callback.send(result.second, null);
7470 }
7471 }
7472 );
Hall Liu82694d52020-12-11 18:22:04 -08007473 });
7474 }
7475
7476 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007477 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007478 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007479 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480
7481 final long identity = Binder.clearCallingIdentity();
7482 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007483 ImsManager.getInstance(defaultPhone.getContext(),
7484 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 } finally {
7486 Binder.restoreCallingIdentity(identity);
7487 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007488 }
7489
7490 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007491 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007492 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7494 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007495 return false;
7496 }
Svet Ganovb320e182015-04-16 12:30:10 -07007497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498 final long identity = Binder.clearCallingIdentity();
7499 try {
7500 // Check the user preference and the system-level IMS setting. Even if the user has
7501 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7502 // In the long run, we may instead need to check if there exists a connection service
7503 // which can support video calling.
7504 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007505 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506 return imsManager.isVtEnabledByPlatform()
7507 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7508 && imsManager.isVtEnabledByUser();
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007512 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007513
Andrew Leea1239f22015-03-02 17:44:07 -08007514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007515 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7516 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007518 mApp, subId, callingPackage, callingFeatureId,
7519 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 return false;
7521 }
7522
7523 final long identity = Binder.clearCallingIdentity();
7524 try {
7525 CarrierConfigManager configManager =
7526 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007527 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7529 } finally {
7530 Binder.restoreCallingIdentity(identity);
7531 }
Andrew Leea1239f22015-03-02 17:44:07 -08007532 }
7533
7534 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007535 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007537 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 return false;
7539 }
7540
7541 final long identity = Binder.clearCallingIdentity();
7542 try {
7543 CarrierConfigManager configManager =
7544 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007545 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007546 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
Andrew Leea1239f22015-03-02 17:44:07 -08007550 }
7551
Andrew Lee9431b832015-03-09 18:46:45 -07007552 @Override
7553 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007554 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007555 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007556 }
7557
7558 @Override
7559 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 final long identity = Binder.clearCallingIdentity();
7561 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007562 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563 } finally {
7564 Binder.restoreCallingIdentity(identity);
7565 }
Andrew Lee9431b832015-03-09 18:46:45 -07007566 }
7567
Hall Liuf6668912018-10-31 17:05:23 -07007568 /**
7569 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7570 * support for the feature and device firmware support.
7571 *
7572 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7573 */
7574 @Override
7575 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007576 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007577 final Phone phone = getPhone(subscriptionId);
7578 if (phone == null) {
7579 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7580 return false;
7581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007583 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007584 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7585 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007586 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 return isCarrierSupported && isDeviceSupported;
7588 } finally {
7589 Binder.restoreCallingIdentity(identity);
7590 }
Hall Liu98187582018-01-22 19:15:32 -08007591 }
7592
Hall Liuf6668912018-10-31 17:05:23 -07007593 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007594 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7595 * RTT setting, will return true if the device and carrier both support RTT.
7596 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007597 */
7598 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599 final long identity = Binder.clearCallingIdentity();
7600 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007601 boolean isRttSupported = isRttSupported(subscriptionId);
7602 boolean isUserRttSettingOn = Settings.Secure.getInt(
7603 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7604 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7605 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7606 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007607 } finally {
7608 Binder.restoreCallingIdentity(identity);
7609 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007610 }
7611
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007612 @Deprecated
7613 @Override
7614 public String getDeviceId(String callingPackage) {
7615 return getDeviceIdWithFeature(callingPackage, null);
7616 }
7617
Sanket Padawe7310cc72015-01-14 09:53:20 -08007618 /**
7619 * Returns the unique device ID of phone, for example, the IMEI for
7620 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7621 *
7622 * <p>Requires Permission:
7623 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7624 */
7625 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007626 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007627 try {
7628 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7629 } catch (SecurityException se) {
7630 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7631 throw new SecurityException("Package " + callingPackage + " does not belong to "
7632 + Binder.getCallingUid());
7633 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007634 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007635 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007636 return null;
7637 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007638 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007639 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007640 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007641 return null;
7642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643
7644 final long identity = Binder.clearCallingIdentity();
7645 try {
7646 return phone.getDeviceId();
7647 } finally {
7648 Binder.restoreCallingIdentity(identity);
7649 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007650 }
7651
Ping Sunc67b7c22016-03-02 19:16:45 +08007652 /**
7653 * {@hide}
7654 * Returns the IMS Registration Status on a particular subid
7655 *
7656 * @param subId
7657 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007658 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007659 Phone phone = getPhone(subId);
7660 if (phone != null) {
7661 return phone.isImsRegistered();
7662 } else {
7663 return false;
7664 }
7665 }
7666
Santos Cordon7a1885b2015-02-03 11:15:19 -08007667 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007668 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007669 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007671 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007672 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7673 }
7674 final long identity = Binder.clearCallingIdentity();
7675 try {
7676 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7677 } finally {
7678 Binder.restoreCallingIdentity(identity);
7679 }
7680 }
7681
7682 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007683 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007684 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007685 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007686 mApp,
7687 subscriptionId,
7688 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007689 final long identity = Binder.clearCallingIdentity();
7690 try {
7691 Phone phone = getPhone(subscriptionId);
7692 if (phone == null) {
7693 return null;
7694 }
7695 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7696 } finally {
7697 Binder.restoreCallingIdentity(identity);
7698 }
7699 }
7700
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007701 /**
7702 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007703 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007704 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007705 final long identity = Binder.clearCallingIdentity();
7706 try {
7707 Phone phone = getPhone(subId);
7708 if (phone != null) {
7709 return phone.isWifiCallingEnabled();
7710 } else {
7711 return false;
7712 }
7713 } finally {
7714 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007715 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007716 }
7717
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007718 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007719 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007720 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007721 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 final long identity = Binder.clearCallingIdentity();
7723 try {
7724 Phone phone = getPhone(subId);
7725 if (phone != null) {
7726 return phone.isVideoEnabled();
7727 } else {
7728 return false;
7729 }
7730 } finally {
7731 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007732 }
7733 }
7734
7735 /**
7736 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7737 * defined in {@link ImsRegistrationImplBase}.
7738 */
7739 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 final long identity = Binder.clearCallingIdentity();
7741 try {
7742 Phone phone = getPhone(subId);
7743 if (phone != null) {
7744 return phone.getImsRegistrationTech();
7745 } else {
7746 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7747 }
7748 } finally {
7749 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007750 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007751 }
7752
Stuart Scott8eef64f2015-04-08 15:13:54 -07007753 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007754 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007755 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007756 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7757 return;
7758 }
Kai Shif70f46f2021-03-03 13:59:46 -08007759 Phone defaultPhone = getDefaultPhone();
7760 if (defaultPhone != null) {
7761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7762 mApp, getDefaultPhone().getSubId(), "factoryReset");
7763 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007764 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007765
Svet Ganovcc087f82015-05-12 20:35:54 -07007766 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007767 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7768 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007769 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007770 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007771 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007772 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007773 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007774 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007775 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007776 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007777 // There has been issues when Sms raw table somehow stores orphan
7778 // fragments. They lead to garbled message when new fragments come
7779 // in and combined with those stale ones. In case this happens again,
7780 // user can reset all network settings which will clean up this table.
7781 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007782 // Clean up IMS settings as well here.
7783 int slotId = getSlotIndex(subId);
7784 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7785 ImsManager.getInstance(mApp, slotId).factoryReset();
7786 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007787
Kai Shif70f46f2021-03-03 13:59:46 -08007788 if (defaultPhone == null) {
7789 return;
7790 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007791 // Erase modem config if erase modem on network setting is enabled.
7792 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7793 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7794 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007795 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007796 }
Kai Shif70f46f2021-03-03 13:59:46 -08007797
7798 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007799 } finally {
7800 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007801 }
7802 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007803
SongFerngWangfd89b102021-05-27 22:44:54 +08007804 @VisibleForTesting
7805 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7806 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7807 return;
7808 }
7809 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7810 RILConstants.PREFERRED_NETWORK_MODE);
7811 SubscriptionManager.setSubscriptionProperty(subId,
7812 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7813 "user=" + defaultNetworkType);
7814 phone.loadAllowedNetworksFromSubscriptionDatabase();
7815 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7816 defaultNetworkType, null);
7817 }
7818
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007819 private void cleanUpSmsRawTable(Context context) {
7820 ContentResolver resolver = context.getContentResolver();
7821 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7822 resolver.delete(uri, null, null);
7823 }
7824
Narayan Kamath1c496c22015-04-16 14:40:19 +01007825 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007826 public String getSimLocaleForSubscriber(int subId) {
7827 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7828 final Phone phone = getPhone(subId);
7829 if (phone == null) {
7830 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007831 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007833 final long identity = Binder.clearCallingIdentity();
7834 try {
chen xu5d3637b2019-01-21 23:31:38 -08007835 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007836 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007837 if (info == null) {
7838 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7839 return null;
7840 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841 // Try and fetch the locale from the carrier properties or from the SIM language
7842 // preferences (EF-PL and EF-LI)...
7843 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007845 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7846 if (localeFromDefaultSim != null) {
7847 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7848 if (DBG) log("Using locale from subId: " + subId + " locale: "
7849 + localeFromDefaultSim);
Greg Kaiser4380e732022-10-25 16:07:20 +00007850 return matchLocaleFromSupportedLocaleList(localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007851 } else {
7852 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 }
7854 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007855
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856 // The SIM language preferences only store a language (e.g. fr = French), not an
7857 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7858 // the SIM and carrier preferences does not include a country we add the country
7859 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007860 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007862 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Greg Kaiser4380e732022-10-25 16:07:20 +00007863 return matchLocaleFromSupportedLocaleList(mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 }
7865
7866 if (DBG) log("No locale found - returning null");
7867 return null;
7868 } finally {
7869 Binder.restoreCallingIdentity(identity);
7870 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007871 }
7872
tom hsu0b59d292022-09-29 23:49:21 +08007873 @VisibleForTesting
Greg Kaiser4380e732022-10-25 16:07:20 +00007874 String matchLocaleFromSupportedLocaleList(@NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007875 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
Greg Kaiser4380e732022-10-25 16:07:20 +00007876 getDefaultPhone().getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007877 for (String localeTag : supportedLocale) {
7878 if (LocaleList.matchesLanguageAndScript(
7879 inputLocale, Locale.forLanguageTag(localeTag))
7880 && inputLocale.getCountry().equals(
7881 Locale.forLanguageTag(localeTag).getCountry())) {
7882 return localeTag;
7883 }
7884 }
7885 return inputLocale.toLanguageTag();
7886 }
7887
Narayan Kamath1c496c22015-04-16 14:40:19 +01007888 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007889 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007890 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007891 }
7892
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007893 /**
7894 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7895 */
7896 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007897 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007898 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007899 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007900
Gary Jian3aa9a762022-01-24 16:41:19 +08007901 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7902 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007903
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007904 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007905 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7906 * representing the state of the modem.
7907 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007908 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7909 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007910 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007911 */
7912 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007913 public void requestModemActivityInfo(ResultReceiver result) {
7914 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007915 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007916
7917 final long identity = Binder.clearCallingIdentity();
7918 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007919 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920 } finally {
7921 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007922 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007923 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007924
Siddharth Rayb8114062018-06-17 15:02:38 -07007925 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7926 // less than total activity duration.
7927 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7928 if (info == null) {
7929 return false;
7930 }
7931 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007932 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7933 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7934
Siddharth Rayb8114062018-06-17 15:02:38 -07007935 return (info.isValid()
7936 && (info.getSleepTimeMillis() <= activityDurationMs)
7937 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007938 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007939 && (totalTxTimeMs <= activityDurationMs));
7940 }
7941
Gary Jian3aa9a762022-01-24 16:41:19 +08007942 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7943 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7944 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7945 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7946
7947 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7948 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7949 }
7950
7951 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7952 mLastModemActivityInfo.setReceiveTimeMillis(
7953 rat,
7954 freq,
7955 info.getReceiveTimeMillis(rat, freq)
7956 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7957 }
7958
7959 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7960 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7961 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7962 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7963
7964 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7965 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7966 }
7967 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7968 mLastModemActivityInfo.setReceiveTimeMillis(
7969 rat,
7970 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7971 }
7972
7973 /**
7974 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7975 * @param info recent ModemActivityInfo
7976 */
7977 private void mergeModemActivityInfo(ModemActivityInfo info) {
7978 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7979 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7980 boolean matched;
7981 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7982 matched = false;
7983 int rat = info.getSpecificInfoRat(i);
7984 int freq = info.getSpecificInfoFrequencyRange(i);
7985 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7986 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7987 //if it already exists
7988 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7989 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7990 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7991 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7992 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7993 updateLastModemActivityInfo(info, rat, freq);
7994 matched = true;
7995 }
7996 } else {
7997 updateLastModemActivityInfo(info, rat);
7998 matched = true;
7999 }
8000 }
8001 }
8002
8003 if (!matched) {
8004 mDeltaSpecificInfo =
8005 new ActivityStatsTechSpecificInfo(
8006 rat,
8007 freq,
8008 info.getTransmitTimeMillis(rat, freq),
8009 (int) info.getReceiveTimeMillis(rat, freq));
8010 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
8011 }
8012 }
8013 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8014 mLastModemActivitySpecificInfo =
8015 new ActivityStatsTechSpecificInfo[merged.size()];
8016 merged.toArray(mLastModemActivitySpecificInfo);
8017
8018 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8019 mLastModemActivityInfo.setSleepTimeMillis(
8020 info.getSleepTimeMillis()
8021 + mLastModemActivityInfo.getSleepTimeMillis());
8022 mLastModemActivityInfo.setIdleTimeMillis(
8023 info.getIdleTimeMillis()
8024 + mLastModemActivityInfo.getIdleTimeMillis());
8025 }
8026
Jack Yu85bd38a2015-11-09 11:34:32 -08008027 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008028 * Returns the service state information on specified subscription.
8029 */
8030 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008031 public ServiceState getServiceStateForSubscriber(int subId,
8032 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8033 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008035 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008036 return null;
8037 }
8038
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008039 boolean hasFinePermission = false;
8040 boolean hasCoarsePermission = false;
8041 if (!renounceFineLocationAccess) {
8042 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8043 LocationAccessPolicy.checkLocationPermission(mApp,
8044 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8045 .setCallingPackage(callingPackage)
8046 .setCallingFeatureId(callingFeatureId)
8047 .setCallingPid(Binder.getCallingPid())
8048 .setCallingUid(Binder.getCallingUid())
8049 .setMethod("getServiceStateForSubscriber")
8050 .setLogAsInfo(true)
8051 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8052 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8053 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8054 .build());
8055 hasFinePermission =
8056 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8057 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008058
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008059 if (!renounceCoarseLocationAccess) {
8060 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8061 LocationAccessPolicy.checkLocationPermission(mApp,
8062 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8063 .setCallingPackage(callingPackage)
8064 .setCallingFeatureId(callingFeatureId)
8065 .setCallingPid(Binder.getCallingPid())
8066 .setCallingUid(Binder.getCallingUid())
8067 .setMethod("getServiceStateForSubscriber")
8068 .setLogAsInfo(true)
8069 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8070 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8071 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8072 .build());
8073 hasCoarsePermission =
8074 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8075 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008076
Jack Yu479f40e2020-10-27 21:29:25 -07008077 final Phone phone = getPhone(subId);
8078 if (phone == null) {
8079 return null;
8080 }
8081
Jordan Liu0f2bc442020-11-18 16:47:37 -08008082 final long identity = Binder.clearCallingIdentity();
8083
Jack Yu479f40e2020-10-27 21:29:25 -07008084 boolean isCallingPackageDataService = phone.getDataServicePackages()
8085 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008087 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8088 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8089 Rlog.d(LOG_TAG,
8090 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8091 return null;
8092 }
8093
Hall Liuf19c44f2018-11-27 14:38:17 -08008094 ServiceState ss = phone.getServiceState();
8095
8096 // Scrub out the location info in ServiceState depending on what level of access
8097 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008098 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008099 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8100 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008104 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008105
8106 /**
8107 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8108 *
8109 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8110 * voicemail ringtone.
8111 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8112 * PhoneAccount.
8113 */
8114 @Override
8115 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008116 final long identity = Binder.clearCallingIdentity();
8117 try {
8118 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8119 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008120 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008123 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8124 } finally {
8125 Binder.restoreCallingIdentity(identity);
8126 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008127 }
8128
8129 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008130 * Sets the per-account voicemail ringtone.
8131 *
8132 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8133 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8134 *
8135 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8136 * voicemail ringtone.
8137 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8138 * PhoneAccount.
8139 */
8140 @Override
8141 public void setVoicemailRingtoneUri(String callingPackage,
8142 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008143 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008144 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008145 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8146 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8148 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8149 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008151
8152 final long identity = Binder.clearCallingIdentity();
8153 try {
8154 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8155 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008156 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008157 }
8158 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8159 } finally {
8160 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008161 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008162 }
8163
8164 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008165 * Returns whether vibration is set for voicemail notification in Phone settings.
8166 *
8167 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8168 * voicemail vibration setting.
8169 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8170 */
8171 @Override
8172 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 final long identity = Binder.clearCallingIdentity();
8174 try {
8175 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8176 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008177 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8181 } finally {
8182 Binder.restoreCallingIdentity(identity);
8183 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008184 }
8185
Youhan Wange64578a2016-05-02 15:32:42 -07008186 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008187 * Sets the per-account voicemail vibration.
8188 *
8189 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8190 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8191 *
8192 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8193 * voicemail vibration setting.
8194 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8195 * specific PhoneAccount.
8196 */
8197 @Override
8198 public void setVoicemailVibrationEnabled(String callingPackage,
8199 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008200 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008201 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008202 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8203 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8205 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8206 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008207 }
8208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 final long identity = Binder.clearCallingIdentity();
8210 try {
8211 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8212 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008213 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 }
8215 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8216 } finally {
8217 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008218 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008219 }
8220
8221 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008222 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8223 *
8224 * @throws SecurityException if the caller does not have the required permission
8225 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008226 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008227 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008228 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008229 }
8230
8231 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008232 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8233 * permission.
8234 *
8235 * @throws SecurityException if the caller does not have the required permission
8236 */
8237 private void enforceSendSmsPermission() {
8238 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8239 }
8240
8241 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008242 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008243 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008244 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008245 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008246 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 final long identity = Binder.clearCallingIdentity();
8248 try {
8249 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008250 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251 if (componentName == null) {
8252 throw new SecurityException(
8253 "Caller not current active visual voicemail package[null]");
8254 }
8255 String vvmPackage = componentName.getPackageName();
8256 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008257 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 }
8259 } finally {
8260 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008261 }
8262 }
8263
8264 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008265 * Return the application ID for the app type.
8266 *
8267 * @param subId the subscription ID that this request applies to.
8268 * @param appType the uicc app type.
8269 * @return Application ID for specificied app type, or null if no uicc.
8270 */
8271 @Override
8272 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008273 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008274 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275
8276 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008277 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 if (phone == null) {
8279 return null;
8280 }
8281 String aid = null;
8282 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008283 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284 .getApplicationByType(appType).getAid();
8285 } catch (Exception e) {
8286 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8287 }
8288 return aid;
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008291 }
Youhan Wange64578a2016-05-02 15:32:42 -07008292 }
8293
Youhan Wang4001d252016-05-11 10:29:41 -07008294 /**
8295 * Return the Electronic Serial Number.
8296 *
8297 * @param subId the subscription ID that this request applies to.
8298 * @return ESN or null if error.
8299 */
8300 @Override
8301 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008302 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008303 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304
8305 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008306 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307 if (phone == null) {
8308 return null;
8309 }
8310 String esn = null;
8311 try {
8312 esn = phone.getEsn();
8313 } catch (Exception e) {
8314 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8315 }
8316 return esn;
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008319 }
Youhan Wang4001d252016-05-11 10:29:41 -07008320 }
8321
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008322 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008323 * Return the Preferred Roaming List Version.
8324 *
8325 * @param subId the subscription ID that this request applies to.
8326 * @return PRLVersion or null if error.
8327 */
8328 @Override
8329 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008330 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008331 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008332
8333 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008334 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335 if (phone == null) {
8336 return null;
8337 }
8338 String cdmaPrlVersion = null;
8339 try {
8340 cdmaPrlVersion = phone.getCdmaPrlVersion();
8341 } catch (Exception e) {
8342 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8343 }
8344 return cdmaPrlVersion;
8345 } finally {
8346 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008347 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008348 }
8349
8350 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008351 * Get snapshot of Telephony histograms
8352 * @return List of Telephony histograms
8353 * @hide
8354 */
8355 @Override
8356 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8358 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008359
8360 final long identity = Binder.clearCallingIdentity();
8361 try {
8362 return RIL.getTelephonyRILTimingHistograms();
8363 } finally {
8364 Binder.restoreCallingIdentity(identity);
8365 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008366 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008367
8368 /**
8369 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008370 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8371 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008372 * Require system privileges. In the future we may add this to carrier APIs.
8373 *
Michele Berionne482f8202018-11-27 18:57:59 -08008374 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008375 */
8376 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008377 @TelephonyManager.SetCarrierRestrictionResult
8378 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008379 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008380 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008381
Michele Berionne482f8202018-11-27 18:57:59 -08008382 if (carrierRestrictionRules == null) {
8383 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008384 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386 final long identity = Binder.clearCallingIdentity();
8387 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008388 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008389 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390 } finally {
8391 Binder.restoreCallingIdentity(identity);
8392 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008393 }
8394
8395 /**
8396 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008397 * Get the allowed carrier list and the excluded carrier list, including the priority between
8398 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008399 * Require system privileges. In the future we may add this to carrier APIs.
8400 *
Michele Berionne482f8202018-11-27 18:57:59 -08008401 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008402 */
8403 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008404 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008405 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008406 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407
8408 final long identity = Binder.clearCallingIdentity();
8409 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008410 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8411 if (response instanceof CarrierRestrictionRules) {
8412 return (CarrierRestrictionRules) response;
8413 }
8414 // Response is an Exception of some kind,
8415 // which is signalled to the user as a NULL retval
8416 return null;
8417 } catch (Exception e) {
8418 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8419 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008420 } finally {
8421 Binder.restoreCallingIdentity(identity);
8422 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008423 }
8424
fionaxu59545b42016-05-25 15:53:37 -07008425 /**
fionaxu59545b42016-05-25 15:53:37 -07008426 * Action set from carrier signalling broadcast receivers to enable/disable radio
8427 * @param subId the subscription ID that this action applies to.
8428 * @param enabled control enable or disable radio.
8429 * {@hide}
8430 */
8431 @Override
8432 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8433 enforceModifyPermission();
8434 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008435
8436 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008437 if (phone == null) {
8438 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8439 return;
8440 }
8441 try {
8442 phone.carrierActionSetRadioEnabled(enabled);
8443 } catch (Exception e) {
8444 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445 } finally {
8446 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008447 }
8448 }
8449
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008450 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008451 * Enable or disable Voice over NR (VoNR)
8452 * @param subId the subscription ID that this action applies to.
8453 * @param enabled enable or disable VoNR.
8454 * @return operation result.
8455 */
8456 @Override
8457 public int setVoNrEnabled(int subId, boolean enabled) {
8458 enforceModifyPermission();
8459 final Phone phone = getPhone(subId);
8460
8461 final long identity = Binder.clearCallingIdentity();
8462 if (phone == null) {
8463 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8464 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8465 }
8466
8467 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8468 try {
8469 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8470 workSource);
8471 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008472
8473 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8474 if (DBG) {
8475 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8476 }
8477 SubscriptionManager.setSubscriptionProperty(
8478 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8479 (enabled ? "1" : "0"));
8480 }
8481
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008482 return result;
8483 } finally {
8484 Binder.restoreCallingIdentity(identity);
8485 }
8486 }
8487
8488 /**
8489 * Is voice over NR enabled
8490 * @return true if VoNR is enabled else false
8491 */
8492 @Override
8493 public boolean isVoNrEnabled(int subId) {
8494 enforceReadPrivilegedPermission("isVoNrEnabled");
8495 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8496 final long identity = Binder.clearCallingIdentity();
8497 try {
8498 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8499 null, subId, workSource);
8500 if (DBG) log("isVoNrEnabled: " + isEnabled);
8501 return isEnabled;
8502 } finally {
8503 Binder.restoreCallingIdentity(identity);
8504 }
8505 }
8506
8507 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008508 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8509 * network status based on which carrier apps could apply actions accordingly,
8510 * enable/disable default url handler for example.
8511 *
8512 * @param subId the subscription ID that this action applies to.
8513 * @param report control start/stop reporting the default network status.
8514 * {@hide}
8515 */
8516 @Override
8517 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8518 enforceModifyPermission();
8519 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520
8521 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008522 if (phone == null) {
8523 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8524 return;
8525 }
8526 try {
8527 phone.carrierActionReportDefaultNetworkStatus(report);
8528 } catch (Exception e) {
8529 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008530 } finally {
8531 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008532 }
8533 }
8534
8535 /**
fionaxud9622282017-07-17 17:51:30 -07008536 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8537 * @param subId the subscription ID that this action applies to.
8538 * {@hide}
8539 */
8540 @Override
8541 public void carrierActionResetAll(int subId) {
8542 enforceModifyPermission();
8543 final Phone phone = getPhone(subId);
8544 if (phone == null) {
8545 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8546 return;
8547 }
8548 try {
8549 phone.carrierActionResetAll();
8550 } catch (Exception e) {
8551 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8552 }
8553 }
8554
8555 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008556 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8557 * bug report is being generated.
8558 */
8559 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008560 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008561 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8562 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008563 writer.println("Permission Denial: can't dump Phone from pid="
8564 + Binder.getCallingPid()
8565 + ", uid=" + Binder.getCallingUid()
8566 + "without permission "
8567 + android.Manifest.permission.DUMP);
8568 return;
8569 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008570 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008571 }
Jack Yueb89b242016-06-22 13:27:47 -07008572
Brad Ebingerdac2f002018-04-03 15:17:52 -07008573 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008574 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8575 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8576 @NonNull String[] args) {
8577 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8578 this, in.getFileDescriptor(), out.getFileDescriptor(),
8579 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008580 }
8581
Jack Yueb89b242016-06-22 13:27:47 -07008582 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008583 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008584 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008585 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008586 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008587 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008588 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008589 */
8590 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008591 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008592 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008593 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8594 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8595 try {
8596 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008597 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008598 } catch (SecurityException se) {
8599 enforceModifyPermission();
8600 }
8601 } else {
8602 enforceModifyPermission();
8603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008604
8605 final long identity = Binder.clearCallingIdentity();
8606 try {
8607 Phone phone = getPhone(subId);
8608 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008609 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8610 phone.carrierActionSetMeteredApnsEnabled(enabled);
8611 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008612 phone.getDataSettingsManager().setDataEnabled(
8613 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008615 }
8616 } finally {
8617 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008618 }
8619 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008620
8621 /**
8622 * Get Client request stats
8623 * @return List of Client Request Stats
8624 * @hide
8625 */
8626 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008627 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8628 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008630 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008631 return null;
8632 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008633 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008635 final long identity = Binder.clearCallingIdentity();
8636 try {
8637 if (phone != null) {
8638 return phone.getClientRequestStats();
8639 }
8640
8641 return null;
8642 } finally {
8643 Binder.restoreCallingIdentity(identity);
8644 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008645 }
8646
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008647 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008648 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008649 if (uid == Process.ROOT_UID && packageName == null) {
8650 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8651 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8652 // exception. ROOT_UID seems not to have a valid package name returned by
8653 // PackageManager, so just fake it here to avoid issues when running telephony shell
8654 // commands that plumb through the RIL as root, like so:
8655 // $ adb root
8656 // $ adb shell cmd phone ...
8657 packageName = "root";
8658 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008659 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008660 }
Jack Yueb4124c2017-02-16 15:32:43 -08008661
8662 /**
Grace Chen70990072017-03-24 17:21:30 -07008663 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008664 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008665 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008666 * @param state State of SIM (power down, power up, pass through)
8667 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8668 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8669 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008670 *
8671 **/
8672 @Override
Grace Chen70990072017-03-24 17:21:30 -07008673 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008674 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008675 Phone phone = PhoneFactory.getPhone(slotIndex);
8676
vagdeviaf9a5b92018-08-15 16:01:53 -07008677 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008679 final long identity = Binder.clearCallingIdentity();
8680 try {
8681 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008682 phone.setSimPowerState(state, null, workSource);
8683 }
8684 } finally {
8685 Binder.restoreCallingIdentity(identity);
8686 }
8687 }
8688
8689 /**
8690 * Set SIM card power state.
8691 *
8692 * @param slotIndex SIM slot id.
8693 * @param state State of SIM (power down, power up, pass through)
8694 * @param callback callback to trigger after success or failure
8695 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8696 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8697 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8698 *
8699 **/
8700 @Override
8701 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8702 IIntegerConsumer callback) {
8703 enforceModifyPermission();
8704 Phone phone = PhoneFactory.getPhone(slotIndex);
8705
8706 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8707
8708 final long identity = Binder.clearCallingIdentity();
8709 try {
8710 if (phone != null) {
8711 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8712 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008713 }
8714 } finally {
8715 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008716 }
8717 }
Shuo Qiandd210312017-04-12 22:11:33 +00008718
Tyler Gunn65d45c22017-06-05 11:22:26 -07008719 private boolean isUssdApiAllowed(int subId) {
8720 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008721 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008722 if (configManager == null) {
8723 return false;
8724 }
8725 PersistableBundle pb = configManager.getConfigForSubId(subId);
8726 if (pb == null) {
8727 return false;
8728 }
8729 return pb.getBoolean(
8730 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8731 }
8732
Shuo Qiandd210312017-04-12 22:11:33 +00008733 /**
8734 * Check if phone is in emergency callback mode
8735 * @return true if phone is in emergency callback mode
8736 * @param subId sub id
8737 */
goneil9c5f4872017-12-05 14:07:56 -08008738 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008739 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008740 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008741 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008742
8743 final long identity = Binder.clearCallingIdentity();
8744 try {
8745 if (phone != null) {
8746 return phone.isInEcm();
8747 } else {
8748 return false;
8749 }
8750 } finally {
8751 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008752 }
8753 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008754
8755 /**
8756 * Get the current signal strength information for the given subscription.
8757 * Because this information is not updated when the device is in a low power state
8758 * it should not be relied-upon to be current.
8759 * @param subId Subscription index
8760 * @return the most recent cached signal strength info from the modem
8761 */
8762 @Override
8763 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008764 final long identity = Binder.clearCallingIdentity();
8765 try {
8766 Phone p = getPhone(subId);
8767 if (p == null) {
8768 return null;
8769 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008771 return p.getSignalStrength();
8772 } finally {
8773 Binder.restoreCallingIdentity(identity);
8774 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008775 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008776
Pengquan Meng77b7f132018-08-22 14:49:57 -07008777 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008778 * Get the current modem radio state for the given slot.
8779 * @param slotIndex slot index.
8780 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008781 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008782 * @return the current radio power state from the modem
8783 */
8784 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008785 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008786 Phone phone = PhoneFactory.getPhone(slotIndex);
8787 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008788 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8789 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008790 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8791 }
8792
8793 final long identity = Binder.clearCallingIdentity();
8794 try {
8795 return phone.getRadioPowerState();
8796 } finally {
8797 Binder.restoreCallingIdentity(identity);
8798 }
8799 }
8800 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8801 }
8802
8803 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008804 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8805 *
8806 * <p>Requires one of the following permissions:
8807 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008808 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008809 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8810 * privileges.
8811 *
8812 * @param subId subscription id
8813 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8814 * {@code false}.
8815 */
8816 @Override
8817 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008818 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008819 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008820 try {
8821 mApp.enforceCallingOrSelfPermission(
8822 android.Manifest.permission.ACCESS_NETWORK_STATE,
8823 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008824 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008825 mApp.enforceCallingOrSelfPermission(
8826 permission.READ_BASIC_PHONE_STATE, functionName);
8827 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008828 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008829 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008830 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008831 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008832
Pengquan Menga1bb6272018-09-06 09:59:22 -07008833 boolean isEnabled = false;
8834 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008835 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008836 Phone phone = getPhone(subId);
8837 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008838 } finally {
8839 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008840 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008841 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008842 }
8843
8844
8845 /**
8846 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8847 *
8848 * <p> Requires permission:
8849 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8850 * privileges.
8851 *
8852 * @param subId subscription id
8853 * @param isEnabled {@code true} means enable, {@code false} means disable.
8854 */
8855 @Override
8856 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8858 mApp, subId, "setDataRoamingEnabled");
8859
Pengquan Menga1bb6272018-09-06 09:59:22 -07008860 final long identity = Binder.clearCallingIdentity();
8861 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008862 Phone phone = getPhone(subId);
8863 if (phone != null) {
8864 phone.setDataRoamingEnabled(isEnabled);
8865 }
8866 } finally {
8867 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008868 }
8869 }
8870
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008871 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008872 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008873 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008874 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008875 mApp, subId, "isManualNetworkSelectionAllowed");
8876
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008877 boolean isAllowed = true;
8878 final long identity = Binder.clearCallingIdentity();
8879 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008880 Phone phone = getPhone(subId);
8881 if (phone != null) {
8882 isAllowed = phone.isCspPlmnEnabled();
8883 }
8884 } finally {
8885 Binder.restoreCallingIdentity(identity);
8886 }
8887 return isAllowed;
8888 }
8889
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008890 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8891 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008892 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008893 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008894 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008895 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8896 if (phone == null) {
8897 return false;
8898 }
8899 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8900 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8901 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008902 }
8903
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008904 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008905 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008906 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008907 mApp.getSystemService(AppOpsManager.class)
8908 .checkPackage(Binder.getCallingUid(), callingPackage);
8909
Jordan Liu1e142fc2019-04-22 15:10:43 -07008910 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008911 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008912 try {
8913 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008914 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008915 } catch (SecurityException e) {
8916 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8917 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008918 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008919 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008920 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008921 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008922 }
sandeepjsb6c87872021-09-27 15:34:44 +00008923 // checking compatibility, if calling app's target SDK is T and beyond.
8924 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8925 Binder.getCallingUid())) {
8926 isIccIdAccessRestricted = true;
8927 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008928 final long identity = Binder.clearCallingIdentity();
8929 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008930 UiccController uiccController = UiccController.getInstance();
8931 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008932 if (hasReadPermission) {
8933 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008934 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008935
8936 // Remove private info if the caller doesn't have access
8937 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8938 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008939 //setting the value after compatibility check
8940 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008941 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8942 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008943 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008944 if (card == null) {
8945 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008946 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008947 continue;
8948 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008949 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8950 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008951 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008952 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008953 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008954 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8955 for (UiccPortInfo portInfo : portInfos) {
8956 UiccPort port = uiccController.getUiccPortForSlot(
8957 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8958 if (port == null) {
8959 // assume no access if port is null
8960 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8961 continue;
8962 }
8963 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8964 uiccPortInfos.add(portInfo);
8965 } else {
8966 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8967 }
8968 }
8969 filteredInfos.add(new UiccCardInfo(
8970 cardInfo.isEuicc(),
8971 cardInfo.getCardId(),
8972 null,
8973 cardInfo.getPhysicalSlotIndex(),
8974 cardInfo.isRemovable(),
8975 cardInfo.isMultipleEnabledProfilesSupported(),
8976 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008977 }
8978 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008979 } finally {
8980 Binder.restoreCallingIdentity(identity);
8981 }
8982 }
8983
sandeepjsb6c87872021-09-27 15:34:44 +00008984 /**
8985 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8986 * generally private and require carrier privileges to view.
8987 *
8988 * @hide
8989 */
8990 @NonNull
8991 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8992 List<UiccPortInfo> portinfo = new ArrayList<>();
8993 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8994 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8995 }
8996 return new UiccCardInfo(
8997 cardInfo.isEuicc(),
8998 cardInfo.getCardId(),
8999 null,
9000 cardInfo.getPhysicalSlotIndex(),
9001 cardInfo.isRemovable(),
9002 cardInfo.isMultipleEnabledProfilesSupported(),
9003 portinfo
9004 );
9005 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009006
sandeepjsb6c87872021-09-27 15:34:44 +00009007 /**
9008 * @hide
9009 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9010 * These values are generally private and require carrier privileges to view.
9011 */
9012 @NonNull
9013 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9014 return new UiccPortInfo(
9015 UiccPortInfo.ICCID_REDACTED,
9016 portInfo.getPortIndex(),
9017 portInfo.getLogicalSlotIndex(),
9018 portInfo.isActive()
9019 );
9020 }
9021 @Override
9022 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009023 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009024 mApp.getSystemService(AppOpsManager.class)
9025 .checkPackage(Binder.getCallingUid(), callingPackage);
9026
sandeepjsb6c87872021-09-27 15:34:44 +00009027 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009028
Aman Guptaf3c90b32022-03-17 04:54:16 +00009029 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9030 // we are reading iccId which is PII data.
9031 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009032
9033 // checking compatibility, if calling app's target SDK is T and beyond.
9034 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9035 Binder.getCallingUid())) {
9036 isLogicalSlotAccessRestricted = true;
9037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009038 final long identity = Binder.clearCallingIdentity();
9039 try {
9040 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009041 if (slots == null || slots.length == 0) {
9042 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009043 return null;
9044 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009045 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9046 for (int i = 0; i < slots.length; i++) {
9047 UiccSlot slot = slots[i];
9048 if (slot == null) {
9049 continue;
9050 }
9051
Jordan Liu7be7e652019-05-06 18:55:02 +00009052 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009053 UiccCard card = slot.getUiccCard();
9054 if (card != null) {
9055 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009056 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009057 cardId = slot.getEid();
9058 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009059 // If cardId is null, use iccId of default port as cardId.
9060 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009062 }
9063
Jordan Liu857451f2019-05-09 16:35:35 -07009064 if (cardId != null) {
9065 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9066 // if cardId is an EID, it's all digits so this is fine
9067 cardId = IccUtils.stripTrailingFs(cardId);
9068 }
9069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009070 int cardState = 0;
9071 switch (slot.getCardState()) {
9072 case CARDSTATE_ABSENT:
9073 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9074 break;
9075 case CARDSTATE_PRESENT:
9076 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9077 break;
9078 case CARDSTATE_ERROR:
9079 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9080 break;
9081 case CARDSTATE_RESTRICTED:
9082 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9083 break;
9084 default:
9085 break;
9086
9087 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009088 List<UiccPortInfo> portInfos = new ArrayList<>();
9089 int[] portIndexes = slot.getPortList();
9090 for (int portIdx : portIndexes) {
9091 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009092 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009093 portInfos.add(new UiccPortInfo(iccId, portIdx,
9094 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009096 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009097 slot.isEuicc(),
9098 cardId,
9099 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009100 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009101 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009102 //setting the value after compatibility check
9103 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009104 }
9105 return infos;
9106 } finally {
9107 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009108 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009109 }
9110
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009111 /* Returns null if doesn't have read permission or carrier privilege access. */
9112 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9113 boolean hasReadPermission) {
9114 String iccId = slot.getIccId(portIndex);
9115 if (hasReadPermission) { // if has read permission
9116 return iccId;
9117 } else {
9118 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9119 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9120 // if no read permission, checking carrier privilege access
9121 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9122 return iccId;
9123 }
9124 }
9125 }
9126 // No read permission or carrier privilege access.
9127 return UiccPortInfo.ICCID_REDACTED;
9128 }
9129
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009130 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009131 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009132 public boolean switchSlots(int[] physicalSlots) {
9133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134
9135 final long identity = Binder.clearCallingIdentity();
9136 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009137 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9138 for (int i = 0; i < physicalSlots.length; i++) {
9139 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9140 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9141 physicalSlots[i], i));
9142 }
9143 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009144 } finally {
9145 Binder.restoreCallingIdentity(identity);
9146 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009147 }
Jack Yu4c988042018-02-27 15:30:01 -08009148
9149 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009150 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9151 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9152 enforceModifyPermission();
9153
9154 final long identity = Binder.clearCallingIdentity();
9155 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009156 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009157 } finally {
9158 Binder.restoreCallingIdentity(identity);
9159 }
9160 }
9161
9162 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009163 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009164 final long identity = Binder.clearCallingIdentity();
9165 try {
9166 return UiccController.getInstance().getCardIdForDefaultEuicc();
9167 } finally {
9168 Binder.restoreCallingIdentity(identity);
9169 }
9170 }
9171
Pengquan Meng85728fb2018-03-12 16:31:21 -07009172 /**
goneil47ffb6e2018-04-06 15:40:58 -07009173 * A test API to reload the UICC profile.
9174 *
9175 * <p>Requires that the calling app has permission
9176 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9177 * @hide
9178 */
9179 @Override
9180 public void refreshUiccProfile(int subId) {
9181 enforceModifyPermission();
9182
9183 final long identity = Binder.clearCallingIdentity();
9184 try {
9185 Phone phone = getPhone(subId);
9186 if (phone == null) {
9187 return;
9188 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009189 UiccPort uiccPort = phone.getUiccPort();
9190 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009191 return;
9192 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009193 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009194 if (uiccProfile == null) {
9195 return;
9196 }
9197 uiccProfile.refresh();
9198 } finally {
9199 Binder.restoreCallingIdentity(identity);
9200 }
9201 }
9202
9203 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009204 * Returns false if the mobile data is disabled by default, otherwise return true.
9205 */
9206 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009207 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009208 }
9209
9210 /**
9211 * Returns true if the data roaming is enabled by default, i.e the system property
9212 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9213 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9214 */
9215 private boolean getDefaultDataRoamingEnabled(int subId) {
9216 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009217 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009218 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009219 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9220 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9221 return isDataRoamingEnabled;
9222 }
9223
9224 /**
9225 * Returns the default network type for the given {@code subId}, if the default network type is
9226 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9227 */
9228 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009229 List<Integer> list = TelephonyProperties.default_network();
9230 int phoneId = mSubscriptionController.getPhoneId(subId);
9231 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9232 return list.get(phoneId);
9233 }
9234 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009235 }
fionaxua13278b2018-03-21 00:08:13 -07009236
9237 @Override
9238 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009239 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009240 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009241
9242 final long identity = Binder.clearCallingIdentity();
9243 try {
9244 final Phone phone = getPhone(subId);
9245 if (phone == null) {
9246 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9247 return;
9248 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009249 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9250 if (cpt != null) {
9251 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9252 }
9253 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009254 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9255 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009256 if (carrierPrivilegeRules == null) {
9257 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9258 } else {
9259 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009261 } finally {
9262 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009263 }
fionaxua13278b2018-03-21 00:08:13 -07009264 }
9265
9266 @Override
9267 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009268 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009269
9270 final long identity = Binder.clearCallingIdentity();
9271 try {
9272 final Phone phone = getPhone(subId);
9273 if (phone == null) {
9274 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9275 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9276 }
9277 return phone.getCarrierIdListVersion();
9278 } finally {
9279 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009280 }
fionaxua13278b2018-03-21 00:08:13 -07009281 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009282
9283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009284 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9285 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009287 mApp, subId, callingPackage, callingFeatureId,
9288 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009289 return -1;
9290 }
9291
9292 final long identity = Binder.clearCallingIdentity();
9293 try {
9294 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9295 } finally {
9296 Binder.restoreCallingIdentity(identity);
9297 }
9298 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009299
9300 @Override
9301 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009302 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009303 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009304 mApp, subId, "getCdmaRoamingMode");
9305
9306 final long identity = Binder.clearCallingIdentity();
9307 try {
9308 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9309 } finally {
9310 Binder.restoreCallingIdentity(identity);
9311 }
9312 }
9313
9314 @Override
9315 public boolean setCdmaRoamingMode(int subId, int mode) {
9316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9317 mApp, subId, "setCdmaRoamingMode");
9318
9319 final long identity = Binder.clearCallingIdentity();
9320 try {
9321 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9322 } finally {
9323 Binder.restoreCallingIdentity(identity);
9324 }
9325 }
9326
9327 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009328 public int getCdmaSubscriptionMode(int subId) {
9329 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009330 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009331 mApp, subId, "getCdmaSubscriptionMode");
9332
9333 final long identity = Binder.clearCallingIdentity();
9334 try {
9335 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9336 } finally {
9337 Binder.restoreCallingIdentity(identity);
9338 }
9339 }
9340
9341 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009342 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9344 mApp, subId, "setCdmaSubscriptionMode");
9345
9346 final long identity = Binder.clearCallingIdentity();
9347 try {
9348 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009353
sqianc5eccab2018-10-19 18:46:41 -07009354 @Override
sqian8c685422019-02-22 15:55:18 -08009355 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009356 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009357 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009358 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9359 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009360 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9361 }
9362 final long identity = Binder.clearCallingIdentity();
9363 try {
sqian854d44b2018-12-12 16:48:18 -08009364 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9365 for (Phone phone: PhoneFactory.getPhones()) {
9366 if (phone.getEmergencyNumberTracker() != null
9367 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9368 emergencyNumberListInternal.put(
9369 phone.getSubId(),
9370 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9371 }
sqian11b7a0e2018-12-05 18:48:28 -08009372 }
sqian854d44b2018-12-12 16:48:18 -08009373 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009374 } finally {
9375 Binder.restoreCallingIdentity(identity);
9376 }
sqianc5eccab2018-10-19 18:46:41 -07009377 }
9378
9379 @Override
sqian8c685422019-02-22 15:55:18 -08009380 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009381 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009382 if (!exactMatch) {
9383 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009384 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009385 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009386 }
9387 final long identity = Binder.clearCallingIdentity();
9388 try {
sqian854d44b2018-12-12 16:48:18 -08009389 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009390 //Note: we ignore passed in param exactMatch. We can remove it once
9391 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009392 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009393 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009394 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009395 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009396 }
sqian11b7a0e2018-12-05 18:48:28 -08009397 }
9398 return false;
9399 } finally {
9400 Binder.restoreCallingIdentity(identity);
9401 }
9402 }
9403
sqianf4ca7ed2019-01-15 18:32:07 -08009404 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009405 * Start emergency callback mode for GsmCdmaPhone for testing.
9406 */
9407 @Override
9408 public void startEmergencyCallbackMode() {
9409 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9410 "startEmergencyCallbackMode");
9411 enforceModifyPermission();
9412 final long identity = Binder.clearCallingIdentity();
9413 try {
9414 for (Phone phone : PhoneFactory.getPhones()) {
9415 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9416 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9417 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9418 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9419 gsmCdmaPhone.obtainMessage(
9420 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9421 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9422 }
9423 }
9424 } finally {
9425 Binder.restoreCallingIdentity(identity);
9426 }
9427 }
9428
9429 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009430 * Update emergency number list for test mode.
9431 */
9432 @Override
9433 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9434 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9435 "updateEmergencyNumberListTestMode");
9436
9437 final long identity = Binder.clearCallingIdentity();
9438 try {
9439 for (Phone phone: PhoneFactory.getPhones()) {
9440 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9441 if (tracker != null) {
9442 tracker.executeEmergencyNumberTestModeCommand(action, num);
9443 }
9444 }
9445 } finally {
9446 Binder.restoreCallingIdentity(identity);
9447 }
9448 }
9449
9450 /**
9451 * Get the full emergency number list for test mode.
9452 */
9453 @Override
9454 public List<String> getEmergencyNumberListTestMode() {
9455 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9456 "getEmergencyNumberListTestMode");
9457
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 Set<String> emergencyNumbers = new HashSet<>();
9461 for (Phone phone: PhoneFactory.getPhones()) {
9462 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9463 if (tracker != null) {
9464 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9465 emergencyNumbers.add(num.getNumber());
9466 }
9467 }
9468 }
9469 return new ArrayList<>(emergencyNumbers);
9470 } finally {
9471 Binder.restoreCallingIdentity(identity);
9472 }
9473 }
9474
chen xud6b45bd2018-10-30 22:27:10 -07009475 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009476 public int getEmergencyNumberDbVersion(int subId) {
9477 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9478
9479 final long identity = Binder.clearCallingIdentity();
9480 try {
9481 final Phone phone = getPhone(subId);
9482 if (phone == null) {
9483 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9484 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9485 }
9486 return phone.getEmergencyNumberDbVersion();
9487 } finally {
9488 Binder.restoreCallingIdentity(identity);
9489 }
9490 }
9491
9492 @Override
9493 public void notifyOtaEmergencyNumberDbInstalled() {
9494 enforceModifyPermission();
9495
9496 final long identity = Binder.clearCallingIdentity();
9497 try {
9498 for (Phone phone: PhoneFactory.getPhones()) {
9499 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9500 if (tracker != null) {
9501 tracker.updateOtaEmergencyNumberDatabase();
9502 }
9503 }
9504 } finally {
9505 Binder.restoreCallingIdentity(identity);
9506 }
9507 }
9508
9509 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009510 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009511 enforceActiveEmergencySessionPermission();
9512
9513 final long identity = Binder.clearCallingIdentity();
9514 try {
9515 for (Phone phone: PhoneFactory.getPhones()) {
9516 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9517 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009518 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9519 }
9520 }
9521 } finally {
9522 Binder.restoreCallingIdentity(identity);
9523 }
9524 }
9525
9526 @Override
9527 public void resetOtaEmergencyNumberDbFilePath() {
9528 enforceActiveEmergencySessionPermission();
9529
9530 final long identity = Binder.clearCallingIdentity();
9531 try {
9532 for (Phone phone: PhoneFactory.getPhones()) {
9533 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9534 if (tracker != null) {
9535 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009536 }
9537 }
9538 } finally {
9539 Binder.restoreCallingIdentity(identity);
9540 }
9541 }
9542
9543 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009544 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9545 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9546 Phone phone = getPhone(subId);
9547 if (phone == null) {
9548 return null;
9549 }
9550 final long identity = Binder.clearCallingIdentity();
9551 try {
9552 UiccProfile profile = UiccController.getInstance()
9553 .getUiccProfileForPhone(phone.getPhoneId());
9554 if (profile != null) {
9555 return profile.getCertsFromCarrierPrivilegeAccessRules();
9556 }
9557 } finally {
9558 Binder.restoreCallingIdentity(identity);
9559 }
9560 return null;
9561 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009562
9563 /**
9564 * Enable or disable a modem stack.
9565 */
9566 @Override
9567 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9568 enforceModifyPermission();
9569
9570 final long identity = Binder.clearCallingIdentity();
9571 try {
9572 Phone phone = PhoneFactory.getPhone(slotIndex);
9573 if (phone == null) {
9574 return false;
9575 } else {
9576 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9577 }
9578 } finally {
9579 Binder.restoreCallingIdentity(identity);
9580 }
9581 }
Michelecea4cf22018-12-21 15:00:11 -08009582
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009583 /**
9584 * Whether a modem stack is enabled or not.
9585 */
9586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009587 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9588 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009589 Phone phone = PhoneFactory.getPhone(slotIndex);
9590 if (phone == null) return false;
9591
9592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009593 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9594 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009595 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9596 }
9597
9598 final long identity = Binder.clearCallingIdentity();
9599 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009600 try {
9601 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9602 } catch (NoSuchElementException ex) {
9603 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9604 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009605 } finally {
9606 Binder.restoreCallingIdentity(identity);
9607 }
9608 }
9609
Michelecea4cf22018-12-21 15:00:11 -08009610 @Override
Michele0ea7d782019-03-19 14:58:42 -07009611 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009612 enforceModifyPermission();
9613
9614 final long identity = Binder.clearCallingIdentity();
9615 try {
9616 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009617 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009618 .commit();
9619 } finally {
9620 Binder.restoreCallingIdentity(identity);
9621 }
9622 }
9623
9624 @Override
Michele0ea7d782019-03-19 14:58:42 -07009625 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009626 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009628 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9629 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009630 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009631 }
Michelecea4cf22018-12-21 15:00:11 -08009632
9633 final long identity = Binder.clearCallingIdentity();
9634 try {
Michele0ea7d782019-03-19 14:58:42 -07009635 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009636 } finally {
9637 Binder.restoreCallingIdentity(identity);
9638 }
9639 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009640
Michele0ea7d782019-03-19 14:58:42 -07009641 @TelephonyManager.IsMultiSimSupportedResult
9642 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009643 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9644 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9645 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009646 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9647 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009648 }
9649 // Check if the hardware supports multisim functionality. If usage of multisim is not
9650 // supported by the modem, indicate that it is restricted.
9651 PhoneCapability staticCapability =
9652 mPhoneConfigurationManager.getStaticPhoneCapability();
9653 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009654 loge("isMultiSimSupportedInternal: no static configuration available");
9655 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009656 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009657 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009658 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9659 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009660 }
9661 // Check if support of multiple SIMs is restricted by carrier
9662 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009663 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009664 }
9665
Michele0ea7d782019-03-19 14:58:42 -07009666 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009667 }
9668
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009669 /**
9670 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009671 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9672 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9673 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009674 * @param numOfSims number of active sims we want to switch to
9675 */
9676 @Override
9677 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009678 if (numOfSims == 1) {
9679 enforceModifyPermission();
9680 } else {
9681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9682 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9683 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009684 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009685
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009686 try {
Michele30b57b22019-03-01 12:01:14 -08009687 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009688 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009689 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9690 return;
9691 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009692 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9693 } finally {
9694 Binder.restoreCallingIdentity(identity);
9695 }
9696 }
9697
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009698 @Override
9699 public boolean isApplicationOnUicc(int subId, int appType) {
9700 enforceReadPrivilegedPermission("isApplicationOnUicc");
9701 Phone phone = getPhone(subId);
9702 if (phone == null) {
9703 return false;
9704 }
9705 final long identity = Binder.clearCallingIdentity();
9706 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009707 UiccPort uiccPort = phone.getUiccPort();
9708 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009709 return false;
9710 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009711 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009712 if (uiccProfile == null) {
9713 return false;
9714 }
9715 if (TelephonyManager.APPTYPE_SIM <= appType
9716 && appType <= TelephonyManager.APPTYPE_ISIM) {
9717 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9718 }
9719 return false;
9720 } finally {
9721 Binder.restoreCallingIdentity(identity);
9722 }
9723 }
9724
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009725 /**
chen xub4baa772019-04-03 10:23:41 -07009726 * Get whether making changes to modem configurations will trigger reboot.
9727 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009728 */
9729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009730 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9731 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009732 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009733 mApp, subId, callingPackage, callingFeatureId,
9734 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009735 return false;
9736 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009737 final long identity = Binder.clearCallingIdentity();
9738 try {
9739 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9740 } finally {
9741 Binder.restoreCallingIdentity(identity);
9742 }
9743 }
9744
Nathan Harold29f5f052019-02-15 13:41:57 -08009745 private void updateModemStateMetrics() {
9746 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9747 // TODO: check the state for each modem if the api is ready.
9748 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9749 }
9750
Pengquan Meng3889a572019-01-23 11:16:29 -08009751 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009752 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009753 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009754 // Verify that the callingPackage belongs to the calling UID
9755 mApp.getSystemService(AppOpsManager.class)
9756 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009757 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009758 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009759 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009760 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9761 if (slotInfos != null) {
9762 for (int i = 0; i < slotInfos.length; i++) {
9763 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9764 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9765 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9766 portInfo.getLogicalSlotIndex()));
9767 }
9768 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009769 }
9770 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009771 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009772 } finally {
9773 Binder.restoreCallingIdentity(identity);
9774 }
9775 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009776
9777 /**
9778 * Get the IRadio HAL Version
9779 */
9780 @Override
9781 public int getRadioHalVersion() {
9782 Phone phone = getDefaultPhone();
9783 if (phone == null) return -1;
9784 HalVersion hv = phone.getHalVersion();
9785 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9786 return hv.major * 100 + hv.minor;
9787 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009788
9789 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009790 * Get the current calling package name.
9791 * @return the current calling package name
9792 */
9793 @Override
9794 public String getCurrentPackageName() {
9795 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9796 }
9797
9798 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009799 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9800 * corresponding network requests on a subId.
9801 *
9802 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009803 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009804 * 2) APN is un-metered for this subscription, or
9805 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009806 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009807 *
9808 * @return whether data is allowed for a apn type.
9809 *
9810 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009811 */
9812 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009813 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009814 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9815 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009816
9817 // Now that all security checks passes, perform the operation as ourselves.
9818 final long identity = Binder.clearCallingIdentity();
9819 try {
9820 Phone phone = getPhone(subId);
9821 if (phone == null) return false;
9822
Jack Yu27422a52022-03-21 10:38:05 -07009823 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009824 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009825 isMetered = phone.getDataNetworkController().getDataConfigManager()
9826 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9827 phone.getServiceState().getDataRoaming());
9828 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009829 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009830 } finally {
9831 Binder.restoreCallingIdentity(identity);
9832 }
9833 }
9834
9835 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009836 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009837 enforceReadPrivilegedPermission("isApnMetered");
9838
9839 // Now that all security checks passes, perform the operation as ourselves.
9840 final long identity = Binder.clearCallingIdentity();
9841 try {
9842 Phone phone = getPhone(subId);
9843 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009844 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9845 DataUtils.apnTypeToNetworkCapability(apnType),
9846 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009847 } finally {
9848 Binder.restoreCallingIdentity(identity);
9849 }
9850 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009851
9852 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009853 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9854 int subscriptionId, IBooleanConsumer resultCallback) {
9855 enforceModifyPermission();
9856 long token = Binder.clearCallingIdentity();
9857 try {
9858 Phone phone = getPhone(subscriptionId);
9859 if (phone == null) {
9860 try {
9861 if (resultCallback != null) {
9862 resultCallback.accept(false);
9863 }
9864 } catch (RemoteException e) {
9865 // ignore
9866 }
9867 return;
9868 }
9869 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9870 Pair.create(specifiers, (x) -> {
9871 try {
9872 if (resultCallback != null) {
9873 resultCallback.accept(x);
9874 }
9875 } catch (RemoteException e) {
9876 // ignore
9877 }
9878 });
9879 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9880 } finally {
9881 Binder.restoreCallingIdentity(token);
9882 }
9883 }
9884
9885 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009886 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9887 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009888 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009889 mApp, subId, "getSystemSelectionChannels");
9890 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9891 final long identity = Binder.clearCallingIdentity();
9892 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009893 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9894 if (result instanceof IllegalStateException) {
9895 throw (IllegalStateException) result;
9896 }
9897 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009898 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9899 return specifiers;
9900 } finally {
9901 Binder.restoreCallingIdentity(identity);
9902 }
9903 }
9904
9905 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009906 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009907 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009908 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009909 }
9910
9911 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009912 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9913 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009914 if (callingPackage == null) {
9915 callingPackage = getCurrentPackageName();
9916 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009917 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9918 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009919 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9920 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009921 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9922 }
9923 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9924 Intent intent = new Intent();
9925 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9926 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9927 // Bring up choose default SMS subscription dialog right now
9928 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9929 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9930 mApp.startActivity(intent);
9931 }
chen xud5ca2d52019-05-28 15:20:57 -07009932
9933 @Override
9934 public String getMmsUAProfUrl(int subId) {
9935 //TODO investigate if this API should require proper permission check in R b/133791609
9936 final long identity = Binder.clearCallingIdentity();
9937 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009938 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9939 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9940 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9941 return carrierUAProfUrl;
9942 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009943 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9944 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009945 } finally {
9946 Binder.restoreCallingIdentity(identity);
9947 }
9948 }
9949
9950 @Override
9951 public String getMmsUserAgent(int subId) {
9952 //TODO investigate if this API should require proper permission check in R b/133791609
9953 final long identity = Binder.clearCallingIdentity();
9954 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009955 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9956 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9957 if (!TextUtils.isEmpty(carrierUserAgent)) {
9958 return carrierUserAgent;
9959 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009960 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9961 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009962 } finally {
9963 Binder.restoreCallingIdentity(identity);
9964 }
9965 }
Jack Yub07d4972019-05-28 16:12:25 -07009966
9967 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009968 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9969 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009970
Jack Yub07d4972019-05-28 16:12:25 -07009971 final long identity = Binder.clearCallingIdentity();
9972 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009973 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009974 if (phone == null) return false;
9975
Ling Maf188d502022-09-16 15:22:36 -07009976 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009977 } finally {
9978 Binder.restoreCallingIdentity(identity);
9979 }
9980 }
9981
9982 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009983 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009984 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009985 enforceModifyPermission();
9986
changbettyd5c246e2019-12-24 15:40:37 +08009987 final long identity = Binder.clearCallingIdentity();
9988 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009989 Phone phone = getPhone(subscriptionId);
9990 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009991
Ling Maf188d502022-09-16 15:22:36 -07009992 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009993 } finally {
9994 Binder.restoreCallingIdentity(identity);
9995 }
9996 }
9997
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009998 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009999 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010000 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10001 * otherwise.
10002 */
10003 @Override
10004 public void setCepEnabled(boolean isCepEnabled) {
10005 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10006
10007 final long identity = Binder.clearCallingIdentity();
10008 try {
10009 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10010 for (Phone phone : PhoneFactory.getPhones()) {
10011 Phone defaultPhone = phone.getImsPhone();
10012 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10013 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10014 ImsPhoneCallTracker imsPhoneCallTracker =
10015 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10016 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10017 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10018 + imsPhone.getMsisdn());
10019 }
10020 }
10021 } finally {
10022 Binder.restoreCallingIdentity(identity);
10023 }
10024 }
allenwtsu46dcc572020-01-08 18:24:03 +080010025
10026 /**
10027 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10028 *
10029 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10030 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10031 * before being read.
10032 */
10033 @Override
10034 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10035 isCompressed) {
10036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10037 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010038 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10039 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10040 }
10041 if (!isImsAvailableOnDevice()) {
10042 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10043 "IMS not available on device.");
10044 }
10045
10046 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010047 try {
Hui Wang761a6682020-10-31 05:12:53 +000010048 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10049 } finally {
10050 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010051 }
10052 }
zoey chene02881a2019-12-30 16:11:23 +080010053
10054 @Override
10055 public boolean isIccLockEnabled(int subId) {
10056 enforceReadPrivilegedPermission("isIccLockEnabled");
10057
10058 // Now that all security checks passes, perform the operation as ourselves.
10059 final long identity = Binder.clearCallingIdentity();
10060 try {
10061 Phone phone = getPhone(subId);
10062 if (phone != null && phone.getIccCard() != null) {
10063 return phone.getIccCard().getIccLockEnabled();
10064 } else {
10065 return false;
10066 }
10067 } finally {
10068 Binder.restoreCallingIdentity(identity);
10069 }
10070 }
10071
10072 /**
10073 * Set the ICC pin lock enabled or disabled.
10074 *
10075 * @return an integer representing the status of IccLock enabled or disabled in the following
10076 * three cases:
10077 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10078 * successfully.
10079 * - Positive number and zero for remaining password attempts.
10080 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10081 *
10082 */
10083 @Override
10084 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10085 enforceModifyPermission();
10086
10087 Phone phone = getPhone(subId);
10088 if (phone == null) {
10089 return 0;
10090 }
10091 // Now that all security checks passes, perform the operation as ourselves.
10092 final long identity = Binder.clearCallingIdentity();
10093 try {
10094 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10095 new Pair<Boolean, String>(enabled, password), phone, null);
10096 return attemptsRemaining;
10097
10098 } catch (Exception e) {
10099 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10100 } finally {
10101 Binder.restoreCallingIdentity(identity);
10102 }
10103 return 0;
10104 }
10105
10106 /**
10107 * Change the ICC password used in ICC pin lock.
10108 *
10109 * @return an integer representing the status of IccLock changed in the following three cases:
10110 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10111 * - Positive number and zero for remaining password attempts.
10112 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10113 *
10114 */
10115 @Override
10116 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10117 enforceModifyPermission();
10118
10119 Phone phone = getPhone(subId);
10120 if (phone == null) {
10121 return 0;
10122 }
10123 // Now that all security checks passes, perform the operation as ourselves.
10124 final long identity = Binder.clearCallingIdentity();
10125 try {
10126 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10127 new Pair<String, String>(oldPassword, newPassword), phone, null);
10128 return attemptsRemaining;
10129
10130 } catch (Exception e) {
10131 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10132 } finally {
10133 Binder.restoreCallingIdentity(identity);
10134 }
10135 return 0;
10136 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010137
10138 /**
10139 * Request for receiving user activity notification
10140 */
10141 @Override
10142 public void requestUserActivityNotification() {
10143 if (!mNotifyUserActivity.get()
10144 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10145 mNotifyUserActivity.set(true);
10146 }
10147 }
10148
10149 /**
10150 * Called when userActivity is signalled in the power manager.
10151 * This is safe to call from any thread, with any window manager locks held or not.
10152 */
10153 @Override
10154 public void userActivity() {
10155 // ***************************************
10156 // * Inherited from PhoneWindowManager *
10157 // ***************************************
10158 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10159 // WITH ITS LOCKS HELD.
10160 //
10161 // This code must be VERY careful about the locks
10162 // it acquires.
10163 // In fact, the current code acquires way too many,
10164 // and probably has lurking deadlocks.
10165
10166 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10167 throw new SecurityException("Only the OS may call notifyUserActivity()");
10168 }
10169
10170 if (mNotifyUserActivity.getAndSet(false)) {
10171 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10172 USER_ACTIVITY_NOTIFICATION_DELAY);
10173 }
10174 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010175
10176 @Override
10177 public boolean canConnectTo5GInDsdsMode() {
10178 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10179 }
Jack Yud10cdd42020-09-28 20:28:01 -070010180
10181 @Override
10182 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10183 String callingFeatureId) {
10184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10185 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10186 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10187 }
10188
10189 Phone phone = getPhone(subId);
10190 if (phone == null) {
10191 throw new RuntimeException("phone is not available");
10192 }
10193 // Now that all security checks passes, perform the operation as ourselves.
10194 final long identity = Binder.clearCallingIdentity();
10195 try {
10196 return phone.getEquivalentHomePlmns();
10197 } finally {
10198 Binder.restoreCallingIdentity(identity);
10199 }
10200 }
Daniel Bright59e67312020-11-13 11:49:37 -080010201
10202 @Override
10203 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010204 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10205 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010206 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010207 if (radioInterfaceCapabilities == null) {
10208 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010209 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010210 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010211 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010212
Hui Wang641e81c2020-10-12 12:14:23 -070010213 @Override
10214 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10215 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010216 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10217 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10218 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10219 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10220 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010221 if (DBG) {
10222 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10223 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10224 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10225 }
10226
10227 if (!SubscriptionManager.isValidSubscriptionId(subId)
10228 || appType < TelephonyManager.APPTYPE_UNKNOWN
10229 || appType > TelephonyManager.APPTYPE_ISIM
10230 || nafUrl == null || securityProtocol == null || callback == null) {
10231 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10232 if (callback != null) {
10233 try {
10234 callback.onAuthenticationFailure(
10235 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10236 } catch (RemoteException exception) {
10237 log("Fail to notify onAuthenticationFailure due to " + exception);
10238 }
10239 return;
10240 }
10241 }
10242
10243 final long token = Binder.clearCallingIdentity();
10244 try {
10245 getGbaManager(subId).bootstrapAuthenticationRequest(
10246 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10247 forceBootStrapping, callback));
10248 } finally {
10249 Binder.restoreCallingIdentity(token);
10250 }
10251 }
10252
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010253 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010254 * Attempts to set the radio power state for all phones for thermal reason.
10255 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010256 * requested radio power state will actually be set. See {@link
10257 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10258 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010259 * @param enable {@code true} if trying to turn radio on.
10260 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10261 * false}.
10262 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010263 private boolean setRadioPowerForThermal(boolean enable) {
10264 boolean isPhoneAvailable = false;
10265 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10266 Phone phone = PhoneFactory.getPhone(i);
10267 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010268 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010269 isPhoneAvailable = true;
10270 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010271 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010272
10273 // return true if successfully informed the phone object about the thermal radio power
10274 // request.
10275 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010276 }
10277
10278 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010279 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010280 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10281 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10282 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10283 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10284 throw new IllegalArgumentException("modem does not support data throttling");
10285 }
10286
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010287 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10288 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010289 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010290 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10291 }
10292
Sarah Chinecc78c42022-03-31 21:16:48 -070010293 setDataEnabledForReason(
10294 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010295
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010296 if (isDataThrottlingSupported) {
10297 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010298 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010299 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10300 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10301 } else if (thermalMitigationResult
10302 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010303 log("Modem likely does not support data throttling on secondary carrier. Data " +
10304 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10305 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010306 }
10307 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010308 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010309
10310 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010311 }
10312
Jack Nudelman644b91a2021-03-12 14:09:48 -080010313 private static List<String> getThermalMitigationAllowlist(Context context) {
10314 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10315 for (String pckg : context.getResources()
10316 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10317 sThermalMitigationAllowlistedPackages.add(pckg);
10318 }
10319 }
10320
10321 return sThermalMitigationAllowlistedPackages;
10322 }
10323
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010324 private boolean isAnyPhoneInEmergencyState() {
10325 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10326 if (tm.isInEmergencyCall()) {
10327 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10328 return true;
10329 }
10330 for (Phone phone : PhoneFactory.getPhones()) {
10331 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10332 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10333 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10334 + phone.isInEcm());
10335 return true;
10336 }
10337 }
10338
10339 return false;
10340 }
10341
Jack Nudelman644b91a2021-03-12 14:09:48 -080010342 /**
10343 * Used by shell commands to add an authorized package name for thermal mitigation.
10344 * @param packageName name of package to be allowlisted
10345 * @param context
10346 */
10347 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10348 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10349 sThermalMitigationAllowlistedPackages.add(packageName);
10350 }
10351
10352 /**
10353 * Used by shell commands to remove an authorized package name for thermal mitigation.
10354 * @param packageName name of package to remove from allowlist
10355 * @param context
10356 */
10357 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10358 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10359 sThermalMitigationAllowlistedPackages.remove(packageName);
10360 }
10361
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010362 /**
10363 * Thermal mitigation request to control functionalities at modem.
10364 *
10365 * @param subId the id of the subscription.
10366 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010367 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010368 *
10369 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10370 */
10371 @Override
10372 @ThermalMitigationResult
10373 public int sendThermalMitigationRequest(
10374 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010375 ThermalMitigationRequest thermalMitigationRequest,
10376 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010377 enforceModifyPermission();
10378
Jack Nudelman644b91a2021-03-12 14:09:48 -080010379 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10380 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10381 .contains(callingPackage)) {
10382 throw new SecurityException("Calling package must be configured in the device config. "
10383 + "calling package: " + callingPackage);
10384 }
10385
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010386 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10387 final long identity = Binder.clearCallingIdentity();
10388
10389 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10390 try {
10391 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10392 switch (thermalMitigationAction) {
10393 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10394 thermalMitigationResult =
10395 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010396 thermalMitigationRequest.getDataThrottlingRequest(),
10397 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010398 break;
10399 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10400 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10401 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10402 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10403 }
10404
10405 // Ensure that radio is on. If not able to power on due to phone being
10406 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010407 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010408 thermalMitigationResult =
10409 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10410 break;
10411 }
10412
10413 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010414 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010415 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10416 break;
10417 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10418 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10419 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10420 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10421 }
10422
10423 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10424 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010425 Phone phone = getPhone(subId);
10426 if (phone == null) {
10427 thermalMitigationResult =
10428 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10429 break;
10430 }
10431
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010432 TelephonyConnectionService service =
10433 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010434 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010435 Log.e(LOG_TAG, "An emergency call is pending");
10436 thermalMitigationResult =
10437 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10438 break;
10439 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010440 thermalMitigationResult =
10441 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10442 break;
10443 }
10444 } else {
10445 thermalMitigationResult =
10446 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10447 break;
10448 }
10449
10450 // Turn radio off. If not able to power off due to phone being unavailable,
10451 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010452 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010453 thermalMitigationResult =
10454 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10455 break;
10456 }
10457 thermalMitigationResult =
10458 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10459 break;
10460 default:
10461 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10462 + "not exist. Requested action: " + thermalMitigationAction);
10463 }
10464 } catch (IllegalArgumentException e) {
10465 throw e;
10466 } catch (Exception e) {
10467 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10468 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10469 } finally {
10470 Binder.restoreCallingIdentity(identity);
10471 }
10472
10473 if (DBG) {
10474 log("thermalMitigationRequest returning with thermalMitigationResult: "
10475 + thermalMitigationResult);
10476 }
10477
10478 return thermalMitigationResult;
10479 }
Hui Wang641e81c2020-10-12 12:14:23 -070010480
10481 /**
10482 * Set the GbaService Package Name that Telephony will bind to.
10483 *
10484 * @param subId The sim that the GbaService is associated with.
10485 * @param packageName The name of the package to be replaced with.
10486 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10487 */
10488 @Override
10489 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10490 enforceModifyPermission();
10491
10492 final long identity = Binder.clearCallingIdentity();
10493 try {
10494 return getGbaManager(subId).overrideServicePackage(packageName);
10495 } finally {
10496 Binder.restoreCallingIdentity(identity);
10497 }
10498 }
10499
10500 /**
10501 * Return the package name of the currently bound GbaService.
10502 *
10503 * @param subId The sim that the GbaService is associated with.
10504 * @return the package name of the GbaService configuration, null if GBA is not supported.
10505 */
10506 @Override
10507 public String getBoundGbaService(int subId) {
10508 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10509
10510 final long identity = Binder.clearCallingIdentity();
10511 try {
10512 return getGbaManager(subId).getServicePackage();
10513 } finally {
10514 Binder.restoreCallingIdentity(identity);
10515 }
10516 }
10517
10518 /**
10519 * Set the release time for telephony to unbind GbaService.
10520 *
10521 * @param subId The sim that the GbaService is associated with.
10522 * @param interval The release time to unbind GbaService by millisecond.
10523 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10524 */
10525 @Override
10526 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10527 enforceModifyPermission();
10528
10529 final long identity = Binder.clearCallingIdentity();
10530 try {
10531 return getGbaManager(subId).overrideReleaseTime(interval);
10532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
10536
10537 /**
10538 * Return the release time for telephony to unbind GbaService.
10539 *
10540 * @param subId The sim that the GbaService is associated with.
10541 * @return The release time to unbind GbaService by millisecond.
10542 */
10543 @Override
10544 public int getGbaReleaseTime(int subId) {
10545 enforceReadPrivilegedPermission("getGbaReleaseTime");
10546
10547 final long identity = Binder.clearCallingIdentity();
10548 try {
10549 return getGbaManager(subId).getReleaseTime();
10550 } finally {
10551 Binder.restoreCallingIdentity(identity);
10552 }
10553 }
10554
10555 private GbaManager getGbaManager(int subId) {
10556 GbaManager instance = GbaManager.getInstance(subId);
10557 if (instance == null) {
10558 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10559 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10560 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10561 }
10562 return instance;
10563 }
Hui Wang761a6682020-10-31 05:12:53 +000010564
10565 /**
10566 * indicate whether the device and the carrier can support
10567 * RCS VoLTE single registration.
10568 */
10569 @Override
10570 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010571 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10572 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10573 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10574 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010575
10576 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10577 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10578 }
10579
10580 final long identity = Binder.clearCallingIdentity();
10581 try {
10582 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10583 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010584 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10585 if (isCapable != null) {
10586 return isCapable;
10587 }
Hui Wang761a6682020-10-31 05:12:53 +000010588 }
Hui Wang67af90e2021-06-04 16:57:15 -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 /**
10597 * Register RCS provisioning callback.
10598 */
10599 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010600 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010601 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010602 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010603 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010604 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10605 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010606
10607 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10608 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10609 }
10610 if (!isImsAvailableOnDevice()) {
10611 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10612 "IMS not available on device.");
10613 }
10614
10615 final long identity = Binder.clearCallingIdentity();
10616 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010617 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010618 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010619 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10620 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010621 }
Hui Wang761a6682020-10-31 05:12:53 +000010622 } finally {
10623 Binder.restoreCallingIdentity(identity);
10624 }
10625 }
10626
10627 /**
10628 * Unregister RCS provisioning callback.
10629 */
10630 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010631 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010632 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010633 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010634 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010635 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10636 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010637
10638 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10639 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10640 }
10641 if (!isImsAvailableOnDevice()) {
10642 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10643 "IMS not available on device.");
10644 }
10645
10646 final long identity = Binder.clearCallingIdentity();
10647 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010648 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010649 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010650 } finally {
10651 Binder.restoreCallingIdentity(identity);
10652 }
10653 }
10654
10655 /**
10656 * trigger RCS reconfiguration.
10657 */
10658 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010659 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10660 "triggerRcsReconfiguration",
10661 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010662
10663 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10664 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10665 }
10666 if (!isImsAvailableOnDevice()) {
10667 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10668 "IMS not available on device.");
10669 }
10670
10671 final long identity = Binder.clearCallingIdentity();
10672 try {
10673 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10674 } finally {
10675 Binder.restoreCallingIdentity(identity);
10676 }
10677 }
10678
10679 /**
10680 * Provide the client configuration parameters of the RCS application.
10681 */
10682 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010683 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10684 "setRcsClientConfiguration",
10685 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010686
10687 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10688 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10689 }
10690 if (!isImsAvailableOnDevice()) {
10691 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10692 "IMS not available on device.");
10693 }
10694
10695 final long identity = Binder.clearCallingIdentity();
10696
10697 try {
10698 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10699 if (configBinder == null) {
10700 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010701 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10702 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010703 } else {
10704 configBinder.setRcsClientConfiguration(rcc);
10705 }
joonhunshin3e154242021-09-17 06:33:39 +000010706
10707 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10708 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010709 } catch (RemoteException e) {
10710 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010711 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10712 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010713 } finally {
10714 Binder.restoreCallingIdentity(identity);
10715 }
10716 }
10717
10718 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010719 * Enables or disables the test mode for RCS VoLTE single registration.
10720 */
10721 @Override
10722 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10723 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10724 "setRcsSingleRegistrationTestModeEnabled");
10725
10726 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10727 }
10728
10729 /**
10730 * Gets the test mode for RCS VoLTE single registration.
10731 */
10732 @Override
10733 public boolean getRcsSingleRegistrationTestModeEnabled() {
10734 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10735 "getRcsSingleRegistrationTestModeEnabled");
10736
10737 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10738 }
10739
10740 /**
Hui Wang761a6682020-10-31 05:12:53 +000010741 * Overrides the config of RCS VoLTE single registration enabled for the device.
10742 */
10743 @Override
10744 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10745 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10746 "setDeviceSingleRegistrationEnabledOverride");
10747 enforceModifyPermission();
10748
10749 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10750 : Boolean.parseBoolean(enabledStr);
10751 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010752 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010753 }
10754
10755 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010756 * Sends a device to device communication message. Only usable via shell.
10757 * @param message message to send.
10758 * @param value message value.
10759 */
10760 @Override
10761 public void sendDeviceToDeviceMessage(int message, int value) {
10762 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010763 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010764 enforceModifyPermission();
10765
10766 final long identity = Binder.clearCallingIdentity();
10767 try {
10768 TelephonyConnectionService service =
10769 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10770 if (service == null) {
10771 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10772 return;
10773 }
10774 service.sendTestDeviceToDeviceMessage(message, value);
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
10779
Tyler Gunnbabbda02021-02-10 11:05:02 -080010780 /**
10781 * Sets the specified device to device transport active.
10782 * @param transport The transport to set active.
10783 */
10784 @Override
10785 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10786 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10787 "setActiveDeviceToDeviceTransport");
10788 enforceModifyPermission();
10789
10790 final long identity = Binder.clearCallingIdentity();
10791 try {
10792 TelephonyConnectionService service =
10793 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10794 if (service == null) {
10795 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10796 return;
10797 }
10798 service.setActiveDeviceToDeviceTransport(transport);
10799 } finally {
10800 Binder.restoreCallingIdentity(identity);
10801 }
10802 }
Tyler Gunn92479152021-01-20 16:30:10 -080010803
Tyler Gunnd4339262021-05-03 14:46:49 -070010804 @Override
10805 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10806 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10807 "setDeviceToDeviceForceEnabled");
10808
10809 final long identity = Binder.clearCallingIdentity();
10810 try {
10811 Arrays.stream(PhoneFactory.getPhones()).forEach(
10812 p -> {
10813 Phone thePhone = p.getImsPhone();
10814 if (thePhone != null && thePhone instanceof ImsPhone) {
10815 ImsPhone imsPhone = (ImsPhone) thePhone;
10816 CallTracker tracker = imsPhone.getCallTracker();
10817 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10818 ImsPhoneCallTracker imsPhoneCallTracker =
10819 (ImsPhoneCallTracker) tracker;
10820 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10821 }
10822 }
10823 }
10824 );
10825 } finally {
10826 Binder.restoreCallingIdentity(identity);
10827 }
10828 }
10829
Tyler Gunn92479152021-01-20 16:30:10 -080010830 /**
Hui Wang761a6682020-10-31 05:12:53 +000010831 * Gets the config of RCS VoLTE single registration enabled for the device.
10832 */
10833 @Override
10834 public boolean getDeviceSingleRegistrationEnabled() {
10835 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10836 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10837 }
10838
10839 /**
10840 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10841 */
10842 @Override
10843 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10845 "setCarrierSingleRegistrationEnabledOverride");
10846 enforceModifyPermission();
10847
10848 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10849 : Boolean.parseBoolean(enabledStr);
10850 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10851 subId, enabled);
10852 }
10853
10854 /**
10855 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10856 */
10857 @Override
10858 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10859 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10860 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10861 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010862
10863 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010864 * Overrides the ims feature validation result
10865 */
10866 @Override
10867 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10868 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10869 "setImsFeatureValidationOverride");
10870
10871 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10872 : Boolean.parseBoolean(enabledStr);
10873 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10874 subId, enabled);
10875 }
10876
10877 /**
10878 * Gets the ims feature validation override value
10879 */
10880 @Override
10881 public boolean getImsFeatureValidationOverride(int subId) {
10882 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10883 "getImsFeatureValidationOverride");
10884 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10885 }
10886
10887 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010888 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10889 * their mobile plan.
10890 */
10891 @Override
10892 public String getMobileProvisioningUrl() {
10893 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10894 final long identity = Binder.clearCallingIdentity();
10895 try {
10896 return getDefaultPhone().getMobileProvisioningUrl();
10897 } finally {
10898 Binder.restoreCallingIdentity(identity);
10899 }
10900 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010901
James.cf Linbcdf8b32021-01-14 16:44:13 +080010902 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010903 * Get the EAB contact from the EAB database.
10904 */
10905 @Override
10906 public String getContactFromEab(String contact) {
10907 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10908 enforceModifyPermission();
10909 final long identity = Binder.clearCallingIdentity();
10910 try {
10911 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10912 } finally {
10913 Binder.restoreCallingIdentity(identity);
10914 }
10915 }
10916
10917 /**
Calvin Pana1434322021-07-01 19:27:01 +080010918 * Get the EAB capability from the EAB database.
10919 */
10920 @Override
10921 public String getCapabilityFromEab(String contact) {
10922 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10923 enforceModifyPermission();
10924 final long identity = Binder.clearCallingIdentity();
10925 try {
10926 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10927 } finally {
10928 Binder.restoreCallingIdentity(identity);
10929 }
10930 }
10931
10932 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010933 * Remove the EAB contacts from the EAB database.
10934 */
10935 @Override
10936 public int removeContactFromEab(int subId, String contacts) {
10937 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10938 enforceModifyPermission();
10939 final long identity = Binder.clearCallingIdentity();
10940 try {
10941 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10942 } finally {
10943 Binder.restoreCallingIdentity(identity);
10944 }
10945 }
10946
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010947 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010948 public boolean getDeviceUceEnabled() {
10949 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10950 final long identity = Binder.clearCallingIdentity();
10951 try {
10952 return mApp.getDeviceUceEnabled();
10953 } finally {
10954 Binder.restoreCallingIdentity(identity);
10955 }
10956 }
10957
10958 @Override
10959 public void setDeviceUceEnabled(boolean isEnabled) {
10960 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10961 final long identity = Binder.clearCallingIdentity();
10962 try {
10963 mApp.setDeviceUceEnabled(isEnabled);
10964 } finally {
10965 Binder.restoreCallingIdentity(identity);
10966 }
10967 }
10968
Brad Ebinger14d467f2021-02-12 06:18:28 +000010969 /**
10970 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10971 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10972 */
10973 // Used for SHELL command only right now.
10974 @Override
10975 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10976 List<String> featureTags) {
10977 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10978 "addUceRegistrationOverrideShell");
10979 final long identity = Binder.clearCallingIdentity();
10980 try {
10981 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10982 new ArraySet<>(featureTags));
10983 } catch (ImsException e) {
10984 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10985 } finally {
10986 Binder.restoreCallingIdentity(identity);
10987 }
10988 }
10989
10990 /**
10991 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10992 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10993 */
10994 // Used for SHELL command only right now.
10995 @Override
10996 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10997 List<String> featureTags) {
10998 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10999 "removeUceRegistrationOverrideShell");
11000 final long identity = Binder.clearCallingIdentity();
11001 try {
11002 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11003 new ArraySet<>(featureTags));
11004 } catch (ImsException e) {
11005 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11006 } finally {
11007 Binder.restoreCallingIdentity(identity);
11008 }
11009 }
11010
11011 /**
11012 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11013 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11014 */
11015 // Used for SHELL command only right now.
11016 @Override
11017 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11018 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11019 "clearUceRegistrationOverrideShell");
11020 final long identity = Binder.clearCallingIdentity();
11021 try {
11022 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11023 } catch (ImsException e) {
11024 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11025 } finally {
11026 Binder.restoreCallingIdentity(identity);
11027 }
11028 }
11029
11030 /**
11031 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11032 */
11033 // Used for SHELL command only right now.
11034 @Override
11035 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11036 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11037 "getLatestRcsContactUceCapabilityShell");
11038 final long identity = Binder.clearCallingIdentity();
11039 try {
11040 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11041 } catch (ImsException e) {
11042 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11043 } finally {
11044 Binder.restoreCallingIdentity(identity);
11045 }
11046 }
11047
11048 /**
11049 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11050 * device does not have an active PUBLISH.
11051 */
11052 // Used for SHELL command only right now.
11053 @Override
11054 public String getLastUcePidfXmlShell(int subId) {
11055 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11056 final long identity = Binder.clearCallingIdentity();
11057 try {
11058 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11059 } catch (ImsException e) {
11060 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11061 } finally {
11062 Binder.restoreCallingIdentity(identity);
11063 }
11064 }
11065
James.cf Line8713a42021-04-29 16:04:26 +080011066 /**
11067 * Remove UCE requests cannot be sent to the network status.
11068 */
11069 // Used for SHELL command only right now.
11070 @Override
11071 public boolean removeUceRequestDisallowedStatus(int subId) {
11072 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11073 final long identity = Binder.clearCallingIdentity();
11074 try {
11075 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11076 } catch (ImsException e) {
11077 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11078 } finally {
11079 Binder.restoreCallingIdentity(identity);
11080 }
11081 }
11082
James.cf Lin18bb9002021-05-25 01:37:38 +080011083 /**
11084 * Remove UCE requests cannot be sent to the network status.
11085 */
11086 // Used for SHELL command only.
11087 @Override
11088 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11089 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11090 final long identity = Binder.clearCallingIdentity();
11091 try {
11092 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11093 } catch (ImsException e) {
11094 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11095 } finally {
11096 Binder.restoreCallingIdentity(identity);
11097 }
11098 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011099
James.cf Lin4b784aa2021-01-31 03:25:15 +080011100 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011101 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11102 String callingPackage) {
11103 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11104 mApp, subId, "setSignalStrengthUpdateRequest");
11105
11106 final int callingUid = Binder.getCallingUid();
11107 // Verify that tha callingPackage belongs to the calling UID
11108 mApp.getSystemService(AppOpsManager.class)
11109 .checkPackage(callingUid, callingPackage);
11110
Rambo Wang3607f502021-02-01 21:51:40 -080011111 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011112
11113 final long identity = Binder.clearCallingIdentity();
11114 try {
11115 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11116 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11117
11118 if (result instanceof IllegalStateException) {
11119 throw (IllegalStateException) result;
11120 }
11121 } finally {
11122 Binder.restoreCallingIdentity(identity);
11123 }
11124 }
11125
11126 @Override
11127 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11128 String callingPackage) {
11129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11130 mApp, subId, "clearSignalStrengthUpdateRequest");
11131
11132 final int callingUid = Binder.getCallingUid();
11133 // Verify that tha callingPackage belongs to the calling UID
11134 mApp.getSystemService(AppOpsManager.class)
11135 .checkPackage(callingUid, callingPackage);
11136
11137 final long identity = Binder.clearCallingIdentity();
11138 try {
11139 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11140 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11141
11142 if (result instanceof IllegalStateException) {
11143 throw (IllegalStateException) result;
11144 }
11145 } finally {
11146 Binder.restoreCallingIdentity(identity);
11147 }
11148 }
11149
Rambo Wang3607f502021-02-01 21:51:40 -080011150 private static void validateSignalStrengthUpdateRequest(Context context,
11151 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011152 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11153 // phone/system process do not have further restriction on request
11154 return;
11155 }
11156
11157 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011158 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011159 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011160 context.enforceCallingOrSelfPermission(
11161 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11162 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011163 }
11164
11165 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11166 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11167 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11168 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11169 || info.isEnabled()) {
11170 throw new IllegalArgumentException(
11171 "Only system can set hide fields in SignalThresholdInfo");
11172 }
11173
11174 // Thresholds length for each RAN need in range. This has been validated in
11175 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11176 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11177 final int[] thresholds = info.getThresholds();
11178 Objects.requireNonNull(thresholds);
11179 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11180 || thresholds.length
11181 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11182 throw new IllegalArgumentException(
11183 "thresholds length is out of range: " + thresholds.length);
11184 }
11185 }
11186 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011187
11188 /**
11189 * Gets the current phone capability.
11190 *
11191 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11192 * @return the PhoneCapability which describes the data connection capability of modem.
11193 * It's used to evaluate possible phone config change, for example from single
11194 * SIM device to multi-SIM device.
11195 */
11196 @Override
11197 public PhoneCapability getPhoneCapability() {
11198 enforceReadPrivilegedPermission("getPhoneCapability");
11199 final long identity = Binder.clearCallingIdentity();
11200 try {
11201 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11202 } finally {
11203 Binder.restoreCallingIdentity(identity);
11204 }
11205 }
Michele Berionne5e411512020-11-13 02:36:59 +000011206
11207 /**
11208 * Prepare TelephonyManager for an unattended reboot. The reboot is
11209 * required to be done shortly after the API is invoked.
11210 */
11211 @Override
11212 @TelephonyManager.PrepareUnattendedRebootResult
11213 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011214 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011215 enforceRebootPermission();
11216
11217 final long identity = Binder.clearCallingIdentity();
11218 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011219 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011220 } finally {
11221 Binder.restoreCallingIdentity(identity);
11222 }
11223 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011224
11225 /**
11226 * Request to get the current slicing configuration including URSP rules and
11227 * NSSAIs (configured, allowed and rejected).
11228 *
11229 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11230 */
11231 @Override
11232 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011233 TelephonyPermissions
11234 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11235 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011236
11237 final long identity = Binder.clearCallingIdentity();
11238 try {
11239 Phone phone = getDefaultPhone();
11240 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11241 } finally {
11242 Binder.restoreCallingIdentity(identity);
11243 }
11244 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011245
11246 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011247 * Check whether the given premium capability is available for purchase from the carrier.
11248 *
11249 * @param capability The premium capability to check.
11250 * @param subId The subId to check the premium capability for.
11251 *
11252 * @return Whether the given premium capability is available to purchase.
11253 */
11254 @Override
11255 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11256 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11257 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11258 log("Premium capability "
11259 + TelephonyManager.convertPremiumCapabilityToString(capability)
11260 + " is not available for purchase due to missing permissions.");
11261 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11262 + "permission READ_BASIC_PHONE_STATE.");
11263 }
11264
11265 Phone phone = getPhone(subId);
11266 final long identity = Binder.clearCallingIdentity();
11267 try {
11268 return SliceStore.getInstance(phone)
11269 .isPremiumCapabilityAvailableForPurchase(capability);
11270 } finally {
11271 Binder.restoreCallingIdentity(identity);
11272 }
11273 }
11274
11275 /**
11276 * Purchase the given premium capability from the carrier.
11277 *
11278 * @param capability The premium capability to purchase.
11279 * @param callback The result of the purchase request.
11280 * @param subId The subId to purchase the premium capability for.
11281 */
11282 @Override
11283 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11284 log("purchasePremiumCapability: capability="
11285 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11286 + getCurrentPackageName());
11287
11288 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11289 mApp, "purchasePremiumCapability")) {
11290 log("purchasePremiumCapability "
11291 + TelephonyManager.convertPremiumCapabilityToString(capability)
11292 + " failed due to missing permissions.");
11293 throw new SecurityException("purchasePremiumCapability requires permission "
11294 + "READ_BASIC_PHONE_STATE.");
11295 }
11296
11297 Phone phone = getPhone(subId);
Sarah Chin71b3a852022-09-28 15:54:19 -070011298 String appName;
11299 try {
11300 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11301 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11302 } catch (PackageManager.NameNotFoundException e) {
11303 appName = "An application";
11304 }
11305 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11306 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011307 }
11308
11309 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011310 * Register an IMS connection state callback
11311 */
11312 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011313 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11314 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011315 if (feature == ImsFeature.FEATURE_MMTEL) {
11316 // ImsMmTelManager
11317 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11318 TelephonyPermissions
11319 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11320 mApp, subId, "registerImsStateCallback");
11321 } else if (feature == ImsFeature.FEATURE_RCS) {
11322 // ImsRcsManager or SipDelegateManager
11323 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11324 Binder.getCallingUid(), "registerImsStateCallback",
11325 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11326 Manifest.permission.READ_PRECISE_PHONE_STATE,
11327 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11328 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11329 }
11330
11331 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11332 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11333 "IMS not available on device.");
11334 }
11335
11336 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11337 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11338 }
11339
11340 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11341 if (controller == null) {
11342 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11343 "IMS not available on device.");
11344 }
11345
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011346 if (callingPackage == null) {
11347 callingPackage = getCurrentPackageName();
11348 }
11349
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011350 final long token = Binder.clearCallingIdentity();
11351 try {
11352 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011353 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011354 } catch (ImsException e) {
11355 throw new ServiceSpecificException(e.getCode());
11356 } finally {
11357 Binder.restoreCallingIdentity(token);
11358 }
11359 }
11360
11361 /**
11362 * Unregister an IMS connection state callback
11363 */
11364 @Override
11365 public void unregisterImsStateCallback(IImsStateCallback cb) {
11366 final long token = Binder.clearCallingIdentity();
11367 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11368 if (controller == null) {
11369 return;
11370 }
11371 try {
11372 controller.unregisterImsStateCallback(cb);
11373 } finally {
11374 Binder.restoreCallingIdentity(token);
11375 }
11376 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011377
11378 /**
11379 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11380 *
11381 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11382 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11383 * SecurityException.
11384 * If there is current registered network this value will be same as the registered cell
11385 * identity. If the device goes out of service the previous cell identity is cached and
11386 * will be returned. If the cache age of the Cell identity is more than 24 hours
11387 * it will be cleared and null will be returned.
11388 *
11389 */
11390 @Override
11391 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11392 String callingFeatureId) {
11393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11394 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11395 LocationAccessPolicy.checkLocationPermission(mApp,
11396 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11397 .setCallingPackage(callingPackage)
11398 .setCallingFeatureId(callingFeatureId)
11399 .setCallingPid(Binder.getCallingPid())
11400 .setCallingUid(Binder.getCallingUid())
11401 .setMethod("getLastKnownCellIdentity")
11402 .setLogAsInfo(true)
11403 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11404 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11405 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11406 .build());
11407
11408 boolean hasFinePermission =
11409 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11410 if (!hasFinePermission
11411 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11412 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011413 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011414 }
11415
11416 final long identity = Binder.clearCallingIdentity();
11417 try {
11418 Phone phone = getPhone(subId);
11419 if (phone == null) return null;
11420 ServiceStateTracker sst = phone.getServiceStateTracker();
11421 if (sst == null) return null;
11422 return sst.getLastKnownCellIdentity();
11423 } finally {
11424 Binder.restoreCallingIdentity(identity);
11425 }
11426 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011427
jimsun3b9ccac2021-10-26 15:01:23 +080011428 /**
11429 * Sets the modem service class Name that Telephony will bind to.
11430 *
11431 * @param serviceName The class name of the modem service.
11432 * @return true if the operation is succeed, otherwise false.
11433 */
11434 public boolean setModemService(String serviceName) {
11435 Log.d(LOG_TAG, "setModemService - " + serviceName);
11436 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11438 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11439 "setModemService");
11440 return mPhoneConfigurationManager.setModemService(serviceName);
11441 }
11442
11443 /**
11444 * Return the class name of the currently bounded modem service.
11445 *
11446 * @return the class name of the modem service.
11447 */
11448 public String getModemService() {
11449 String result;
11450 Log.d(LOG_TAG, "getModemService");
11451 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11452 TelephonyPermissions
11453 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11454 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11455 "getModemService");
11456 result = mPhoneConfigurationManager.getModemService();
11457 Log.d(LOG_TAG, "result = " + result);
11458 return result;
11459 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011460
11461 @Override
11462 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11463 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11464 mApp.enforceCallingOrSelfPermission(
11465 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11466 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11467
11468 final long identity = Binder.clearCallingIdentity();
11469 try {
11470 Phone phone = getPhone(subId);
11471 if (phone == null) return;
11472 phone.setVoiceServiceStateOverride(hasService);
11473 } finally {
11474 Binder.restoreCallingIdentity(identity);
11475 }
11476 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011477
11478 /**
11479 * set removable eSIM as default eUICC.
11480 *
11481 * @hide
11482 */
11483 @Override
11484 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11485 enforceModifyPermission();
11486 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11487
11488 final long identity = Binder.clearCallingIdentity();
11489 try {
11490 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11491 } finally {
11492 Binder.restoreCallingIdentity(identity);
11493 }
11494 }
11495
11496 /**
11497 * Returns whether the removable eSIM is default eUICC or not.
11498 *
11499 * @hide
11500 */
11501 @Override
11502 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11503 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11504 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11505
11506 final long identity = Binder.clearCallingIdentity();
11507 try {
11508 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11509 } finally {
11510 Binder.restoreCallingIdentity(identity);
11511 }
11512 }
11513
11514
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011515}