blob: c48f0febfc61c2058a3a2cf0bcb2059d59223960 [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;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Hall Liu82694d52020-12-11 18:22:04 -080032import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070033import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070034import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.content.Context;
36import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070037import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070038import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080039import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070040import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.net.Uri;
42import android.os.AsyncResult;
43import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080044import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Bundle;
46import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.Looper;
49import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070050import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080051import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070052import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070053import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080054import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080055import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070056import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070057import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080058import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070060import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070061import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070062import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070063import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080064import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070065import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090066import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080067import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080068import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070069import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070070import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080071import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080072import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070073import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
111import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700112import android.telephony.gba.GbaAuthRequest;
113import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700114import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000116import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700117import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700118import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800119import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700120import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700122import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000123import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700124import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800126import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800128import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700131import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800133import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800134
Andrew Lee312e8172014-10-23 17:01:36 -0700135import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800136import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800137import com.android.ims.rcs.uce.eab.EabUtil;
Shuo Qian4a594052020-01-23 11:59:30 -0800138import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700140import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700141import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800142import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700143import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700144import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800145import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700147import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800148import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800149import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800150import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700151import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800153import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800155import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700156import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700157import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700158import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700160import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800161import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700162import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700163import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700164import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700165import com.android.internal.telephony.RIL;
Daniel Bright94f43662021-03-01 14:43:40 -0800166import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700167import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700168import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800170import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800171import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800172import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700173import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800174import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700175import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800176import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700177import com.android.internal.telephony.imsphone.ImsPhone;
178import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800179import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700180import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700181import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800182import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800184import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700185import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800186import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800188import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000189import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800190import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700191import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700192import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800193import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800194import com.android.phone.callcomposer.CallComposerPictureManager;
195import com.android.phone.callcomposer.CallComposerPictureTransfer;
196import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700197import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700198import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800199import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700200import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700201import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800202import com.android.services.telephony.TelecomAccountRegistry;
203import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800204import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800205
Hall Liu82694d52020-12-11 18:22:04 -0800206import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700207import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800208import java.io.IOException;
209import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700210import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800212import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800213import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800214import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800215import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100216import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800217import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700218import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800219import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800220import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800222import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800223import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224
225/**
226 * Implementation of the ITelephony interface.
227 */
Santos Cordon117fee72014-05-16 17:56:12 -0700228public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229 private static final String LOG_TAG = "PhoneInterfaceManager";
230 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
231 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233
234 // Message codes used with mMainThreadHandler
235 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700236 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
237 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700238 private static final int CMD_OPEN_CHANNEL = 9;
239 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
240 private static final int CMD_CLOSE_CHANNEL = 11;
241 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800242 private static final int CMD_NV_READ_ITEM = 13;
243 private static final int EVENT_NV_READ_ITEM_DONE = 14;
244 private static final int CMD_NV_WRITE_ITEM = 15;
245 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
246 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
247 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700248 private static final int CMD_RESET_MODEM_CONFIG = 19;
249 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800250 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
251 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800252 private static final int CMD_SEND_ENVELOPE = 25;
253 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000254 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
255 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700256 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
257 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
258 private static final int CMD_EXCHANGE_SIM_IO = 31;
259 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800260 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
261 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700262 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
263 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700264 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
265 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700266 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
267 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
268 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
269 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700270 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
271 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
272 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
273 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700274 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800275 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
276 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000277 private static final int CMD_SWITCH_SLOTS = 50;
278 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700279 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
280 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
281 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
282 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
283 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
284 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
285 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
286 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700287 private static final int CMD_GET_ALL_CELL_INFO = 60;
288 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
289 private static final int CMD_GET_CELL_LOCATION = 62;
290 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700291 private static final int CMD_MODEM_REBOOT = 64;
292 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700293 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
294 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800295 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
296 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700297 private static final int CMD_GET_MODEM_STATUS = 70;
298 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700299 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
300 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700301 private static final int CMD_ERASE_MODEM_CONFIG = 74;
302 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800303 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
304 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
305 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
306 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800307 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
308 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800309 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800310 private static final int CMD_GET_CALL_FORWARDING = 83;
311 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
312 private static final int CMD_SET_CALL_FORWARDING = 85;
313 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
314 private static final int CMD_GET_CALL_WAITING = 87;
315 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
316 private static final int CMD_SET_CALL_WAITING = 89;
317 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700318 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
319 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
320 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
321 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700322 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
323 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800324 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
325 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800326 private static final int CMD_SET_DATA_THROTTLING = 99;
327 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800328 private static final int CMD_SET_SIM_POWER = 101;
329 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800330 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
331 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
332 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
333 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800334 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
335 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000336 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800338 // Parameters of select command.
339 private static final int SELECT_COMMAND = 0xA4;
340 private static final int SELECT_P1 = 0x04;
341 private static final int SELECT_P2 = 0;
342 private static final int SELECT_P3 = 0x10;
343
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 /** The singleton instance. */
345 private static PhoneInterfaceManager sInstance;
346
Wink Saville3ab207e2014-11-20 13:07:20 -0800347 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800348 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800349 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700350 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800351 private AppOpsManager mAppOps;
352 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800353 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800354 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700355 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800356 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Peter Wangdafb9ac2020-01-15 14:13:38 -0800358 /** User Activity */
359 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800360 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
361
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700362 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
363
Derek Tan97ebb422014-09-05 16:55:38 -0700364 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
365 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800366 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800367 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700368
Michelecea4cf22018-12-21 15:00:11 -0800369 // String to store multi SIM allowed
370 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
371
Derek Tan740e1672017-06-27 14:56:27 -0700372 // The AID of ISD-R.
373 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
374
yinxub1bed742017-04-17 11:45:04 -0700375 private NetworkScanRequestTracker mNetworkScanRequestTracker;
376
David Kelly5e06a7f2018-03-12 14:10:59 +0000377 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
378 private static final int MANUFACTURER_CODE_LENGTH = 8;
379
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800380 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
381
Derek Tan89e89d42014-07-08 17:00:10 -0700382 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700383 * Experiment flag to enable erase modem config on reset network, default value is false
384 */
385 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
386 "reset_network_erase_modem_config_enabled";
387
Rambo Wang0f050d82021-02-12 11:43:36 -0800388 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
389
Naina Nallurid63128d2019-09-17 14:10:30 -0700390 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700391 * A request object to use for transmitting data to an ICC.
392 */
393 private static final class IccAPDUArgument {
394 public int channel, cla, command, p1, p2, p3;
395 public String data;
396
397 public IccAPDUArgument(int channel, int cla, int command,
398 int p1, int p2, int p3, String data) {
399 this.channel = channel;
400 this.cla = cla;
401 this.command = command;
402 this.p1 = p1;
403 this.p2 = p2;
404 this.p3 = p3;
405 this.data = data;
406 }
407 }
408
409 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700410 * A request object to use for transmitting data to an ICC.
411 */
412 private static final class ManualNetworkSelectionArgument {
413 public OperatorInfo operatorInfo;
414 public boolean persistSelection;
415
416 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
417 this.operatorInfo = operatorInfo;
418 this.persistSelection = persistSelection;
419 }
420 }
421
422 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
424 * request after sending. The main thread will notify the request when it is complete.
425 */
426 private static final class MainThreadRequest {
427 /** The argument to use for the request */
428 public Object argument;
429 /** The result of the request that is run on the main thread */
430 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800431 // The subscriber id that this request applies to. Defaults to
432 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
433 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434
Nathan Harold92bed182018-10-12 18:16:49 -0700435 // In cases where subId is unavailable, the caller needs to specify the phone.
436 public Phone phone;
437
vagdeviaf9a5b92018-08-15 16:01:53 -0700438 public WorkSource workSource;
439
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 public MainThreadRequest(Object argument) {
441 this.argument = argument;
442 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800443
Nathan Harold92bed182018-10-12 18:16:49 -0700444 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
445 this.argument = argument;
446 if (phone != null) {
447 this.phone = phone;
448 }
449 this.workSource = workSource;
450 }
451
vagdeviaf9a5b92018-08-15 16:01:53 -0700452 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800453 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800454 if (subId != null) {
455 this.subId = subId;
456 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700457 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 }
460
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800461 private static final class IncomingThirdPartyCallArgs {
462 public final ComponentName component;
463 public final String callId;
464 public final String callerDisplayName;
465
466 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
467 String callerDisplayName) {
468 this.component = component;
469 this.callId = callId;
470 this.callerDisplayName = callerDisplayName;
471 }
472 }
473
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 /**
475 * A handler that processes messages on the main thread in the phone process. Since many
476 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
477 * inbound binder threads to the main thread in the phone process. The Binder thread
478 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
479 * on, which will be notified when the operation completes and will contain the result of the
480 * request.
481 *
482 * <p>If a MainThreadRequest object is provided in the msg.obj field,
483 * note that request.result must be set to something non-null for the calling thread to
484 * unblock.
485 */
486 private final class MainThreadHandler extends Handler {
487 @Override
488 public void handleMessage(Message msg) {
489 MainThreadRequest request;
490 Message onCompleted;
491 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800494 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700495
496 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 case CMD_HANDLE_USSD_REQUEST: {
498 request = (MainThreadRequest) msg.obj;
499 final Phone phone = getPhoneFromRequest(request);
500 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
501 String ussdRequest = ussdObject.first;
502 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700503
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 if (!isUssdApiAllowed(request.subId)) {
505 // Carrier does not support use of this API, return failure.
506 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
507 UssdResponse response = new UssdResponse(ussdRequest, null);
508 Bundle returnData = new Bundle();
509 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
510 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700511
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 request.result = true;
513 notifyRequester(request);
514 return;
515 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700516
Pengquan Menga1bb6272018-09-06 09:59:22 -0700517 try {
518 request.result = phone != null
519 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
520 } catch (CallStateException cse) {
521 request.result = false;
522 }
523 // Wake up the requesting thread
524 notifyRequester(request);
525 break;
pkanwar32d516d2016-10-14 19:37:38 -0700526 }
527
Yorke Lee716f67e2015-06-17 15:39:16 -0700528 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700530 final Phone phone = getPhoneFromRequest(request);
531 request.result = phone != null ?
532 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
533 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800542 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 if (uiccCard == null) {
544 loge("iccTransmitApduLogicalChannel: No UICC");
545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
549 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 iccArgument.channel, iccArgument.cla, iccArgument.command,
552 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 break;
556
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 ar = (AsyncResult) msg.obj;
559 request = (MainThreadRequest) ar.userObj;
560 if (ar.exception == null && ar.result != null) {
561 request.result = ar.result;
562 } else {
563 request.result = new IccIoResult(0x6F, 0, (byte[])null);
564 if (ar.result == null) {
565 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800566 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800568 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 } else {
570 loge("iccTransmitApduLogicalChannel: Unknown exception");
571 }
572 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 break;
575
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
577 request = (MainThreadRequest) msg.obj;
578 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800579 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 if (uiccCard == null) {
581 loge("iccTransmitApduBasicChannel: No UICC");
582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 } else {
585 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
586 request);
587 uiccCard.iccTransmitApduBasicChannel(
588 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
589 iccArgument.p3, iccArgument.data, onCompleted);
590 }
591 break;
592
593 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
594 ar = (AsyncResult) msg.obj;
595 request = (MainThreadRequest) ar.userObj;
596 if (ar.exception == null && ar.result != null) {
597 request.result = ar.result;
598 } else {
599 request.result = new IccIoResult(0x6F, 0, (byte[])null);
600 if (ar.result == null) {
601 loge("iccTransmitApduBasicChannel: Empty response");
602 } else if (ar.exception instanceof CommandException) {
603 loge("iccTransmitApduBasicChannel: CommandException: " +
604 ar.exception);
605 } else {
606 loge("iccTransmitApduBasicChannel: Unknown exception");
607 }
608 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 break;
611
612 case CMD_EXCHANGE_SIM_IO:
613 request = (MainThreadRequest) msg.obj;
614 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800615 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 if (uiccCard == null) {
617 loge("iccExchangeSimIO: No UICC");
618 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 } else {
621 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
622 request);
623 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
624 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
625 iccArgument.data, onCompleted);
626 }
627 break;
628
629 case EVENT_EXCHANGE_SIM_IO_DONE:
630 ar = (AsyncResult) msg.obj;
631 request = (MainThreadRequest) ar.userObj;
632 if (ar.exception == null && ar.result != null) {
633 request.result = ar.result;
634 } else {
635 request.result = new IccIoResult(0x6f, 0, (byte[])null);
636 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 break;
639
Derek Tan4d5e5c12014-02-04 11:54:58 -0800640 case CMD_SEND_ENVELOPE:
641 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800642 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 if (uiccCard == null) {
644 loge("sendEnvelopeWithStatus: No UICC");
645 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 } else {
648 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
649 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
650 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800651 break;
652
653 case EVENT_SEND_ENVELOPE_DONE:
654 ar = (AsyncResult) msg.obj;
655 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700656 if (ar.exception == null && ar.result != null) {
657 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800658 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700659 request.result = new IccIoResult(0x6F, 0, (byte[])null);
660 if (ar.result == null) {
661 loge("sendEnvelopeWithStatus: Empty response");
662 } else if (ar.exception instanceof CommandException) {
663 loge("sendEnvelopeWithStatus: CommandException: " +
664 ar.exception);
665 } else {
666 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
667 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800670 break;
671
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 case CMD_OPEN_CHANNEL:
673 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800674 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800675 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 if (uiccCard == null) {
677 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800678 request.result = new IccOpenLogicalChannelResponse(-1,
679 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 } else {
682 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800683 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
684 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 break;
687
688 case EVENT_OPEN_CHANNEL_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 int[] result = (int[]) ar.result;
694 int channelId = result[0];
695 byte[] selectResponse = null;
696 if (result.length > 1) {
697 selectResponse = new byte[result.length - 1];
698 for (int i = 1; i < result.length; ++i) {
699 selectResponse[i - 1] = (byte) result[i];
700 }
701 }
702 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700703 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 if (ar.result == null) {
706 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 if (ar.exception != null) {
709 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
710 }
711
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700712 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700713 if (ar.exception instanceof CommandException) {
714 CommandException.Error error =
715 ((CommandException) (ar.exception)).getCommandError();
716 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700717 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700718 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700719 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700720 }
721 }
722 openChannelResp = new IccOpenLogicalChannelResponse(
723 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700725 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 break;
728
729 case CMD_CLOSE_CHANNEL:
730 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800731 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700732 if (uiccCard == null) {
733 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900734 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700736 } else {
737 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
738 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
739 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 break;
741
742 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800743 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
744 break;
745
746 case CMD_NV_READ_ITEM:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800749 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
750 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800751 break;
752
753 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 ar = (AsyncResult) msg.obj;
755 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800756 if (ar.exception == null && ar.result != null) {
757 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800759 request.result = "";
760 if (ar.result == null) {
761 loge("nvReadItem: Empty response");
762 } else if (ar.exception instanceof CommandException) {
763 loge("nvReadItem: CommandException: " +
764 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800766 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 }
768 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 break;
771
Jake Hambye994d462014-02-03 13:10:13 -0800772 case CMD_NV_WRITE_ITEM:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
775 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800776 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700777 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800778 break;
779
780 case EVENT_NV_WRITE_ITEM_DONE:
781 handleNullReturnEvent(msg, "nvWriteItem");
782 break;
783
784 case CMD_NV_WRITE_CDMA_PRL:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800787 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
790 case EVENT_NV_WRITE_CDMA_PRL_DONE:
791 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
792 break;
793
chen xu6dac5ab2018-10-26 17:39:23 -0700794 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800795 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700796 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800797 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800798 break;
799
chen xu6dac5ab2018-10-26 17:39:23 -0700800 case EVENT_RESET_MODEM_CONFIG_DONE:
801 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800802 break;
803
Sooraj Sasindran37444802020-08-11 10:40:43 -0700804 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
805 request = (MainThreadRequest) msg.obj;
806 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
807 request);
808 Phone phone = getPhoneFromRequest(request);
809 if (phone != null) {
810 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
811 } else {
812 loge("isNRDualConnectivityEnabled: No phone object");
813 request.result = false;
814 notifyRequester(request);
815 }
816 break;
817 }
818
819 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null && ar.result != null) {
823 request.result = ar.result;
824 } else {
825 // request.result must be set to something non-null
826 // for the calling thread to unblock
827 if (request.result != null) {
828 request.result = ar.result;
829 } else {
830 request.result = false;
831 }
832 if (ar.result == null) {
833 loge("isNRDualConnectivityEnabled: Empty response");
834 } else if (ar.exception instanceof CommandException) {
835 loge("isNRDualConnectivityEnabled: CommandException: "
836 + ar.exception);
837 } else {
838 loge("isNRDualConnectivityEnabled: Unknown exception");
839 }
840 }
841 notifyRequester(request);
842 break;
843
844 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
847 Phone phone = getPhoneFromRequest(request);
848 if (phone != null) {
849 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
850 request.workSource);
851 } else {
852 loge("enableNrDualConnectivity: No phone object");
853 request.result =
854 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
855 notifyRequester(request);
856 }
857 break;
858 }
859
860 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
861 ar = (AsyncResult) msg.obj;
862 request = (MainThreadRequest) ar.userObj;
863 if (ar.exception == null) {
864 request.result =
865 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
866 } else {
867 request.result =
868 TelephonyManager
869 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
870 if (ar.exception instanceof CommandException) {
871 CommandException.Error error =
872 ((CommandException) (ar.exception)).getCommandError();
873 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
874 request.result =
875 TelephonyManager
876 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000877 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
878 request.result =
879 TelephonyManager
880 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700881 }
882 loge("enableNrDualConnectivity" + ": CommandException: "
883 + ar.exception);
884 } else {
885 loge("enableNrDualConnectivity" + ": Unknown exception");
886 }
887 }
888 notifyRequester(request);
889 break;
890 }
891
SongFerngWang3ef3e072020-12-21 16:41:52 +0800892 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800893 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800894 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
895 request);
896 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 break;
898
SongFerngWang3ef3e072020-12-21 16:41:52 +0800899 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 ar = (AsyncResult) msg.obj;
901 request = (MainThreadRequest) ar.userObj;
902 if (ar.exception == null && ar.result != null) {
903 request.result = ar.result; // Integer
904 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530905 // request.result must be set to something non-null
906 // for the calling thread to unblock
907 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800909 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800911 loge("getAllowedNetworkTypesBitmask: CommandException: "
912 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800913 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800914 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800915 }
916 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700917 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 break;
919
SongFerngWang3ef3e072020-12-21 16:41:52 +0800920 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800921 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800922 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
923 request);
924 Pair<Integer, Long> reasonWithNetworkTypes =
925 (Pair<Integer, Long>) request.argument;
926 getPhoneFromRequest(request).setAllowedNetworkTypes(
927 reasonWithNetworkTypes.first,
928 reasonWithNetworkTypes.second,
929 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800930 break;
931
SongFerngWang3ef3e072020-12-21 16:41:52 +0800932 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
933 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800934 break;
935
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000936 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
937 request = (MainThreadRequest)msg.obj;
938 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800939 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000940 break;
941
942 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
943 ar = (AsyncResult)msg.obj;
944 request = (MainThreadRequest)ar.userObj;
945 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700946 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000947 break;
948
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800949 case CMD_SET_VOICEMAIL_NUMBER:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
952 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800953 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
954 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800955 break;
956
957 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
958 handleNullReturnEvent(msg, "setVoicemailNumber");
959 break;
960
Stuart Scott54788802015-03-30 13:18:01 -0700961 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
964 request);
965 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
966 break;
967
968 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
969 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
970 break;
971
Shishir Agrawal302c8692015-06-19 13:49:39 -0700972 case CMD_PERFORM_NETWORK_SCAN:
973 request = (MainThreadRequest) msg.obj;
974 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
975 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
976 break;
977
Hall Liu27d24262020-09-18 19:04:59 -0700978 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800979 request = (MainThreadRequest) msg.obj;
980 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700981 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
982 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
983 request.argument;
984 int callForwardingReason = args.first;
985 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800986 break;
Hall Liu27d24262020-09-18 19:04:59 -0700987 }
988 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800989 ar = (AsyncResult) msg.obj;
990 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700991 TelephonyManager.CallForwardingInfoCallback callback =
992 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
993 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800994 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700995 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800996 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
997 for (CallForwardInfo callForwardInfo : callForwardInfos) {
998 // Service Class is a bit mask per 3gpp 27.007. Search for
999 // any service for voice call.
1000 if ((callForwardInfo.serviceClass
1001 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001002 callForwardingInfo = new CallForwardingInfo(true,
1003 callForwardInfo.reason,
1004 callForwardInfo.number,
1005 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001006 break;
1007 }
1008 }
1009 // Didn't find a call forward info for voice call.
1010 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001011 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1012 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001013 }
Hall Liu27d24262020-09-18 19:04:59 -07001014 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001015 } else {
1016 if (ar.result == null) {
1017 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1018 }
1019 if (ar.exception != null) {
1020 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1021 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001022 int errorCode = TelephonyManager
1023 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001024 if (ar.exception instanceof CommandException) {
1025 CommandException.Error error =
1026 ((CommandException) (ar.exception)).getCommandError();
1027 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001028 errorCode = TelephonyManager
1029 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001030 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001031 errorCode = TelephonyManager
1032 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001033 }
1034 }
Hall Liu27d24262020-09-18 19:04:59 -07001035 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001036 }
Shuo Qian4a594052020-01-23 11:59:30 -08001037 break;
Hall Liu27d24262020-09-18 19:04:59 -07001038 }
Shuo Qian4a594052020-01-23 11:59:30 -08001039
Hall Liu27d24262020-09-18 19:04:59 -07001040 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001041 request = (MainThreadRequest) msg.obj;
1042 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001043 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001044 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001045 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1046 request.argument).first;
1047 request.phone.setCallForwardingOption(
1048 callForwardingInfoToSet.isEnabled()
1049 ? CommandsInterface.CF_ACTION_ENABLE
1050 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001051 callForwardingInfoToSet.getReason(),
1052 callForwardingInfoToSet.getNumber(),
1053 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1054 break;
Hall Liu27d24262020-09-18 19:04:59 -07001055 }
Shuo Qian4a594052020-01-23 11:59:30 -08001056
Hall Liu27d24262020-09-18 19:04:59 -07001057 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001060 Consumer<Integer> callback =
1061 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1062 request.argument).second;
1063 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001064 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001065 int errorCode = TelephonyManager.CallForwardingInfoCallback
1066 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001067 if (ar.exception instanceof CommandException) {
1068 CommandException.Error error =
1069 ((CommandException) (ar.exception)).getCommandError();
1070 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001071 errorCode = TelephonyManager.CallForwardingInfoCallback
1072 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001073 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001074 errorCode = TelephonyManager.CallForwardingInfoCallback
1075 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001076 }
1077 }
1078 callback.accept(errorCode);
1079 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001080 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001081 }
Shuo Qian4a594052020-01-23 11:59:30 -08001082 break;
Hall Liu27d24262020-09-18 19:04:59 -07001083 }
Shuo Qian4a594052020-01-23 11:59:30 -08001084
Hall Liu27d24262020-09-18 19:04:59 -07001085 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001086 request = (MainThreadRequest) msg.obj;
1087 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1088 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1089 break;
Hall Liu27d24262020-09-18 19:04:59 -07001090 }
Shuo Qian4a594052020-01-23 11:59:30 -08001091
Hall Liu27d24262020-09-18 19:04:59 -07001092 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001095 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001096 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1097 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001098 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001099 // Service Class is a bit mask per 3gpp 27.007.
1100 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001101 if (callForwardResults.length > 1
1102 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001103 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001104 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001105 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1106 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001107 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001108 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001109 }
1110 } else {
1111 if (ar.result == null) {
1112 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1113 }
1114 if (ar.exception != null) {
1115 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1116 }
1117 if (ar.exception instanceof CommandException) {
1118 CommandException.Error error =
1119 ((CommandException) (ar.exception)).getCommandError();
1120 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1121 callForwardingStatus =
1122 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1123 }
1124 }
1125 }
Hall Liu27d24262020-09-18 19:04:59 -07001126 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001127 break;
Hall Liu27d24262020-09-18 19:04:59 -07001128 }
Shuo Qian4a594052020-01-23 11:59:30 -08001129
Hall Liu27d24262020-09-18 19:04:59 -07001130 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001131 request = (MainThreadRequest) msg.obj;
1132 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001133 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1134 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001135 break;
Hall Liu27d24262020-09-18 19:04:59 -07001136 }
Shuo Qian4a594052020-01-23 11:59:30 -08001137
Hall Liu27d24262020-09-18 19:04:59 -07001138 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001139 ar = (AsyncResult) msg.obj;
1140 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001141 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1142 Consumer<Integer> callback =
1143 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1144 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001145 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001146 if (ar.exception instanceof CommandException) {
1147 CommandException.Error error =
1148 ((CommandException) (ar.exception)).getCommandError();
1149 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1150 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1151 } else {
1152 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1153 }
1154 } else {
1155 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1156 }
1157 } else {
1158 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1159 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001160 }
Shuo Qian4a594052020-01-23 11:59:30 -08001161 break;
Hall Liu27d24262020-09-18 19:04:59 -07001162 }
Shuo Qian4a594052020-01-23 11:59:30 -08001163
Shishir Agrawal302c8692015-06-19 13:49:39 -07001164 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1165 ar = (AsyncResult) msg.obj;
1166 request = (MainThreadRequest) ar.userObj;
1167 CellNetworkScanResult cellScanResult;
1168 if (ar.exception == null && ar.result != null) {
1169 cellScanResult = new CellNetworkScanResult(
1170 CellNetworkScanResult.STATUS_SUCCESS,
1171 (List<OperatorInfo>) ar.result);
1172 } else {
1173 if (ar.result == null) {
1174 loge("getCellNetworkScanResults: Empty response");
1175 }
1176 if (ar.exception != null) {
1177 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1178 }
1179 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1180 if (ar.exception instanceof CommandException) {
1181 CommandException.Error error =
1182 ((CommandException) (ar.exception)).getCommandError();
1183 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1184 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1185 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1186 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1187 }
1188 }
1189 cellScanResult = new CellNetworkScanResult(errorCode, null);
1190 }
1191 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001192 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001193 break;
1194
1195 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1196 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001197 ManualNetworkSelectionArgument selArg =
1198 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001199 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1200 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001201 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1202 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001203 break;
1204
1205 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001206 ar = (AsyncResult) msg.obj;
1207 request = (MainThreadRequest) ar.userObj;
1208 if (ar.exception == null) {
1209 request.result = true;
1210 } else {
1211 request.result = false;
1212 loge("setNetworkSelectionModeManual " + ar.exception);
1213 }
1214 notifyRequester(request);
1215 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001216 break;
1217
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001218 case CMD_GET_MODEM_ACTIVITY_INFO:
1219 request = (MainThreadRequest) msg.obj;
1220 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001221 if (defaultPhone != null) {
1222 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001223 } else {
1224 ResultReceiver result = (ResultReceiver) request.argument;
1225 Bundle bundle = new Bundle();
1226 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001227 new ModemActivityInfo(0, 0, 0,
1228 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001229 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001230 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001231 break;
1232
Hall Liud0f208c2020-10-14 16:54:44 -07001233 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001234 ar = (AsyncResult) msg.obj;
1235 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001236 ResultReceiver result = (ResultReceiver) request.argument;
1237
Hall Liud0f208c2020-10-14 16:54:44 -07001238 ModemActivityInfo ret = null;
1239 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001240 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001241 // Update the last modem activity info and the result of the request.
1242 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1243 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001244 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001245 int[] txTimeMs = info.getTransmitTimeMillis();
1246 int[] lastModemTxTimeMs = mLastModemActivityInfo
1247 .getTransmitTimeMillis();
1248 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1249 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1250 }
Hall Liu49656c02020-10-09 19:00:11 -07001251 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001252 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1253 + mLastModemActivityInfo.getSleepTimeMillis());
1254 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1255 + mLastModemActivityInfo.getIdleTimeMillis());
1256 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1257 mLastModemActivityInfo.setReceiveTimeMillis(
1258 info.getReceiveTimeMillis()
1259 + mLastModemActivityInfo.getReceiveTimeMillis());
1260 }
Hall Liu49656c02020-10-09 19:00:11 -07001261 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001262 mLastModemActivityInfo.getSleepTimeMillis(),
1263 mLastModemActivityInfo.getIdleTimeMillis(),
1264 mLastModemActivityInfo.getTransmitTimeMillis(),
1265 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001266 } else {
1267 if (ar.result == null) {
1268 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001269 error = TelephonyManager.ModemActivityInfoException
1270 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001271 } else if (ar.exception instanceof CommandException) {
1272 loge("queryModemActivityInfo: CommandException: " +
1273 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001274 error = TelephonyManager.ModemActivityInfoException
1275 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001276 } else {
1277 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001278 error = TelephonyManager.ModemActivityInfoException
1279 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001280 }
1281 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001282 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001283 if (ret != null) {
1284 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1285 } else {
1286 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1287 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001288 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001289 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001290 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001291 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001292
Meng Wang1a7c35a2016-05-05 20:56:15 -07001293 case CMD_SET_ALLOWED_CARRIERS:
1294 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001295 CarrierRestrictionRules argument =
1296 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001297 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001298 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 break;
1300
1301 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
1304 if (ar.exception == null && ar.result != null) {
1305 request.result = ar.result;
1306 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001307 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1308 if (ar.exception instanceof CommandException) {
1309 loge("setAllowedCarriers: CommandException: " + ar.exception);
1310 CommandException.Error error =
1311 ((CommandException) (ar.exception)).getCommandError();
1312 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1313 request.result =
1314 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1315 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001316 } else {
1317 loge("setAllowedCarriers: Unknown exception");
1318 }
1319 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001320 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001321 break;
1322
1323 case CMD_GET_ALLOWED_CARRIERS:
1324 request = (MainThreadRequest) msg.obj;
1325 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001326 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001327 break;
1328
1329 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
1332 if (ar.exception == null && ar.result != null) {
1333 request.result = ar.result;
1334 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001335 request.result = new IllegalStateException(
1336 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001337 if (ar.result == null) {
1338 loge("getAllowedCarriers: Empty response");
1339 } else if (ar.exception instanceof CommandException) {
1340 loge("getAllowedCarriers: CommandException: " +
1341 ar.exception);
1342 } else {
1343 loge("getAllowedCarriers: Unknown exception");
1344 }
1345 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001346 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001347 break;
1348
Nathan Haroldb3014052017-01-25 15:57:32 -08001349 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1350 ar = (AsyncResult) msg.obj;
1351 request = (MainThreadRequest) ar.userObj;
1352 if (ar.exception == null && ar.result != null) {
1353 request.result = ar.result;
1354 } else {
1355 request.result = new IllegalArgumentException(
1356 "Failed to retrieve Forbidden Plmns");
1357 if (ar.result == null) {
1358 loge("getForbiddenPlmns: Empty response");
1359 } else {
1360 loge("getForbiddenPlmns: Unknown exception");
1361 }
1362 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001363 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001364 break;
1365
1366 case CMD_GET_FORBIDDEN_PLMNS:
1367 request = (MainThreadRequest) msg.obj;
1368 uiccCard = getUiccCardFromRequest(request);
1369 if (uiccCard == null) {
1370 loge("getForbiddenPlmns() UiccCard is null");
1371 request.result = new IllegalArgumentException(
1372 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001373 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001374 break;
1375 }
1376 Integer appType = (Integer) request.argument;
1377 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1378 if (uiccApp == null) {
1379 loge("getForbiddenPlmns() no app with specified type -- "
1380 + appType);
1381 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001382 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001383 break;
1384 } else {
1385 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1386 + " specified type -- " + appType);
1387 }
1388 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1389 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1390 onCompleted);
1391 break;
1392
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001393 case CMD_SWITCH_SLOTS:
1394 request = (MainThreadRequest) msg.obj;
1395 int[] physicalSlots = (int[]) request.argument;
1396 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1397 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1398 break;
1399
1400 case EVENT_SWITCH_SLOTS_DONE:
1401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
1403 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001404 notifyRequester(request);
1405 break;
1406 case CMD_GET_NETWORK_SELECTION_MODE:
1407 request = (MainThreadRequest) msg.obj;
1408 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1409 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1410 break;
1411
1412 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1413 ar = (AsyncResult) msg.obj;
1414 request = (MainThreadRequest) ar.userObj;
1415 if (ar.exception != null) {
1416 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1417 } else {
1418 int mode = ((int[]) ar.result)[0];
1419 if (mode == 0) {
1420 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1421 } else {
1422 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1423 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001424 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001425 notifyRequester(request);
1426 break;
1427 case CMD_GET_CDMA_ROAMING_MODE:
1428 request = (MainThreadRequest) msg.obj;
1429 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1430 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1431 break;
1432 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1433 ar = (AsyncResult) msg.obj;
1434 request = (MainThreadRequest) ar.userObj;
1435 if (ar.exception != null) {
1436 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1437 } else {
1438 request.result = ((int[]) ar.result)[0];
1439 }
1440 notifyRequester(request);
1441 break;
1442 case CMD_SET_CDMA_ROAMING_MODE:
1443 request = (MainThreadRequest) msg.obj;
1444 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1445 int mode = (int) request.argument;
1446 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1447 break;
1448 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 request.result = ar.exception == null;
1452 notifyRequester(request);
1453 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001454 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1455 request = (MainThreadRequest) msg.obj;
1456 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1457 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1458 break;
1459 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 if (ar.exception != null) {
1463 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1464 } else {
1465 request.result = ((int[]) ar.result)[0];
1466 }
1467 notifyRequester(request);
1468 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001469 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1470 request = (MainThreadRequest) msg.obj;
1471 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1472 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001473 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1474 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001475 break;
1476 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1477 ar = (AsyncResult) msg.obj;
1478 request = (MainThreadRequest) ar.userObj;
1479 request.result = ar.exception == null;
1480 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001481 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001482 case CMD_GET_ALL_CELL_INFO:
1483 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001484 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001485 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001486 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001487 case EVENT_GET_ALL_CELL_INFO_DONE:
1488 ar = (AsyncResult) msg.obj;
1489 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001490 // If a timeout occurs, the response will be null
1491 request.result = (ar.exception == null && ar.result != null)
1492 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 synchronized (request) {
1494 request.notifyAll();
1495 }
1496 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001497 case CMD_REQUEST_CELL_INFO_UPDATE:
1498 request = (MainThreadRequest) msg.obj;
1499 request.phone.requestCellInfoUpdate(request.workSource,
1500 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1501 break;
1502 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1503 ar = (AsyncResult) msg.obj;
1504 request = (MainThreadRequest) ar.userObj;
1505 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1506 try {
1507 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001508 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001509 cb.onError(
1510 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1511 ar.exception.getClass().getName(),
1512 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001513 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001514 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001515 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001516 } else {
1517 // use the result as returned
1518 cb.onCellInfo((List<CellInfo>) ar.result);
1519 }
1520 } catch (RemoteException re) {
1521 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1522 }
1523 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001524 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001525 request = (MainThreadRequest) msg.obj;
1526 WorkSource ws = (WorkSource) request.argument;
1527 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001528 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001529 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001530 }
1531 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001532 ar = (AsyncResult) msg.obj;
1533 request = (MainThreadRequest) ar.userObj;
1534 if (ar.exception == null) {
1535 request.result = ar.result;
1536 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001537 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001538 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001539 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001540 }
1541
1542 synchronized (request) {
1543 request.notifyAll();
1544 }
1545 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001546 }
chen xu6dac5ab2018-10-26 17:39:23 -07001547 case CMD_MODEM_REBOOT:
1548 request = (MainThreadRequest) msg.obj;
1549 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001550 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001551 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001552 case EVENT_CMD_MODEM_REBOOT_DONE:
1553 handleNullReturnEvent(msg, "rebootModem");
1554 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001555 case CMD_REQUEST_ENABLE_MODEM:
1556 request = (MainThreadRequest) msg.obj;
1557 boolean enable = (boolean) request.argument;
1558 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001559 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001560 PhoneConfigurationManager.getInstance()
1561 .enablePhone(request.phone, enable, onCompleted);
1562 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001563 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001564 ar = (AsyncResult) msg.obj;
1565 request = (MainThreadRequest) ar.userObj;
1566 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001567 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001568 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001569 if ((boolean) request.result) {
1570 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1571 updateModemStateMetrics();
1572 } else {
1573 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1574 + ar.exception);
1575 }
1576 notifyRequester(request);
1577 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001578 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001579 case CMD_GET_MODEM_STATUS:
1580 request = (MainThreadRequest) msg.obj;
1581 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1582 PhoneConfigurationManager.getInstance()
1583 .getPhoneStatusFromModem(request.phone, onCompleted);
1584 break;
1585 case EVENT_GET_MODEM_STATUS_DONE:
1586 ar = (AsyncResult) msg.obj;
1587 request = (MainThreadRequest) ar.userObj;
1588 int id = request.phone.getPhoneId();
1589 if (ar.exception == null && ar.result != null) {
1590 request.result = ar.result;
1591 //update the cache as modem status has changed
1592 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1593 (boolean) request.result);
1594 } else {
1595 // Return true if modem status cannot be retrieved. For most cases,
1596 // modem status is on. And for older version modems, GET_MODEM_STATUS
1597 // and disable modem are not supported. Modem is always on.
1598 // TODO: this should be fixed in R to support a third
1599 // status UNKNOWN b/131631629
1600 request.result = true;
1601 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1602 + ar.exception);
1603 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001604 notifyRequester(request);
1605 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001606 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1607 request = (MainThreadRequest) msg.obj;
1608 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1609 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1610 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1611 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1612 break;
1613 }
1614 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1618 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1619 args.second.accept(ar.exception == null);
1620 notifyRequester(request);
1621 break;
1622 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001623 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1624 request = (MainThreadRequest) msg.obj;
1625 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1626 Phone phone = getPhoneFromRequest(request);
1627 if (phone != null) {
1628 phone.getSystemSelectionChannels(onCompleted);
1629 } else {
1630 loge("getSystemSelectionChannels: No phone object");
1631 request.result = new ArrayList<RadioAccessSpecifier>();
1632 notifyRequester(request);
1633 }
1634 break;
1635 }
1636 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1637 ar = (AsyncResult) msg.obj;
1638 request = (MainThreadRequest) ar.userObj;
1639 if (ar.exception == null && ar.result != null) {
1640 request.result = ar.result;
1641 } else {
1642 request.result = new IllegalArgumentException(
1643 "Failed to retrieve system selection channels");
1644 if (ar.result == null) {
1645 loge("getSystemSelectionChannels: Empty response");
1646 } else {
1647 loge("getSystemSelectionChannels: Unknown exception");
1648 }
1649 }
1650 notifyRequester(request);
1651 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001652 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1653 ar = (AsyncResult) msg.obj;
1654 request = (MainThreadRequest) ar.userObj;
1655 if (ar.exception == null && ar.result != null) {
1656 request.result = ar.result;
1657 } else {
1658 request.result = -1;
1659 loge("Failed to set Forbidden Plmns");
1660 if (ar.result == null) {
1661 loge("setForbidenPlmns: Empty response");
1662 } else if (ar.exception != null) {
1663 loge("setForbiddenPlmns: Exception: " + ar.exception);
1664 request.result = -1;
1665 } else {
1666 loge("setForbiddenPlmns: Unknown exception");
1667 }
1668 }
1669 notifyRequester(request);
1670 break;
1671 case CMD_SET_FORBIDDEN_PLMNS:
1672 request = (MainThreadRequest) msg.obj;
1673 uiccCard = getUiccCardFromRequest(request);
1674 if (uiccCard == null) {
1675 loge("setForbiddenPlmns: UiccCard is null");
1676 request.result = -1;
1677 notifyRequester(request);
1678 break;
1679 }
1680 Pair<Integer, List<String>> setFplmnsArgs =
1681 (Pair<Integer, List<String>>) request.argument;
1682 appType = setFplmnsArgs.first;
1683 List<String> fplmns = setFplmnsArgs.second;
1684 uiccApp = uiccCard.getApplicationByType(appType);
1685 if (uiccApp == null) {
1686 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1687 request.result = -1;
1688 loge("Failed to get UICC App");
1689 notifyRequester(request);
1690 } else {
1691 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1692 ((SIMRecords) uiccApp.getIccRecords())
1693 .setForbiddenPlmns(onCompleted, fplmns);
1694 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001695 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001696 case CMD_ERASE_MODEM_CONFIG:
1697 request = (MainThreadRequest) msg.obj;
1698 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1699 defaultPhone.eraseModemConfig(onCompleted);
1700 break;
1701 case EVENT_ERASE_MODEM_CONFIG_DONE:
1702 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001703 break;
zoey chene02881a2019-12-30 16:11:23 +08001704
1705 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1708 Pair<String, String> changed = (Pair<String, String>) request.argument;
1709 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1710 changed.first, changed.second, onCompleted);
1711 break;
1712 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 if (ar.exception == null) {
1716 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001717 // If the operation is successful, update the PIN storage
1718 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1719 int phoneId = getPhoneFromRequest(request).getPhoneId();
1720 UiccController.getInstance().getPinStorage()
1721 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001722 } else {
1723 request.result = msg.arg1;
1724 }
1725 notifyRequester(request);
1726 break;
1727
Michele Berionne5e411512020-11-13 02:36:59 +00001728 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001729 request = (MainThreadRequest) msg.obj;
1730 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1731 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1732 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1733 enabled.first, enabled.second, onCompleted);
1734 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001735 }
zoey chene02881a2019-12-30 16:11:23 +08001736 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1737 ar = (AsyncResult) msg.obj;
1738 request = (MainThreadRequest) ar.userObj;
1739 if (ar.exception == null) {
1740 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001741 // If the operation is successful, update the PIN storage
1742 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1743 int phoneId = getPhoneFromRequest(request).getPhoneId();
1744 if (enabled.first) {
1745 UiccController.getInstance().getPinStorage()
1746 .storePin(enabled.second, phoneId);
1747 } else {
1748 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1749 }
zoey chene02881a2019-12-30 16:11:23 +08001750 } else {
1751 request.result = msg.arg1;
1752 }
Michele Berionne5e411512020-11-13 02:36:59 +00001753
1754
zoey chene02881a2019-12-30 16:11:23 +08001755 notifyRequester(request);
1756 break;
1757
Peter Wangdafb9ac2020-01-15 14:13:38 -08001758 case MSG_NOTIFY_USER_ACTIVITY:
1759 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001760 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001761 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1762 getDefaultPhone().getContext().sendBroadcastAsUser(
1763 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1764 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001765
1766 case CMD_SET_DATA_THROTTLING: {
1767 request = (MainThreadRequest) msg.obj;
1768 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1769 DataThrottlingRequest dataThrottlingRequest =
1770 (DataThrottlingRequest) request.argument;
1771 Phone phone = getPhoneFromRequest(request);
1772 if (phone != null) {
1773 phone.setDataThrottling(onCompleted,
1774 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1775 dataThrottlingRequest.getCompletionDurationMillis());
1776 } else {
1777 loge("setDataThrottling: No phone object");
1778 request.result =
1779 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1780 notifyRequester(request);
1781 }
1782
1783 break;
1784 }
1785 case EVENT_SET_DATA_THROTTLING_DONE:
1786 ar = (AsyncResult) msg.obj;
1787 request = (MainThreadRequest) ar.userObj;
1788
1789 if (ar.exception == null) {
1790 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1791 } else if (ar.exception instanceof CommandException) {
1792 loge("setDataThrottling: CommandException: " + ar.exception);
1793 CommandException.Error error =
1794 ((CommandException) (ar.exception)).getCommandError();
1795
1796 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1797 request.result = TelephonyManager
1798 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1799 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1800 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1801 } else {
1802 request.result =
1803 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1804 }
1805 } else {
1806 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1807 }
1808 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1809 notifyRequester(request);
1810 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001811
1812 case CMD_SET_SIM_POWER: {
1813 request = (MainThreadRequest) msg.obj;
1814 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1815 request = (MainThreadRequest) msg.obj;
1816 int stateToSet =
1817 ((Pair<Integer, IIntegerConsumer>)
1818 request.argument).first;
1819 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1820 break;
1821 }
1822 case EVENT_SET_SIM_POWER_DONE: {
1823 ar = (AsyncResult) msg.obj;
1824 request = (MainThreadRequest) ar.userObj;
1825 IIntegerConsumer callback =
1826 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1827 if (ar.exception != null) {
1828 loge("setSimPower exception: " + ar.exception);
1829 int errorCode = TelephonyManager.CallForwardingInfoCallback
1830 .RESULT_ERROR_UNKNOWN;
1831 if (ar.exception instanceof CommandException) {
1832 CommandException.Error error =
1833 ((CommandException) (ar.exception)).getCommandError();
1834 if (error == CommandException.Error.SIM_ERR) {
1835 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1836 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1837 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1838 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1839 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1840 } else {
1841 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1842 }
1843 }
1844 try {
1845 callback.accept(errorCode);
1846 } catch (RemoteException e) {
1847 // Ignore if the remote process is no longer available to call back.
1848 Log.w(LOG_TAG, "setSimPower: callback not available.");
1849 }
1850 } else {
1851 try {
1852 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1853 } catch (RemoteException e) {
1854 // Ignore if the remote process is no longer available to call back.
1855 Log.w(LOG_TAG, "setSimPower: callback not available.");
1856 }
1857 }
1858 break;
1859 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001860 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1861 request = (MainThreadRequest) msg.obj;
1862
1863 final Phone phone = getPhoneFromRequest(request);
1864 if (phone == null || phone.getServiceStateTracker() == null) {
1865 request.result = new IllegalStateException("Phone or SST is null");
1866 notifyRequester(request);
1867 break;
1868 }
1869
1870 Pair<Integer, SignalStrengthUpdateRequest> pair =
1871 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1872 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1873 request);
1874 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1875 request.subId, pair.first /*callingUid*/,
1876 pair.second /*request*/, onCompleted);
1877 break;
1878 }
1879 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1880 ar = (AsyncResult) msg.obj;
1881 request = (MainThreadRequest) ar.userObj;
1882 // request.result will be the exception of ar if present, true otherwise.
1883 // Be cautious not to leave result null which will wait() forever
1884 request.result = ar.exception != null ? ar.exception : true;
1885 notifyRequester(request);
1886 break;
1887 }
1888 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1889 request = (MainThreadRequest) msg.obj;
1890
1891 Phone phone = getPhoneFromRequest(request);
1892 if (phone == null || phone.getServiceStateTracker() == null) {
1893 request.result = new IllegalStateException("Phone or SST is null");
1894 notifyRequester(request);
1895 break;
1896 }
1897
1898 Pair<Integer, SignalStrengthUpdateRequest> pair =
1899 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1900 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1901 request);
1902 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1903 request.subId, pair.first /*callingUid*/,
1904 pair.second /*request*/, onCompleted);
1905 break;
1906 }
1907 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1908 ar = (AsyncResult) msg.obj;
1909 request = (MainThreadRequest) ar.userObj;
1910 request.result = ar.exception != null ? ar.exception : true;
1911 notifyRequester(request);
1912 break;
1913 }
Jordan Liu109698e2020-11-24 14:50:34 -08001914
Michele Berionne5e411512020-11-13 02:36:59 +00001915 case CMD_PREPARE_UNATTENDED_REBOOT:
1916 request = (MainThreadRequest) msg.obj;
1917 request.result =
1918 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1919 notifyRequester(request);
1920 break;
1921
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 default:
1923 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1924 break;
1925 }
1926 }
Jake Hambye994d462014-02-03 13:10:13 -08001927
Pengquan Menga1bb6272018-09-06 09:59:22 -07001928 private void notifyRequester(MainThreadRequest request) {
1929 synchronized (request) {
1930 request.notifyAll();
1931 }
1932 }
1933
Jake Hambye994d462014-02-03 13:10:13 -08001934 private void handleNullReturnEvent(Message msg, String command) {
1935 AsyncResult ar = (AsyncResult) msg.obj;
1936 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1937 if (ar.exception == null) {
1938 request.result = true;
1939 } else {
1940 request.result = false;
1941 if (ar.exception instanceof CommandException) {
1942 loge(command + ": CommandException: " + ar.exception);
1943 } else {
1944 loge(command + ": Unknown exception");
1945 }
1946 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001947 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 }
1950
1951 /**
1952 * Posts the specified command to be executed on the main thread,
1953 * waits for the request to complete, and returns the result.
1954 * @see #sendRequestAsync
1955 */
1956 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001957 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1958 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001959 }
1960
1961 /**
1962 * Posts the specified command to be executed on the main thread,
1963 * waits for the request to complete, and returns the result.
1964 * @see #sendRequestAsync
1965 */
1966 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1967 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001968 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001969 }
1970
1971 /**
1972 * Posts the specified command to be executed on the main thread,
1973 * waits for the request to complete, and returns the result.
1974 * @see #sendRequestAsync
1975 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001976 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001977 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1978 }
1979
1980 /**
1981 * Posts the specified command to be executed on the main thread,
1982 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1983 * if not timeout or null otherwise.
1984 * @see #sendRequestAsync
1985 */
1986 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1987 long timeoutInMs) {
1988 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001989 }
1990
1991 /**
1992 * Posts the specified command to be executed on the main thread,
1993 * waits for the request to complete, and returns the result.
1994 * @see #sendRequestAsync
1995 */
Nathan Harold92bed182018-10-12 18:16:49 -07001996 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001997 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001998 }
1999
2000 /**
2001 * Posts the specified command to be executed on the main thread,
2002 * waits for the request to complete, and returns the result.
2003 * @see #sendRequestAsync
2004 */
2005 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002006 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2007 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002008 }
2009
2010 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002011 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2012 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2013 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002014 * @see #sendRequestAsync
2015 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002016 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2017 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2019 throw new RuntimeException("This method will deadlock if called from the main thread.");
2020 }
2021
Nathan Harold92bed182018-10-12 18:16:49 -07002022 MainThreadRequest request = null;
2023 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2024 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2025 } else if (phone != null) {
2026 request = new MainThreadRequest(argument, phone, workSource);
2027 } else {
2028 request = new MainThreadRequest(argument, subId, workSource);
2029 }
2030
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 Message msg = mMainThreadHandler.obtainMessage(command, request);
2032 msg.sendToTarget();
2033
Rambo Wang0f050d82021-02-12 11:43:36 -08002034
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002035 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002036 if (timeoutInMs >= 0) {
2037 // Wait for at least timeoutInMs before returning null request result
2038 long now = SystemClock.elapsedRealtime();
2039 long deadline = now + timeoutInMs;
2040 while (request == null && now < deadline) {
2041 try {
2042 request.wait(deadline - now);
2043 } catch (InterruptedException e) {
2044 // Do nothing, go back and check if request is completed or timeout
2045 } finally {
2046 now = SystemClock.elapsedRealtime();
2047 }
2048 }
2049 } else {
2050 // Wait for the request to complete
2051 while (request.result == null) {
2052 try {
2053 request.wait();
2054 } catch (InterruptedException e) {
2055 // Do nothing, go back and wait until the request is complete
2056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 }
2058 }
2059 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002060 if (request.result == null) {
2061 Log.wtf(LOG_TAG,
2062 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 return request.result;
2065 }
2066
2067 /**
2068 * Asynchronous ("fire and forget") version of sendRequest():
2069 * Posts the specified command to be executed on the main thread, and
2070 * returns immediately.
2071 * @see #sendRequest
2072 */
2073 private void sendRequestAsync(int command) {
2074 mMainThreadHandler.sendEmptyMessage(command);
2075 }
2076
2077 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002078 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002079 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002080 */
2081 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002082 sendRequestAsync(command, argument, null, null);
2083 }
2084
2085 /**
2086 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2087 * @see {@link #sendRequest(int,Object)}
2088 */
2089 private void sendRequestAsync(
2090 int command, Object argument, Phone phone, WorkSource workSource) {
2091 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002092 Message msg = mMainThreadHandler.obtainMessage(command, request);
2093 msg.sendToTarget();
2094 }
2095
2096 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 * Initialize the singleton PhoneInterfaceManager instance.
2098 * This is only done once, at startup, from PhoneApp.onCreate().
2099 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002100 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 synchronized (PhoneInterfaceManager.class) {
2102 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002103 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 } else {
2105 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2106 }
2107 return sInstance;
2108 }
2109 }
2110
2111 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002112 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002115 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002116 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2118 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002119 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002120 mTelephonySharedPreferences =
2121 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002122 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002123 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002124 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002125 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002126
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 publish();
2128 }
2129
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002130 private Phone getDefaultPhone() {
2131 Phone thePhone = getPhone(getDefaultSubscription());
2132 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2133 }
2134
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 private void publish() {
2136 if (DBG) log("publish: " + this);
2137
Peter Wangc035ce42020-01-08 21:00:22 -08002138 TelephonyFrameworkInitializer
2139 .getTelephonyServiceManager()
2140 .getTelephonyServiceRegisterer()
2141 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 }
2143
Stuart Scott584921c2015-01-15 17:10:34 -08002144 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002145 if (request.phone != null) {
2146 return request.phone;
2147 } else {
2148 return getPhoneFromSubId(request.subId);
2149 }
2150 }
2151
2152 private Phone getPhoneFromSubId(int subId) {
2153 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2154 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002155 }
2156
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002157 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2158 Phone phone = getPhoneFromRequest(request);
2159 return phone == null ? null :
2160 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2161 }
2162
Wink Saville36469e72014-06-11 15:17:00 -07002163 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002164 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002165 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167
Naina Nallurid63128d2019-09-17 14:10:30 -07002168 private void sendEraseModemConfig(Phone phone) {
2169 if (phone != null) {
2170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2171 mApp, phone.getSubId(), "eraseModemConfig");
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2175 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2176 } finally {
2177 Binder.restoreCallingIdentity(identity);
2178 }
2179 }
2180 }
2181
Peter Wang44b186e2020-01-13 23:33:09 -08002182 private boolean isImsAvailableOnDevice() {
2183 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2184 if (pm == null) {
2185 // For some reason package manger is not available.. This will fail internally anyway,
2186 // so do not throw error and allow.
2187 return true;
2188 }
2189 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2190 }
2191
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002193 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
Wink Savilleb564aae2014-10-23 10:18:09 -07002196 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 if (DBG) log("dial: " + number);
2198 // No permission check needed here: This is just a wrapper around the
2199 // ACTION_DIAL intent, which is available to any app since it puts up
2200 // the UI before it does anything.
2201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002202 final long identity = Binder.clearCallingIdentity();
2203 try {
2204 String url = createTelUrl(number);
2205 if (url == null) {
2206 return;
2207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 // PENDING: should we just silently fail if phone is offhook or ringing?
2210 PhoneConstants.State state = mCM.getState(subId);
2211 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2212 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2213 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2214 mApp.startActivity(intent);
2215 }
2216 } finally {
2217 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
2219 }
2220
2221 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002222 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002223 }
2224
Wink Savilleb564aae2014-10-23 10:18:09 -07002225 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002226 if (DBG) log("call: " + number);
2227
2228 // This is just a wrapper around the ACTION_CALL intent, but we still
2229 // need to do a permission check since we're calling startActivity()
2230 // from the context of the phone app.
2231 enforceCallPermission();
2232
Jordan Liu1617b712019-07-10 15:06:26 -07002233 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 != AppOpsManager.MODE_ALLOWED) {
2235 return;
2236 }
2237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238 final long identity = Binder.clearCallingIdentity();
2239 try {
2240 String url = createTelUrl(number);
2241 if (url == null) {
2242 return;
2243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245 boolean isValid = false;
2246 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2247 if (slist != null) {
2248 for (SubscriptionInfo subInfoRecord : slist) {
2249 if (subInfoRecord.getSubscriptionId() == subId) {
2250 isValid = true;
2251 break;
2252 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002253 }
Wink Saville08874612014-08-31 19:19:58 -07002254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255 if (!isValid) {
2256 return;
2257 }
Wink Saville08874612014-08-31 19:19:58 -07002258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2260 intent.putExtra(SUBSCRIPTION_KEY, subId);
2261 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2262 mApp.startActivity(intent);
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
2265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
Wink Savilleb564aae2014-10-23 10:18:09 -07002268 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002269 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002270 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2271 }
2272
Wink Savilleb564aae2014-10-23 10:18:09 -07002273 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002274 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002275 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2276 }
2277
Wink Savilleb564aae2014-10-23 10:18:09 -07002278 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002280
2281 final long identity = Binder.clearCallingIdentity();
2282 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002283 Phone phone = getPhone(subId);
2284 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285 checkSimPin.start();
2286 return checkSimPin.unlockSim(null, pin);
2287 } finally {
2288 Binder.restoreCallingIdentity(identity);
2289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 }
2291
Wink Savilleb564aae2014-10-23 10:18:09 -07002292 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294
2295 final long identity = Binder.clearCallingIdentity();
2296 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002297 Phone phone = getPhone(subId);
2298 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002299 checkSimPuk.start();
2300 return checkSimPuk.unlockSim(puk, pin);
2301 } finally {
2302 Binder.restoreCallingIdentity(identity);
2303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 }
2305
2306 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002307 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 * a synchronous one.
2309 */
2310 private static class UnlockSim extends Thread {
2311
2312 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002313 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314
2315 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002316 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2317 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318
2319 // For replies from SimCard interface
2320 private Handler mHandler;
2321
2322 // For async handler to identify request type
2323 private static final int SUPPLY_PIN_COMPLETE = 100;
2324
Michele Berionne5e411512020-11-13 02:36:59 +00002325 UnlockSim(int phoneId, IccCard simCard) {
2326 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 mSimCard = simCard;
2328 }
2329
2330 @Override
2331 public void run() {
2332 Looper.prepare();
2333 synchronized (UnlockSim.this) {
2334 mHandler = new Handler() {
2335 @Override
2336 public void handleMessage(Message msg) {
2337 AsyncResult ar = (AsyncResult) msg.obj;
2338 switch (msg.what) {
2339 case SUPPLY_PIN_COMPLETE:
2340 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2341 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002342 mRetryCount = msg.arg1;
2343 if (ar.exception != null) {
2344 if (ar.exception instanceof CommandException &&
2345 ((CommandException)(ar.exception)).getCommandError()
2346 == CommandException.Error.PASSWORD_INCORRECT) {
2347 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002348 } //When UiccCardApp dispose,handle message and return exception
2349 else if (ar.exception instanceof CommandException &&
2350 ((CommandException) (ar.exception)).getCommandError()
2351 == CommandException.Error.ABORTED) {
2352 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002353 } else {
2354 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2355 }
2356 } else {
2357 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 mDone = true;
2360 UnlockSim.this.notifyAll();
2361 }
2362 break;
2363 }
2364 }
2365 };
2366 UnlockSim.this.notifyAll();
2367 }
2368 Looper.loop();
2369 }
2370
2371 /*
2372 * Use PIN or PUK to unlock SIM card
2373 *
2374 * If PUK is null, unlock SIM card with PIN
2375 *
2376 * If PUK is not null, unlock SIM card with PUK and set PIN code
2377 */
Wink Saville9de0f752013-10-22 19:04:03 -07002378 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379
2380 while (mHandler == null) {
2381 try {
2382 wait();
2383 } catch (InterruptedException e) {
2384 Thread.currentThread().interrupt();
2385 }
2386 }
2387 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2388
2389 if (puk == null) {
2390 mSimCard.supplyPin(pin, callback);
2391 } else {
2392 mSimCard.supplyPuk(puk, pin, callback);
2393 }
2394
2395 while (!mDone) {
2396 try {
2397 Log.d(LOG_TAG, "wait for done");
2398 wait();
2399 } catch (InterruptedException e) {
2400 // Restore the interrupted status
2401 Thread.currentThread().interrupt();
2402 }
2403 }
2404 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002405 int[] resultArray = new int[2];
2406 resultArray[0] = mResult;
2407 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002408
2409 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2410 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2411 }
2412
Wink Saville9de0f752013-10-22 19:04:03 -07002413 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 }
2415 }
2416
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002417 /**
2418 * This method has been removed due to privacy and stability concerns.
2419 */
2420 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002422 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2423 return;
Wink Saville36469e72014-06-11 15:17:00 -07002424 }
2425
Nathan Harold1f889d82020-06-04 17:05:26 -07002426 @Override
2427 public void updateServiceLocationWithPackageName(String callingPackage) {
2428 mApp.getSystemService(AppOpsManager.class)
2429 .checkPackage(Binder.getCallingUid(), callingPackage);
2430
Nathan Haroldf096d982020-11-18 17:18:06 -08002431 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002432 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2433 // Callers targeting S have no business invoking this method.
2434 return;
2435 }
2436
2437 LocationAccessPolicy.LocationPermissionResult locationResult =
2438 LocationAccessPolicy.checkLocationPermission(mApp,
2439 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2440 .setCallingPackage(callingPackage)
2441 .setCallingFeatureId(null)
2442 .setCallingPid(Binder.getCallingPid())
2443 .setCallingUid(Binder.getCallingUid())
2444 .setMethod("updateServiceLocation")
2445 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2446 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2447 .build());
2448 // Apps that lack location permission have no business calling this method;
2449 // however, because no permission was declared in the public API, denials must
2450 // all be "soft".
2451 switch (locationResult) {
2452 case DENIED_HARD: /* fall through */
2453 case DENIED_SOFT:
2454 return;
2455 }
2456
2457 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002458 final long identity = Binder.clearCallingIdentity();
2459 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002460 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002462 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 }
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 }
2468
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002469 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002470 @Override
2471 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002472 return isRadioOnWithFeature(callingPackage, null);
2473 }
2474
2475
2476 @Override
2477 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2478 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2479 callingFeatureId);
2480 }
2481
2482 @Deprecated
2483 @Override
2484 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2485 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002486 }
2487
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002488 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002489 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2490 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002492 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002493 return false;
2494 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002495
2496 final long identity = Binder.clearCallingIdentity();
2497 try {
2498 return isRadioOnForSubscriber(subId);
2499 } finally {
2500 Binder.restoreCallingIdentity(identity);
2501 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002502 }
2503
2504 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 final Phone phone = getPhone(subId);
2508 if (phone != null) {
2509 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2510 } else {
2511 return false;
2512 }
2513 } finally {
2514 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 }
2517
2518 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002519 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 }
Wink Saville36469e72014-06-11 15:17:00 -07002521
Wink Savilleb564aae2014-10-23 10:18:09 -07002522 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524
2525 final long identity = Binder.clearCallingIdentity();
2526 try {
2527 final Phone phone = getPhone(subId);
2528 if (phone != null) {
2529 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2530 }
2531 } finally {
2532 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002533 }
Wink Saville36469e72014-06-11 15:17:00 -07002534 }
2535
2536 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002537 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002538 }
2539
Wink Savilleb564aae2014-10-23 10:18:09 -07002540 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542
2543 final long identity = Binder.clearCallingIdentity();
2544 try {
2545 final Phone phone = getPhone(subId);
2546 if (phone == null) {
2547 return false;
2548 }
2549 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2550 toggleRadioOnOffForSubscriber(subId);
2551 }
2552 return true;
2553 } finally {
2554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 }
Wink Saville36469e72014-06-11 15:17:00 -07002557
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002558 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002559 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002560 /*
2561 * If any of the Radios are available, it will need to be
2562 * shutdown. So return true if any Radio is available.
2563 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2567 Phone phone = PhoneFactory.getPhone(i);
2568 if (phone != null && phone.isRadioAvailable()) return true;
2569 }
2570 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2571 return false;
2572 } finally {
2573 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002574 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002575 }
2576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002578 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579 enforceModifyPermission();
2580
2581 final long identity = Binder.clearCallingIdentity();
2582 try {
2583 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2584 logv("Shutting down Phone " + i);
2585 shutdownRadioUsingPhoneId(i);
2586 }
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002589 }
2590 }
2591
2592 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002593 Phone phone = PhoneFactory.getPhone(phoneId);
2594 if (phone != null && phone.isRadioAvailable()) {
2595 phone.shutdownRadio();
2596 }
2597 }
2598
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002600 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601
2602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2605 if (defaultPhone != null) {
2606 defaultPhone.setRadioPower(turnOn);
2607 return true;
2608 } else {
2609 loge("There's no default phone.");
2610 return false;
2611 }
2612 } finally {
2613 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002614 }
Wink Saville36469e72014-06-11 15:17:00 -07002615 }
2616
Wink Savilleb564aae2014-10-23 10:18:09 -07002617 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619
2620 final long identity = Binder.clearCallingIdentity();
2621 try {
2622 final Phone phone = getPhone(subId);
2623 if (phone != null) {
2624 phone.setRadioPower(turnOn);
2625 return true;
2626 } else {
2627 return false;
2628 }
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 }
2633
Wink Saville36469e72014-06-11 15:17:00 -07002634 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002635 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 public boolean enableDataConnectivity() {
2637 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 int subId = mSubscriptionController.getDefaultDataSubId();
2642 final Phone phone = getPhone(subId);
2643 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002644 phone.getDataEnabledSettings().setDataEnabled(
2645 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 return true;
2647 } else {
2648 return false;
2649 }
2650 } finally {
2651 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 }
2654
Wink Saville36469e72014-06-11 15:17:00 -07002655 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002656 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 public boolean disableDataConnectivity() {
2658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659
2660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 int subId = mSubscriptionController.getDefaultDataSubId();
2663 final Phone phone = getPhone(subId);
2664 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002665 phone.getDataEnabledSettings().setDataEnabled(
2666 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 return true;
2668 } else {
2669 return false;
2670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
Sanket Padawe356d7632015-06-22 14:03:32 -07002676 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002677 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678 final long identity = Binder.clearCallingIdentity();
2679 try {
2680 final Phone phone = getPhone(subId);
2681 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002682 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 } else {
2684 return false;
2685 }
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 }
2690
2691 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002692 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002693 }
2694
pkanwarae03a6b2016-11-06 20:37:09 -08002695 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 enforceCallPermission();
2697
2698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2701 return;
2702 }
2703 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2704 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
2707 }
pkanwar32d516d2016-10-14 19:37:38 -07002708 };
2709
Wink Savilleb564aae2014-10-23 10:18:09 -07002710 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712
2713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2716 return false;
2717 }
2718 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2719 } finally {
2720 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 }
2723
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002725 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002726 }
2727
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002728 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729 final long identity = Binder.clearCallingIdentity();
2730 try {
2731 Phone phone = PhoneFactory.getPhone(slotIndex);
2732 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2733 PhoneConstantConversions.convertCallState(phone.getState());
2734 } finally {
2735 Binder.restoreCallingIdentity(identity);
2736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 }
2738
Sanket Padawe356d7632015-06-22 14:03:32 -07002739 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002740 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002741 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2742 }
2743
2744 @Override
2745 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746 final long identity = Binder.clearCallingIdentity();
2747 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002748 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749 if (phone != null) {
2750 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2751 } else {
2752 return PhoneConstantConversions.convertDataState(
2753 PhoneConstants.DataState.DISCONNECTED);
2754 }
2755 } finally {
2756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 }
2759
Sanket Padawe356d7632015-06-22 14:03:32 -07002760 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002761 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002762 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2763 }
2764
2765 @Override
2766 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767 final long identity = Binder.clearCallingIdentity();
2768 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002769 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002770 if (phone != null) {
2771 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2772 } else {
2773 return TelephonyManager.DATA_ACTIVITY_NONE;
2774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779
2780 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002781 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002782 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002783 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002784
2785 LocationAccessPolicy.LocationPermissionResult locationResult =
2786 LocationAccessPolicy.checkLocationPermission(mApp,
2787 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2788 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002789 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002790 .setCallingPid(Binder.getCallingPid())
2791 .setCallingUid(Binder.getCallingUid())
2792 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002793 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002794 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2795 .build());
2796 switch (locationResult) {
2797 case DENIED_HARD:
2798 throw new SecurityException("Not allowed to access cell location");
2799 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002800 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2801 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802 }
2803
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002804 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002808 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002809 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810 } finally {
2811 Binder.restoreCallingIdentity(identity);
2812 }
Svetoslav64fad262015-04-14 14:35:21 -07002813 }
2814
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002816 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002817 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2818 // registered cell info, so return a NULL country instead.
2819 final long identity = Binder.clearCallingIdentity();
2820 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002821 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2822 // Get default phone in this case.
2823 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2824 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002825 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002827 if (phone == null) return "";
2828 ServiceStateTracker sst = phone.getServiceStateTracker();
2829 if (sst == null) return "";
2830 LocaleTracker lt = sst.getLocaleTracker();
2831 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002832 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002833 } finally {
2834 Binder.restoreCallingIdentity(identity);
2835 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002836 }
2837
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002838 /**
2839 * This method was removed due to potential issues caused by performing partial
2840 * updates of service state, and lack of a credible use case.
2841 *
2842 * This has the ability to break the telephony implementation by disabling notification of
2843 * changes in device connectivity. DO NOT USE THIS!
2844 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002845 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 public void enableLocationUpdates() {
2847 mApp.enforceCallingOrSelfPermission(
2848 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 }
2850
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002851 /**
2852 * This method was removed due to potential issues caused by performing partial
2853 * updates of service state, and lack of a credible use case.
2854 *
2855 * This has the ability to break the telephony implementation by disabling notification of
2856 * changes in device connectivity. DO NOT USE THIS!
2857 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002858 @Override
2859 public void disableLocationUpdates() {
2860 mApp.enforceCallingOrSelfPermission(
2861 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 }
2863
2864 @Override
2865 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002866 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2867 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002868 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002869 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2870 throw new SecurityException(
2871 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2872 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002873
Jordan Liu1617b712019-07-10 15:06:26 -07002874 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2876 return null;
2877 }
Svetoslav64fad262015-04-14 14:35:21 -07002878
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002879 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002881 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002882 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883
Nathan Haroldf180aac2018-06-01 18:43:55 -07002884 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2885 for (CellInfo ci : info) {
2886 if (ci instanceof CellInfoGsm) {
2887 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2888 } else if (ci instanceof CellInfoWcdma) {
2889 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002892 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002893 }
2894
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002895 private List<CellInfo> getCachedCellInfo() {
2896 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2897 for (Phone phone : PhoneFactory.getPhones()) {
2898 List<CellInfo> info = phone.getAllCellInfo();
2899 if (info != null) cellInfos.addAll(info);
2900 }
2901 return cellInfos;
2902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002903
2904 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002905 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002906 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002907 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002908
2909 LocationAccessPolicy.LocationPermissionResult locationResult =
2910 LocationAccessPolicy.checkLocationPermission(mApp,
2911 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2912 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002913 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002914 .setCallingPid(Binder.getCallingPid())
2915 .setCallingUid(Binder.getCallingUid())
2916 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002917 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002918 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2919 .build());
2920 switch (locationResult) {
2921 case DENIED_HARD:
2922 throw new SecurityException("Not allowed to access cell info");
2923 case DENIED_SOFT:
2924 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002925 }
2926
Nathan Haroldf096d982020-11-18 17:18:06 -08002927 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002928 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2929 return getCachedCellInfo();
2930 }
2931
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002932 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002933 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2937 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002938 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002939 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 if (info != null) cellInfos.addAll(info);
2941 }
2942 return cellInfos;
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 }
2946 }
2947
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002948 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002949 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2950 String callingFeatureId) {
2951 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2952 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002953 }
2954
2955 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002956 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2957 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002958 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002959 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002960 }
2961
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002962 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2963 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002964 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002965 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002966
2967 LocationAccessPolicy.LocationPermissionResult locationResult =
2968 LocationAccessPolicy.checkLocationPermission(mApp,
2969 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2970 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002971 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002972 .setCallingPid(Binder.getCallingPid())
2973 .setCallingUid(Binder.getCallingUid())
2974 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002975 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2976 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002977 .build());
2978 switch (locationResult) {
2979 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002980 if (TelephonyPermissions
2981 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002982 // Safetynet logging for b/154934934
2983 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2984 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002985 throw new SecurityException("Not allowed to access cell info");
2986 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002987 if (TelephonyPermissions
2988 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002989 // Safetynet logging for b/154934934
2990 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2991 }
Nathan Harold5320c422019-05-09 10:26:08 -07002992 try {
2993 cb.onCellInfo(new ArrayList<CellInfo>());
2994 } catch (RemoteException re) {
2995 // Drop without consequences
2996 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002997 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002998 }
2999
Nathan Harolda939a962019-05-09 10:13:47 -07003000
3001 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003002 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3003
3004 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3005 }
3006
3007 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003008 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003009 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003010 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003011
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003014 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003018 }
3019
Shishir Agrawala9f32182016-04-12 12:00:16 -07003020 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003021 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003022 Phone phone = PhoneFactory.getPhone(slotIndex);
3023 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003024 return null;
3025 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003026 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003027 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003028 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003029 return null;
3030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031
3032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 return phone.getImei();
3035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003038 }
3039
3040 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003041 public String getTypeAllocationCodeForSlot(int slotIndex) {
3042 Phone phone = PhoneFactory.getPhone(slotIndex);
3043 String tac = null;
3044 if (phone != null) {
3045 String imei = phone.getImei();
3046 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3047 }
3048 return tac;
3049 }
3050
3051 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003052 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003053 Phone phone = PhoneFactory.getPhone(slotIndex);
3054 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003055 return null;
3056 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003057
Jeff Davidson913390f2018-02-23 17:11:49 -08003058 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003059 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003060 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003061 return null;
3062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003063
3064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 return phone.getMeid();
3067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
Jack Yu2af8d712017-03-15 17:14:14 -07003070 }
3071
3072 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003073 public String getManufacturerCodeForSlot(int slotIndex) {
3074 Phone phone = PhoneFactory.getPhone(slotIndex);
3075 String manufacturerCode = null;
3076 if (phone != null) {
3077 String meid = phone.getMeid();
3078 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3079 }
3080 return manufacturerCode;
3081 }
3082
3083 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003084 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3085 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003086 Phone phone = PhoneFactory.getPhone(slotIndex);
3087 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003088 return null;
3089 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003090 int subId = phone.getSubId();
3091 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003092 mApp, subId, callingPackage, callingFeatureId,
3093 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003094 return null;
3095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096
3097 final long identity = Binder.clearCallingIdentity();
3098 try {
3099 return phone.getDeviceSvn();
3100 } finally {
3101 Binder.restoreCallingIdentity(identity);
3102 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003103 }
3104
fionaxu43304da2017-11-27 22:51:16 -08003105 @Override
3106 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 final Phone phone = getPhone(subId);
3110 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3111 } finally {
3112 Binder.restoreCallingIdentity(identity);
3113 }
fionaxu43304da2017-11-27 22:51:16 -08003114 }
3115
3116 @Override
3117 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 final Phone phone = getPhone(subId);
3121 return phone == null ? null : phone.getCarrierName();
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
fionaxu43304da2017-11-27 22:51:16 -08003125 }
3126
calvinpanffe225e2018-11-01 19:43:06 +08003127 @Override
chen xu0026ca62019-03-06 15:28:50 -08003128 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003129 final long identity = Binder.clearCallingIdentity();
3130 try {
3131 final Phone phone = getPhone(subId);
3132 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003133 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003134 } finally {
3135 Binder.restoreCallingIdentity(identity);
3136 }
3137 }
3138
3139 @Override
chen xu0026ca62019-03-06 15:28:50 -08003140 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003141 final long identity = Binder.clearCallingIdentity();
3142 try {
3143 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003144 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003145 } finally {
3146 Binder.restoreCallingIdentity(identity);
3147 }
3148 }
3149
chen xu651eec72018-11-11 19:03:44 -08003150 @Override
chen xu864e11c2018-12-06 22:10:03 -08003151 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3152 if (!isSubscriptionMccMnc) {
3153 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3154 }
chen xu651eec72018-11-11 19:03:44 -08003155 final Phone phone = PhoneFactory.getPhone(slotIndex);
3156 if (phone == null) {
3157 return TelephonyManager.UNKNOWN_CARRIER_ID;
3158 }
3159 final long identity = Binder.clearCallingIdentity();
3160 try {
3161 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3162 } finally {
3163 Binder.restoreCallingIdentity(identity);
3164 }
3165 }
3166
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167 //
3168 // Internal helper methods.
3169 //
3170
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003171 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3173 *
3174 * @throws SecurityException if the caller does not have the required permission
3175 */
3176 private void enforceModifyPermission() {
3177 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3178 }
3179
Shuo Qiancd19c462020-01-16 20:51:11 -08003180 /**
3181 * Make sure the caller is system.
3182 *
3183 * @throws SecurityException if the caller is not system.
3184 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003185 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003186 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3187 throw new SecurityException("Caller must be system");
3188 }
3189 }
3190
Shuo Qian3b6ee772019-11-13 17:43:31 -08003191 private void enforceActiveEmergencySessionPermission() {
3192 mApp.enforceCallingOrSelfPermission(
3193 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3194 }
3195
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 /**
3197 * Make sure the caller has the CALL_PHONE permission.
3198 *
3199 * @throws SecurityException if the caller does not have the required permission
3200 */
3201 private void enforceCallPermission() {
3202 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3203 }
3204
paulhu5a773602019-08-23 19:17:33 +08003205 private void enforceSettingsPermission() {
3206 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003207 }
3208
Michele Berionne5e411512020-11-13 02:36:59 +00003209 private void enforceRebootPermission() {
3210 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3211 }
3212
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 private String createTelUrl(String number) {
3214 if (TextUtils.isEmpty(number)) {
3215 return null;
3216 }
3217
Jake Hambye994d462014-02-03 13:10:13 -08003218 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 }
3220
Ihab Awadf9e92732013-12-05 18:02:52 -08003221 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003222 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3223 }
3224
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003225 private static void logv(String msg) {
3226 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3227 }
3228
Ihab Awadf9e92732013-12-05 18:02:52 -08003229 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003230 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3231 }
3232
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003233 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003234 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003235 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003236 }
3237
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003239 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 final Phone phone = PhoneFactory.getPhone(slotIndex);
3243 if (phone == null) {
3244 return PhoneConstants.PHONE_TYPE_NONE;
3245 } else {
3246 return phone.getPhoneType();
3247 }
3248 } finally {
3249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003251 }
3252
3253 /**
3254 * Returns the CDMA ERI icon index to display
3255 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003256 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003257 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3258 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3259 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003260 }
3261
Sanket Padawe356d7632015-06-22 14:03:32 -07003262 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003263 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3264 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003266 mApp, subId, callingPackage, callingFeatureId,
3267 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003268 return -1;
3269 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270
3271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 final Phone phone = getPhone(subId);
3274 if (phone != null) {
3275 return phone.getCdmaEriIconIndex();
3276 } else {
3277 return -1;
3278 }
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003282 }
3283
3284 /**
3285 * Returns the CDMA ERI icon mode,
3286 * 0 - ON
3287 * 1 - FLASHING
3288 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003289 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003290 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3291 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3292 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003293 }
3294
Sanket Padawe356d7632015-06-22 14:03:32 -07003295 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003296 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3297 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003299 mApp, subId, callingPackage, callingFeatureId,
3300 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003301 return -1;
3302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303
3304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 final Phone phone = getPhone(subId);
3307 if (phone != null) {
3308 return phone.getCdmaEriIconMode();
3309 } else {
3310 return -1;
3311 }
3312 } finally {
3313 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003315 }
3316
3317 /**
3318 * Returns the CDMA ERI text,
3319 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003320 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003321 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3322 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3323 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003324 }
3325
Sanket Padawe356d7632015-06-22 14:03:32 -07003326 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003327 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3328 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003330 mApp, subId, callingPackage, callingFeatureId,
3331 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003332 return null;
3333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334
3335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 final Phone phone = getPhone(subId);
3338 if (phone != null) {
3339 return phone.getCdmaEriText();
3340 } else {
3341 return null;
3342 }
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003346 }
3347
3348 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003349 * Returns the CDMA MDN.
3350 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003351 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003352 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3354 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355
3356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003359 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360 return phone.getLine1Number();
3361 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003362 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003363 return null;
3364 }
3365 } finally {
3366 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003367 }
3368 }
3369
3370 /**
3371 * Returns the CDMA MIN.
3372 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003373 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003374 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3376 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003377
3378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 final Phone phone = getPhone(subId);
3381 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3382 return phone.getCdmaMin();
3383 } else {
3384 return null;
3385 }
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003388 }
3389 }
3390
Hall Liud892bec2018-11-30 14:51:45 -08003391 @Override
3392 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3393 INumberVerificationCallback callback, String callingPackage) {
3394 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3395 != PERMISSION_GRANTED) {
3396 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3397 }
3398 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3399
3400 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3401 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003402 throw new SecurityException("Calling package must be configured in the device config: "
3403 + "calling package: " + callingPackage
3404 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003405 }
3406
3407 if (range == null) {
3408 throw new NullPointerException("Range must be non-null");
3409 }
3410
3411 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003412 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003413
3414 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3415 }
3416
Junda Liuca05d5d2014-08-14 22:36:34 -07003417 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003418 * Returns true if CDMA provisioning needs to run.
3419 */
3420 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421 final long identity = Binder.clearCallingIdentity();
3422 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 }
3428
3429 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003430 * Sets the voice mail number of a given subId.
3431 */
3432 @Override
3433 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003434 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3435 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003436
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3440 new Pair<String, String>(alphaTag, number), new Integer(subId));
3441 return success;
3442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003445 }
3446
Ta-wei Yen87c49842016-05-13 21:19:52 -07003447 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003448 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3449 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003450 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3451 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003452 if (!TextUtils.equals(callingPackage, systemDialer)) {
3453 throw new SecurityException("caller must be system dialer");
3454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003455
3456 final long identity = Binder.clearCallingIdentity();
3457 try {
3458 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3459 if (phoneAccountHandle == null) {
3460 return null;
3461 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003462 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463 } finally {
3464 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003465 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003466 }
3467
3468 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003469 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3470 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003473 mApp, subId, callingPackage, callingFeatureId,
3474 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003475 return null;
3476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003477
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003478 final long identity = Binder.clearCallingIdentity();
3479 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003480 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003481 } finally {
3482 Binder.restoreCallingIdentity(identity);
3483 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003484 }
3485
3486 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003487 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3488 VisualVoicemailSmsFilterSettings settings) {
3489 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003490
3491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003494 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003495 } finally {
3496 Binder.restoreCallingIdentity(identity);
3497 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003498 }
3499
3500 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003501 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003503
3504 final long identity = Binder.clearCallingIdentity();
3505 try {
3506 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003507 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003508 } finally {
3509 Binder.restoreCallingIdentity(identity);
3510 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003511 }
3512
3513 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003514 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3515 String callingPackage, int subId) {
3516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003517
3518 final long identity = Binder.clearCallingIdentity();
3519 try {
3520 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003521 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003522 } finally {
3523 Binder.restoreCallingIdentity(identity);
3524 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003525 }
3526
3527 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003528 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530
3531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003534 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535 } finally {
3536 Binder.restoreCallingIdentity(identity);
3537 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003538 }
3539
3540 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003541 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3542 String callingAttributionTag, int subId, String number, int port, String text,
3543 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003544 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003545 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003546 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003547 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003548 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3549 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003550 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003551
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003552 /**
fionaxu0152e512016-11-14 13:36:14 -08003553 * Sets the voice activation state of a given subId.
3554 */
3555 @Override
3556 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3558 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559
3560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 final Phone phone = getPhone(subId);
3563 if (phone != null) {
3564 phone.setVoiceActivationState(activationState);
3565 } else {
3566 loge("setVoiceActivationState fails with invalid subId: " + subId);
3567 }
3568 } finally {
3569 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003570 }
3571 }
3572
3573 /**
3574 * Sets the data activation state of a given subId.
3575 */
3576 @Override
3577 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3579 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003580
3581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 final Phone phone = getPhone(subId);
3584 if (phone != null) {
3585 phone.setDataActivationState(activationState);
3586 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003587 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003588 }
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003591 }
3592 }
3593
3594 /**
3595 * Returns the voice activation state of a given subId.
3596 */
3597 @Override
3598 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003599 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003600
fionaxu0152e512016-11-14 13:36:14 -08003601 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 if (phone != null) {
3605 return phone.getVoiceActivationState();
3606 } else {
3607 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3608 }
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003611 }
3612 }
3613
3614 /**
3615 * Returns the data activation state of a given subId.
3616 */
3617 @Override
3618 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003619 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620
fionaxu0152e512016-11-14 13:36:14 -08003621 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 if (phone != null) {
3625 return phone.getDataActivationState();
3626 } else {
3627 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3628 }
3629 } finally {
3630 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003631 }
3632 }
3633
3634 /**
Wink Saville36469e72014-06-11 15:17:00 -07003635 * Returns the unread count of voicemails for a subId
3636 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003637 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003638 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3639 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003640 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003641 mApp, subId, callingPackage, callingFeatureId,
3642 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003643 return 0;
3644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 final Phone phone = getPhone(subId);
3648 if (phone != null) {
3649 return phone.getVoiceMessageCount();
3650 } else {
3651 return 0;
3652 }
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003656 }
3657
3658 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003659 * returns true, if the device is in a state where both voice and data
3660 * are supported simultaneously. This can change based on location or network condition.
3661 */
3662 @Override
3663 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 final Phone phone = getPhone(subId);
3667 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003671 }
3672
3673 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003674 * Send the dialer code if called from the current default dialer or the caller has
3675 * carrier privilege.
3676 * @param inputCode The dialer code to send
3677 */
3678 @Override
3679 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003680 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003682 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3683 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003684 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003685 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003686 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003691 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
fionaxu235cc5e2017-03-06 22:25:57 -08003695 }
3696
Pengquan Menga1bb6272018-09-06 09:59:22 -07003697 @Override
3698 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003699 TelephonyPermissions
3700 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3701 mApp, subId, "getNetworkSelectionMode");
3702 final long identity = Binder.clearCallingIdentity();
3703 try {
3704 if (!isActiveSubscription(subId)) {
3705 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3706 }
3707 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003710 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003711 }
3712
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003714 public boolean isInEmergencySmsMode() {
3715 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 for (Phone phone : PhoneFactory.getPhones()) {
3719 if (phone.isInEmergencySmsMode()) {
3720 return true;
3721 }
3722 }
3723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
3726 return false;
3727 }
3728
shilu366312e2019-12-17 09:28:10 -08003729 /**
3730 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3731 * @param subId The subscription to use to check the configuration.
3732 * @param c The callback that will be used to send the result.
3733 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003734 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003735 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3736 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003737 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3738 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003739
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003740 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3741 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3742 "IMS not available on device.");
3743 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 final long token = Binder.clearCallingIdentity();
3745 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003746 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003747 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003748 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003749 } catch (ImsException e) {
3750 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003751 } finally {
3752 Binder.restoreCallingIdentity(token);
3753 }
3754 }
3755
shilu366312e2019-12-17 09:28:10 -08003756 /**
3757 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3758 * @param subId The subscription to use to check the configuration.
3759 * @param c The callback that will be used to send the result.
3760 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003762 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003763 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3764 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003765 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3766 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3767 }
Meng Wangafbc5852019-09-19 17:37:13 -07003768 final long token = Binder.clearCallingIdentity();
3769 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003770 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003771 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3772 .removeRegistrationCallbackForSubscription(c, subId);
3773 } catch (ImsException e) {
3774 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3775 + "is inactive, ignoring unregister.");
3776 // If the subscription is no longer active, just return, since the callback
3777 // will already have been removed internally.
3778 } finally {
3779 Binder.restoreCallingIdentity(token);
3780 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003781 }
3782
Brad Ebingera34a6c22019-10-22 17:36:18 -07003783 /**
3784 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3785 */
3786 @Override
3787 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3788 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3789 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3790 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3791 "IMS not available on device.");
3792 }
3793 final long token = Binder.clearCallingIdentity();
3794 try {
3795 Phone phone = getPhone(subId);
3796 if (phone == null) {
3797 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3798 + subId + "'");
3799 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3800 }
3801 phone.getImsRegistrationState(regState -> {
3802 try {
3803 consumer.accept((regState == null)
3804 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3805 } catch (RemoteException e) {
3806 // Ignore if the remote process is no longer available to call back.
3807 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3808 }
3809 });
3810 } finally {
3811 Binder.restoreCallingIdentity(token);
3812 }
3813 }
3814
3815 /**
3816 * Get the transport type for the IMS service registration state.
3817 */
3818 @Override
3819 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003820 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3821 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003822 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3823 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3824 "IMS not available on device.");
3825 }
3826 final long token = Binder.clearCallingIdentity();
3827 try {
3828 Phone phone = getPhone(subId);
3829 if (phone == null) {
3830 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3831 + subId + "'");
3832 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3833 }
3834 phone.getImsRegistrationTech(regTech -> {
3835 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3836 int regTechConverted = (regTech == null)
3837 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3838 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3839 regTechConverted);
3840 try {
3841 consumer.accept(regTechConverted);
3842 } catch (RemoteException e) {
3843 // Ignore if the remote process is no longer available to call back.
3844 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3845 }
3846 });
3847 } finally {
3848 Binder.restoreCallingIdentity(token);
3849 }
3850 }
3851
shilu366312e2019-12-17 09:28:10 -08003852 /**
3853 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3854 * @param subId The subscription to use to check the configuration.
3855 * @param c The callback that will be used to send the result.
3856 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003857 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003858 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3859 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003860 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3861 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003862 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3863 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3864 "IMS not available on device.");
3865 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003866 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3867 final long token = Binder.clearCallingIdentity();
3868 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003869 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003870 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003871 } catch (ImsException e) {
3872 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003873 } finally {
3874 Binder.restoreCallingIdentity(token);
3875 }
3876 }
3877
shilu366312e2019-12-17 09:28:10 -08003878 /**
3879 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3880 * @param subId The subscription to use to check the configuration.
3881 * @param c The callback that will be used to send the result.
3882 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003883 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003884 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003885 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3886 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003887 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3888 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3889 }
Meng Wangafbc5852019-09-19 17:37:13 -07003890
3891 final long token = Binder.clearCallingIdentity();
3892 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003893 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003894 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003895 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003896 } catch (ImsException e) {
3897 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3898 + "is inactive, ignoring unregister.");
3899 // If the subscription is no longer active, just return, since the callback
3900 // will already have been removed internally.
3901 } finally {
3902 Binder.restoreCallingIdentity(token);
3903 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003904 }
3905
3906 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003907 public boolean isCapable(int subId, int capability, int regTech) {
3908 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3910 final long token = Binder.clearCallingIdentity();
3911 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003912 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003914 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3916 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003917 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003918 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3919 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003920 } finally {
3921 Binder.restoreCallingIdentity(token);
3922 }
3923 }
3924
3925 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003926 public boolean isAvailable(int subId, int capability, int regTech) {
3927 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 final long token = Binder.clearCallingIdentity();
3929 try {
3930 Phone phone = getPhone(subId);
3931 if (phone == null) return false;
3932 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003933 } catch (com.android.ims.ImsException e) {
3934 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3935 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 } finally {
3937 Binder.restoreCallingIdentity(token);
3938 }
3939 }
3940
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003941 /**
3942 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3943 * subscription.
3944 * @param subId The subscription to use to check the configuration.
3945 * @param callback The callback that will be used to send the result.
3946 * @param capability The MmTelFeature capability that will be used to send the result.
3947 * @param transportType The transport type of the MmTelFeature capability.
3948 */
3949 @Override
3950 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3951 int transportType) {
3952 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3953 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3954 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3955 "IMS not available on device.");
3956 }
3957 final long token = Binder.clearCallingIdentity();
3958 try {
3959 int slotId = getSlotIndex(subId);
3960 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3961 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3962 + subId + "'");
3963 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3964 }
3965 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3966 transportType, aBoolean -> {
3967 try {
3968 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3969 } catch (RemoteException e) {
3970 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3971 + "running. Ignore");
3972 }
3973 });
3974 } finally {
3975 Binder.restoreCallingIdentity(token);
3976 }
3977 }
3978
shilu366312e2019-12-17 09:28:10 -08003979 /**
3980 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3981 * @param subId The subscription to use to check the configuration.
3982 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 @Override
3984 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003985 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3986 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003987
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3989 final long token = Binder.clearCallingIdentity();
3990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003991 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003993 } catch (ImsException e) {
3994 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 } finally {
3996 Binder.restoreCallingIdentity(token);
3997 }
3998 }
3999
4000 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004001 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004003 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004007 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004009 } catch (ImsException e) {
4010 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
4014 }
4015
shilu366312e2019-12-17 09:28:10 -08004016 /**
4017 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4018 * @param subId The subscription to use to check the configuration.
4019 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004021 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004022 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4023 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 final long identity = Binder.clearCallingIdentity();
4025 try {
4026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004027 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4028 } catch (ImsException e) {
4029 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 } finally {
4031 Binder.restoreCallingIdentity(identity);
4032 }
4033 }
4034
4035 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004036 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004038 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004042 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004043 } catch (ImsException e) {
4044 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 } finally {
4046 Binder.restoreCallingIdentity(identity);
4047 }
4048 }
4049
shilu366312e2019-12-17 09:28:10 -08004050 /**
4051 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4052 * @param subId The subscription to use to check the configuration.
4053 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 @Override
4055 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004056 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4057 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 final long identity = Binder.clearCallingIdentity();
4059 try {
4060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004061 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004063 } catch (ImsException e) {
4064 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004065 } finally {
4066 Binder.restoreCallingIdentity(identity);
4067 }
4068 }
4069
4070 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004071 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004073 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004077 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004078 } catch (ImsException e) {
4079 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004080 } finally {
4081 Binder.restoreCallingIdentity(identity);
4082 }
4083 }
4084
shilu366312e2019-12-17 09:28:10 -08004085 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004086 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4087 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4088 * @param subId The subscription to use to check the configuration.
4089 */
4090 @Override
4091 public boolean isCrossSimCallingEnabledByUser(int subId) {
4092 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4093 mApp, subId, "isCrossSimCallingEnabledByUser");
4094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4097 return ImsManager.getInstance(mApp,
4098 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4099 } catch (ImsException e) {
4100 throw new ServiceSpecificException(e.getCode());
4101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
4104 }
4105
4106 /**
4107 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4108 * Requires MODIFY_PHONE_STATE permission.
4109 * @param subId The subscription to use to check the configuration.
4110 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4111 * false otherwise
4112 */
4113 @Override
4114 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4116 "setCrossSimCallingEnabled");
4117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4120 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4121 .setCrossSimCallingEnabled(isEnabled);
4122 } catch (ImsException e) {
4123 throw new ServiceSpecificException(e.getCode());
4124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
4127 }
4128
4129 /**
shilu366312e2019-12-17 09:28:10 -08004130 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4131 * @param subId The subscription to use to check the configuration.
4132 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 @Override
4134 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004135 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4136 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004140 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004142 } catch (ImsException e) {
4143 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
4147 }
4148
4149 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004150 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004152 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004156 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004158 } catch (ImsException e) {
4159 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
4163 }
4164
4165 @Override
4166 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4168 "setVoWiFiNonPersistent");
4169 final long identity = Binder.clearCallingIdentity();
4170 try {
4171 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004172 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004173 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004174 } catch (ImsException e) {
4175 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 } finally {
4177 Binder.restoreCallingIdentity(identity);
4178 }
4179 }
4180
shilu366312e2019-12-17 09:28:10 -08004181 /**
4182 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4183 * @param subId The subscription to use to check the configuration.
4184 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 @Override
4186 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004187 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4188 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004189 final long identity = Binder.clearCallingIdentity();
4190 try {
4191 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004192 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004194 } catch (ImsException e) {
4195 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 } finally {
4197 Binder.restoreCallingIdentity(identity);
4198 }
4199 }
4200
4201 @Override
4202 public void setVoWiFiModeSetting(int subId, int mode) {
4203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4204 "setVoWiFiModeSetting");
4205 final long identity = Binder.clearCallingIdentity();
4206 try {
4207 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004208 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 } catch (ImsException e) {
4211 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 } finally {
4213 Binder.restoreCallingIdentity(identity);
4214 }
4215 }
4216
4217 @Override
4218 public int getVoWiFiRoamingModeSetting(int subId) {
4219 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4220 final long identity = Binder.clearCallingIdentity();
4221 try {
4222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004223 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004225 } catch (ImsException e) {
4226 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
4230 }
4231
4232 @Override
4233 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4235 "setVoWiFiRoamingModeSetting");
4236 final long identity = Binder.clearCallingIdentity();
4237 try {
4238 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004239 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004241 } catch (ImsException e) {
4242 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 } finally {
4244 Binder.restoreCallingIdentity(identity);
4245 }
4246 }
4247
4248 @Override
4249 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4251 "setRttCapabilityEnabled");
4252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004255 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4256 } catch (ImsException e) {
4257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 } finally {
4259 Binder.restoreCallingIdentity(identity);
4260 }
4261 }
4262
shilu366312e2019-12-17 09:28:10 -08004263 /**
4264 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4265 * @param subId The subscription to use to check the configuration.
4266 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 @Override
4268 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004269 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4270 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 final long identity = Binder.clearCallingIdentity();
4272 try {
4273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004274 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004276 } catch (ImsException e) {
4277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004278 } finally {
4279 Binder.restoreCallingIdentity(identity);
4280 }
4281 }
4282
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004283 @Override
4284 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4285 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4286 final long identity = Binder.clearCallingIdentity();
4287 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004288 if (!isImsAvailableOnDevice()) {
4289 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4290 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004291 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004292 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004293 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004294 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004295 } catch (ImsException e) {
4296 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004297 } finally {
4298 Binder.restoreCallingIdentity(identity);
4299 }
4300 }
4301
4302 @Override
4303 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4304 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4305 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004306 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4307 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4308 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004309 try {
4310 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004311 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004312 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004313 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004314 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4315 + "is inactive, ignoring unregister.");
4316 // If the subscription is no longer active, just return, since the callback will already
4317 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
4321 }
4322
allenwtsu99c623b2020-01-03 18:24:23 +08004323
4324 private void checkModifyPhoneStatePermission(int subId, String message) {
4325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4326 message);
4327 }
4328
4329 private boolean isImsProvisioningRequired(int subId, int capability,
4330 boolean isMmtelCapability) {
4331 Phone phone = getPhone(subId);
4332 if (phone == null) {
4333 loge("phone instance null for subid " + subId);
4334 return false;
4335 }
4336 if (isMmtelCapability) {
4337 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4338 return false;
4339 }
4340 } else {
4341 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4342 return false;
4343 }
4344 }
4345 return true;
4346 }
4347
4348 @Override
4349 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4350 boolean isProvisioned) {
4351 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4352
4353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4356 if (!isImsProvisioningRequired(subId, capability, false)) {
4357 return;
4358 }
4359
4360 // this capability requires provisioning, route to the correct API.
4361 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4362 switch (capability) {
4363 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4364 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4365 ims.setEabProvisioned(isProvisioned);
4366 break;
4367 default: {
4368 throw new IllegalArgumentException("Tried to set provisioning for "
4369 + "rcs capability '" + capability + "', which does not require "
4370 + "provisioning.");
4371 }
4372 }
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
4376
4377 }
4378
4379
4380 @Override
4381 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4382 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4383 final long identity = Binder.clearCallingIdentity();
4384 try {
4385 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4386 if (!isImsProvisioningRequired(subId, capability, false)) {
4387 return true;
4388 }
4389
4390 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4391 switch (capability) {
4392 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4393 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4394 return ims.isEabProvisionedOnDevice();
4395
4396 default: {
4397 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4398 + "capability '" + capability + "', which does not require "
4399 + "provisioning.");
4400 }
4401 }
4402
4403 } finally {
4404 Binder.restoreCallingIdentity(identity);
4405 }
4406 }
4407
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004408 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004409 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4410 boolean isProvisioned) {
4411 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4412 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4413 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4414 }
allenwtsu99c623b2020-01-03 18:24:23 +08004415 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004416 final long identity = Binder.clearCallingIdentity();
4417 try {
4418 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004419 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004420 return;
4421 }
4422
4423 // this capability requires provisioning, route to the correct API.
4424 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4425 switch (capability) {
4426 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4427 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4428 ims.setVolteProvisioned(isProvisioned);
4429 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4430 ims.setWfcProvisioned(isProvisioned);
4431 }
4432 break;
4433 }
4434 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4435 // There is currently no difference in VT provisioning type.
4436 ims.setVtProvisioned(isProvisioned);
4437 break;
4438 }
4439 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4440 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4441 // change the capability of the feature instead if needed.
4442 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4443 == isProvisioned) {
4444 // No change in provisioning.
4445 return;
4446 }
4447 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4448 try {
4449 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004450 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004451 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4452 + ", Exception" + e.getMessage());
4453 }
4454 break;
4455 }
4456 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004457 throw new IllegalArgumentException("Tried to set provisioning for "
4458 + "MmTel capability '" + capability + "', which does not require "
4459 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004460 }
4461 }
4462
4463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
4466 }
4467
4468 @Override
4469 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4470 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4471 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4472 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4473 }
4474 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004478 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004479 return true;
4480 }
4481
4482 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4483 switch (capability) {
4484 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4485 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4486 return ims.isVolteProvisionedOnDevice();
4487 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4488 return ims.isWfcProvisionedOnDevice();
4489 }
4490 // This should never happen, since we are checking tech above to make sure it
4491 // is either LTE or IWLAN.
4492 throw new IllegalArgumentException("Invalid radio technology for voice "
4493 + "capability.");
4494 }
4495 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4496 // There is currently no difference in VT provisioning type.
4497 return ims.isVtProvisionedOnDevice();
4498 }
4499 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4500 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4501 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4502 }
4503 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004504 throw new IllegalArgumentException(
4505 "Tried to get provisioning for MmTel capability '" + capability
4506 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004507 }
4508 }
4509
4510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
4513 }
4514
4515 @Override
4516 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4517 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4518 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4519 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4520 }
4521 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4522 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4523 return (provisionedBits & capability) > 0;
4524 }
4525
4526 @Override
4527 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4528 boolean isProvisioned) {
4529 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4530 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4531 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4532 }
4533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4534 "setProvisioningStatusForCapability");
4535 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4536 // If the current provisioning status for capability already matches isProvisioned,
4537 // do nothing.
4538 if (((provisionedBits & capability) > 0) == isProvisioned) {
4539 return;
4540 }
4541 if (isProvisioned) {
4542 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4543 } else {
4544 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4545 }
4546 }
4547
4548 /**
4549 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4550 * technology. The bitfield should mirror the bitfield defined by
4551 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4552 */
4553 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4554 String key = getMmTelProvisioningKey(subId, tech);
4555 // Default is no capabilities are provisioned.
4556 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4557 }
4558
4559 /**
4560 * Sets the MmTel capability provisioning bitfield (defined by
4561 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4562 * technology specified.
4563 *
4564 * Note: This is a synchronous command and should not be called on UI thread.
4565 */
4566 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4567 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4568 String key = getMmTelProvisioningKey(subId, tech);
4569 editor.putInt(key, newField);
4570 editor.commit();
4571 }
4572
4573 private static String getMmTelProvisioningKey(int subId, int tech) {
4574 // resulting key is provision_ims_mmtel_{subId}_{tech}
4575 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4576 }
4577
4578 /**
4579 * Query CarrierConfig to see if the specified capability requires provisioning for the
4580 * carrier associated with the subscription id.
4581 */
4582 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4583 int capability) {
4584 CarrierConfigManager configManager = new CarrierConfigManager(context);
4585 PersistableBundle c = configManager.getConfigForSubId(subId);
4586 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004587 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004588 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4589 false);
4590 boolean requireVoiceVtProvisioning = c.getBoolean(
4591 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4592
4593 // First check to make sure that the capability requires provisioning.
4594 switch (capability) {
4595 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4596 // intentional fallthrough
4597 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4598 if (requireVoiceVtProvisioning) {
4599 // Voice and Video requires provisioning
4600 return true;
4601 }
4602 break;
4603 }
4604 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4605 if (requireUtProvisioning) {
4606 // UT requires provisioning
4607 return true;
4608 }
4609 break;
4610 }
4611 }
4612 return false;
4613 }
4614
allenwtsu99c623b2020-01-03 18:24:23 +08004615 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4616 int capability) {
4617 CarrierConfigManager configManager = new CarrierConfigManager(context);
4618 PersistableBundle c = configManager.getConfigForSubId(subId);
4619
4620 boolean requireRcsProvisioning = c.getBoolean(
4621 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4622
4623 // First check to make sure that the capability requires provisioning.
4624 switch (capability) {
4625 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4626 // intentional fallthrough
4627 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4628 if (requireRcsProvisioning) {
4629 // OPTION or PRESENCE requires provisioning
4630 return true;
4631 }
4632 break;
4633 }
4634 }
4635 return false;
4636 }
4637
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004638 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004639 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004640 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4641 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4642 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004643 enforceReadPrivilegedPermission("getImsProvisioningInt");
4644 final long identity = Binder.clearCallingIdentity();
4645 try {
4646 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004647 int slotId = getSlotIndex(subId);
4648 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4649 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4650 + subId + "' for key:" + key);
4651 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4652 }
calvinpanb5a34062021-02-08 19:59:36 +08004653 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004654 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004655 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4656 + subId + "' for key:" + key);
4657 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004658 } finally {
4659 Binder.restoreCallingIdentity(identity);
4660 }
4661 }
4662
4663 @Override
4664 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4666 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4667 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004668 enforceReadPrivilegedPermission("getImsProvisioningString");
4669 final long identity = Binder.clearCallingIdentity();
4670 try {
4671 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004672 int slotId = getSlotIndex(subId);
4673 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4674 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4675 + subId + "' for key:" + key);
4676 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4677 }
calvinpanb5a34062021-02-08 19:59:36 +08004678 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004679 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004680 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4681 + subId + "' for key:" + key);
4682 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004683 } finally {
4684 Binder.restoreCallingIdentity(identity);
4685 }
4686 }
4687
4688 @Override
4689 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004690 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4691 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4692 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4694 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004695 final long identity = Binder.clearCallingIdentity();
4696 try {
4697 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004698 int slotId = getSlotIndex(subId);
4699 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4700 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4701 + subId + "' for key:" + key);
4702 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4703 }
calvinpanb5a34062021-02-08 19:59:36 +08004704 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4705 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004706 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004707 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004709 } finally {
4710 Binder.restoreCallingIdentity(identity);
4711 }
4712 }
4713
4714 @Override
4715 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004716 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4717 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4718 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4720 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004721 final long identity = Binder.clearCallingIdentity();
4722 try {
4723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004724 int slotId = getSlotIndex(subId);
4725 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4726 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4727 + subId + "' for key:" + key);
4728 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4729 }
calvinpanb5a34062021-02-08 19:59:36 +08004730 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4731 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004732 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004733 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
4738 }
4739
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004740 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004741 int slotId = SubscriptionManager.getSlotIndex(subId);
4742 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004743 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4744 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004745 }
4746 return slotId;
4747 }
4748
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004749 private int getSlotIndex(int subId) {
4750 int slotId = SubscriptionManager.getSlotIndex(subId);
4751 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4752 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4753 }
4754 return slotId;
4755 }
4756
Wink Saville36469e72014-06-11 15:17:00 -07004757 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004758 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004759 */
4760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004761 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4762 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004763 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004764 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004765 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004766 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004767 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004768 mApp, subId, callingPackage, callingFeatureId,
4769 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004770 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4771 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773 final long identity = Binder.clearCallingIdentity();
4774 try {
4775 final Phone phone = getPhone(subId);
4776 if (phone != null) {
4777 return phone.getServiceState().getDataNetworkType();
4778 } else {
4779 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4780 }
4781 } finally {
4782 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004784 }
4785
4786 /**
4787 * Returns the data network type
4788 */
4789 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004790 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4791 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4792 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004793 }
4794
4795 /**
4796 * Returns the data network type for a subId
4797 */
4798 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004799 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4800 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004802 mApp, subId, callingPackage, callingFeatureId,
4803 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004804 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4805 }
4806
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807 final long identity = Binder.clearCallingIdentity();
4808 try {
4809 final Phone phone = getPhone(subId);
4810 if (phone != null) {
4811 return phone.getServiceState().getDataNetworkType();
4812 } else {
4813 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4814 }
4815 } finally {
4816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004818 }
4819
4820 /**
Wink Saville36469e72014-06-11 15:17:00 -07004821 * Returns the Voice network type for a subId
4822 */
4823 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004824 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4825 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004827 mApp, subId, callingPackage, callingFeatureId,
4828 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004829 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4830 }
4831
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832 final long identity = Binder.clearCallingIdentity();
4833 try {
4834 final Phone phone = getPhone(subId);
4835 if (phone != null) {
4836 return phone.getServiceState().getVoiceNetworkType();
4837 } else {
4838 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4839 }
4840 } finally {
4841 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004843 }
4844
4845 /**
4846 * @return true if a ICC card is present
4847 */
4848 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004849 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004850 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4851 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004852 }
4853
4854 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004855 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004856 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004857 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004858 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 final long identity = Binder.clearCallingIdentity();
4860 try {
4861 final Phone phone = PhoneFactory.getPhone(slotIndex);
4862 if (phone != null) {
4863 return phone.getIccCard().hasIccCard();
4864 } else {
4865 return false;
4866 }
4867 } finally {
4868 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004870 }
4871
4872 /**
4873 * Return if the current radio is LTE on CDMA. This
4874 * is a tri-state return value as for a period of time
4875 * the mode may be unknown.
4876 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004877 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004878 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004879 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004880 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004881 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004882 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4883 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4884 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004885 }
4886
Sanket Padawe356d7632015-06-22 14:03:32 -07004887 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004888 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4889 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004890 try {
4891 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4892 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004893 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4894 }
4895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 final Phone phone = getPhone(subId);
4899 if (phone == null) {
4900 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4901 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004902 return TelephonyProperties.lte_on_cdma_device()
4903 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 }
4905 } finally {
4906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004907 }
Wink Saville36469e72014-06-11 15:17:00 -07004908 }
4909
Wink Saville36469e72014-06-11 15:17:00 -07004910 /**
4911 * {@hide}
4912 * Returns Default subId, 0 in the case of single standby.
4913 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004914 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004915 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004916 }
4917
Shishir Agrawala9f32182016-04-12 12:00:16 -07004918 private int getSlotForDefaultSubscription() {
4919 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4920 }
4921
Wink Savilleb564aae2014-10-23 10:18:09 -07004922 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004923 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004924 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004925
Pengquan Menge92a50d2018-09-21 15:54:48 -07004926 private boolean isActiveSubscription(int subId) {
4927 return mSubscriptionController.isActiveSubId(subId);
4928 }
4929
Ihab Awadf2177b72013-11-25 13:33:23 -08004930 /**
4931 * @see android.telephony.TelephonyManager.WifiCallingChoices
4932 */
4933 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 final long identity = Binder.clearCallingIdentity();
4935 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004936 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4938 getWhenToMakeWifiCallsDefaultPreference());
4939 } finally {
4940 Binder.restoreCallingIdentity(identity);
4941 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004942 }
4943
4944 /**
4945 * @see android.telephony.TelephonyManager.WifiCallingChoices
4946 */
4947 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 final long identity = Binder.clearCallingIdentity();
4949 try {
4950 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004951 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004956 }
4957
Sailesh Nepald1e68152013-12-12 19:08:02 -08004958 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004959 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004960 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004961 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004962
Jordan Liu4c733742019-02-28 12:03:40 -08004963 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4964 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4965 if (phoneId == -1) {
4966 throw new IllegalArgumentException("Given slot index: " + slotIndex
4967 + " does not correspond to an active phone");
4968 }
4969 return PhoneFactory.getPhone(phoneId);
4970 }
4971
Shishir Agrawal566b7612013-10-28 14:41:00 -07004972 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004973 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4974 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4976 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004978 if (DBG) {
4979 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4980 }
4981 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4982 p2);
4983 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004984
Jordan Liu4c733742019-02-28 12:03:40 -08004985
4986 @Override
4987 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4988 int slotIndex, String callingPackage, String aid, int p2) {
4989 enforceModifyPermission();
4990 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4991 if (DBG) {
4992 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4993 }
4994 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4995 callingPackage, aid, p2);
4996 }
4997
4998 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4999 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 final long identity = Binder.clearCallingIdentity();
5001 try {
5002 if (TextUtils.equals(ISDR_AID, aid)) {
5003 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005004 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5005 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 if (bestComponent == null
5007 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5008 loge("The calling package is not allowed to access ISD-R.");
5009 throw new SecurityException(
5010 "The calling package is not allowed to access ISD-R.");
5011 }
Derek Tan740e1672017-06-27 14:56:27 -07005012 }
Derek Tan740e1672017-06-27 14:56:27 -07005013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005015 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5016 null /* workSource */);
5017 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 return response;
5019 } finally {
5020 Binder.restoreCallingIdentity(identity);
5021 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005022 }
5023
5024 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005025 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5027 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005028 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5029 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5030 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005031
Jordan Liu4c733742019-02-28 12:03:40 -08005032 @Override
5033 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5034 enforceModifyPermission();
5035 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5036 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5037 channel);
5038 }
5039
5040 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 final long identity = Binder.clearCallingIdentity();
5042 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 if (channel < 0) {
5044 return false;
5045 }
Jordan Liu4c733742019-02-28 12:03:40 -08005046 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5047 null /* workSource */);
5048 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 return success;
5050 } finally {
5051 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005052 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005053 }
5054
5055 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005056 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005057 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5059 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005060 if (DBG) {
5061 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5062 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5063 + p3 + " data=" + data);
5064 }
5065 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5066 command, p1, p2, p3, data);
5067 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005068
Jordan Liu4c733742019-02-28 12:03:40 -08005069 @Override
5070 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5071 int command, int p1, int p2, int p3, String data) {
5072 enforceModifyPermission();
5073 if (DBG) {
5074 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5075 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5076 + p3 + " data=" + data);
5077 }
5078 return iccTransmitApduLogicalChannelWithPermission(
5079 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5080 data);
5081 }
5082
5083 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5084 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 final long identity = Binder.clearCallingIdentity();
5086 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005087 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 return "";
5089 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005092 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5093 null /* workSource */);
5094 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 // Append the returned status code to the end of the response payload.
5097 String s = Integer.toHexString(
5098 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5099 if (response.payload != null) {
5100 s = IccUtils.bytesToHexString(response.payload) + s;
5101 }
5102 return s;
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005105 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005106 }
Jake Hambye994d462014-02-03 13:10:13 -08005107
Evan Charltonc66da362014-05-16 14:06:40 -07005108 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005109 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5110 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5112 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005114 if (DBG) {
5115 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5116 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5117 }
5118 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5119 cla, command, p1, p2, p3, data);
5120 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005121
Jordan Liu4c733742019-02-28 12:03:40 -08005122 @Override
5123 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5124 int command, int p1, int p2, int p3, String data) {
5125 enforceModifyPermission();
5126 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5127 if (DBG) {
5128 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5129 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5130 + " data=" + data);
5131 }
5132
5133 return iccTransmitApduBasicChannelWithPermission(
5134 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5135 p2, p3, data);
5136 }
5137
5138 // open APDU basic channel assuming the caller has sufficient permissions
5139 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5140 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141 final long identity = Binder.clearCallingIdentity();
5142 try {
5143 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5144 && TextUtils.equals(ISDR_AID, data)) {
5145 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005146 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5147 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148 if (bestComponent == null
5149 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5150 loge("The calling package is not allowed to select ISD-R.");
5151 throw new SecurityException(
5152 "The calling package is not allowed to select ISD-R.");
5153 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005154 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005157 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5158 null /* workSource */);
5159 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 // Append the returned status code to the end of the response payload.
5162 String s = Integer.toHexString(
5163 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5164 if (response.payload != null) {
5165 s = IccUtils.bytesToHexString(response.payload) + s;
5166 }
5167 return s;
5168 } finally {
5169 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005170 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005171 }
5172
5173 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005174 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005175 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5177 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 if (DBG) {
5182 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5183 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5184 }
5185
5186 IccIoResult response =
5187 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5188 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5189 subId);
5190
5191 if (DBG) {
5192 log("Exchange SIM_IO [R]" + response);
5193 }
5194
5195 byte[] result = null;
5196 int length = 2;
5197 if (response.payload != null) {
5198 length = 2 + response.payload.length;
5199 result = new byte[length];
5200 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5201 } else {
5202 result = new byte[length];
5203 }
5204
5205 result[length - 1] = (byte) response.sw2;
5206 result[length - 2] = (byte) response.sw1;
5207 return result;
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005210 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005211 }
5212
Nathan Haroldb3014052017-01-25 15:57:32 -08005213 /**
5214 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5215 * on a particular subscription
5216 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005217 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5218 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005220 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005221 return null;
5222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223
5224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 if (appType != TelephonyManager.APPTYPE_USIM
5227 && appType != TelephonyManager.APPTYPE_SIM) {
5228 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5229 return null;
5230 }
5231 Object response = sendRequest(
5232 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5233 if (response instanceof String[]) {
5234 return (String[]) response;
5235 }
yincheng zhao2737e882019-09-06 17:06:54 -07005236 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005238 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 } finally {
5240 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005241 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005242 }
5243
yincheng zhao2737e882019-09-06 17:06:54 -07005244 /**
5245 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5246 * subscription.
5247 *
5248 * @param subId the id of the subscription.
5249 * @param appType the uicc app type, must be USIM or SIM.
5250 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5251 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005252 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005253 * @return number of fplmns that is successfully written to the SIM.
5254 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005255 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5256 String callingFeatureId) {
5257 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5258 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005259 if (DBG) logv("no permissions for setForbiddenplmns");
5260 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5261 }
5262 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5263 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5264 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5265 }
5266 if (fplmns == null) {
5267 throw new IllegalArgumentException("Fplmn List provided is null");
5268 }
5269 for (String fplmn : fplmns) {
5270 if (!CellIdentity.isValidPlmn(fplmn)) {
5271 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5272 }
5273 }
5274 final long identity = Binder.clearCallingIdentity();
5275 try {
5276 Object response = sendRequest(
5277 CMD_SET_FORBIDDEN_PLMNS,
5278 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5279 subId);
5280 return (int) response;
5281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
5284 }
5285
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005286 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005287 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5289 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 final long identity = Binder.clearCallingIdentity();
5292 try {
5293 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5294 if (response.payload == null) {
5295 return "";
5296 }
Evan Charltonc66da362014-05-16 14:06:40 -07005297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 // Append the returned status code to the end of the response payload.
5299 String s = Integer.toHexString(
5300 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5301 s = IccUtils.bytesToHexString(response.payload) + s;
5302 return s;
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
Evan Charltonc66da362014-05-16 14:06:40 -07005306 }
5307
Jake Hambye994d462014-02-03 13:10:13 -08005308 /**
5309 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5310 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5311 *
5312 * @param itemID the ID of the item to read
5313 * @return the NV item as a String, or null on error.
5314 */
5315 @Override
5316 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005317 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5319 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320
5321 final long identity = Binder.clearCallingIdentity();
5322 try {
5323 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005324 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5326 return value;
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
5329 }
Jake Hambye994d462014-02-03 13:10:13 -08005330 }
5331
5332 /**
5333 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5334 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5335 *
5336 * @param itemID the ID of the item to read
5337 * @param itemValue the value to write, as a String
5338 * @return true on success; false on any failure
5339 */
5340 @Override
5341 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005342 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5344 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345
5346 final long identity = Binder.clearCallingIdentity();
5347 try {
5348 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5349 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005350 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5352 return success;
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
5355 }
Jake Hambye994d462014-02-03 13:10:13 -08005356 }
5357
5358 /**
5359 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5360 * Used for device configuration by some CDMA operators.
5361 *
5362 * @param preferredRoamingList byte array containing the new PRL
5363 * @return true on success; false on any failure
5364 */
5365 @Override
5366 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5368 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369
5370 final long identity = Binder.clearCallingIdentity();
5371 try {
5372 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5373 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5374 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5375 return success;
5376 } finally {
5377 Binder.restoreCallingIdentity(identity);
5378 }
Jake Hambye994d462014-02-03 13:10:13 -08005379 }
5380
5381 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005382 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005383 * Used for device configuration by some CDMA operators.
5384 *
chen xu6dac5ab2018-10-26 17:39:23 -07005385 * @param slotIndex - device slot.
5386 *
Jake Hambye994d462014-02-03 13:10:13 -08005387 * @return true on success; false on any failure
5388 */
5389 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005390 public boolean resetModemConfig(int slotIndex) {
5391 Phone phone = PhoneFactory.getPhone(slotIndex);
5392 if (phone != null) {
5393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5394 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395
chen xu6dac5ab2018-10-26 17:39:23 -07005396 final long identity = Binder.clearCallingIdentity();
5397 try {
5398 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5399 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5400 return success;
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 }
chen xu6dac5ab2018-10-26 17:39:23 -07005405 return false;
5406 }
5407
5408 /**
5409 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5410 *
5411 * @param slotIndex - device slot.
5412 *
5413 * @return true on success; false on any failure
5414 */
5415 @Override
5416 public boolean rebootModem(int slotIndex) {
5417 Phone phone = PhoneFactory.getPhone(slotIndex);
5418 if (phone != null) {
5419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5420 mApp, phone.getSubId(), "rebootModem");
5421
5422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5425 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5426 return success;
5427 } finally {
5428 Binder.restoreCallingIdentity(identity);
5429 }
5430 }
5431 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005432 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005433
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005434 public String[] getPcscfAddress(String apnType, String callingPackage,
5435 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005436 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5438 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005439 return new String[0];
5440 }
5441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 final long identity = Binder.clearCallingIdentity();
5443 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005444 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 } finally {
5446 Binder.restoreCallingIdentity(identity);
5447 }
Wink Saville36469e72014-06-11 15:17:00 -07005448 }
5449
Brad Ebinger51f743a2017-01-23 13:50:20 -08005450 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005451 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5452 * {@link #disableIms(int)}.
5453 * @param slotIndex device slot.
5454 */
5455 public void resetIms(int slotIndex) {
5456 enforceModifyPermission();
5457
5458 final long identity = Binder.clearCallingIdentity();
5459 try {
5460 if (mImsResolver == null) {
5461 // may happen if the does not support IMS.
5462 return;
5463 }
5464 mImsResolver.disableIms(slotIndex);
5465 mImsResolver.enableIms(slotIndex);
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
5468 }
5469 }
5470
5471 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005472 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5473 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005474 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005475 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005476 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477
5478 final long identity = Binder.clearCallingIdentity();
5479 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005480 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005481 // may happen if the device does not support IMS.
5482 return;
5483 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005484 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 } finally {
5486 Binder.restoreCallingIdentity(identity);
5487 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005488 }
5489
5490 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005491 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5492 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005493 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005494 public void disableIms(int slotId) {
5495 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496
5497 final long identity = Binder.clearCallingIdentity();
5498 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005499 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005500 // may happen if the device does not support IMS.
5501 return;
5502 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005503 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 } finally {
5505 Binder.restoreCallingIdentity(identity);
5506 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005507 }
5508
5509 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005510 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5511 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005512 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005513 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005514 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005515 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516
5517 final long identity = Binder.clearCallingIdentity();
5518 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005519 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005520 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5521 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005522 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005523 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 } finally {
5525 Binder.restoreCallingIdentity(identity);
5526 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005527 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005528 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005529 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5530 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005531 @Override
5532 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005533 enforceModifyPermission();
5534
5535 final long identity = Binder.clearCallingIdentity();
5536 try {
5537 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005538 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
5542 }
5543
5544 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005545 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005546 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005547 */
5548 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5549 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550
5551 final long identity = Binder.clearCallingIdentity();
5552 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005553 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005554 // may happen if the device does not support IMS.
5555 return null;
5556 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005557 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 } finally {
5559 Binder.restoreCallingIdentity(identity);
5560 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005561 }
5562
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005563 /**
5564 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005565 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005566 */
5567 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5568 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569
5570 final long identity = Binder.clearCallingIdentity();
5571 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005572 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005573 // may happen if the device does not support IMS.
5574 return null;
5575 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005576 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 } finally {
5578 Binder.restoreCallingIdentity(identity);
5579 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005580 }
5581
Brad Ebinger884c07b2018-02-15 16:17:40 -08005582 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005583 * Sets the ImsService Package Name that Telephony will bind to.
5584 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005585 * @param slotIndex the slot ID that the ImsService should bind for.
5586 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005587 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005588 * @param featureTypes An integer array of feature types associated with a packageName.
5589 * @param packageName The name of the package that the current configuration will be replaced
5590 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005591 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005592 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005593 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5594 int[] featureTypes, String packageName) {
5595 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5596 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5598 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005599 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005601 final long identity = Binder.clearCallingIdentity();
5602 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005603 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005604 // may happen if the device does not support IMS.
5605 return false;
5606 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005607 Map<Integer, String> featureConfig = new HashMap<>();
5608 for (int featureType : featureTypes) {
5609 featureConfig.put(featureType, packageName);
5610 }
5611 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5612 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613 } finally {
5614 Binder.restoreCallingIdentity(identity);
5615 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005616 }
5617
5618 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005619 * Clears any carrier ImsService overrides for the slot index specified that were previously
5620 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5621 *
5622 * This should only be used for testing.
5623 *
5624 * @param slotIndex the slot ID that the ImsService should bind for.
5625 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5626 */
5627 @Override
5628 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5629 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5630 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5631 "clearCarrierImsServiceOverride");
5632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5633 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5634 "clearCarrierImsServiceOverride");
5635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 if (mImsResolver == null) {
5639 // may happen if the device does not support IMS.
5640 return false;
5641 }
5642 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
5646 }
5647
5648 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005649 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005650 *
5651 * @param slotId The slot that the ImsService is associated with.
5652 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5653 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005654 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005655 * @return the package name of the ImsService configuration.
5656 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005657 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5658 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005659 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005660 TelephonyPermissions
5661 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5662 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5663 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 final long identity = Binder.clearCallingIdentity();
5666 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005667 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005668 // may happen if the device does not support IMS.
5669 return "";
5670 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005671 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005672 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5673 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005677 }
5678
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005679 /**
5680 * Get the MmTelFeature state associated with the requested subscription id.
5681 * @param subId The subscription that the MmTelFeature is associated with.
5682 * @param callback A callback with an integer containing the
5683 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5684 */
5685 @Override
5686 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5687 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5688 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5689 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5690 "IMS not available on device.");
5691 }
5692 final long token = Binder.clearCallingIdentity();
5693 try {
5694 int slotId = getSlotIndex(subId);
5695 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5696 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5697 + subId + "'");
5698 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5699 }
5700 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5701 try {
5702 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5703 } catch (RemoteException e) {
5704 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5705 + "Ignore");
5706 }
5707 });
5708 } finally {
5709 Binder.restoreCallingIdentity(token);
5710 }
5711 }
5712
Daniel Brightbb5840b2021-01-12 15:48:18 -08005713 /**
5714 * Sets the ims registration state on all valid {@link Phone}s.
5715 */
5716 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005717 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718
5719 final long identity = Binder.clearCallingIdentity();
5720 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005721 // NOTE: Before S, this method only set the default phone.
5722 for (final Phone phone : PhoneFactory.getPhones()) {
5723 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5724 phone.setImsRegistrationState(registered);
5725 }
5726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
Wink Saville36469e72014-06-11 15:17:00 -07005730 }
5731
5732 /**
Stuart Scott54788802015-03-30 13:18:01 -07005733 * Set the network selection mode to automatic.
5734 *
5735 */
5736 @Override
5737 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5739 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740
5741 final long identity = Binder.clearCallingIdentity();
5742 try {
shilufc958392020-01-20 11:36:01 -08005743 if (!isActiveSubscription(subId)) {
5744 return;
5745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005747 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5748 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Stuart Scott54788802015-03-30 13:18:01 -07005752 }
5753
Jack Yud10cdd42020-09-28 20:28:01 -07005754 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005755 * Ask the radio to connect to the input network and change selection mode to manual.
5756 *
5757 * @param subId the id of the subscription.
5758 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5759 * the operator to attach to.
5760 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5761 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5762 * normal network selection next time.
5763 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005764 */
5765 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005766 public boolean setNetworkSelectionModeManual(
5767 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5769 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005770
5771 if (!isActiveSubscription(subId)) {
5772 return false;
5773 }
5774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 final long identity = Binder.clearCallingIdentity();
5776 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005777 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005779 if (DBG) {
5780 log("setNetworkSelectionModeManual: subId: " + subId
5781 + " operator: " + operatorInfo);
5782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5784 } finally {
5785 Binder.restoreCallingIdentity(identity);
5786 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005787 }
shilu84f6e8b2019-12-19 13:58:01 -08005788 /**
5789 * Get the manual network selection
5790 *
5791 * @param subId the id of the subscription.
5792 *
5793 * @return the previously saved user selected PLMN
5794 */
5795 @Override
5796 public String getManualNetworkSelectionPlmn(int subId) {
5797 TelephonyPermissions
5798 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5799 mApp, subId, "getManualNetworkSelectionPlmn");
5800
5801 final long identity = Binder.clearCallingIdentity();
5802 try {
5803 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005804 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005805 }
5806
5807 final Phone phone = getPhone(subId);
5808 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005809 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005810 }
5811 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5812 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5813 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
5816 }
5817 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005818
5819 /**
5820 * Scans for available networks.
5821 */
5822 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005823 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5824 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5826 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005827 LocationAccessPolicy.LocationPermissionResult locationResult =
5828 LocationAccessPolicy.checkLocationPermission(mApp,
5829 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5830 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005831 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005832 .setCallingPid(Binder.getCallingPid())
5833 .setCallingUid(Binder.getCallingUid())
5834 .setMethod("getCellNetworkScanResults")
5835 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005836 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5837 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005838 .build());
5839 switch (locationResult) {
5840 case DENIED_HARD:
5841 throw new SecurityException("Not allowed to access scan results -- location");
5842 case DENIED_SOFT:
5843 return null;
5844 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005845
Pengquan Menga1bb6272018-09-06 09:59:22 -07005846 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 try {
5848 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005849 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 } finally {
5852 Binder.restoreCallingIdentity(identity);
5853 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005854 }
5855
5856 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005857 * Get the call forwarding info, given the call forwarding reason.
5858 */
5859 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005860 public void getCallForwarding(int subId, int callForwardingReason,
5861 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005862 enforceReadPrivilegedPermission("getCallForwarding");
5863 long identity = Binder.clearCallingIdentity();
5864 try {
5865 if (DBG) {
5866 log("getCallForwarding: subId " + subId
5867 + " callForwardingReason" + callForwardingReason);
5868 }
Hall Liu27d24262020-09-18 19:04:59 -07005869
5870 Phone phone = getPhone(subId);
5871 if (phone == null) {
5872 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005873 callback.onError(
5874 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005875 } catch (RemoteException e) {
5876 // ignore
5877 }
5878 return;
5879 }
5880
5881 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5882 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5883 @Override
5884 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5885 try {
5886 callback.onCallForwardingInfoAvailable(info);
5887 } catch (RemoteException e) {
5888 // ignore
5889 }
5890 }
5891
5892 @Override
5893 public void onError(int error) {
5894 try {
5895 callback.onError(error);
5896 } catch (RemoteException e) {
5897 // ignore
5898 }
5899 }
5900 });
5901 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005902 } finally {
5903 Binder.restoreCallingIdentity(identity);
5904 }
5905 }
5906
5907 /**
5908 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5909 * reason, the number to forward, and the timeout before the forwarding is attempted.
5910 */
5911 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005912 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5913 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005914 enforceModifyPermission();
5915 long identity = Binder.clearCallingIdentity();
5916 try {
5917 if (DBG) {
5918 log("setCallForwarding: subId " + subId
5919 + " callForwardingInfo" + callForwardingInfo);
5920 }
Hall Liu27d24262020-09-18 19:04:59 -07005921
5922 Phone phone = getPhone(subId);
5923 if (phone == null) {
5924 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005925 callback.accept(
5926 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005927 } catch (RemoteException e) {
5928 // ignore
5929 }
5930 return;
5931 }
5932
5933 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5934 FunctionalUtils.ignoreRemoteException(callback::accept));
5935
5936 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
5940 }
5941
5942 /**
Hall Liu27d24262020-09-18 19:04:59 -07005943 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005944 */
5945 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005946 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005947 enforceReadPrivilegedPermission("getCallForwarding");
5948 long identity = Binder.clearCallingIdentity();
5949 try {
Hall Liu27d24262020-09-18 19:04:59 -07005950
5951 Phone phone = getPhone(subId);
5952 if (phone == null) {
5953 try {
5954 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5955 } catch (RemoteException e) {
5956 // ignore
5957 }
5958 return;
5959 }
5960
5961 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5962
Shuo Qian4a594052020-01-23 11:59:30 -08005963 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005964 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
5967 }
5968 }
5969
5970 /**
Hall Liu27d24262020-09-18 19:04:59 -07005971 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005972 */
5973 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005974 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005975 enforceModifyPermission();
5976 long identity = Binder.clearCallingIdentity();
5977 try {
Hall Liu27d24262020-09-18 19:04:59 -07005978 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5979
5980 Phone phone = getPhone(subId);
5981 if (phone == null) {
5982 try {
5983 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5984 } catch (RemoteException e) {
5985 // ignore
5986 }
5987 return;
5988 }
5989
5990 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5991 FunctionalUtils.ignoreRemoteException(callback::accept));
5992
5993 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
5997 }
5998
5999 /**
yinxub1bed742017-04-17 11:45:04 -07006000 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006001 *
yinxub1bed742017-04-17 11:45:04 -07006002 * @param subId id of the subscription
6003 * @param request contains the radio access networks with bands/channels to scan
6004 * @param messenger callback messenger for scan results or errors
6005 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006006 * @return the id of the requested scan which can be used to stop the scan.
6007 */
6008 @Override
6009 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006010 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6012 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006013 LocationAccessPolicy.LocationPermissionResult locationResult =
6014 LocationAccessPolicy.checkLocationPermission(mApp,
6015 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6016 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006017 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006018 .setCallingPid(Binder.getCallingPid())
6019 .setCallingUid(Binder.getCallingUid())
6020 .setMethod("requestNetworkScan")
6021 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006022 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6023 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006024 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006025 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006026 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6027 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006028 if (e != null) {
6029 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6030 throw e;
6031 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006032 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006033 return TelephonyScanManager.INVALID_SCAN_ID;
6034 }
6035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 }
Hall Liu912dfd32019-04-25 14:02:26 -07006037 int callingUid = Binder.getCallingUid();
6038 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006039 final long identity = Binder.clearCallingIdentity();
6040 try {
6041 return mNetworkScanRequestTracker.startNetworkScan(
6042 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006043 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006044 } finally {
6045 Binder.restoreCallingIdentity(identity);
6046 }
yinxu504e1392017-04-12 16:03:22 -07006047 }
6048
Hall Liub2ac8ef2019-02-28 15:56:23 -08006049 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006050 NetworkScanRequest request, int subId, String callingPackage) {
6051 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006052 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6053 boolean hasNetworkScanPermission =
6054 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6055 == PERMISSION_GRANTED;
6056
6057 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6058 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6059 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006060 }
6061
6062 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6063 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006064 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6065 return new SecurityException("Specific channels must not be"
6066 + " scanned without location access.");
6067 }
6068 }
6069 }
6070
Hall Liub2ac8ef2019-02-28 15:56:23 -08006071 return null;
6072 }
6073
yinxu504e1392017-04-12 16:03:22 -07006074 /**
6075 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006076 *
6077 * @param subId id of the subscription
6078 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006079 */
6080 @Override
6081 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6083 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084
Hall Liu912dfd32019-04-25 14:02:26 -07006085 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 final long identity = Binder.clearCallingIdentity();
6087 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006088 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 } finally {
6090 Binder.restoreCallingIdentity(identity);
6091 }
yinxu504e1392017-04-12 16:03:22 -07006092 }
6093
6094 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006095 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006096 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006097 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006098 */
6099 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006100 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006101 TelephonyPermissions
6102 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006103 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104
6105 final long identity = Binder.clearCallingIdentity();
6106 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006107 if (DBG) log("getAllowedNetworkTypesBitmask");
6108 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6109 int networkTypesBitmask = (result != null ? result[0] : -1);
6110 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6111 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 } finally {
6113 Binder.restoreCallingIdentity(identity);
6114 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006115 }
6116
6117 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006118 * Get the allowed network types for certain reason.
6119 *
6120 * @param subId the id of the subscription.
6121 * @param reason the reason the allowed network type change is taking place
6122 * @return the allowed network types.
6123 */
6124 @Override
6125 public long getAllowedNetworkTypesForReason(int subId,
6126 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6127 TelephonyPermissions
6128 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6129 mApp, subId, "getAllowedNetworkTypesForReason");
6130 final long identity = Binder.clearCallingIdentity();
6131 try {
6132 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6133 } finally {
6134 Binder.restoreCallingIdentity(identity);
6135 }
6136 }
6137
6138 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006139 * Enable/Disable E-UTRA-NR Dual Connectivity
6140 * @param subId subscription id of the sim card
6141 * @param nrDualConnectivityState expected NR dual connectivity state
6142 * This can be passed following states
6143 * <ol>
6144 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6145 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6146 * <li>Disable NR dual connectivity and force secondary cell to be released
6147 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6148 * </ol>
6149 * @return operation result.
6150 */
6151 @Override
6152 public int setNrDualConnectivityState(int subId,
6153 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6155 mApp, subId, "enableNRDualConnectivity");
6156 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6157 final long identity = Binder.clearCallingIdentity();
6158 try {
6159 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6160 nrDualConnectivityState, subId,
6161 workSource);
6162 if (DBG) log("enableNRDualConnectivity result: " + result);
6163 return result;
6164 } finally {
6165 Binder.restoreCallingIdentity(identity);
6166 }
6167 }
6168
6169 /**
6170 * Is E-UTRA-NR Dual Connectivity enabled
6171 * @return true if dual connectivity is enabled else false
6172 */
6173 @Override
6174 public boolean isNrDualConnectivityEnabled(int subId) {
6175 TelephonyPermissions
6176 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6177 mApp, subId, "isNRDualConnectivityEnabled");
6178 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6179 final long identity = Binder.clearCallingIdentity();
6180 try {
6181 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6182 null, subId, workSource);
6183 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6184 return isEnabled;
6185 } finally {
6186 Binder.restoreCallingIdentity(identity);
6187 }
6188 }
6189
6190 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006191 * get carrier bandwidth per primary and secondary carrier
6192 * @param subId subscription id of the sim card
6193 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6194 */
6195 @Override
6196 public CarrierBandwidth getCarrierBandwidth(int subId) {
6197 TelephonyPermissions
6198 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6199 mApp, subId, "isNRDualConnectivityEnabled");
6200 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6201 final long identity = Binder.clearCallingIdentity();
6202 try {
6203 CarrierBandwidth carrierBandwidth =
6204 getPhoneFromSubId(subId).getCarrierBandwidth();
6205 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6206 return carrierBandwidth;
6207 } finally {
6208 Binder.restoreCallingIdentity(identity);
6209 }
6210 }
6211
6212 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006213 * Set the allowed network types of the device and
6214 * provide the reason triggering the allowed network change.
6215 *
6216 * @param subId the id of the subscription.
6217 * @param reason the reason the allowed network type change is taking place
6218 * @param allowedNetworkTypes the allowed network types.
6219 * @return true on success; false on any failure.
6220 */
6221 @Override
6222 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006223 @TelephonyManager.AllowedNetworkTypesReason int reason,
6224 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6226 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006227 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6228 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6229 return false;
6230 }
6231
6232 if (DBG) {
6233 log("setAllowedNetworkTypesForReason: " + reason
6234 + " value: " + allowedNetworkTypes);
6235 }
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006236 final long identity = Binder.clearCallingIdentity();
6237 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006238 Boolean success = (Boolean) sendRequest(
6239 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6240 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6241
6242 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6243 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006244 } finally {
6245 Binder.restoreCallingIdentity(identity);
6246 }
6247 }
6248
6249 /**
Miaoa84611c2019-03-15 09:21:10 +08006250 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006251 *
Miaoa84611c2019-03-15 09:21:10 +08006252 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006253 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006254 * @hide
6255 */
6256 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006257 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006258 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006260 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261 try {
Miaoa84611c2019-03-15 09:21:10 +08006262 if (phone != null) {
6263 return phone.hasMatchedTetherApnSetting();
6264 } else {
6265 return false;
6266 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 } finally {
6268 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006269 }
Junda Liu475951f2014-11-07 16:45:03 -08006270 }
6271
6272 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006273 * Enable or disable always reporting signal strength changes from radio.
6274 *
6275 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6276 */
6277 @Override
6278 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6279 enforceModifyPermission();
6280 enforceSystemCaller();
6281
6282 final long identity = Binder.clearCallingIdentity();
6283 final Phone phone = getPhone(subId);
6284 try {
6285 if (phone != null) {
6286 if (DBG) {
6287 log("setAlwaysReportSignalStrength: subId=" + subId
6288 + " isEnable=" + isEnable);
6289 }
6290 phone.setAlwaysReportSignalStrength(isEnable);
6291 } else {
6292 loge("setAlwaysReportSignalStrength: no phone found for subId="
6293 + subId);
6294 }
6295 } finally {
6296 Binder.restoreCallingIdentity(identity);
6297 }
6298 }
6299
6300 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006301 * Get the user enabled state of Mobile Data.
6302 *
6303 * TODO: remove and use isUserDataEnabled.
6304 * This can't be removed now because some vendor codes
6305 * calls through ITelephony directly while they should
6306 * use TelephonyManager.
6307 *
6308 * @return true on enabled
6309 */
6310 @Override
6311 public boolean getDataEnabled(int subId) {
6312 return isUserDataEnabled(subId);
6313 }
6314
6315 /**
6316 * Get whether mobile data is enabled per user setting.
6317 *
6318 * There are other factors deciding whether mobile data is actually enabled, but they are
6319 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006320 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006321 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006322 *
6323 * @return {@code true} if data is enabled else {@code false}
6324 */
6325 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006326 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006327 try {
6328 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6329 null);
6330 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6332 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334
6335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 int phoneId = mSubscriptionController.getPhoneId(subId);
6338 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6339 Phone phone = PhoneFactory.getPhone(phoneId);
6340 if (phone != null) {
6341 boolean retVal = phone.isUserDataEnabled();
6342 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6343 return retVal;
6344 } else {
6345 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6346 return false;
6347 }
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006350 }
6351 }
6352
6353 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006354 * Checks if the device is capable of mobile data by considering whether whether the
6355 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6356 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006357 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006358 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006359 */
6360 @Override
6361 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006362 try {
6363 try {
6364 mApp.enforceCallingOrSelfPermission(
6365 android.Manifest.permission.ACCESS_NETWORK_STATE,
6366 null);
6367 } catch (Exception e) {
6368 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6369 "isDataEnabled");
6370 }
6371 } catch (Exception e) {
6372 enforceReadPrivilegedPermission("isDataEnabled");
6373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374
6375 final long identity = Binder.clearCallingIdentity();
6376 try {
6377 int phoneId = mSubscriptionController.getPhoneId(subId);
6378 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6379 Phone phone = PhoneFactory.getPhone(phoneId);
6380 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006381 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6383 return retVal;
6384 } else {
6385 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6386 return false;
6387 }
6388 } finally {
6389 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006390 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006391 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006392
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006393 /**
6394 * Check if data is enabled for a specific reason
6395 * @param subId Subscription index
6396 * @param reason the reason the data enable change is taking place
6397 * @return {@code true} if the overall data is enabled; {@code false} if not.
6398 */
6399 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006400 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006401 @TelephonyManager.DataEnabledReason int reason) {
6402 try {
6403 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6404 null);
6405 } catch (Exception e) {
6406 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006407 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006408 }
6409
6410
6411 final long identity = Binder.clearCallingIdentity();
6412 try {
6413 int phoneId = mSubscriptionController.getPhoneId(subId);
6414 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006415 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006416 + " reason=" + reason);
6417 }
6418 Phone phone = PhoneFactory.getPhone(phoneId);
6419 if (phone != null) {
6420 boolean retVal;
6421 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6422 retVal = phone.isUserDataEnabled();
6423 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006424 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006425 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006426 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006427 return retVal;
6428 } else {
6429 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006430 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006431 + subId + " retVal=false");
6432 }
6433 return false;
6434 }
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
6437 }
6438 }
6439
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006440 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006441 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006442 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6443 // Skip the check if it's one of these special uids
6444 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6445 }
6446
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006447 //load access rules from carrier configs, and check those as well: b/139133814
6448 SubscriptionController subController = SubscriptionController.getInstance();
6449 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6450 || subController == null) return privilegeFromSim;
6451
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006452 PackageManager pkgMgr = phone.getContext().getPackageManager();
6453 String[] packages = pkgMgr.getPackagesForUid(uid);
6454
6455 final long identity = Binder.clearCallingIdentity();
6456 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006457 int subId = phone.getSubId();
6458 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6459 // A test override is in place for the privileges for this subId, so don't try to
6460 // read the subscription privileges.
6461 return privilegeFromSim;
6462 }
6463 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006464 SubscriptionManager subManager = (SubscriptionManager)
6465 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6466 for (String pkg : packages) {
6467 if (subManager.canManageSubscription(subInfo, pkg)) {
6468 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6469 }
6470 }
6471 return privilegeFromSim;
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
6475 }
6476
6477 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6478 String pkgName) {
6479 //load access rules from carrier configs, and check those as well: b/139133814
6480 SubscriptionController subController = SubscriptionController.getInstance();
6481 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6482 || subController == null) return privilegeFromSim;
6483
6484 final long identity = Binder.clearCallingIdentity();
6485 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006486 int subId = phone.getSubId();
6487 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6488 // A test override is in place for the privileges for this subId, so don't try to
6489 // read the subscription privileges.
6490 return privilegeFromSim;
6491 }
6492 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006493 SubscriptionManager subManager = (SubscriptionManager)
6494 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6495 return subManager.canManageSubscription(subInfo, pkgName)
6496 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
6500 }
6501
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006502 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006503 public int getCarrierPrivilegeStatus(int subId) {
6504 final Phone phone = getPhone(subId);
6505 if (phone == null) {
6506 loge("getCarrierPrivilegeStatus: Invalid subId");
6507 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6508 }
6509 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006510 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006511 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006512 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6513 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006514
6515 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6516 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006517 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006518 }
Junda Liu29340342014-07-10 15:23:27 -07006519
6520 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006521 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006522 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006523 final Phone phone = getPhone(subId);
6524 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006525 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006526 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6527 }
6528 UiccProfile profile =
6529 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6530 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006531 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006532 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6533 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006534 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006535 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006536 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006537 }
6538
6539 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006540 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6541 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006542 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006543 }
6544
6545 int phoneId = SubscriptionManager.getPhoneId(subId);
6546 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006547 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006548 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006549 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6550 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006551 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6552 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6553 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006554 }
6555
6556 @Override
6557 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006558 if (TextUtils.isEmpty(pkgName))
6559 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006560 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6561 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6562 UiccCard card = UiccController.getInstance().getUiccCard(i);
6563 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006564 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006565 continue;
6566 }
6567
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006568 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6569 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6570 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006571 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6572 break;
6573 }
6574 }
6575
6576 return result;
Junda Liu29340342014-07-10 15:23:27 -07006577 }
Derek Tan89e89d42014-07-08 17:00:10 -07006578
6579 @Override
Junda Liue64de782015-04-16 17:19:16 -07006580 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6581 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6582 loge("phoneId " + phoneId + " is not valid.");
6583 return null;
6584 }
6585 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006586 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006587 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006588 return null ;
6589 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006590 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006591 }
6592
Amith Yamasani6e118872016-02-19 12:53:51 -08006593 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006594 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006595 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006596 List<String> privilegedPackages = new ArrayList<>();
6597 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006598 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6599 // has UICC in that slot.
6600 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006601 if (card.hasCarrierPrivilegeRules()) {
6602 if (packages == null) {
6603 // Only check packages in user 0 for now
6604 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006605 PackageManager.MATCH_DISABLED_COMPONENTS
6606 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006607 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006608 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006609 }
6610 for (int p = packages.size() - 1; p >= 0; p--) {
6611 PackageInfo pkgInfo = packages.get(p);
6612 if (pkgInfo != null && pkgInfo.packageName != null
6613 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006614 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006615 privilegedPackages.add(pkgInfo.packageName);
6616 }
6617 }
6618 }
6619 }
6620 return privilegedPackages;
6621 }
6622
chen xuf7e9fe82019-05-09 19:31:02 -07006623 @Override
6624 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006625 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6626
6627 final long identity = Binder.clearCallingIdentity();
6628
chen xuf7e9fe82019-05-09 19:31:02 -07006629 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006630 try {
6631 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6632 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6633 }
6634 } finally {
6635 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006636 }
6637 return privilegedPackages;
6638 }
6639
Wink Savilleb564aae2014-10-23 10:18:09 -07006640 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006641 final Phone phone = getPhone(subId);
6642 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006643 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006644 return null;
6645 }
6646 String iccId = card.getIccId();
6647 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006648 return null;
6649 }
6650 return iccId;
6651 }
6652
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006653 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006654 public void setCallComposerStatus(int subId, int status) {
6655 enforceModifyPermission();
6656
6657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 Phone phone = getPhone(subId);
6660 if (phone != null) {
6661 Phone defaultPhone = phone.getImsPhone();
6662 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6663 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6664 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006665 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6666 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006667 }
6668 }
Shuo Qian284ae752020-12-22 19:10:14 -08006669 } catch (ImsException e) {
6670 throw new ServiceSpecificException(e.getCode());
6671 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006672 Binder.restoreCallingIdentity(identity);
6673 }
6674 }
6675
6676 @Override
6677 public int getCallComposerStatus(int subId) {
6678 enforceReadPrivilegedPermission("getCallComposerStatus");
6679
6680 final long identity = Binder.clearCallingIdentity();
6681 try {
6682 Phone phone = getPhone(subId);
6683 if (phone != null) {
6684 Phone defaultPhone = phone.getImsPhone();
6685 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6686 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6687 return imsPhone.getCallComposerStatus();
6688 }
6689 }
6690 } finally {
6691 Binder.restoreCallingIdentity(identity);
6692 }
6693 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6694 }
6695
6696 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006697 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6698 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006699 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006700 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702 final long identity = Binder.clearCallingIdentity();
6703 try {
6704 final String iccId = getIccId(subId);
6705 final Phone phone = getPhone(subId);
6706 if (phone == null) {
6707 return false;
6708 }
6709 final String subscriberId = phone.getSubscriberId();
6710
6711 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006712 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 + subscriberId + " to " + number);
6714 }
6715
6716 if (TextUtils.isEmpty(iccId)) {
6717 return false;
6718 }
6719
6720 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6721
6722 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6723 if (alphaTag == null) {
6724 editor.remove(alphaTagPrefKey);
6725 } else {
6726 editor.putString(alphaTagPrefKey, alphaTag);
6727 }
6728
6729 // Record both the line number and IMSI for this ICCID, since we need to
6730 // track all merged IMSIs based on line number
6731 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6732 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6733 if (number == null) {
6734 editor.remove(numberPrefKey);
6735 editor.remove(subscriberPrefKey);
6736 } else {
6737 editor.putString(numberPrefKey, number);
6738 editor.putString(subscriberPrefKey, subscriberId);
6739 }
6740
6741 editor.commit();
6742 return true;
6743 } finally {
6744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006745 }
Derek Tan7226c842014-07-02 17:42:23 -07006746 }
6747
6748 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006749 public String getLine1NumberForDisplay(int subId, String callingPackage,
6750 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006751 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006752 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006753 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006754 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006755 return null;
6756 }
Derek Tan97ebb422014-09-05 16:55:38 -07006757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 final long identity = Binder.clearCallingIdentity();
6759 try {
6760 String iccId = getIccId(subId);
6761 if (iccId != null) {
6762 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6763 if (DBG_MERGE) {
6764 log("getLine1NumberForDisplay returning "
6765 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6766 }
6767 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6770 return null;
6771 } finally {
6772 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006773 }
Derek Tan7226c842014-07-02 17:42:23 -07006774 }
6775
6776 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006777 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6778 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006780 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006781 return null;
6782 }
Derek Tan97ebb422014-09-05 16:55:38 -07006783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 final long identity = Binder.clearCallingIdentity();
6785 try {
6786 String iccId = getIccId(subId);
6787 if (iccId != null) {
6788 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6789 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6790 }
6791 return null;
6792 } finally {
6793 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006794 }
Derek Tan7226c842014-07-02 17:42:23 -07006795 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006796
6797 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006798 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6799 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006800 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6801 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006803 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006804 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006805 return null;
6806 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006807
Jordan Liub49b04b2019-05-06 14:45:15 -07006808 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6809 // the process, where TelephonyManager was instantiated.
6810 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006811 final long identity = Binder.clearCallingIdentity();
6812 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006813 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814 final TelephonyManager tele = TelephonyManager.from(context);
6815 final SubscriptionManager sub = SubscriptionManager.from(context);
6816
6817 // Figure out what subscribers are currently active
6818 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819
Jordan Liub49b04b2019-05-06 14:45:15 -07006820 // Only consider subs which match the current subId
6821 // This logic can be simplified. See b/131189269 for progress.
6822 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006823 activeSubscriberIds.add(tele.getSubscriberId(subId));
6824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825
6826 // First pass, find a number override for an active subscriber
6827 String mergeNumber = null;
6828 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6829 for (String key : prefs.keySet()) {
6830 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6831 final String subscriberId = (String) prefs.get(key);
6832 if (activeSubscriberIds.contains(subscriberId)) {
6833 final String iccId = key.substring(
6834 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6835 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6836 mergeNumber = (String) prefs.get(numberKey);
6837 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006838 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 + " for active subscriber " + subscriberId);
6840 }
6841 if (!TextUtils.isEmpty(mergeNumber)) {
6842 break;
6843 }
6844 }
6845 }
6846 }
6847
6848 // Shortcut when no active merged subscribers
6849 if (TextUtils.isEmpty(mergeNumber)) {
6850 return null;
6851 }
6852
6853 // Second pass, find all subscribers under that line override
6854 final ArraySet<String> result = new ArraySet<>();
6855 for (String key : prefs.keySet()) {
6856 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6857 final String number = (String) prefs.get(key);
6858 if (mergeNumber.equals(number)) {
6859 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6860 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6861 final String subscriberId = (String) prefs.get(subscriberKey);
6862 if (!TextUtils.isEmpty(subscriberId)) {
6863 result.add(subscriberId);
6864 }
6865 }
6866 }
6867 }
6868
6869 final String[] resultArray = result.toArray(new String[result.size()]);
6870 Arrays.sort(resultArray);
6871 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006872 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6874 }
6875 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006876 } finally {
6877 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006878 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006879 }
6880
6881 @Override
zoey chen38003472019-12-13 17:16:31 +08006882 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6883 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006884
6885 final long identity = Binder.clearCallingIdentity();
6886 try {
6887 final TelephonyManager telephonyManager = mApp.getSystemService(
6888 TelephonyManager.class);
6889 String subscriberId = telephonyManager.getSubscriberId(subId);
6890 if (subscriberId == null) {
6891 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006892 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006893 + subId);
6894 }
6895 return null;
6896 }
6897
6898 final SubscriptionInfo info = SubscriptionController.getInstance()
6899 .getSubscriptionInfo(subId);
6900 final ParcelUuid groupUuid = info.getGroupUuid();
6901 // If it doesn't belong to any group, return just subscriberId of itself.
6902 if (groupUuid == null) {
6903 return new String[]{subscriberId};
6904 }
6905
6906 // Get all subscriberIds from the group.
6907 final List<String> mergedSubscriberIds = new ArrayList<>();
6908 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006909 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006910 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006911 for (SubscriptionInfo subInfo : groupInfos) {
6912 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6913 if (subscriberId != null) {
6914 mergedSubscriberIds.add(subscriberId);
6915 }
6916 }
6917
6918 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6919 } finally {
6920 Binder.restoreCallingIdentity(identity);
6921
6922 }
6923 }
6924
6925 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006926 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006927 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006928 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929
6930 final long identity = Binder.clearCallingIdentity();
6931 try {
6932 final Phone phone = getPhone(subId);
6933 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6934 } finally {
6935 Binder.restoreCallingIdentity(identity);
6936 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006937 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006938
6939 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006940 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006941 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6942 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006943 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6944 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945
6946 final long identity = Binder.clearCallingIdentity();
6947 try {
6948 final Phone phone = getPhone(subId);
6949 if (phone == null) {
6950 return false;
6951 }
6952 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6953 cdmaNonRoamingList);
6954 } finally {
6955 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006956 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006957 }
6958
6959 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006960 @Deprecated
6961 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6962 enforceModifyPermission();
6963
6964 int returnValue = 0;
6965 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006966 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006967 if(result.exception == null) {
6968 if (result.result != null) {
6969 byte[] responseData = (byte[])(result.result);
6970 if(responseData.length > oemResp.length) {
6971 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6972 responseData.length + "bytes. Buffer Size is " +
6973 oemResp.length + "bytes.");
6974 }
6975 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6976 returnValue = responseData.length;
6977 }
6978 } else {
6979 CommandException ex = (CommandException) result.exception;
6980 returnValue = ex.getCommandError().ordinal();
6981 if(returnValue > 0) returnValue *= -1;
6982 }
6983 } catch (RuntimeException e) {
6984 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6985 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6986 if(returnValue > 0) returnValue *= -1;
6987 }
6988
6989 return returnValue;
6990 }
6991
6992 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006993 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006994 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006995 try {
6996 TelephonyPermissions
6997 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6998 mApp, phone.getSubId(), "getRadioAccessFamily");
6999 } catch (SecurityException e) {
7000 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7001 throw e;
7002 }
chen xub97461a2018-10-26 14:17:57 -07007003 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007004 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007005 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 final long identity = Binder.clearCallingIdentity();
7008 try {
chen xub97461a2018-10-26 14:17:57 -07007009 TelephonyPermissions
7010 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7011 mApp, phone.getSubId(), "getRadioAccessFamily");
7012 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013 } finally {
7014 Binder.restoreCallingIdentity(identity);
7015 }
chen xub97461a2018-10-26 14:17:57 -07007016 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007017 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007018
7019 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007020 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007021 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007022 try {
7023 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7024 Binder.getCallingUid())) {
7025 throw new SecurityException("Package uid and package name do not match: "
7026 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7027 }
7028 } catch (PackageManager.NameNotFoundException e) {
7029 throw new SecurityException("Package name invalid:" + callingPackage);
7030 }
7031 RoleManager rm = mApp.getSystemService(RoleManager.class);
7032 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7033 if (!dialerRoleHolders.contains(callingPackage)) {
7034 throw new SecurityException("App must be the dialer role holder to"
7035 + " upload a call composer pic");
7036 }
7037
7038 Executors.newSingleThreadExecutor().execute(() -> {
7039 ByteArrayOutputStream output = new ByteArrayOutputStream(
7040 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7041 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7042 boolean readUntilEnd = false;
7043 int totalBytesRead = 0;
7044 byte[] buffer = new byte[16 * 1024];
7045 while (true) {
7046 int numRead;
7047 try {
7048 numRead = input.read(buffer);
7049 } catch (IOException e) {
7050 try {
7051 fd.checkError();
7052 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7053 null);
7054 } catch (IOException e1) {
7055 // This means that the other side closed explicitly with an error. If this
7056 // happens, log and ignore.
7057 loge("Remote end of call composer picture pipe closed: " + e1);
7058 }
7059 break;
7060 }
7061 if (numRead == -1) {
7062 readUntilEnd = true;
7063 break;
7064 }
7065 totalBytesRead += numRead;
7066 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7067 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7068 try {
7069 input.close();
7070 } catch (IOException e) {
7071 // ignore
7072 }
7073 break;
7074 }
7075 output.write(buffer, 0, numRead);
7076 }
7077 // Generally, the remote end will close the file descriptors. The only case where we
7078 // close is above, where the picture size is too big.
7079
7080 try {
7081 fd.checkError();
7082 } catch (IOException e) {
7083 loge("Remote end for call composer closed with an error: " + e);
7084 return;
7085 }
7086
Hall Liuaa4211e2021-01-20 15:43:39 -08007087 if (!readUntilEnd) {
7088 loge("Did not finish reading entire image; aborting");
7089 return;
7090 }
Hall Liu82694d52020-12-11 18:22:04 -08007091
Hall Liuaa4211e2021-01-20 15:43:39 -08007092 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7093 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7094 new CallComposerPictureTransfer.Factory() {},
7095 imageData,
7096 (result) -> {
7097 if (result.first != null) {
7098 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7099 Bundle outputResult = new Bundle();
7100 outputResult.putParcelable(
7101 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7102 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7103 outputResult);
7104 } else {
7105 callback.send(result.second, null);
7106 }
7107 }
7108 );
Hall Liu82694d52020-12-11 18:22:04 -08007109 });
7110 }
7111
7112 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007113 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007114 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007115 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116
7117 final long identity = Binder.clearCallingIdentity();
7118 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007119 ImsManager.getInstance(defaultPhone.getContext(),
7120 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 } finally {
7122 Binder.restoreCallingIdentity(identity);
7123 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007124 }
7125
7126 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007127 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007128 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7130 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007131 return false;
7132 }
Svet Ganovb320e182015-04-16 12:30:10 -07007133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134 final long identity = Binder.clearCallingIdentity();
7135 try {
7136 // Check the user preference and the system-level IMS setting. Even if the user has
7137 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7138 // In the long run, we may instead need to check if there exists a connection service
7139 // which can support video calling.
7140 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007141 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142 return imsManager.isVtEnabledByPlatform()
7143 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7144 && imsManager.isVtEnabledByUser();
7145 } finally {
7146 Binder.restoreCallingIdentity(identity);
7147 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007148 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007149
Andrew Leea1239f22015-03-02 17:44:07 -08007150 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007151 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7152 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007154 mApp, subId, callingPackage, callingFeatureId,
7155 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156 return false;
7157 }
7158
7159 final long identity = Binder.clearCallingIdentity();
7160 try {
7161 CarrierConfigManager configManager =
7162 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007163 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167 }
Andrew Leea1239f22015-03-02 17:44:07 -08007168 }
7169
7170 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007171 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007173 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174 return false;
7175 }
7176
7177 final long identity = Binder.clearCallingIdentity();
7178 try {
7179 CarrierConfigManager configManager =
7180 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007181 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007182 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
7185 }
Andrew Leea1239f22015-03-02 17:44:07 -08007186 }
7187
Andrew Lee9431b832015-03-09 18:46:45 -07007188 @Override
7189 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007190 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007191 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007192 }
7193
7194 @Override
7195 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 final long identity = Binder.clearCallingIdentity();
7197 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007198 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199 } finally {
7200 Binder.restoreCallingIdentity(identity);
7201 }
Andrew Lee9431b832015-03-09 18:46:45 -07007202 }
7203
Hall Liuf6668912018-10-31 17:05:23 -07007204 /**
7205 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7206 * support for the feature and device firmware support.
7207 *
7208 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7209 */
7210 @Override
7211 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007213 final Phone phone = getPhone(subscriptionId);
7214 if (phone == null) {
7215 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7216 return false;
7217 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007218 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007219 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007220 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7221 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007222 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223 return isCarrierSupported && isDeviceSupported;
7224 } finally {
7225 Binder.restoreCallingIdentity(identity);
7226 }
Hall Liu98187582018-01-22 19:15:32 -08007227 }
7228
Hall Liuf6668912018-10-31 17:05:23 -07007229 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007230 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7231 * RTT setting, will return true if the device and carrier both support RTT.
7232 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007233 */
7234 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 final long identity = Binder.clearCallingIdentity();
7236 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007237 boolean isRttSupported = isRttSupported(subscriptionId);
7238 boolean isUserRttSettingOn = Settings.Secure.getInt(
7239 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7240 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7241 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7242 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 } finally {
7244 Binder.restoreCallingIdentity(identity);
7245 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007246 }
7247
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007248 @Deprecated
7249 @Override
7250 public String getDeviceId(String callingPackage) {
7251 return getDeviceIdWithFeature(callingPackage, null);
7252 }
7253
Sanket Padawe7310cc72015-01-14 09:53:20 -08007254 /**
7255 * Returns the unique device ID of phone, for example, the IMEI for
7256 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7257 *
7258 * <p>Requires Permission:
7259 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7260 */
7261 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007262 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007263 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007264 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007265 return null;
7266 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007267 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007268 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007269 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007270 return null;
7271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272
7273 final long identity = Binder.clearCallingIdentity();
7274 try {
7275 return phone.getDeviceId();
7276 } finally {
7277 Binder.restoreCallingIdentity(identity);
7278 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007279 }
7280
Ping Sunc67b7c22016-03-02 19:16:45 +08007281 /**
7282 * {@hide}
7283 * Returns the IMS Registration Status on a particular subid
7284 *
7285 * @param subId
7286 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007287 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007288 Phone phone = getPhone(subId);
7289 if (phone != null) {
7290 return phone.isImsRegistered();
7291 } else {
7292 return false;
7293 }
7294 }
7295
Santos Cordon7a1885b2015-02-03 11:15:19 -08007296 @Override
7297 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298 final long identity = Binder.clearCallingIdentity();
7299 try {
7300 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007304 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007305
Tyler Gunnf70ed162019-04-03 15:28:53 -07007306 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007307 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007308 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007310 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007311 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7312 }
7313 final long identity = Binder.clearCallingIdentity();
7314 try {
7315 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7316 } finally {
7317 Binder.restoreCallingIdentity(identity);
7318 }
7319 }
7320
7321 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007322 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007323 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7324 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007325 final long identity = Binder.clearCallingIdentity();
7326 try {
7327 Phone phone = getPhone(subscriptionId);
7328 if (phone == null) {
7329 return null;
7330 }
7331 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7332 } finally {
7333 Binder.restoreCallingIdentity(identity);
7334 }
7335 }
7336
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007337 /**
7338 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007339 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007340 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 final long identity = Binder.clearCallingIdentity();
7342 try {
7343 Phone phone = getPhone(subId);
7344 if (phone != null) {
7345 return phone.isWifiCallingEnabled();
7346 } else {
7347 return false;
7348 }
7349 } finally {
7350 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007351 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007352 }
7353
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007354 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007355 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007356 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007357 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358 final long identity = Binder.clearCallingIdentity();
7359 try {
7360 Phone phone = getPhone(subId);
7361 if (phone != null) {
7362 return phone.isVideoEnabled();
7363 } else {
7364 return false;
7365 }
7366 } finally {
7367 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007368 }
7369 }
7370
7371 /**
7372 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7373 * defined in {@link ImsRegistrationImplBase}.
7374 */
7375 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 final long identity = Binder.clearCallingIdentity();
7377 try {
7378 Phone phone = getPhone(subId);
7379 if (phone != null) {
7380 return phone.getImsRegistrationTech();
7381 } else {
7382 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7383 }
7384 } finally {
7385 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007386 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007387 }
7388
Stuart Scott8eef64f2015-04-08 15:13:54 -07007389 @Override
7390 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007391 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007392 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7393 return;
7394 }
7395
Svet Ganovcc087f82015-05-12 20:35:54 -07007396 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007397
Svet Ganovcc087f82015-05-12 20:35:54 -07007398 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007399 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7400 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007401 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007402 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007403 setNetworkSelectionModeAutomatic(subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007404 setAllowedNetworkTypesForReason(subId,
7405 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7406 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7407 setAllowedNetworkTypesForReason(subId,
7408 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7409 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7410 setAllowedNetworkTypesForReason(subId,
7411 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7412 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Yomna Nasser3f777b62021-02-17 03:38:52 +00007413 setAllowedNetworkTypesForReason(subId,
7414 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G,
7415 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007416 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7417 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007418 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007419 // There has been issues when Sms raw table somehow stores orphan
7420 // fragments. They lead to garbled message when new fragments come
7421 // in and combined with those stale ones. In case this happens again,
7422 // user can reset all network settings which will clean up this table.
7423 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007424 // Clean up IMS settings as well here.
7425 int slotId = getSlotIndex(subId);
7426 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7427 ImsManager.getInstance(mApp, slotId).factoryReset();
7428 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007429
7430 // Erase modem config if erase modem on network setting is enabled.
7431 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7432 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7433 if (configValue != null && Boolean.parseBoolean(configValue)) {
7434 sendEraseModemConfig(getDefaultPhone());
7435 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007436 } finally {
7437 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007438 }
7439 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007440
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007441 private void cleanUpSmsRawTable(Context context) {
7442 ContentResolver resolver = context.getContentResolver();
7443 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7444 resolver.delete(uri, null, null);
7445 }
7446
Narayan Kamath1c496c22015-04-16 14:40:19 +01007447 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007448 public String getSimLocaleForSubscriber(int subId) {
7449 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7450 final Phone phone = getPhone(subId);
7451 if (phone == null) {
7452 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007453 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007455 final long identity = Binder.clearCallingIdentity();
7456 try {
chen xu5d3637b2019-01-21 23:31:38 -08007457 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007458 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007459 if (info == null) {
7460 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7461 return null;
7462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 // Try and fetch the locale from the carrier properties or from the SIM language
7464 // preferences (EF-PL and EF-LI)...
7465 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007467 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7468 if (localeFromDefaultSim != null) {
7469 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7470 if (DBG) log("Using locale from subId: " + subId + " locale: "
7471 + localeFromDefaultSim);
7472 return localeFromDefaultSim.toLanguageTag();
7473 } else {
7474 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 }
7476 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 // The SIM language preferences only store a language (e.g. fr = French), not an
7479 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7480 // the SIM and carrier preferences does not include a country we add the country
7481 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007482 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007484 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 return mccLocale.toLanguageTag();
7486 }
7487
7488 if (DBG) log("No locale found - returning null");
7489 return null;
7490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007493 }
7494
7495 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007496 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007497 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007498 }
7499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 /**
7501 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7502 */
7503 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007504 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007505 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007506 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007507
Chenjie Yu1ba97252018-01-11 18:16:20 -08007508 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007509 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007510
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007511 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007512 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7513 * representing the state of the modem.
7514 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007515 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7516 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007517 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007518 */
7519 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007520 public void requestModemActivityInfo(ResultReceiver result) {
7521 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007522 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523
7524 final long identity = Binder.clearCallingIdentity();
7525 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007526 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 } finally {
7528 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007529 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007530 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007531
Siddharth Rayb8114062018-06-17 15:02:38 -07007532 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7533 // less than total activity duration.
7534 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7535 if (info == null) {
7536 return false;
7537 }
7538 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007539 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7540 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7541
Siddharth Rayb8114062018-06-17 15:02:38 -07007542 return (info.isValid()
7543 && (info.getSleepTimeMillis() <= activityDurationMs)
7544 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007545 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007546 && (totalTxTimeMs <= activityDurationMs));
7547 }
7548
Jack Yu85bd38a2015-11-09 11:34:32 -08007549 /**
7550 * {@hide}
7551 * Returns the service state information on specified subscription.
7552 */
7553 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007554 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7555 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007557 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007558 return null;
7559 }
7560
Hall Liuf19c44f2018-11-27 14:38:17 -08007561 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7562 LocationAccessPolicy.checkLocationPermission(mApp,
7563 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7564 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007565 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007566 .setCallingPid(Binder.getCallingPid())
7567 .setCallingUid(Binder.getCallingUid())
7568 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007569 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007570 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007571 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7572 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007573 .build());
7574
7575 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7576 LocationAccessPolicy.checkLocationPermission(mApp,
7577 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7578 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007579 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007580 .setCallingPid(Binder.getCallingPid())
7581 .setCallingUid(Binder.getCallingUid())
7582 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007583 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007584 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007585 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7586 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007587 .build());
7588 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7589 boolean hasFinePermission =
7590 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7591 boolean hasCoarsePermission =
7592 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7593
Jack Yu479f40e2020-10-27 21:29:25 -07007594 final Phone phone = getPhone(subId);
7595 if (phone == null) {
7596 return null;
7597 }
7598
Jordan Liu0f2bc442020-11-18 16:47:37 -08007599 final long identity = Binder.clearCallingIdentity();
7600
Jack Yu479f40e2020-10-27 21:29:25 -07007601 boolean isCallingPackageDataService = phone.getDataServicePackages()
7602 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007603 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007604 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7605 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7606 Rlog.d(LOG_TAG,
7607 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7608 return null;
7609 }
7610
Hall Liuf19c44f2018-11-27 14:38:17 -08007611 ServiceState ss = phone.getServiceState();
7612
7613 // Scrub out the location info in ServiceState depending on what level of access
7614 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007615 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007616 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7617 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007618 } finally {
7619 Binder.restoreCallingIdentity(identity);
7620 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007621 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007622
7623 /**
7624 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7625 *
7626 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7627 * voicemail ringtone.
7628 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7629 * PhoneAccount.
7630 */
7631 @Override
7632 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007633 final long identity = Binder.clearCallingIdentity();
7634 try {
7635 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7636 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007637 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007638 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007640 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7641 } finally {
7642 Binder.restoreCallingIdentity(identity);
7643 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007644 }
7645
7646 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007647 * Sets the per-account voicemail ringtone.
7648 *
7649 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7650 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7651 *
7652 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7653 * voicemail ringtone.
7654 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7655 * PhoneAccount.
7656 */
7657 @Override
7658 public void setVoicemailRingtoneUri(String callingPackage,
7659 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007660 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007662 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7663 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7665 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7666 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007667 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007668
7669 final long identity = Binder.clearCallingIdentity();
7670 try {
7671 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7672 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007673 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 }
7675 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7676 } finally {
7677 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007678 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007679 }
7680
7681 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007682 * Returns whether vibration is set for voicemail notification in Phone settings.
7683 *
7684 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7685 * voicemail vibration setting.
7686 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7687 */
7688 @Override
7689 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 final long identity = Binder.clearCallingIdentity();
7691 try {
7692 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7693 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007694 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7698 } finally {
7699 Binder.restoreCallingIdentity(identity);
7700 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007701 }
7702
Youhan Wange64578a2016-05-02 15:32:42 -07007703 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007704 * Sets the per-account voicemail vibration.
7705 *
7706 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7707 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7708 *
7709 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7710 * voicemail vibration setting.
7711 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7712 * specific PhoneAccount.
7713 */
7714 @Override
7715 public void setVoicemailVibrationEnabled(String callingPackage,
7716 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007717 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007719 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7720 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7722 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7723 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007724 }
7725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007726 final long identity = Binder.clearCallingIdentity();
7727 try {
7728 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7729 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007730 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 }
7732 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7733 } finally {
7734 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007735 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007736 }
7737
7738 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007739 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7740 *
7741 * @throws SecurityException if the caller does not have the required permission
7742 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007743 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007744 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007745 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007746 }
7747
7748 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007749 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7750 * permission.
7751 *
7752 * @throws SecurityException if the caller does not have the required permission
7753 */
7754 private void enforceSendSmsPermission() {
7755 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7756 }
7757
7758 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007759 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007760 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007761 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007762 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007763 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 final long identity = Binder.clearCallingIdentity();
7765 try {
7766 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007767 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007768 if (componentName == null) {
7769 throw new SecurityException(
7770 "Caller not current active visual voicemail package[null]");
7771 }
7772 String vvmPackage = componentName.getPackageName();
7773 if (!callingPackage.equals(vvmPackage)) {
7774 throw new SecurityException("Caller not current active visual voicemail package["
7775 + vvmPackage + "]");
7776 }
7777 } finally {
7778 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007779 }
7780 }
7781
7782 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007783 * Return the application ID for the app type.
7784 *
7785 * @param subId the subscription ID that this request applies to.
7786 * @param appType the uicc app type.
7787 * @return Application ID for specificied app type, or null if no uicc.
7788 */
7789 @Override
7790 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007791 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007792 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007793
7794 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007795 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796 if (phone == null) {
7797 return null;
7798 }
7799 String aid = null;
7800 try {
7801 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7802 .getApplicationByType(appType).getAid();
7803 } catch (Exception e) {
7804 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7805 }
7806 return aid;
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007809 }
Youhan Wange64578a2016-05-02 15:32:42 -07007810 }
7811
Youhan Wang4001d252016-05-11 10:29:41 -07007812 /**
7813 * Return the Electronic Serial Number.
7814 *
7815 * @param subId the subscription ID that this request applies to.
7816 * @return ESN or null if error.
7817 */
7818 @Override
7819 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007820 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007821 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822
7823 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007824 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 if (phone == null) {
7826 return null;
7827 }
7828 String esn = null;
7829 try {
7830 esn = phone.getEsn();
7831 } catch (Exception e) {
7832 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7833 }
7834 return esn;
7835 } finally {
7836 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007837 }
Youhan Wang4001d252016-05-11 10:29:41 -07007838 }
7839
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007840 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007841 * Return the Preferred Roaming List Version.
7842 *
7843 * @param subId the subscription ID that this request applies to.
7844 * @return PRLVersion or null if error.
7845 */
7846 @Override
7847 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007848 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007849 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850
7851 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007852 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 if (phone == null) {
7854 return null;
7855 }
7856 String cdmaPrlVersion = null;
7857 try {
7858 cdmaPrlVersion = phone.getCdmaPrlVersion();
7859 } catch (Exception e) {
7860 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7861 }
7862 return cdmaPrlVersion;
7863 } finally {
7864 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007865 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007866 }
7867
7868 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007869 * Get snapshot of Telephony histograms
7870 * @return List of Telephony histograms
7871 * @hide
7872 */
7873 @Override
7874 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7876 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007877
7878 final long identity = Binder.clearCallingIdentity();
7879 try {
7880 return RIL.getTelephonyRILTimingHistograms();
7881 } finally {
7882 Binder.restoreCallingIdentity(identity);
7883 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007884 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007885
7886 /**
7887 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007888 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7889 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007890 * Require system privileges. In the future we may add this to carrier APIs.
7891 *
Michele Berionne482f8202018-11-27 18:57:59 -08007892 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007893 */
7894 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007895 @TelephonyManager.SetCarrierRestrictionResult
7896 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007897 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007898 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007899
Michele Berionne482f8202018-11-27 18:57:59 -08007900 if (carrierRestrictionRules == null) {
7901 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007902 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904 final long identity = Binder.clearCallingIdentity();
7905 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007906 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007907 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007908 } finally {
7909 Binder.restoreCallingIdentity(identity);
7910 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007911 }
7912
7913 /**
7914 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007915 * Get the allowed carrier list and the excluded carrier list, including the priority between
7916 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007917 * Require system privileges. In the future we may add this to carrier APIs.
7918 *
Michele Berionne482f8202018-11-27 18:57:59 -08007919 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007920 */
7921 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007922 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007923 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007924 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925
7926 final long identity = Binder.clearCallingIdentity();
7927 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007928 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7929 if (response instanceof CarrierRestrictionRules) {
7930 return (CarrierRestrictionRules) response;
7931 }
7932 // Response is an Exception of some kind,
7933 // which is signalled to the user as a NULL retval
7934 return null;
7935 } catch (Exception e) {
7936 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7937 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007938 } finally {
7939 Binder.restoreCallingIdentity(identity);
7940 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007941 }
7942
fionaxu59545b42016-05-25 15:53:37 -07007943 /**
fionaxu59545b42016-05-25 15:53:37 -07007944 * Action set from carrier signalling broadcast receivers to enable/disable radio
7945 * @param subId the subscription ID that this action applies to.
7946 * @param enabled control enable or disable radio.
7947 * {@hide}
7948 */
7949 @Override
7950 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7951 enforceModifyPermission();
7952 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007953
7954 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007955 if (phone == null) {
7956 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7957 return;
7958 }
7959 try {
7960 phone.carrierActionSetRadioEnabled(enabled);
7961 } catch (Exception e) {
7962 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 } finally {
7964 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007965 }
7966 }
7967
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007968 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007969 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7970 * network status based on which carrier apps could apply actions accordingly,
7971 * enable/disable default url handler for example.
7972 *
7973 * @param subId the subscription ID that this action applies to.
7974 * @param report control start/stop reporting the default network status.
7975 * {@hide}
7976 */
7977 @Override
7978 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7979 enforceModifyPermission();
7980 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981
7982 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007983 if (phone == null) {
7984 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7985 return;
7986 }
7987 try {
7988 phone.carrierActionReportDefaultNetworkStatus(report);
7989 } catch (Exception e) {
7990 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007991 } finally {
7992 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007993 }
7994 }
7995
7996 /**
fionaxud9622282017-07-17 17:51:30 -07007997 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7998 * @param subId the subscription ID that this action applies to.
7999 * {@hide}
8000 */
8001 @Override
8002 public void carrierActionResetAll(int subId) {
8003 enforceModifyPermission();
8004 final Phone phone = getPhone(subId);
8005 if (phone == null) {
8006 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8007 return;
8008 }
8009 try {
8010 phone.carrierActionResetAll();
8011 } catch (Exception e) {
8012 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8013 }
8014 }
8015
8016 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008017 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8018 * bug report is being generated.
8019 */
8020 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008021 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008022 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8023 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008024 writer.println("Permission Denial: can't dump Phone from pid="
8025 + Binder.getCallingPid()
8026 + ", uid=" + Binder.getCallingUid()
8027 + "without permission "
8028 + android.Manifest.permission.DUMP);
8029 return;
8030 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008031 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008032 }
Jack Yueb89b242016-06-22 13:27:47 -07008033
Brad Ebingerdac2f002018-04-03 15:17:52 -07008034 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008035 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8036 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8037 @NonNull String[] args) {
8038 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8039 this, in.getFileDescriptor(), out.getFileDescriptor(),
8040 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008041 }
8042
Jack Yueb89b242016-06-22 13:27:47 -07008043 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008044 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008045 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008046 * @param reason the reason the data enable change is taking place
8047 * @param enabled True if enabling the data, otherwise disabling.
8048 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008049 */
8050 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008051 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008052 boolean enabled) {
8053 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8054 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8055 try {
8056 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008057 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008058 } catch (SecurityException se) {
8059 enforceModifyPermission();
8060 }
8061 } else {
8062 enforceModifyPermission();
8063 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008064
8065 final long identity = Binder.clearCallingIdentity();
8066 try {
8067 Phone phone = getPhone(subId);
8068 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008069 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8070 phone.carrierActionSetMeteredApnsEnabled(enabled);
8071 } else {
8072 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074 }
8075 } finally {
8076 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008077 }
8078 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008079
8080 /**
8081 * Get Client request stats
8082 * @return List of Client Request Stats
8083 * @hide
8084 */
8085 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008086 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8087 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008089 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008090 return null;
8091 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008092 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008094 final long identity = Binder.clearCallingIdentity();
8095 try {
8096 if (phone != null) {
8097 return phone.getClientRequestStats();
8098 }
8099
8100 return null;
8101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008104 }
8105
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008106 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008107 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008108 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008109 }
Jack Yueb4124c2017-02-16 15:32:43 -08008110
8111 /**
Grace Chen70990072017-03-24 17:21:30 -07008112 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008113 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008114 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008115 * @param state State of SIM (power down, power up, pass through)
8116 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8117 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8118 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008119 *
8120 **/
8121 @Override
Grace Chen70990072017-03-24 17:21:30 -07008122 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008123 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008124 Phone phone = PhoneFactory.getPhone(slotIndex);
8125
vagdeviaf9a5b92018-08-15 16:01:53 -07008126 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008128 final long identity = Binder.clearCallingIdentity();
8129 try {
8130 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008131 phone.setSimPowerState(state, null, workSource);
8132 }
8133 } finally {
8134 Binder.restoreCallingIdentity(identity);
8135 }
8136 }
8137
8138 /**
8139 * Set SIM card power state.
8140 *
8141 * @param slotIndex SIM slot id.
8142 * @param state State of SIM (power down, power up, pass through)
8143 * @param callback callback to trigger after success or failure
8144 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8145 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8146 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8147 *
8148 **/
8149 @Override
8150 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8151 IIntegerConsumer callback) {
8152 enforceModifyPermission();
8153 Phone phone = PhoneFactory.getPhone(slotIndex);
8154
8155 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8156
8157 final long identity = Binder.clearCallingIdentity();
8158 try {
8159 if (phone != null) {
8160 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8161 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162 }
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008165 }
8166 }
Shuo Qiandd210312017-04-12 22:11:33 +00008167
Tyler Gunn65d45c22017-06-05 11:22:26 -07008168 private boolean isUssdApiAllowed(int subId) {
8169 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008170 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008171 if (configManager == null) {
8172 return false;
8173 }
8174 PersistableBundle pb = configManager.getConfigForSubId(subId);
8175 if (pb == null) {
8176 return false;
8177 }
8178 return pb.getBoolean(
8179 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8180 }
8181
Shuo Qiandd210312017-04-12 22:11:33 +00008182 /**
8183 * Check if phone is in emergency callback mode
8184 * @return true if phone is in emergency callback mode
8185 * @param subId sub id
8186 */
goneil9c5f4872017-12-05 14:07:56 -08008187 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008188 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008189 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008190 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008191
8192 final long identity = Binder.clearCallingIdentity();
8193 try {
8194 if (phone != null) {
8195 return phone.isInEcm();
8196 } else {
8197 return false;
8198 }
8199 } finally {
8200 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008201 }
8202 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008203
8204 /**
8205 * Get the current signal strength information for the given subscription.
8206 * Because this information is not updated when the device is in a low power state
8207 * it should not be relied-upon to be current.
8208 * @param subId Subscription index
8209 * @return the most recent cached signal strength info from the modem
8210 */
8211 @Override
8212 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213 final long identity = Binder.clearCallingIdentity();
8214 try {
8215 Phone p = getPhone(subId);
8216 if (p == null) {
8217 return null;
8218 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008220 return p.getSignalStrength();
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
8223 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008224 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008225
Pengquan Meng77b7f132018-08-22 14:49:57 -07008226 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008227 * Get the current modem radio state for the given slot.
8228 * @param slotIndex slot index.
8229 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008230 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008231 * @return the current radio power state from the modem
8232 */
8233 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008234 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008235 Phone phone = PhoneFactory.getPhone(slotIndex);
8236 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8238 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008239 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8240 }
8241
8242 final long identity = Binder.clearCallingIdentity();
8243 try {
8244 return phone.getRadioPowerState();
8245 } finally {
8246 Binder.restoreCallingIdentity(identity);
8247 }
8248 }
8249 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8250 }
8251
8252 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008253 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8254 *
8255 * <p>Requires one of the following permissions:
8256 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8257 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8258 * privileges.
8259 *
8260 * @param subId subscription id
8261 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8262 * {@code false}.
8263 */
8264 @Override
8265 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008266 try {
8267 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8268 null);
8269 } catch (Exception e) {
8270 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8271 mApp, subId, "isDataRoamingEnabled");
8272 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008273
Pengquan Menga1bb6272018-09-06 09:59:22 -07008274 boolean isEnabled = false;
8275 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008276 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008277 Phone phone = getPhone(subId);
8278 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008279 } finally {
8280 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008281 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008282 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008283 }
8284
8285
8286 /**
8287 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8288 *
8289 * <p> Requires permission:
8290 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8291 * privileges.
8292 *
8293 * @param subId subscription id
8294 * @param isEnabled {@code true} means enable, {@code false} means disable.
8295 */
8296 @Override
8297 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8299 mApp, subId, "setDataRoamingEnabled");
8300
Pengquan Menga1bb6272018-09-06 09:59:22 -07008301 final long identity = Binder.clearCallingIdentity();
8302 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008303 Phone phone = getPhone(subId);
8304 if (phone != null) {
8305 phone.setDataRoamingEnabled(isEnabled);
8306 }
8307 } finally {
8308 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008309 }
8310 }
8311
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008312 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008313 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008314 TelephonyPermissions
8315 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008316 mApp, subId, "isManualNetworkSelectionAllowed");
8317
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008318 boolean isAllowed = true;
8319 final long identity = Binder.clearCallingIdentity();
8320 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008321 Phone phone = getPhone(subId);
8322 if (phone != null) {
8323 isAllowed = phone.isCspPlmnEnabled();
8324 }
8325 } finally {
8326 Binder.restoreCallingIdentity(identity);
8327 }
8328 return isAllowed;
8329 }
8330
8331 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008332 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008333 // Verify that tha callingPackage belongs to the calling UID
8334 mApp.getSystemService(AppOpsManager.class)
8335 .checkPackage(Binder.getCallingUid(), callingPackage);
8336
Jordan Liu1e142fc2019-04-22 15:10:43 -07008337 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008338 try {
8339 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008340 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008341 } catch (SecurityException e) {
8342 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8343 // has carrier privileges on an active UICC
8344 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8345 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008346 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008347 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008348 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008349
8350 final long identity = Binder.clearCallingIdentity();
8351 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008352 UiccController uiccController = UiccController.getInstance();
8353 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008354 if (hasReadPermission) {
8355 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008356 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008357
8358 // Remove private info if the caller doesn't have access
8359 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8360 for (UiccCardInfo cardInfo : cardInfos) {
8361 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8362 // is available
8363 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8364 if (card == null || card.getUiccProfile() == null) {
8365 // assume no access if the card or profile is unavailable
8366 filteredInfos.add(cardInfo.getUnprivileged());
8367 continue;
8368 }
8369 UiccProfile profile = card.getUiccProfile();
8370 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8371 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8372 filteredInfos.add(cardInfo);
8373 } else {
8374 filteredInfos.add(cardInfo.getUnprivileged());
8375 }
8376 }
8377 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008378 } finally {
8379 Binder.restoreCallingIdentity(identity);
8380 }
8381 }
8382
8383 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008384 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008385 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008387 final long identity = Binder.clearCallingIdentity();
8388 try {
8389 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8390 if (slots == null) {
8391 Rlog.i(LOG_TAG, "slots is null.");
8392 return null;
8393 }
8394
8395 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8396 for (int i = 0; i < slots.length; i++) {
8397 UiccSlot slot = slots[i];
8398 if (slot == null) {
8399 continue;
8400 }
8401
Jordan Liu7be7e652019-05-06 18:55:02 +00008402 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008403 UiccCard card = slot.getUiccCard();
8404 if (card != null) {
8405 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008406 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008407 cardId = slot.getEid();
8408 if (TextUtils.isEmpty(cardId)) {
8409 cardId = slot.getIccId();
8410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008411 }
8412
Jordan Liu857451f2019-05-09 16:35:35 -07008413 if (cardId != null) {
8414 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8415 // if cardId is an EID, it's all digits so this is fine
8416 cardId = IccUtils.stripTrailingFs(cardId);
8417 }
8418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008419 int cardState = 0;
8420 switch (slot.getCardState()) {
8421 case CARDSTATE_ABSENT:
8422 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8423 break;
8424 case CARDSTATE_PRESENT:
8425 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8426 break;
8427 case CARDSTATE_ERROR:
8428 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8429 break;
8430 case CARDSTATE_RESTRICTED:
8431 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8432 break;
8433 default:
8434 break;
8435
8436 }
8437
8438 infos[i] = new UiccSlotInfo(
8439 slot.isActive(),
8440 slot.isEuicc(),
8441 cardId,
8442 cardState,
8443 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008444 slot.isExtendedApduSupported(),
8445 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008446 }
8447 return infos;
8448 } finally {
8449 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008450 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008451 }
8452
8453 @Override
8454 public boolean switchSlots(int[] physicalSlots) {
8455 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008456
8457 final long identity = Binder.clearCallingIdentity();
8458 try {
8459 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8460 } finally {
8461 Binder.restoreCallingIdentity(identity);
8462 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008463 }
Jack Yu4c988042018-02-27 15:30:01 -08008464
8465 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008466 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008467 final long identity = Binder.clearCallingIdentity();
8468 try {
8469 return UiccController.getInstance().getCardIdForDefaultEuicc();
8470 } finally {
8471 Binder.restoreCallingIdentity(identity);
8472 }
8473 }
8474
Pengquan Meng85728fb2018-03-12 16:31:21 -07008475 /**
goneil47ffb6e2018-04-06 15:40:58 -07008476 * A test API to reload the UICC profile.
8477 *
8478 * <p>Requires that the calling app has permission
8479 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8480 * @hide
8481 */
8482 @Override
8483 public void refreshUiccProfile(int subId) {
8484 enforceModifyPermission();
8485
8486 final long identity = Binder.clearCallingIdentity();
8487 try {
8488 Phone phone = getPhone(subId);
8489 if (phone == null) {
8490 return;
8491 }
8492 UiccCard uiccCard = phone.getUiccCard();
8493 if (uiccCard == null) {
8494 return;
8495 }
8496 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8497 if (uiccProfile == null) {
8498 return;
8499 }
8500 uiccProfile.refresh();
8501 } finally {
8502 Binder.restoreCallingIdentity(identity);
8503 }
8504 }
8505
8506 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008507 * Returns false if the mobile data is disabled by default, otherwise return true.
8508 */
8509 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008510 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008511 }
8512
8513 /**
8514 * Returns true if the data roaming is enabled by default, i.e the system property
8515 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8516 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8517 */
8518 private boolean getDefaultDataRoamingEnabled(int subId) {
8519 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008520 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008521 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008522 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8523 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8524 return isDataRoamingEnabled;
8525 }
8526
8527 /**
8528 * Returns the default network type for the given {@code subId}, if the default network type is
8529 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8530 */
8531 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008532 List<Integer> list = TelephonyProperties.default_network();
8533 int phoneId = mSubscriptionController.getPhoneId(subId);
8534 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8535 return list.get(phoneId);
8536 }
8537 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008538 }
fionaxua13278b2018-03-21 00:08:13 -07008539
8540 @Override
8541 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008542 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008544
8545 final long identity = Binder.clearCallingIdentity();
8546 try {
8547 final Phone phone = getPhone(subId);
8548 if (phone == null) {
8549 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8550 return;
8551 }
chen xueaba88a2019-03-15 13:15:10 -07008552 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8553 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008554 if (carrierPrivilegeRules == null) {
8555 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8556 } else {
8557 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008559 } finally {
8560 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008561 }
fionaxua13278b2018-03-21 00:08:13 -07008562 }
8563
8564 @Override
8565 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008566 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008567
8568 final long identity = Binder.clearCallingIdentity();
8569 try {
8570 final Phone phone = getPhone(subId);
8571 if (phone == null) {
8572 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8573 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8574 }
8575 return phone.getCarrierIdListVersion();
8576 } finally {
8577 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008578 }
fionaxua13278b2018-03-21 00:08:13 -07008579 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008580
8581 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008582 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8583 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008585 mApp, subId, callingPackage, callingFeatureId,
8586 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008587 return -1;
8588 }
8589
8590 final long identity = Binder.clearCallingIdentity();
8591 try {
8592 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8593 } finally {
8594 Binder.restoreCallingIdentity(identity);
8595 }
8596 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008597
8598 @Override
8599 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008600 TelephonyPermissions
8601 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008602 mApp, subId, "getCdmaRoamingMode");
8603
8604 final long identity = Binder.clearCallingIdentity();
8605 try {
8606 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8607 } finally {
8608 Binder.restoreCallingIdentity(identity);
8609 }
8610 }
8611
8612 @Override
8613 public boolean setCdmaRoamingMode(int subId, int mode) {
8614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8615 mApp, subId, "setCdmaRoamingMode");
8616
8617 final long identity = Binder.clearCallingIdentity();
8618 try {
8619 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8620 } finally {
8621 Binder.restoreCallingIdentity(identity);
8622 }
8623 }
8624
8625 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008626 public int getCdmaSubscriptionMode(int subId) {
8627 TelephonyPermissions
8628 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8629 mApp, subId, "getCdmaSubscriptionMode");
8630
8631 final long identity = Binder.clearCallingIdentity();
8632 try {
8633 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8634 } finally {
8635 Binder.restoreCallingIdentity(identity);
8636 }
8637 }
8638
8639 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008640 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8642 mApp, subId, "setCdmaSubscriptionMode");
8643
8644 final long identity = Binder.clearCallingIdentity();
8645 try {
8646 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8647 } finally {
8648 Binder.restoreCallingIdentity(identity);
8649 }
8650 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008651
sqianc5eccab2018-10-19 18:46:41 -07008652 @Override
sqian8c685422019-02-22 15:55:18 -08008653 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008654 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008655 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008656 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8657 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008658 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8659 }
8660 final long identity = Binder.clearCallingIdentity();
8661 try {
sqian854d44b2018-12-12 16:48:18 -08008662 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8663 for (Phone phone: PhoneFactory.getPhones()) {
8664 if (phone.getEmergencyNumberTracker() != null
8665 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8666 emergencyNumberListInternal.put(
8667 phone.getSubId(),
8668 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8669 }
sqian11b7a0e2018-12-05 18:48:28 -08008670 }
sqian854d44b2018-12-12 16:48:18 -08008671 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008672 } finally {
8673 Binder.restoreCallingIdentity(identity);
8674 }
sqianc5eccab2018-10-19 18:46:41 -07008675 }
8676
8677 @Override
sqian8c685422019-02-22 15:55:18 -08008678 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008679 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008680 if (!exactMatch) {
8681 TelephonyPermissions
8682 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008683 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008684 }
8685 final long identity = Binder.clearCallingIdentity();
8686 try {
sqian854d44b2018-12-12 16:48:18 -08008687 for (Phone phone: PhoneFactory.getPhones()) {
8688 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008689 && phone.getEmergencyNumberTracker()
8690 .isEmergencyNumber(number, exactMatch)) {
8691 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008692 }
sqian11b7a0e2018-12-05 18:48:28 -08008693 }
8694 return false;
8695 } finally {
8696 Binder.restoreCallingIdentity(identity);
8697 }
8698 }
8699
sqianf4ca7ed2019-01-15 18:32:07 -08008700 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008701 * Start emergency callback mode for GsmCdmaPhone for testing.
8702 */
8703 @Override
8704 public void startEmergencyCallbackMode() {
8705 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8706 "startEmergencyCallbackMode");
8707 enforceModifyPermission();
8708 final long identity = Binder.clearCallingIdentity();
8709 try {
8710 for (Phone phone : PhoneFactory.getPhones()) {
8711 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8712 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8713 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8714 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8715 gsmCdmaPhone.obtainMessage(
8716 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8717 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8718 }
8719 }
8720 } finally {
8721 Binder.restoreCallingIdentity(identity);
8722 }
8723 }
8724
8725 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008726 * Update emergency number list for test mode.
8727 */
8728 @Override
8729 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8730 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8731 "updateEmergencyNumberListTestMode");
8732
8733 final long identity = Binder.clearCallingIdentity();
8734 try {
8735 for (Phone phone: PhoneFactory.getPhones()) {
8736 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8737 if (tracker != null) {
8738 tracker.executeEmergencyNumberTestModeCommand(action, num);
8739 }
8740 }
8741 } finally {
8742 Binder.restoreCallingIdentity(identity);
8743 }
8744 }
8745
8746 /**
8747 * Get the full emergency number list for test mode.
8748 */
8749 @Override
8750 public List<String> getEmergencyNumberListTestMode() {
8751 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8752 "getEmergencyNumberListTestMode");
8753
8754 final long identity = Binder.clearCallingIdentity();
8755 try {
8756 Set<String> emergencyNumbers = new HashSet<>();
8757 for (Phone phone: PhoneFactory.getPhones()) {
8758 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8759 if (tracker != null) {
8760 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8761 emergencyNumbers.add(num.getNumber());
8762 }
8763 }
8764 }
8765 return new ArrayList<>(emergencyNumbers);
8766 } finally {
8767 Binder.restoreCallingIdentity(identity);
8768 }
8769 }
8770
chen xud6b45bd2018-10-30 22:27:10 -07008771 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008772 public int getEmergencyNumberDbVersion(int subId) {
8773 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8774
8775 final long identity = Binder.clearCallingIdentity();
8776 try {
8777 final Phone phone = getPhone(subId);
8778 if (phone == null) {
8779 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8780 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8781 }
8782 return phone.getEmergencyNumberDbVersion();
8783 } finally {
8784 Binder.restoreCallingIdentity(identity);
8785 }
8786 }
8787
8788 @Override
8789 public void notifyOtaEmergencyNumberDbInstalled() {
8790 enforceModifyPermission();
8791
8792 final long identity = Binder.clearCallingIdentity();
8793 try {
8794 for (Phone phone: PhoneFactory.getPhones()) {
8795 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8796 if (tracker != null) {
8797 tracker.updateOtaEmergencyNumberDatabase();
8798 }
8799 }
8800 } finally {
8801 Binder.restoreCallingIdentity(identity);
8802 }
8803 }
8804
8805 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008806 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008807 enforceActiveEmergencySessionPermission();
8808
8809 final long identity = Binder.clearCallingIdentity();
8810 try {
8811 for (Phone phone: PhoneFactory.getPhones()) {
8812 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8813 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008814 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8815 }
8816 }
8817 } finally {
8818 Binder.restoreCallingIdentity(identity);
8819 }
8820 }
8821
8822 @Override
8823 public void resetOtaEmergencyNumberDbFilePath() {
8824 enforceActiveEmergencySessionPermission();
8825
8826 final long identity = Binder.clearCallingIdentity();
8827 try {
8828 for (Phone phone: PhoneFactory.getPhones()) {
8829 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8830 if (tracker != null) {
8831 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008832 }
8833 }
8834 } finally {
8835 Binder.restoreCallingIdentity(identity);
8836 }
8837 }
8838
8839 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008840 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8841 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8842 Phone phone = getPhone(subId);
8843 if (phone == null) {
8844 return null;
8845 }
8846 final long identity = Binder.clearCallingIdentity();
8847 try {
8848 UiccProfile profile = UiccController.getInstance()
8849 .getUiccProfileForPhone(phone.getPhoneId());
8850 if (profile != null) {
8851 return profile.getCertsFromCarrierPrivilegeAccessRules();
8852 }
8853 } finally {
8854 Binder.restoreCallingIdentity(identity);
8855 }
8856 return null;
8857 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008858
8859 /**
8860 * Enable or disable a modem stack.
8861 */
8862 @Override
8863 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8864 enforceModifyPermission();
8865
8866 final long identity = Binder.clearCallingIdentity();
8867 try {
8868 Phone phone = PhoneFactory.getPhone(slotIndex);
8869 if (phone == null) {
8870 return false;
8871 } else {
8872 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8873 }
8874 } finally {
8875 Binder.restoreCallingIdentity(identity);
8876 }
8877 }
Michelecea4cf22018-12-21 15:00:11 -08008878
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008879 /**
8880 * Whether a modem stack is enabled or not.
8881 */
8882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008883 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8884 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008885 Phone phone = PhoneFactory.getPhone(slotIndex);
8886 if (phone == null) return false;
8887
8888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008889 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8890 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008891 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8892 }
8893
8894 final long identity = Binder.clearCallingIdentity();
8895 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008896 try {
8897 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8898 } catch (NoSuchElementException ex) {
8899 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8900 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008901 } finally {
8902 Binder.restoreCallingIdentity(identity);
8903 }
8904 }
8905
Michelecea4cf22018-12-21 15:00:11 -08008906 @Override
Michele0ea7d782019-03-19 14:58:42 -07008907 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008908 enforceModifyPermission();
8909
8910 final long identity = Binder.clearCallingIdentity();
8911 try {
8912 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008913 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008914 .commit();
8915 } finally {
8916 Binder.restoreCallingIdentity(identity);
8917 }
8918 }
8919
8920 @Override
Michele0ea7d782019-03-19 14:58:42 -07008921 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008922 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008924 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8925 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008926 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008927 }
Michelecea4cf22018-12-21 15:00:11 -08008928
8929 final long identity = Binder.clearCallingIdentity();
8930 try {
Michele0ea7d782019-03-19 14:58:42 -07008931 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008932 } finally {
8933 Binder.restoreCallingIdentity(identity);
8934 }
8935 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008936
Michele0ea7d782019-03-19 14:58:42 -07008937 @TelephonyManager.IsMultiSimSupportedResult
8938 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008939 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8940 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8941 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008942 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8943 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008944 }
8945 // Check if the hardware supports multisim functionality. If usage of multisim is not
8946 // supported by the modem, indicate that it is restricted.
8947 PhoneCapability staticCapability =
8948 mPhoneConfigurationManager.getStaticPhoneCapability();
8949 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008950 loge("isMultiSimSupportedInternal: no static configuration available");
8951 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008952 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008953 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008954 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8955 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008956 }
8957 // Check if support of multiple SIMs is restricted by carrier
8958 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008959 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008960 }
8961
Michele0ea7d782019-03-19 14:58:42 -07008962 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008963 }
8964
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008965 /**
8966 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008967 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8968 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8969 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008970 * @param numOfSims number of active sims we want to switch to
8971 */
8972 @Override
8973 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008974 if (numOfSims == 1) {
8975 enforceModifyPermission();
8976 } else {
8977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8978 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8979 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008980 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008981
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008982 try {
Michele30b57b22019-03-01 12:01:14 -08008983 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008984 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008985 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8986 return;
8987 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008988 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8989 } finally {
8990 Binder.restoreCallingIdentity(identity);
8991 }
8992 }
8993
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008994 @Override
8995 public boolean isApplicationOnUicc(int subId, int appType) {
8996 enforceReadPrivilegedPermission("isApplicationOnUicc");
8997 Phone phone = getPhone(subId);
8998 if (phone == null) {
8999 return false;
9000 }
9001 final long identity = Binder.clearCallingIdentity();
9002 try {
9003 UiccCard uiccCard = phone.getUiccCard();
9004 if (uiccCard == null) {
9005 return false;
9006 }
9007 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9008 if (uiccProfile == null) {
9009 return false;
9010 }
9011 if (TelephonyManager.APPTYPE_SIM <= appType
9012 && appType <= TelephonyManager.APPTYPE_ISIM) {
9013 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9014 }
9015 return false;
9016 } finally {
9017 Binder.restoreCallingIdentity(identity);
9018 }
9019 }
9020
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009021 /**
chen xub4baa772019-04-03 10:23:41 -07009022 * Get whether making changes to modem configurations will trigger reboot.
9023 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009024 */
9025 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009026 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9027 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009028 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009029 mApp, subId, callingPackage, callingFeatureId,
9030 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009031 return false;
9032 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009033 final long identity = Binder.clearCallingIdentity();
9034 try {
9035 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9036 } finally {
9037 Binder.restoreCallingIdentity(identity);
9038 }
9039 }
9040
Nathan Harold29f5f052019-02-15 13:41:57 -08009041 private void updateModemStateMetrics() {
9042 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9043 // TODO: check the state for each modem if the api is ready.
9044 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9045 }
9046
Pengquan Meng3889a572019-01-23 11:16:29 -08009047 @Override
9048 public int[] getSlotsMapping() {
9049 enforceReadPrivilegedPermission("getSlotsMapping");
9050
9051 final long identity = Binder.clearCallingIdentity();
9052 try {
9053 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9054 // All logical slots should have a mapping to a physical slot.
9055 int[] logicalSlotsMapping = new int[phoneCount];
9056 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9057 for (int i = 0; i < slotInfos.length; i++) {
9058 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9059 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9060 }
9061 }
9062 return logicalSlotsMapping;
9063 } finally {
9064 Binder.restoreCallingIdentity(identity);
9065 }
9066 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009067
9068 /**
9069 * Get the IRadio HAL Version
9070 */
9071 @Override
9072 public int getRadioHalVersion() {
9073 Phone phone = getDefaultPhone();
9074 if (phone == null) return -1;
9075 HalVersion hv = phone.getHalVersion();
9076 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9077 return hv.major * 100 + hv.minor;
9078 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009079
9080 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009081 * Get the current calling package name.
9082 * @return the current calling package name
9083 */
9084 @Override
9085 public String getCurrentPackageName() {
9086 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9087 }
9088
9089 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009090 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9091 * corresponding network requests on a subId.
9092 *
9093 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009094 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009095 * 2) APN is un-metered for this subscription, or
9096 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009097 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009098 *
9099 * @return whether data is allowed for a apn type.
9100 *
9101 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009102 */
9103 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009104 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009105 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9106 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009107
9108 // Now that all security checks passes, perform the operation as ourselves.
9109 final long identity = Binder.clearCallingIdentity();
9110 try {
9111 Phone phone = getPhone(subId);
9112 if (phone == null) return false;
9113
Jack Yu41407ee2019-05-13 16:54:09 -07009114 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009115 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9116 } finally {
9117 Binder.restoreCallingIdentity(identity);
9118 }
9119 }
9120
9121 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009122 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009123 enforceReadPrivilegedPermission("isApnMetered");
9124
9125 // Now that all security checks passes, perform the operation as ourselves.
9126 final long identity = Binder.clearCallingIdentity();
9127 try {
9128 Phone phone = getPhone(subId);
9129 if (phone == null) return true; // By default return true.
9130
Jack Yu41407ee2019-05-13 16:54:09 -07009131 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009136
9137 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009138 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9139 int subscriptionId, IBooleanConsumer resultCallback) {
9140 enforceModifyPermission();
9141 long token = Binder.clearCallingIdentity();
9142 try {
9143 Phone phone = getPhone(subscriptionId);
9144 if (phone == null) {
9145 try {
9146 if (resultCallback != null) {
9147 resultCallback.accept(false);
9148 }
9149 } catch (RemoteException e) {
9150 // ignore
9151 }
9152 return;
9153 }
9154 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9155 Pair.create(specifiers, (x) -> {
9156 try {
9157 if (resultCallback != null) {
9158 resultCallback.accept(x);
9159 }
9160 } catch (RemoteException e) {
9161 // ignore
9162 }
9163 });
9164 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9165 } finally {
9166 Binder.restoreCallingIdentity(token);
9167 }
9168 }
9169
9170 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009171 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9172 TelephonyPermissions
9173 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9174 mApp, subId, "getSystemSelectionChannels");
9175 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9176 final long identity = Binder.clearCallingIdentity();
9177 try {
9178 List<RadioAccessSpecifier> specifiers =
9179 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9180 null, subId, workSource);
9181 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9182 return specifiers;
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
9186 }
9187
9188 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009189 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009190 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009191 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9192 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9193 if (iccRecords == null) {
9194 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9195 return false;
9196 }
9197 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9198 }
9199
9200 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009201 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9202 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009203 if (callingPackage == null) {
9204 callingPackage = getCurrentPackageName();
9205 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009206 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9207 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009208 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9209 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009210 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9211 }
9212 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9213 Intent intent = new Intent();
9214 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9215 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9216 // Bring up choose default SMS subscription dialog right now
9217 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9218 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9219 mApp.startActivity(intent);
9220 }
chen xud5ca2d52019-05-28 15:20:57 -07009221
9222 @Override
9223 public String getMmsUAProfUrl(int subId) {
9224 //TODO investigate if this API should require proper permission check in R b/133791609
9225 final long identity = Binder.clearCallingIdentity();
9226 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009227 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9228 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9229 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9230 return carrierUAProfUrl;
9231 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009232 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9233 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009234 } finally {
9235 Binder.restoreCallingIdentity(identity);
9236 }
9237 }
9238
9239 @Override
9240 public String getMmsUserAgent(int subId) {
9241 //TODO investigate if this API should require proper permission check in R b/133791609
9242 final long identity = Binder.clearCallingIdentity();
9243 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009244 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9245 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9246 if (!TextUtils.isEmpty(carrierUserAgent)) {
9247 return carrierUserAgent;
9248 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009249 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9250 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009251 } finally {
9252 Binder.restoreCallingIdentity(identity);
9253 }
9254 }
Jack Yub07d4972019-05-28 16:12:25 -07009255
9256 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009257 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9258 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009259
Jack Yub07d4972019-05-28 16:12:25 -07009260 final long identity = Binder.clearCallingIdentity();
9261 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009262 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009263 if (phone == null) return false;
9264
Hall Liua62f5da2020-09-25 10:42:19 -07009265 switch (policy) {
9266 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9267 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9268 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9269 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9270 default:
9271 throw new IllegalArgumentException(policy + " is not a valid policy");
9272 }
Jack Yub07d4972019-05-28 16:12:25 -07009273 } finally {
9274 Binder.restoreCallingIdentity(identity);
9275 }
9276 }
9277
9278 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009279 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009280 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009281 enforceModifyPermission();
9282
changbettyd5c246e2019-12-24 15:40:37 +08009283 final long identity = Binder.clearCallingIdentity();
9284 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009285 Phone phone = getPhone(subscriptionId);
9286 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009287
Hall Liua62f5da2020-09-25 10:42:19 -07009288 switch (policy) {
9289 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9290 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9291 break;
9292 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9293 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9294 break;
9295 default:
9296 throw new IllegalArgumentException(policy + " is not a valid policy");
9297 }
changbettyd5c246e2019-12-24 15:40:37 +08009298 } finally {
9299 Binder.restoreCallingIdentity(identity);
9300 }
9301 }
9302
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009303 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009304 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009305 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9306 * otherwise.
9307 */
9308 @Override
9309 public void setCepEnabled(boolean isCepEnabled) {
9310 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9311
9312 final long identity = Binder.clearCallingIdentity();
9313 try {
9314 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9315 for (Phone phone : PhoneFactory.getPhones()) {
9316 Phone defaultPhone = phone.getImsPhone();
9317 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9318 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9319 ImsPhoneCallTracker imsPhoneCallTracker =
9320 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9321 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9322 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9323 + imsPhone.getMsisdn());
9324 }
9325 }
9326 } finally {
9327 Binder.restoreCallingIdentity(identity);
9328 }
9329 }
allenwtsu46dcc572020-01-08 18:24:03 +08009330
9331 /**
9332 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9333 *
9334 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9335 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9336 * before being read.
9337 */
9338 @Override
9339 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9340 isCompressed) {
9341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9342 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009343 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9344 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9345 }
9346 if (!isImsAvailableOnDevice()) {
9347 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9348 "IMS not available on device.");
9349 }
9350
9351 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009352 try {
Hui Wang761a6682020-10-31 05:12:53 +00009353 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9354 } finally {
9355 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009356 }
9357 }
zoey chene02881a2019-12-30 16:11:23 +08009358
9359 @Override
9360 public boolean isIccLockEnabled(int subId) {
9361 enforceReadPrivilegedPermission("isIccLockEnabled");
9362
9363 // Now that all security checks passes, perform the operation as ourselves.
9364 final long identity = Binder.clearCallingIdentity();
9365 try {
9366 Phone phone = getPhone(subId);
9367 if (phone != null && phone.getIccCard() != null) {
9368 return phone.getIccCard().getIccLockEnabled();
9369 } else {
9370 return false;
9371 }
9372 } finally {
9373 Binder.restoreCallingIdentity(identity);
9374 }
9375 }
9376
9377 /**
9378 * Set the ICC pin lock enabled or disabled.
9379 *
9380 * @return an integer representing the status of IccLock enabled or disabled in the following
9381 * three cases:
9382 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9383 * successfully.
9384 * - Positive number and zero for remaining password attempts.
9385 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9386 *
9387 */
9388 @Override
9389 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9390 enforceModifyPermission();
9391
9392 Phone phone = getPhone(subId);
9393 if (phone == null) {
9394 return 0;
9395 }
9396 // Now that all security checks passes, perform the operation as ourselves.
9397 final long identity = Binder.clearCallingIdentity();
9398 try {
9399 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9400 new Pair<Boolean, String>(enabled, password), phone, null);
9401 return attemptsRemaining;
9402
9403 } catch (Exception e) {
9404 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
9408 return 0;
9409 }
9410
9411 /**
9412 * Change the ICC password used in ICC pin lock.
9413 *
9414 * @return an integer representing the status of IccLock changed in the following three cases:
9415 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9416 * - Positive number and zero for remaining password attempts.
9417 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9418 *
9419 */
9420 @Override
9421 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9422 enforceModifyPermission();
9423
9424 Phone phone = getPhone(subId);
9425 if (phone == null) {
9426 return 0;
9427 }
9428 // Now that all security checks passes, perform the operation as ourselves.
9429 final long identity = Binder.clearCallingIdentity();
9430 try {
9431 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9432 new Pair<String, String>(oldPassword, newPassword), phone, null);
9433 return attemptsRemaining;
9434
9435 } catch (Exception e) {
9436 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 return 0;
9441 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009442
9443 /**
9444 * Request for receiving user activity notification
9445 */
9446 @Override
9447 public void requestUserActivityNotification() {
9448 if (!mNotifyUserActivity.get()
9449 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9450 mNotifyUserActivity.set(true);
9451 }
9452 }
9453
9454 /**
9455 * Called when userActivity is signalled in the power manager.
9456 * This is safe to call from any thread, with any window manager locks held or not.
9457 */
9458 @Override
9459 public void userActivity() {
9460 // ***************************************
9461 // * Inherited from PhoneWindowManager *
9462 // ***************************************
9463 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9464 // WITH ITS LOCKS HELD.
9465 //
9466 // This code must be VERY careful about the locks
9467 // it acquires.
9468 // In fact, the current code acquires way too many,
9469 // and probably has lurking deadlocks.
9470
9471 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9472 throw new SecurityException("Only the OS may call notifyUserActivity()");
9473 }
9474
9475 if (mNotifyUserActivity.getAndSet(false)) {
9476 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9477 USER_ACTIVITY_NOTIFICATION_DELAY);
9478 }
9479 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009480
9481 @Override
9482 public boolean canConnectTo5GInDsdsMode() {
9483 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9484 }
Jack Yud10cdd42020-09-28 20:28:01 -07009485
9486 @Override
9487 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9488 String callingFeatureId) {
9489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9490 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9491 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9492 }
9493
9494 Phone phone = getPhone(subId);
9495 if (phone == null) {
9496 throw new RuntimeException("phone is not available");
9497 }
9498 // Now that all security checks passes, perform the operation as ourselves.
9499 final long identity = Binder.clearCallingIdentity();
9500 try {
9501 return phone.getEquivalentHomePlmns();
9502 } finally {
9503 Binder.restoreCallingIdentity(identity);
9504 }
9505 }
Daniel Bright59e67312020-11-13 11:49:37 -08009506
9507 @Override
9508 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009509 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9510 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009511 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009512 if (radioInterfaceCapabilities == null) {
9513 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009514 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009515 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009516 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009517
Hui Wang641e81c2020-10-12 12:14:23 -07009518 @Override
9519 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9520 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009521 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9522 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9523 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9524 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9525 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009526 if (DBG) {
9527 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9528 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9529 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9530 }
9531
9532 if (!SubscriptionManager.isValidSubscriptionId(subId)
9533 || appType < TelephonyManager.APPTYPE_UNKNOWN
9534 || appType > TelephonyManager.APPTYPE_ISIM
9535 || nafUrl == null || securityProtocol == null || callback == null) {
9536 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9537 if (callback != null) {
9538 try {
9539 callback.onAuthenticationFailure(
9540 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9541 } catch (RemoteException exception) {
9542 log("Fail to notify onAuthenticationFailure due to " + exception);
9543 }
9544 return;
9545 }
9546 }
9547
9548 final long token = Binder.clearCallingIdentity();
9549 try {
9550 getGbaManager(subId).bootstrapAuthenticationRequest(
9551 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9552 forceBootStrapping, callback));
9553 } finally {
9554 Binder.restoreCallingIdentity(token);
9555 }
9556 }
9557
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009558 /**
9559 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9560 * requested radio power state will actually be set. See {@link
9561 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9562 *
9563 * @param subId the subscription ID of the phone requesting to set the radio power state.
9564 * @param enable {@code true} if trying to turn radio on.
9565 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9566 * false}.
9567 */
9568 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9569 Phone phone = getPhone(subId);
9570 if (phone != null) {
9571 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9572 return true;
9573 }
9574 return false;
9575 }
9576
9577 private int handleDataThrottlingRequest(int subId,
9578 DataThrottlingRequest dataThrottlingRequest) {
9579 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9580 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9581 if (!setRadioPowerForThermal(subId, true)) {
9582 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9583 }
9584
9585 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9586
9587 int thermalMitigationResult =
9588 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9589 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9590 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9591 }
9592 return thermalMitigationResult;
9593 }
9594
9595 /**
9596 * Thermal mitigation request to control functionalities at modem.
9597 *
9598 * @param subId the id of the subscription.
9599 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9600 *
9601 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9602 */
9603 @Override
9604 @ThermalMitigationResult
9605 public int sendThermalMitigationRequest(
9606 int subId,
9607 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9608 enforceModifyPermission();
9609
9610 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9611 final long identity = Binder.clearCallingIdentity();
9612
9613 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9614 try {
9615 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9616 switch (thermalMitigationAction) {
9617 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9618 thermalMitigationResult =
9619 handleDataThrottlingRequest(subId,
9620 thermalMitigationRequest.getDataThrottlingRequest());
9621 break;
9622 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9623 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9624 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9625 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9626 }
9627
9628 // Ensure that radio is on. If not able to power on due to phone being
9629 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9630 if (!setRadioPowerForThermal(subId, true)) {
9631 thermalMitigationResult =
9632 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9633 break;
9634 }
9635
9636 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9637 false);
9638 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9639 break;
9640 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9641 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9642 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9643 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9644 }
9645
9646 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9647 if (registry != null) {
9648 TelephonyConnectionService service =
9649 registry.getTelephonyConnectionService();
9650 Phone phone = getPhone(subId);
9651 if (phone == null) {
9652 thermalMitigationResult =
9653 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9654 break;
9655 }
9656
9657 if (PhoneConstantConversions.convertCallState(phone.getState())
9658 != TelephonyManager.CALL_STATE_IDLE
9659 || phone.isInEmergencySmsMode() || phone.isInEcm()
9660 || (service != null && service.isEmergencyCallPending())) {
9661 String errorMessage = "Phone state is not valid. call state = "
9662 + PhoneConstantConversions.convertCallState(phone.getState())
9663 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9664 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9665 errorMessage += service == null
9666 ? " TelephonyConnectionService is null"
9667 : " isEmergencyCallPending = "
9668 + service.isEmergencyCallPending();
9669 Log.e(LOG_TAG, errorMessage);
9670 thermalMitigationResult =
9671 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9672 break;
9673 }
9674 } else {
9675 thermalMitigationResult =
9676 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9677 break;
9678 }
9679
9680 // Turn radio off. If not able to power off due to phone being unavailable,
9681 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9682 if (!setRadioPowerForThermal(subId, false)) {
9683 thermalMitigationResult =
9684 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9685 break;
9686 }
9687 thermalMitigationResult =
9688 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9689 break;
9690 default:
9691 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9692 + "not exist. Requested action: " + thermalMitigationAction);
9693 }
9694 } catch (IllegalArgumentException e) {
9695 throw e;
9696 } catch (Exception e) {
9697 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9698 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9699 } finally {
9700 Binder.restoreCallingIdentity(identity);
9701 }
9702
9703 if (DBG) {
9704 log("thermalMitigationRequest returning with thermalMitigationResult: "
9705 + thermalMitigationResult);
9706 }
9707
9708 return thermalMitigationResult;
9709 }
Hui Wang641e81c2020-10-12 12:14:23 -07009710
9711 /**
9712 * Set the GbaService Package Name that Telephony will bind to.
9713 *
9714 * @param subId The sim that the GbaService is associated with.
9715 * @param packageName The name of the package to be replaced with.
9716 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9717 */
9718 @Override
9719 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9720 enforceModifyPermission();
9721
9722 final long identity = Binder.clearCallingIdentity();
9723 try {
9724 return getGbaManager(subId).overrideServicePackage(packageName);
9725 } finally {
9726 Binder.restoreCallingIdentity(identity);
9727 }
9728 }
9729
9730 /**
9731 * Return the package name of the currently bound GbaService.
9732 *
9733 * @param subId The sim that the GbaService is associated with.
9734 * @return the package name of the GbaService configuration, null if GBA is not supported.
9735 */
9736 @Override
9737 public String getBoundGbaService(int subId) {
9738 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9739
9740 final long identity = Binder.clearCallingIdentity();
9741 try {
9742 return getGbaManager(subId).getServicePackage();
9743 } finally {
9744 Binder.restoreCallingIdentity(identity);
9745 }
9746 }
9747
9748 /**
9749 * Set the release time for telephony to unbind GbaService.
9750 *
9751 * @param subId The sim that the GbaService is associated with.
9752 * @param interval The release time to unbind GbaService by millisecond.
9753 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9754 */
9755 @Override
9756 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9757 enforceModifyPermission();
9758
9759 final long identity = Binder.clearCallingIdentity();
9760 try {
9761 return getGbaManager(subId).overrideReleaseTime(interval);
9762 } finally {
9763 Binder.restoreCallingIdentity(identity);
9764 }
9765 }
9766
9767 /**
9768 * Return the release time for telephony to unbind GbaService.
9769 *
9770 * @param subId The sim that the GbaService is associated with.
9771 * @return The release time to unbind GbaService by millisecond.
9772 */
9773 @Override
9774 public int getGbaReleaseTime(int subId) {
9775 enforceReadPrivilegedPermission("getGbaReleaseTime");
9776
9777 final long identity = Binder.clearCallingIdentity();
9778 try {
9779 return getGbaManager(subId).getReleaseTime();
9780 } finally {
9781 Binder.restoreCallingIdentity(identity);
9782 }
9783 }
9784
9785 private GbaManager getGbaManager(int subId) {
9786 GbaManager instance = GbaManager.getInstance(subId);
9787 if (instance == null) {
9788 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9789 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9790 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9791 }
9792 return instance;
9793 }
Hui Wang761a6682020-10-31 05:12:53 +00009794
9795 /**
9796 * indicate whether the device and the carrier can support
9797 * RCS VoLTE single registration.
9798 */
9799 @Override
9800 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009801 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9802 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9803 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9804 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009805
9806 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9807 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9808 }
9809
9810 final long identity = Binder.clearCallingIdentity();
9811 try {
9812 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9813 if (rpm != null) {
9814 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9815 }
9816 return false;
9817 } finally {
9818 Binder.restoreCallingIdentity(identity);
9819 }
9820 }
9821
9822 /**
9823 * Register RCS provisioning callback.
9824 */
9825 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009826 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009827 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009828 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009829 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009830 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9831 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009832
9833 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9834 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9835 }
9836 if (!isImsAvailableOnDevice()) {
9837 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9838 "IMS not available on device.");
9839 }
9840
9841 final long identity = Binder.clearCallingIdentity();
9842 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009843 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009844 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -08009845 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9846 "Service not available for the subscription.");
9847 }
Hui Wang761a6682020-10-31 05:12:53 +00009848 } finally {
9849 Binder.restoreCallingIdentity(identity);
9850 }
9851 }
9852
9853 /**
9854 * Unregister RCS provisioning callback.
9855 */
9856 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009857 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009858 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009859 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009860 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009861 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9862 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009863
9864 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9865 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9866 }
9867 if (!isImsAvailableOnDevice()) {
9868 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9869 "IMS not available on device.");
9870 }
9871
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009874 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009875 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 }
9880
9881 /**
9882 * trigger RCS reconfiguration.
9883 */
9884 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009885 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9886 "triggerRcsReconfiguration",
9887 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009888
9889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9890 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9891 }
9892 if (!isImsAvailableOnDevice()) {
9893 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9894 "IMS not available on device.");
9895 }
9896
9897 final long identity = Binder.clearCallingIdentity();
9898 try {
9899 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9900 } finally {
9901 Binder.restoreCallingIdentity(identity);
9902 }
9903 }
9904
9905 /**
9906 * Provide the client configuration parameters of the RCS application.
9907 */
9908 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009909 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9910 "setRcsClientConfiguration",
9911 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009912
9913 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9914 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9915 }
9916 if (!isImsAvailableOnDevice()) {
9917 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9918 "IMS not available on device.");
9919 }
9920
9921 final long identity = Binder.clearCallingIdentity();
9922
9923 try {
9924 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9925 if (configBinder == null) {
9926 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9927 } else {
9928 configBinder.setRcsClientConfiguration(rcc);
9929 }
9930 } catch (RemoteException e) {
9931 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9932 } finally {
9933 Binder.restoreCallingIdentity(identity);
9934 }
9935 }
9936
9937 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -08009938 * Enables or disables the test mode for RCS VoLTE single registration.
9939 */
9940 @Override
9941 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9942 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9943 "setRcsSingleRegistrationTestModeEnabled");
9944
9945 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9946 }
9947
9948 /**
9949 * Gets the test mode for RCS VoLTE single registration.
9950 */
9951 @Override
9952 public boolean getRcsSingleRegistrationTestModeEnabled() {
9953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9954 "getRcsSingleRegistrationTestModeEnabled");
9955
9956 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9957 }
9958
9959 /**
Hui Wang761a6682020-10-31 05:12:53 +00009960 * Overrides the config of RCS VoLTE single registration enabled for the device.
9961 */
9962 @Override
9963 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9964 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9965 "setDeviceSingleRegistrationEnabledOverride");
9966 enforceModifyPermission();
9967
9968 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9969 : Boolean.parseBoolean(enabledStr);
9970 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009971 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +00009972 }
9973
9974 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009975 * Sends a device to device communication message. Only usable via shell.
9976 * @param message message to send.
9977 * @param value message value.
9978 */
9979 @Override
9980 public void sendDeviceToDeviceMessage(int message, int value) {
9981 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -08009982 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -08009983 enforceModifyPermission();
9984
9985 final long identity = Binder.clearCallingIdentity();
9986 try {
9987 TelephonyConnectionService service =
9988 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9989 if (service == null) {
9990 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9991 return;
9992 }
9993 service.sendTestDeviceToDeviceMessage(message, value);
9994 } finally {
9995 Binder.restoreCallingIdentity(identity);
9996 }
9997 }
9998
Tyler Gunnbabbda02021-02-10 11:05:02 -08009999 /**
10000 * Sets the specified device to device transport active.
10001 * @param transport The transport to set active.
10002 */
10003 @Override
10004 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10005 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10006 "setActiveDeviceToDeviceTransport");
10007 enforceModifyPermission();
10008
10009 final long identity = Binder.clearCallingIdentity();
10010 try {
10011 TelephonyConnectionService service =
10012 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10013 if (service == null) {
10014 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10015 return;
10016 }
10017 service.setActiveDeviceToDeviceTransport(transport);
10018 } finally {
10019 Binder.restoreCallingIdentity(identity);
10020 }
10021 }
Tyler Gunn92479152021-01-20 16:30:10 -080010022
10023 /**
Hui Wang761a6682020-10-31 05:12:53 +000010024 * Gets the config of RCS VoLTE single registration enabled for the device.
10025 */
10026 @Override
10027 public boolean getDeviceSingleRegistrationEnabled() {
10028 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10029 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10030 }
10031
10032 /**
10033 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10034 */
10035 @Override
10036 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10037 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10038 "setCarrierSingleRegistrationEnabledOverride");
10039 enforceModifyPermission();
10040
10041 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10042 : Boolean.parseBoolean(enabledStr);
10043 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10044 subId, enabled);
10045 }
10046
10047 /**
10048 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10049 */
10050 @Override
10051 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10052 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10053 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10054 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010055
10056 /**
10057 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10058 * their mobile plan.
10059 */
10060 @Override
10061 public String getMobileProvisioningUrl() {
10062 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10063 final long identity = Binder.clearCallingIdentity();
10064 try {
10065 return getDefaultPhone().getMobileProvisioningUrl();
10066 } finally {
10067 Binder.restoreCallingIdentity(identity);
10068 }
10069 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010070
James.cf Linbcdf8b32021-01-14 16:44:13 +080010071 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010072 * Get the EAB contact from the EAB database.
10073 */
10074 @Override
10075 public String getContactFromEab(String contact) {
10076 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10077 enforceModifyPermission();
10078 final long identity = Binder.clearCallingIdentity();
10079 try {
10080 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10081 } finally {
10082 Binder.restoreCallingIdentity(identity);
10083 }
10084 }
10085
10086 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010087 * Remove the EAB contacts from the EAB database.
10088 */
10089 @Override
10090 public int removeContactFromEab(int subId, String contacts) {
10091 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10092 enforceModifyPermission();
10093 final long identity = Binder.clearCallingIdentity();
10094 try {
10095 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10096 } finally {
10097 Binder.restoreCallingIdentity(identity);
10098 }
10099 }
10100
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010101 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010102 public boolean getDeviceUceEnabled() {
10103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10104 final long identity = Binder.clearCallingIdentity();
10105 try {
10106 return mApp.getDeviceUceEnabled();
10107 } finally {
10108 Binder.restoreCallingIdentity(identity);
10109 }
10110 }
10111
10112 @Override
10113 public void setDeviceUceEnabled(boolean isEnabled) {
10114 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10115 final long identity = Binder.clearCallingIdentity();
10116 try {
10117 mApp.setDeviceUceEnabled(isEnabled);
10118 } finally {
10119 Binder.restoreCallingIdentity(identity);
10120 }
10121 }
10122
10123 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010124 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10125 String callingPackage) {
10126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10127 mApp, subId, "setSignalStrengthUpdateRequest");
10128
10129 final int callingUid = Binder.getCallingUid();
10130 // Verify that tha callingPackage belongs to the calling UID
10131 mApp.getSystemService(AppOpsManager.class)
10132 .checkPackage(callingUid, callingPackage);
10133
10134 validateSignalStrengthUpdateRequest(request, callingUid);
10135
10136 final long identity = Binder.clearCallingIdentity();
10137 try {
10138 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10139 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10140
10141 if (result instanceof IllegalStateException) {
10142 throw (IllegalStateException) result;
10143 }
10144 } finally {
10145 Binder.restoreCallingIdentity(identity);
10146 }
10147 }
10148
10149 @Override
10150 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10151 String callingPackage) {
10152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10153 mApp, subId, "clearSignalStrengthUpdateRequest");
10154
10155 final int callingUid = Binder.getCallingUid();
10156 // Verify that tha callingPackage belongs to the calling UID
10157 mApp.getSystemService(AppOpsManager.class)
10158 .checkPackage(callingUid, callingPackage);
10159
10160 final long identity = Binder.clearCallingIdentity();
10161 try {
10162 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10163 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10164
10165 if (result instanceof IllegalStateException) {
10166 throw (IllegalStateException) result;
10167 }
10168 } finally {
10169 Binder.restoreCallingIdentity(identity);
10170 }
10171 }
10172
10173 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10174 int callingUid) {
10175 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10176 // phone/system process do not have further restriction on request
10177 return;
10178 }
10179
10180 // Applications has restrictions on how to use the request:
10181 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10182 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10183 // This is not system caller which has been checked above
10184 throw new IllegalArgumentException(
10185 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10186 }
10187
10188 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10189 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10190 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10191 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10192 || info.isEnabled()) {
10193 throw new IllegalArgumentException(
10194 "Only system can set hide fields in SignalThresholdInfo");
10195 }
10196
10197 // Thresholds length for each RAN need in range. This has been validated in
10198 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10199 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10200 final int[] thresholds = info.getThresholds();
10201 Objects.requireNonNull(thresholds);
10202 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10203 || thresholds.length
10204 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10205 throw new IllegalArgumentException(
10206 "thresholds length is out of range: " + thresholds.length);
10207 }
10208 }
10209 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010210
10211 /**
10212 * Gets the current phone capability.
10213 *
10214 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10215 * @return the PhoneCapability which describes the data connection capability of modem.
10216 * It's used to evaluate possible phone config change, for example from single
10217 * SIM device to multi-SIM device.
10218 */
10219 @Override
10220 public PhoneCapability getPhoneCapability() {
10221 enforceReadPrivilegedPermission("getPhoneCapability");
10222 final long identity = Binder.clearCallingIdentity();
10223 try {
10224 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10225 } finally {
10226 Binder.restoreCallingIdentity(identity);
10227 }
10228 }
Michele Berionne5e411512020-11-13 02:36:59 +000010229
10230 /**
10231 * Prepare TelephonyManager for an unattended reboot. The reboot is
10232 * required to be done shortly after the API is invoked.
10233 */
10234 @Override
10235 @TelephonyManager.PrepareUnattendedRebootResult
10236 public int prepareForUnattendedReboot() {
10237 enforceRebootPermission();
10238
10239 final long identity = Binder.clearCallingIdentity();
10240 try {
10241 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10242 } finally {
10243 Binder.restoreCallingIdentity(identity);
10244 }
10245 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010246}