blob: cd207aa6751ee6b4b9157a1e523fc93af9e1d325 [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 Ebinger14d467f2021-02-12 06:18:28 +0000117import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700118import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800120import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700121import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800122import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700123import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000124import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700125import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800126import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800127import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800128import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800129import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800131import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700132import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800134import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800135
Andrew Lee312e8172014-10-23 17:01:36 -0700136import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800137import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800138import com.android.ims.rcs.uce.eab.EabUtil;
Shuo Qian4a594052020-01-23 11:59:30 -0800139import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700141import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700142import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800143import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700144import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800146import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700148import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800149import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800150import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800151import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700152import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800154import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800156import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700157import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700158import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700159import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700161import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800162import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700163import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700164import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700165import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700166import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800167import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800168import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700170import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800172import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800173import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800174import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700175import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800176import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700177import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800178import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700179import com.android.internal.telephony.imsphone.ImsPhone;
180import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800181import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700182import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800184import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800186import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700187import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800190import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000191import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800192import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700193import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700194import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800195import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800196import com.android.phone.callcomposer.CallComposerPictureManager;
197import com.android.phone.callcomposer.CallComposerPictureTransfer;
198import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700199import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700200import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800201import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700202import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700203import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800204import com.android.services.telephony.TelecomAccountRegistry;
205import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800206import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800207
Hall Liu82694d52020-12-11 18:22:04 -0800208import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700209import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.io.IOException;
211import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700212import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800214import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800215import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800216import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800217import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100218import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800219import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700220import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800222import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800224import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800225import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226
227/**
228 * Implementation of the ITelephony interface.
229 */
Santos Cordon117fee72014-05-16 17:56:12 -0700230public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231 private static final String LOG_TAG = "PhoneInterfaceManager";
232 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
233 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800234 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235
236 // Message codes used with mMainThreadHandler
237 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700238 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
239 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700240 private static final int CMD_OPEN_CHANNEL = 9;
241 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
242 private static final int CMD_CLOSE_CHANNEL = 11;
243 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800244 private static final int CMD_NV_READ_ITEM = 13;
245 private static final int EVENT_NV_READ_ITEM_DONE = 14;
246 private static final int CMD_NV_WRITE_ITEM = 15;
247 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
248 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
249 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700250 private static final int CMD_RESET_MODEM_CONFIG = 19;
251 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800252 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
253 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800254 private static final int CMD_SEND_ENVELOPE = 25;
255 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000256 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
257 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700258 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
259 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
260 private static final int CMD_EXCHANGE_SIM_IO = 31;
261 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800262 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
263 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700264 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
265 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700266 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
267 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700268 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
269 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
270 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
271 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700272 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
273 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
274 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
275 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700276 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800277 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
278 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000279 private static final int CMD_SWITCH_SLOTS = 50;
280 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700281 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
282 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
283 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
284 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
285 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
286 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
287 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
288 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700289 private static final int CMD_GET_ALL_CELL_INFO = 60;
290 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
291 private static final int CMD_GET_CELL_LOCATION = 62;
292 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700293 private static final int CMD_MODEM_REBOOT = 64;
294 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700295 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
296 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800297 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
298 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700299 private static final int CMD_GET_MODEM_STATUS = 70;
300 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700301 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
302 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700303 private static final int CMD_ERASE_MODEM_CONFIG = 74;
304 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800305 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
306 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
307 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
308 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800309 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
310 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800311 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800312 private static final int CMD_GET_CALL_FORWARDING = 83;
313 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
314 private static final int CMD_SET_CALL_FORWARDING = 85;
315 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
316 private static final int CMD_GET_CALL_WAITING = 87;
317 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
318 private static final int CMD_SET_CALL_WAITING = 89;
319 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700320 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
321 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
322 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
323 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700324 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
325 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800326 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
327 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800328 private static final int CMD_SET_DATA_THROTTLING = 99;
329 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800330 private static final int CMD_SET_SIM_POWER = 101;
331 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800332 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
333 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
334 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
335 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800336 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
337 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000338 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800340 // Parameters of select command.
341 private static final int SELECT_COMMAND = 0xA4;
342 private static final int SELECT_P1 = 0x04;
343 private static final int SELECT_P2 = 0;
344 private static final int SELECT_P3 = 0x10;
345
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 /** The singleton instance. */
347 private static PhoneInterfaceManager sInstance;
348
Wink Saville3ab207e2014-11-20 13:07:20 -0800349 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800350 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800351 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700352 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800353 private AppOpsManager mAppOps;
354 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800355 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800356 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700357 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800358 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Peter Wangdafb9ac2020-01-15 14:13:38 -0800360 /** User Activity */
361 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800362 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
363
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700364 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
365
Derek Tan97ebb422014-09-05 16:55:38 -0700366 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
367 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800368 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800369 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700370
Michelecea4cf22018-12-21 15:00:11 -0800371 // String to store multi SIM allowed
372 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
373
Derek Tan740e1672017-06-27 14:56:27 -0700374 // The AID of ISD-R.
375 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
376
yinxub1bed742017-04-17 11:45:04 -0700377 private NetworkScanRequestTracker mNetworkScanRequestTracker;
378
David Kelly5e06a7f2018-03-12 14:10:59 +0000379 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
380 private static final int MANUFACTURER_CODE_LENGTH = 8;
381
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800382 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
383
Derek Tan89e89d42014-07-08 17:00:10 -0700384 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700385 * Experiment flag to enable erase modem config on reset network, default value is false
386 */
387 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
388 "reset_network_erase_modem_config_enabled";
389
Rambo Wang0f050d82021-02-12 11:43:36 -0800390 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
391
Naina Nallurid63128d2019-09-17 14:10:30 -0700392 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700393 * A request object to use for transmitting data to an ICC.
394 */
395 private static final class IccAPDUArgument {
396 public int channel, cla, command, p1, p2, p3;
397 public String data;
398
399 public IccAPDUArgument(int channel, int cla, int command,
400 int p1, int p2, int p3, String data) {
401 this.channel = channel;
402 this.cla = cla;
403 this.command = command;
404 this.p1 = p1;
405 this.p2 = p2;
406 this.p3 = p3;
407 this.data = data;
408 }
409 }
410
411 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700412 * A request object to use for transmitting data to an ICC.
413 */
414 private static final class ManualNetworkSelectionArgument {
415 public OperatorInfo operatorInfo;
416 public boolean persistSelection;
417
418 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
419 this.operatorInfo = operatorInfo;
420 this.persistSelection = persistSelection;
421 }
422 }
423
424 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
426 * request after sending. The main thread will notify the request when it is complete.
427 */
428 private static final class MainThreadRequest {
429 /** The argument to use for the request */
430 public Object argument;
431 /** The result of the request that is run on the main thread */
432 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800433 // The subscriber id that this request applies to. Defaults to
434 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
435 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436
Nathan Harold92bed182018-10-12 18:16:49 -0700437 // In cases where subId is unavailable, the caller needs to specify the phone.
438 public Phone phone;
439
vagdeviaf9a5b92018-08-15 16:01:53 -0700440 public WorkSource workSource;
441
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 public MainThreadRequest(Object argument) {
443 this.argument = argument;
444 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800445
Nathan Harold92bed182018-10-12 18:16:49 -0700446 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
447 this.argument = argument;
448 if (phone != null) {
449 this.phone = phone;
450 }
451 this.workSource = workSource;
452 }
453
vagdeviaf9a5b92018-08-15 16:01:53 -0700454 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800455 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800456 if (subId != null) {
457 this.subId = subId;
458 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700459 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461 }
462
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800463 private static final class IncomingThirdPartyCallArgs {
464 public final ComponentName component;
465 public final String callId;
466 public final String callerDisplayName;
467
468 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
469 String callerDisplayName) {
470 this.component = component;
471 this.callId = callId;
472 this.callerDisplayName = callerDisplayName;
473 }
474 }
475
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 /**
477 * A handler that processes messages on the main thread in the phone process. Since many
478 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
479 * inbound binder threads to the main thread in the phone process. The Binder thread
480 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
481 * on, which will be notified when the operation completes and will contain the result of the
482 * request.
483 *
484 * <p>If a MainThreadRequest object is provided in the msg.obj field,
485 * note that request.result must be set to something non-null for the calling thread to
486 * unblock.
487 */
488 private final class MainThreadHandler extends Handler {
489 @Override
490 public void handleMessage(Message msg) {
491 MainThreadRequest request;
492 Message onCompleted;
493 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800494 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800496 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700497
498 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700499 case CMD_HANDLE_USSD_REQUEST: {
500 request = (MainThreadRequest) msg.obj;
501 final Phone phone = getPhoneFromRequest(request);
502 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
503 String ussdRequest = ussdObject.first;
504 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700505
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 if (!isUssdApiAllowed(request.subId)) {
507 // Carrier does not support use of this API, return failure.
508 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
509 UssdResponse response = new UssdResponse(ussdRequest, null);
510 Bundle returnData = new Bundle();
511 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
512 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700513
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 request.result = true;
515 notifyRequester(request);
516 return;
517 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700518
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 try {
520 request.result = phone != null
521 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
522 } catch (CallStateException cse) {
523 request.result = false;
524 }
525 // Wake up the requesting thread
526 notifyRequester(request);
527 break;
pkanwar32d516d2016-10-14 19:37:38 -0700528 }
529
Yorke Lee716f67e2015-06-17 15:39:16 -0700530 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700532 final Phone phone = getPhoneFromRequest(request);
533 request.result = phone != null ?
534 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
535 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700537 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800544 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 if (uiccCard == null) {
546 loge("iccTransmitApduLogicalChannel: No UICC");
547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700549 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700550 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
551 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 iccArgument.channel, iccArgument.cla, iccArgument.command,
554 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 break;
558
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 ar = (AsyncResult) msg.obj;
561 request = (MainThreadRequest) ar.userObj;
562 if (ar.exception == null && ar.result != null) {
563 request.result = ar.result;
564 } else {
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
566 if (ar.result == null) {
567 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800568 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800570 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 } else {
572 loge("iccTransmitApduLogicalChannel: Unknown exception");
573 }
574 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700575 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 break;
577
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700578 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
579 request = (MainThreadRequest) msg.obj;
580 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 if (uiccCard == null) {
583 loge("iccTransmitApduBasicChannel: No UICC");
584 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 } else {
587 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
588 request);
589 uiccCard.iccTransmitApduBasicChannel(
590 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
591 iccArgument.p3, iccArgument.data, onCompleted);
592 }
593 break;
594
595 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
596 ar = (AsyncResult) msg.obj;
597 request = (MainThreadRequest) ar.userObj;
598 if (ar.exception == null && ar.result != null) {
599 request.result = ar.result;
600 } else {
601 request.result = new IccIoResult(0x6F, 0, (byte[])null);
602 if (ar.result == null) {
603 loge("iccTransmitApduBasicChannel: Empty response");
604 } else if (ar.exception instanceof CommandException) {
605 loge("iccTransmitApduBasicChannel: CommandException: " +
606 ar.exception);
607 } else {
608 loge("iccTransmitApduBasicChannel: Unknown exception");
609 }
610 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 break;
613
614 case CMD_EXCHANGE_SIM_IO:
615 request = (MainThreadRequest) msg.obj;
616 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800617 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 if (uiccCard == null) {
619 loge("iccExchangeSimIO: No UICC");
620 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 } else {
623 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
624 request);
625 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
626 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
627 iccArgument.data, onCompleted);
628 }
629 break;
630
631 case EVENT_EXCHANGE_SIM_IO_DONE:
632 ar = (AsyncResult) msg.obj;
633 request = (MainThreadRequest) ar.userObj;
634 if (ar.exception == null && ar.result != null) {
635 request.result = ar.result;
636 } else {
637 request.result = new IccIoResult(0x6f, 0, (byte[])null);
638 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 break;
641
Derek Tan4d5e5c12014-02-04 11:54:58 -0800642 case CMD_SEND_ENVELOPE:
643 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800644 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700645 if (uiccCard == null) {
646 loge("sendEnvelopeWithStatus: No UICC");
647 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700649 } else {
650 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
651 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
652 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800653 break;
654
655 case EVENT_SEND_ENVELOPE_DONE:
656 ar = (AsyncResult) msg.obj;
657 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700658 if (ar.exception == null && ar.result != null) {
659 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800660 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700661 request.result = new IccIoResult(0x6F, 0, (byte[])null);
662 if (ar.result == null) {
663 loge("sendEnvelopeWithStatus: Empty response");
664 } else if (ar.exception instanceof CommandException) {
665 loge("sendEnvelopeWithStatus: CommandException: " +
666 ar.exception);
667 } else {
668 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
669 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800670 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800672 break;
673
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 case CMD_OPEN_CHANNEL:
675 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800676 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800677 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 if (uiccCard == null) {
679 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800680 request.result = new IccOpenLogicalChannelResponse(-1,
681 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700682 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 } else {
684 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800685 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
686 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 break;
689
690 case EVENT_OPEN_CHANNEL_DONE:
691 ar = (AsyncResult) msg.obj;
692 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 int[] result = (int[]) ar.result;
696 int channelId = result[0];
697 byte[] selectResponse = null;
698 if (result.length > 1) {
699 selectResponse = new byte[result.length - 1];
700 for (int i = 1; i < result.length; ++i) {
701 selectResponse[i - 1] = (byte) result[i];
702 }
703 }
704 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700705 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 if (ar.result == null) {
708 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700710 if (ar.exception != null) {
711 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
712 }
713
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700714 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700715 if (ar.exception instanceof CommandException) {
716 CommandException.Error error =
717 ((CommandException) (ar.exception)).getCommandError();
718 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700719 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700720 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700721 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700722 }
723 }
724 openChannelResp = new IccOpenLogicalChannelResponse(
725 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700726 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700727 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700729 break;
730
731 case CMD_CLOSE_CHANNEL:
732 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800733 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700734 if (uiccCard == null) {
735 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900736 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700738 } else {
739 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
740 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
741 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 break;
743
744 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800745 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
746 break;
747
748 case CMD_NV_READ_ITEM:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800751 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
752 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800753 break;
754
755 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 ar = (AsyncResult) msg.obj;
757 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800758 if (ar.exception == null && ar.result != null) {
759 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800761 request.result = "";
762 if (ar.result == null) {
763 loge("nvReadItem: Empty response");
764 } else if (ar.exception instanceof CommandException) {
765 loge("nvReadItem: CommandException: " +
766 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800768 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 }
770 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 break;
773
Jake Hambye994d462014-02-03 13:10:13 -0800774 case CMD_NV_WRITE_ITEM:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
777 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800778 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700779 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800780 break;
781
782 case EVENT_NV_WRITE_ITEM_DONE:
783 handleNullReturnEvent(msg, "nvWriteItem");
784 break;
785
786 case CMD_NV_WRITE_CDMA_PRL:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800789 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800790 break;
791
792 case EVENT_NV_WRITE_CDMA_PRL_DONE:
793 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
794 break;
795
chen xu6dac5ab2018-10-26 17:39:23 -0700796 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800797 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700798 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800799 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800800 break;
801
chen xu6dac5ab2018-10-26 17:39:23 -0700802 case EVENT_RESET_MODEM_CONFIG_DONE:
803 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800804 break;
805
Sooraj Sasindran37444802020-08-11 10:40:43 -0700806 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
807 request = (MainThreadRequest) msg.obj;
808 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
809 request);
810 Phone phone = getPhoneFromRequest(request);
811 if (phone != null) {
812 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
813 } else {
814 loge("isNRDualConnectivityEnabled: No phone object");
815 request.result = false;
816 notifyRequester(request);
817 }
818 break;
819 }
820
821 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 if (ar.exception == null && ar.result != null) {
825 request.result = ar.result;
826 } else {
827 // request.result must be set to something non-null
828 // for the calling thread to unblock
829 if (request.result != null) {
830 request.result = ar.result;
831 } else {
832 request.result = false;
833 }
834 if (ar.result == null) {
835 loge("isNRDualConnectivityEnabled: Empty response");
836 } else if (ar.exception instanceof CommandException) {
837 loge("isNRDualConnectivityEnabled: CommandException: "
838 + ar.exception);
839 } else {
840 loge("isNRDualConnectivityEnabled: Unknown exception");
841 }
842 }
843 notifyRequester(request);
844 break;
845
846 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
847 request = (MainThreadRequest) msg.obj;
848 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
849 Phone phone = getPhoneFromRequest(request);
850 if (phone != null) {
851 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
852 request.workSource);
853 } else {
854 loge("enableNrDualConnectivity: No phone object");
855 request.result =
856 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
857 notifyRequester(request);
858 }
859 break;
860 }
861
862 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
863 ar = (AsyncResult) msg.obj;
864 request = (MainThreadRequest) ar.userObj;
865 if (ar.exception == null) {
866 request.result =
867 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
868 } else {
869 request.result =
870 TelephonyManager
871 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
872 if (ar.exception instanceof CommandException) {
873 CommandException.Error error =
874 ((CommandException) (ar.exception)).getCommandError();
875 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
876 request.result =
877 TelephonyManager
878 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000879 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
880 request.result =
881 TelephonyManager
882 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700883 }
884 loge("enableNrDualConnectivity" + ": CommandException: "
885 + ar.exception);
886 } else {
887 loge("enableNrDualConnectivity" + ": Unknown exception");
888 }
889 }
890 notifyRequester(request);
891 break;
892 }
893
SongFerngWang3ef3e072020-12-21 16:41:52 +0800894 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800895 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800896 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
897 request);
898 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800899 break;
900
SongFerngWang3ef3e072020-12-21 16:41:52 +0800901 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 ar = (AsyncResult) msg.obj;
903 request = (MainThreadRequest) ar.userObj;
904 if (ar.exception == null && ar.result != null) {
905 request.result = ar.result; // Integer
906 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530907 // request.result must be set to something non-null
908 // for the calling thread to unblock
909 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800911 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800912 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800913 loge("getAllowedNetworkTypesBitmask: CommandException: "
914 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800915 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800916 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 }
918 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700919 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800920 break;
921
SongFerngWang3ef3e072020-12-21 16:41:52 +0800922 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800923 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800924 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
925 request);
926 Pair<Integer, Long> reasonWithNetworkTypes =
927 (Pair<Integer, Long>) request.argument;
928 getPhoneFromRequest(request).setAllowedNetworkTypes(
929 reasonWithNetworkTypes.first,
930 reasonWithNetworkTypes.second,
931 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800932 break;
933
SongFerngWang3ef3e072020-12-21 16:41:52 +0800934 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
935 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800936 break;
937
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000938 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
939 request = (MainThreadRequest)msg.obj;
940 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800941 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000942 break;
943
944 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
945 ar = (AsyncResult)msg.obj;
946 request = (MainThreadRequest)ar.userObj;
947 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700948 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000949 break;
950
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800951 case CMD_SET_VOICEMAIL_NUMBER:
952 request = (MainThreadRequest) msg.obj;
953 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
954 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800955 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
956 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800957 break;
958
959 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
960 handleNullReturnEvent(msg, "setVoicemailNumber");
961 break;
962
Stuart Scott54788802015-03-30 13:18:01 -0700963 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
964 request = (MainThreadRequest) msg.obj;
965 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
966 request);
967 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
968 break;
969
970 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
971 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
972 break;
973
Shishir Agrawal302c8692015-06-19 13:49:39 -0700974 case CMD_PERFORM_NETWORK_SCAN:
975 request = (MainThreadRequest) msg.obj;
976 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
977 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
978 break;
979
Hall Liu27d24262020-09-18 19:04:59 -0700980 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800981 request = (MainThreadRequest) msg.obj;
982 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700983 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
984 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
985 request.argument;
986 int callForwardingReason = args.first;
987 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800988 break;
Hall Liu27d24262020-09-18 19:04:59 -0700989 }
990 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800991 ar = (AsyncResult) msg.obj;
992 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700993 TelephonyManager.CallForwardingInfoCallback callback =
994 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
995 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800996 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700997 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800998 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
999 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1000 // Service Class is a bit mask per 3gpp 27.007. Search for
1001 // any service for voice call.
1002 if ((callForwardInfo.serviceClass
1003 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001004 callForwardingInfo = new CallForwardingInfo(true,
1005 callForwardInfo.reason,
1006 callForwardInfo.number,
1007 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001008 break;
1009 }
1010 }
1011 // Didn't find a call forward info for voice call.
1012 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001013 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1014 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001015 }
Hall Liu27d24262020-09-18 19:04:59 -07001016 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001017 } else {
1018 if (ar.result == null) {
1019 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1020 }
1021 if (ar.exception != null) {
1022 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1023 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001024 int errorCode = TelephonyManager
1025 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001026 if (ar.exception instanceof CommandException) {
1027 CommandException.Error error =
1028 ((CommandException) (ar.exception)).getCommandError();
1029 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001030 errorCode = TelephonyManager
1031 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001032 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001033 errorCode = TelephonyManager
1034 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001035 }
1036 }
Hall Liu27d24262020-09-18 19:04:59 -07001037 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001038 }
Shuo Qian4a594052020-01-23 11:59:30 -08001039 break;
Hall Liu27d24262020-09-18 19:04:59 -07001040 }
Shuo Qian4a594052020-01-23 11:59:30 -08001041
Hall Liu27d24262020-09-18 19:04:59 -07001042 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001043 request = (MainThreadRequest) msg.obj;
1044 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001045 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001046 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001047 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1048 request.argument).first;
1049 request.phone.setCallForwardingOption(
1050 callForwardingInfoToSet.isEnabled()
1051 ? CommandsInterface.CF_ACTION_ENABLE
1052 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001053 callForwardingInfoToSet.getReason(),
1054 callForwardingInfoToSet.getNumber(),
1055 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1056 break;
Hall Liu27d24262020-09-18 19:04:59 -07001057 }
Shuo Qian4a594052020-01-23 11:59:30 -08001058
Hall Liu27d24262020-09-18 19:04:59 -07001059 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001060 ar = (AsyncResult) msg.obj;
1061 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001062 Consumer<Integer> callback =
1063 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1064 request.argument).second;
1065 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001066 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001067 int errorCode = TelephonyManager.CallForwardingInfoCallback
1068 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001069 if (ar.exception instanceof CommandException) {
1070 CommandException.Error error =
1071 ((CommandException) (ar.exception)).getCommandError();
1072 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001073 errorCode = TelephonyManager.CallForwardingInfoCallback
1074 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001075 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001076 errorCode = TelephonyManager.CallForwardingInfoCallback
1077 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001078 }
1079 }
1080 callback.accept(errorCode);
1081 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001082 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001083 }
Shuo Qian4a594052020-01-23 11:59:30 -08001084 break;
Hall Liu27d24262020-09-18 19:04:59 -07001085 }
Shuo Qian4a594052020-01-23 11:59:30 -08001086
Hall Liu27d24262020-09-18 19:04:59 -07001087 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001088 request = (MainThreadRequest) msg.obj;
1089 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1090 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1091 break;
Hall Liu27d24262020-09-18 19:04:59 -07001092 }
Shuo Qian4a594052020-01-23 11:59:30 -08001093
Hall Liu27d24262020-09-18 19:04:59 -07001094 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001095 ar = (AsyncResult) msg.obj;
1096 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001097 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001098 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1099 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001100 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001101 // Service Class is a bit mask per 3gpp 27.007.
1102 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001103 if (callForwardResults.length > 1
1104 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001105 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001106 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001107 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1108 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001109 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001110 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001111 }
1112 } else {
1113 if (ar.result == null) {
1114 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1115 }
1116 if (ar.exception != null) {
1117 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1118 }
1119 if (ar.exception instanceof CommandException) {
1120 CommandException.Error error =
1121 ((CommandException) (ar.exception)).getCommandError();
1122 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1123 callForwardingStatus =
1124 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1125 }
1126 }
1127 }
Hall Liu27d24262020-09-18 19:04:59 -07001128 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001129 break;
Hall Liu27d24262020-09-18 19:04:59 -07001130 }
Shuo Qian4a594052020-01-23 11:59:30 -08001131
Hall Liu27d24262020-09-18 19:04:59 -07001132 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001133 request = (MainThreadRequest) msg.obj;
1134 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001135 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1136 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001137 break;
Hall Liu27d24262020-09-18 19:04:59 -07001138 }
Shuo Qian4a594052020-01-23 11:59:30 -08001139
Hall Liu27d24262020-09-18 19:04:59 -07001140 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001143 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1144 Consumer<Integer> callback =
1145 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1146 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001147 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001148 if (ar.exception instanceof CommandException) {
1149 CommandException.Error error =
1150 ((CommandException) (ar.exception)).getCommandError();
1151 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1152 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1153 } else {
1154 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1155 }
1156 } else {
1157 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1158 }
1159 } else {
1160 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1161 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001162 }
Shuo Qian4a594052020-01-23 11:59:30 -08001163 break;
Hall Liu27d24262020-09-18 19:04:59 -07001164 }
Shuo Qian4a594052020-01-23 11:59:30 -08001165
Shishir Agrawal302c8692015-06-19 13:49:39 -07001166 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1167 ar = (AsyncResult) msg.obj;
1168 request = (MainThreadRequest) ar.userObj;
1169 CellNetworkScanResult cellScanResult;
1170 if (ar.exception == null && ar.result != null) {
1171 cellScanResult = new CellNetworkScanResult(
1172 CellNetworkScanResult.STATUS_SUCCESS,
1173 (List<OperatorInfo>) ar.result);
1174 } else {
1175 if (ar.result == null) {
1176 loge("getCellNetworkScanResults: Empty response");
1177 }
1178 if (ar.exception != null) {
1179 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1180 }
1181 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1182 if (ar.exception instanceof CommandException) {
1183 CommandException.Error error =
1184 ((CommandException) (ar.exception)).getCommandError();
1185 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1186 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1187 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1188 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1189 }
1190 }
1191 cellScanResult = new CellNetworkScanResult(errorCode, null);
1192 }
1193 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001194 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001195 break;
1196
1197 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1198 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001199 ManualNetworkSelectionArgument selArg =
1200 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001201 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1202 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001203 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1204 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001205 break;
1206
1207 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
1210 if (ar.exception == null) {
1211 request.result = true;
1212 } else {
1213 request.result = false;
1214 loge("setNetworkSelectionModeManual " + ar.exception);
1215 }
1216 notifyRequester(request);
1217 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001218 break;
1219
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001220 case CMD_GET_MODEM_ACTIVITY_INFO:
1221 request = (MainThreadRequest) msg.obj;
1222 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001223 if (defaultPhone != null) {
1224 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001225 } else {
1226 ResultReceiver result = (ResultReceiver) request.argument;
1227 Bundle bundle = new Bundle();
1228 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001229 new ModemActivityInfo(0, 0, 0,
1230 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001231 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001232 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001233 break;
1234
Hall Liud0f208c2020-10-14 16:54:44 -07001235 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001236 ar = (AsyncResult) msg.obj;
1237 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001238 ResultReceiver result = (ResultReceiver) request.argument;
1239
Hall Liud0f208c2020-10-14 16:54:44 -07001240 ModemActivityInfo ret = null;
1241 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001242 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001243 // Update the last modem activity info and the result of the request.
1244 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1245 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001246 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001247 int[] txTimeMs = info.getTransmitTimeMillis();
1248 int[] lastModemTxTimeMs = mLastModemActivityInfo
1249 .getTransmitTimeMillis();
1250 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1251 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1252 }
Hall Liu49656c02020-10-09 19:00:11 -07001253 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001254 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1255 + mLastModemActivityInfo.getSleepTimeMillis());
1256 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1257 + mLastModemActivityInfo.getIdleTimeMillis());
1258 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1259 mLastModemActivityInfo.setReceiveTimeMillis(
1260 info.getReceiveTimeMillis()
1261 + mLastModemActivityInfo.getReceiveTimeMillis());
1262 }
Hall Liu49656c02020-10-09 19:00:11 -07001263 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001264 mLastModemActivityInfo.getSleepTimeMillis(),
1265 mLastModemActivityInfo.getIdleTimeMillis(),
1266 mLastModemActivityInfo.getTransmitTimeMillis(),
1267 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001268 } else {
1269 if (ar.result == null) {
1270 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001271 error = TelephonyManager.ModemActivityInfoException
1272 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001273 } else if (ar.exception instanceof CommandException) {
1274 loge("queryModemActivityInfo: CommandException: " +
1275 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001276 error = TelephonyManager.ModemActivityInfoException
1277 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001278 } else {
1279 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001280 error = TelephonyManager.ModemActivityInfoException
1281 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001282 }
1283 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001284 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001285 if (ret != null) {
1286 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1287 } else {
1288 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1289 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001290 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001291 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001292 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001293 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001294
Meng Wang1a7c35a2016-05-05 20:56:15 -07001295 case CMD_SET_ALLOWED_CARRIERS:
1296 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001297 CarrierRestrictionRules argument =
1298 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001300 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001301 break;
1302
1303 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
1306 if (ar.exception == null && ar.result != null) {
1307 request.result = ar.result;
1308 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001309 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1310 if (ar.exception instanceof CommandException) {
1311 loge("setAllowedCarriers: CommandException: " + ar.exception);
1312 CommandException.Error error =
1313 ((CommandException) (ar.exception)).getCommandError();
1314 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1315 request.result =
1316 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1317 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001318 } else {
1319 loge("setAllowedCarriers: Unknown exception");
1320 }
1321 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001322 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001323 break;
1324
1325 case CMD_GET_ALLOWED_CARRIERS:
1326 request = (MainThreadRequest) msg.obj;
1327 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001328 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001329 break;
1330
1331 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
1334 if (ar.exception == null && ar.result != null) {
1335 request.result = ar.result;
1336 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001337 request.result = new IllegalStateException(
1338 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001339 if (ar.result == null) {
1340 loge("getAllowedCarriers: Empty response");
1341 } else if (ar.exception instanceof CommandException) {
1342 loge("getAllowedCarriers: CommandException: " +
1343 ar.exception);
1344 } else {
1345 loge("getAllowedCarriers: Unknown exception");
1346 }
1347 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001348 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001349 break;
1350
Nathan Haroldb3014052017-01-25 15:57:32 -08001351 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1352 ar = (AsyncResult) msg.obj;
1353 request = (MainThreadRequest) ar.userObj;
1354 if (ar.exception == null && ar.result != null) {
1355 request.result = ar.result;
1356 } else {
1357 request.result = new IllegalArgumentException(
1358 "Failed to retrieve Forbidden Plmns");
1359 if (ar.result == null) {
1360 loge("getForbiddenPlmns: Empty response");
1361 } else {
1362 loge("getForbiddenPlmns: Unknown exception");
1363 }
1364 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001365 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001366 break;
1367
1368 case CMD_GET_FORBIDDEN_PLMNS:
1369 request = (MainThreadRequest) msg.obj;
1370 uiccCard = getUiccCardFromRequest(request);
1371 if (uiccCard == null) {
1372 loge("getForbiddenPlmns() UiccCard is null");
1373 request.result = new IllegalArgumentException(
1374 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001375 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001376 break;
1377 }
1378 Integer appType = (Integer) request.argument;
1379 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1380 if (uiccApp == null) {
1381 loge("getForbiddenPlmns() no app with specified type -- "
1382 + appType);
1383 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001384 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001385 break;
1386 } else {
1387 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1388 + " specified type -- " + appType);
1389 }
1390 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1391 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1392 onCompleted);
1393 break;
1394
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001395 case CMD_SWITCH_SLOTS:
1396 request = (MainThreadRequest) msg.obj;
1397 int[] physicalSlots = (int[]) request.argument;
1398 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1399 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1400 break;
1401
1402 case EVENT_SWITCH_SLOTS_DONE:
1403 ar = (AsyncResult) msg.obj;
1404 request = (MainThreadRequest) ar.userObj;
1405 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001406 notifyRequester(request);
1407 break;
1408 case CMD_GET_NETWORK_SELECTION_MODE:
1409 request = (MainThreadRequest) msg.obj;
1410 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1411 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1412 break;
1413
1414 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1415 ar = (AsyncResult) msg.obj;
1416 request = (MainThreadRequest) ar.userObj;
1417 if (ar.exception != null) {
1418 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1419 } else {
1420 int mode = ((int[]) ar.result)[0];
1421 if (mode == 0) {
1422 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1423 } else {
1424 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1425 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001426 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001427 notifyRequester(request);
1428 break;
1429 case CMD_GET_CDMA_ROAMING_MODE:
1430 request = (MainThreadRequest) msg.obj;
1431 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1432 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1433 break;
1434 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1435 ar = (AsyncResult) msg.obj;
1436 request = (MainThreadRequest) ar.userObj;
1437 if (ar.exception != null) {
1438 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1439 } else {
1440 request.result = ((int[]) ar.result)[0];
1441 }
1442 notifyRequester(request);
1443 break;
1444 case CMD_SET_CDMA_ROAMING_MODE:
1445 request = (MainThreadRequest) msg.obj;
1446 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1447 int mode = (int) request.argument;
1448 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1449 break;
1450 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1451 ar = (AsyncResult) msg.obj;
1452 request = (MainThreadRequest) ar.userObj;
1453 request.result = ar.exception == null;
1454 notifyRequester(request);
1455 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001456 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1457 request = (MainThreadRequest) msg.obj;
1458 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1459 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1460 break;
1461 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1462 ar = (AsyncResult) msg.obj;
1463 request = (MainThreadRequest) ar.userObj;
1464 if (ar.exception != null) {
1465 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1466 } else {
1467 request.result = ((int[]) ar.result)[0];
1468 }
1469 notifyRequester(request);
1470 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001471 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1472 request = (MainThreadRequest) msg.obj;
1473 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1474 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001475 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1476 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001477 break;
1478 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1479 ar = (AsyncResult) msg.obj;
1480 request = (MainThreadRequest) ar.userObj;
1481 request.result = ar.exception == null;
1482 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001483 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001484 case CMD_GET_ALL_CELL_INFO:
1485 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001486 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001487 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001488 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 case EVENT_GET_ALL_CELL_INFO_DONE:
1490 ar = (AsyncResult) msg.obj;
1491 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001492 // If a timeout occurs, the response will be null
1493 request.result = (ar.exception == null && ar.result != null)
1494 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 synchronized (request) {
1496 request.notifyAll();
1497 }
1498 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001499 case CMD_REQUEST_CELL_INFO_UPDATE:
1500 request = (MainThreadRequest) msg.obj;
1501 request.phone.requestCellInfoUpdate(request.workSource,
1502 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1503 break;
1504 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1505 ar = (AsyncResult) msg.obj;
1506 request = (MainThreadRequest) ar.userObj;
1507 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1508 try {
1509 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001510 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001511 cb.onError(
1512 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1513 ar.exception.getClass().getName(),
1514 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001515 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001516 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001517 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001518 } else {
1519 // use the result as returned
1520 cb.onCellInfo((List<CellInfo>) ar.result);
1521 }
1522 } catch (RemoteException re) {
1523 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1524 }
1525 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001526 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001527 request = (MainThreadRequest) msg.obj;
1528 WorkSource ws = (WorkSource) request.argument;
1529 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001530 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001531 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001532 }
1533 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001534 ar = (AsyncResult) msg.obj;
1535 request = (MainThreadRequest) ar.userObj;
1536 if (ar.exception == null) {
1537 request.result = ar.result;
1538 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001539 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001540 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001541 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001542 }
1543
1544 synchronized (request) {
1545 request.notifyAll();
1546 }
1547 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001548 }
chen xu6dac5ab2018-10-26 17:39:23 -07001549 case CMD_MODEM_REBOOT:
1550 request = (MainThreadRequest) msg.obj;
1551 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001552 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001553 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001554 case EVENT_CMD_MODEM_REBOOT_DONE:
1555 handleNullReturnEvent(msg, "rebootModem");
1556 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001557 case CMD_REQUEST_ENABLE_MODEM:
1558 request = (MainThreadRequest) msg.obj;
1559 boolean enable = (boolean) request.argument;
1560 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001561 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001562 PhoneConfigurationManager.getInstance()
1563 .enablePhone(request.phone, enable, onCompleted);
1564 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001565 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001569 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001570 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001571 if ((boolean) request.result) {
1572 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1573 updateModemStateMetrics();
1574 } else {
1575 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1576 + ar.exception);
1577 }
1578 notifyRequester(request);
1579 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001580 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001581 case CMD_GET_MODEM_STATUS:
1582 request = (MainThreadRequest) msg.obj;
1583 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1584 PhoneConfigurationManager.getInstance()
1585 .getPhoneStatusFromModem(request.phone, onCompleted);
1586 break;
1587 case EVENT_GET_MODEM_STATUS_DONE:
1588 ar = (AsyncResult) msg.obj;
1589 request = (MainThreadRequest) ar.userObj;
1590 int id = request.phone.getPhoneId();
1591 if (ar.exception == null && ar.result != null) {
1592 request.result = ar.result;
1593 //update the cache as modem status has changed
1594 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1595 (boolean) request.result);
1596 } else {
1597 // Return true if modem status cannot be retrieved. For most cases,
1598 // modem status is on. And for older version modems, GET_MODEM_STATUS
1599 // and disable modem are not supported. Modem is always on.
1600 // TODO: this should be fixed in R to support a third
1601 // status UNKNOWN b/131631629
1602 request.result = true;
1603 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1604 + ar.exception);
1605 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001606 notifyRequester(request);
1607 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001608 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1609 request = (MainThreadRequest) msg.obj;
1610 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1611 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1612 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1613 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1614 break;
1615 }
1616 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1617 ar = (AsyncResult) msg.obj;
1618 request = (MainThreadRequest) ar.userObj;
1619 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1620 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1621 args.second.accept(ar.exception == null);
1622 notifyRequester(request);
1623 break;
1624 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001625 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1626 request = (MainThreadRequest) msg.obj;
1627 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1628 Phone phone = getPhoneFromRequest(request);
1629 if (phone != null) {
1630 phone.getSystemSelectionChannels(onCompleted);
1631 } else {
1632 loge("getSystemSelectionChannels: No phone object");
1633 request.result = new ArrayList<RadioAccessSpecifier>();
1634 notifyRequester(request);
1635 }
1636 break;
1637 }
1638 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1639 ar = (AsyncResult) msg.obj;
1640 request = (MainThreadRequest) ar.userObj;
1641 if (ar.exception == null && ar.result != null) {
1642 request.result = ar.result;
1643 } else {
1644 request.result = new IllegalArgumentException(
1645 "Failed to retrieve system selection channels");
1646 if (ar.result == null) {
1647 loge("getSystemSelectionChannels: Empty response");
1648 } else {
1649 loge("getSystemSelectionChannels: Unknown exception");
1650 }
1651 }
1652 notifyRequester(request);
1653 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001654 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1655 ar = (AsyncResult) msg.obj;
1656 request = (MainThreadRequest) ar.userObj;
1657 if (ar.exception == null && ar.result != null) {
1658 request.result = ar.result;
1659 } else {
1660 request.result = -1;
1661 loge("Failed to set Forbidden Plmns");
1662 if (ar.result == null) {
1663 loge("setForbidenPlmns: Empty response");
1664 } else if (ar.exception != null) {
1665 loge("setForbiddenPlmns: Exception: " + ar.exception);
1666 request.result = -1;
1667 } else {
1668 loge("setForbiddenPlmns: Unknown exception");
1669 }
1670 }
1671 notifyRequester(request);
1672 break;
1673 case CMD_SET_FORBIDDEN_PLMNS:
1674 request = (MainThreadRequest) msg.obj;
1675 uiccCard = getUiccCardFromRequest(request);
1676 if (uiccCard == null) {
1677 loge("setForbiddenPlmns: UiccCard is null");
1678 request.result = -1;
1679 notifyRequester(request);
1680 break;
1681 }
1682 Pair<Integer, List<String>> setFplmnsArgs =
1683 (Pair<Integer, List<String>>) request.argument;
1684 appType = setFplmnsArgs.first;
1685 List<String> fplmns = setFplmnsArgs.second;
1686 uiccApp = uiccCard.getApplicationByType(appType);
1687 if (uiccApp == null) {
1688 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1689 request.result = -1;
1690 loge("Failed to get UICC App");
1691 notifyRequester(request);
1692 } else {
1693 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1694 ((SIMRecords) uiccApp.getIccRecords())
1695 .setForbiddenPlmns(onCompleted, fplmns);
1696 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001697 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001698 case CMD_ERASE_MODEM_CONFIG:
1699 request = (MainThreadRequest) msg.obj;
1700 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1701 defaultPhone.eraseModemConfig(onCompleted);
1702 break;
1703 case EVENT_ERASE_MODEM_CONFIG_DONE:
1704 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001705 break;
zoey chene02881a2019-12-30 16:11:23 +08001706
1707 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1710 Pair<String, String> changed = (Pair<String, String>) request.argument;
1711 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1712 changed.first, changed.second, onCompleted);
1713 break;
1714 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1715 ar = (AsyncResult) msg.obj;
1716 request = (MainThreadRequest) ar.userObj;
1717 if (ar.exception == null) {
1718 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001719 // If the operation is successful, update the PIN storage
1720 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1721 int phoneId = getPhoneFromRequest(request).getPhoneId();
1722 UiccController.getInstance().getPinStorage()
1723 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001724 } else {
1725 request.result = msg.arg1;
1726 }
1727 notifyRequester(request);
1728 break;
1729
Michele Berionne5e411512020-11-13 02:36:59 +00001730 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001731 request = (MainThreadRequest) msg.obj;
1732 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1733 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1734 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1735 enabled.first, enabled.second, onCompleted);
1736 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001737 }
zoey chene02881a2019-12-30 16:11:23 +08001738 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1739 ar = (AsyncResult) msg.obj;
1740 request = (MainThreadRequest) ar.userObj;
1741 if (ar.exception == null) {
1742 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001743 // If the operation is successful, update the PIN storage
1744 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1745 int phoneId = getPhoneFromRequest(request).getPhoneId();
1746 if (enabled.first) {
1747 UiccController.getInstance().getPinStorage()
1748 .storePin(enabled.second, phoneId);
1749 } else {
1750 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1751 }
zoey chene02881a2019-12-30 16:11:23 +08001752 } else {
1753 request.result = msg.arg1;
1754 }
Michele Berionne5e411512020-11-13 02:36:59 +00001755
1756
zoey chene02881a2019-12-30 16:11:23 +08001757 notifyRequester(request);
1758 break;
1759
Peter Wangdafb9ac2020-01-15 14:13:38 -08001760 case MSG_NOTIFY_USER_ACTIVITY:
1761 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001762 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001763 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1764 getDefaultPhone().getContext().sendBroadcastAsUser(
1765 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1766 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001767
1768 case CMD_SET_DATA_THROTTLING: {
1769 request = (MainThreadRequest) msg.obj;
1770 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1771 DataThrottlingRequest dataThrottlingRequest =
1772 (DataThrottlingRequest) request.argument;
1773 Phone phone = getPhoneFromRequest(request);
1774 if (phone != null) {
1775 phone.setDataThrottling(onCompleted,
1776 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1777 dataThrottlingRequest.getCompletionDurationMillis());
1778 } else {
1779 loge("setDataThrottling: No phone object");
1780 request.result =
1781 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1782 notifyRequester(request);
1783 }
1784
1785 break;
1786 }
1787 case EVENT_SET_DATA_THROTTLING_DONE:
1788 ar = (AsyncResult) msg.obj;
1789 request = (MainThreadRequest) ar.userObj;
1790
1791 if (ar.exception == null) {
1792 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1793 } else if (ar.exception instanceof CommandException) {
1794 loge("setDataThrottling: CommandException: " + ar.exception);
1795 CommandException.Error error =
1796 ((CommandException) (ar.exception)).getCommandError();
1797
1798 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1799 request.result = TelephonyManager
1800 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1801 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1802 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1803 } else {
1804 request.result =
1805 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1806 }
1807 } else {
1808 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1809 }
1810 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1811 notifyRequester(request);
1812 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001813
1814 case CMD_SET_SIM_POWER: {
1815 request = (MainThreadRequest) msg.obj;
1816 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1817 request = (MainThreadRequest) msg.obj;
1818 int stateToSet =
1819 ((Pair<Integer, IIntegerConsumer>)
1820 request.argument).first;
1821 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1822 break;
1823 }
1824 case EVENT_SET_SIM_POWER_DONE: {
1825 ar = (AsyncResult) msg.obj;
1826 request = (MainThreadRequest) ar.userObj;
1827 IIntegerConsumer callback =
1828 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1829 if (ar.exception != null) {
1830 loge("setSimPower exception: " + ar.exception);
1831 int errorCode = TelephonyManager.CallForwardingInfoCallback
1832 .RESULT_ERROR_UNKNOWN;
1833 if (ar.exception instanceof CommandException) {
1834 CommandException.Error error =
1835 ((CommandException) (ar.exception)).getCommandError();
1836 if (error == CommandException.Error.SIM_ERR) {
1837 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1838 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1839 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1840 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1841 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1842 } else {
1843 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1844 }
1845 }
1846 try {
1847 callback.accept(errorCode);
1848 } catch (RemoteException e) {
1849 // Ignore if the remote process is no longer available to call back.
1850 Log.w(LOG_TAG, "setSimPower: callback not available.");
1851 }
1852 } else {
1853 try {
1854 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1855 } catch (RemoteException e) {
1856 // Ignore if the remote process is no longer available to call back.
1857 Log.w(LOG_TAG, "setSimPower: callback not available.");
1858 }
1859 }
1860 break;
1861 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001862 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1863 request = (MainThreadRequest) msg.obj;
1864
1865 final Phone phone = getPhoneFromRequest(request);
1866 if (phone == null || phone.getServiceStateTracker() == null) {
1867 request.result = new IllegalStateException("Phone or SST is null");
1868 notifyRequester(request);
1869 break;
1870 }
1871
1872 Pair<Integer, SignalStrengthUpdateRequest> pair =
1873 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1874 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1875 request);
1876 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1877 request.subId, pair.first /*callingUid*/,
1878 pair.second /*request*/, onCompleted);
1879 break;
1880 }
1881 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1882 ar = (AsyncResult) msg.obj;
1883 request = (MainThreadRequest) ar.userObj;
1884 // request.result will be the exception of ar if present, true otherwise.
1885 // Be cautious not to leave result null which will wait() forever
1886 request.result = ar.exception != null ? ar.exception : true;
1887 notifyRequester(request);
1888 break;
1889 }
1890 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1891 request = (MainThreadRequest) msg.obj;
1892
1893 Phone phone = getPhoneFromRequest(request);
1894 if (phone == null || phone.getServiceStateTracker() == null) {
1895 request.result = new IllegalStateException("Phone or SST is null");
1896 notifyRequester(request);
1897 break;
1898 }
1899
1900 Pair<Integer, SignalStrengthUpdateRequest> pair =
1901 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1902 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1903 request);
1904 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1905 request.subId, pair.first /*callingUid*/,
1906 pair.second /*request*/, onCompleted);
1907 break;
1908 }
1909 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1910 ar = (AsyncResult) msg.obj;
1911 request = (MainThreadRequest) ar.userObj;
1912 request.result = ar.exception != null ? ar.exception : true;
1913 notifyRequester(request);
1914 break;
1915 }
Jordan Liu109698e2020-11-24 14:50:34 -08001916
Michele Berionne5e411512020-11-13 02:36:59 +00001917 case CMD_PREPARE_UNATTENDED_REBOOT:
1918 request = (MainThreadRequest) msg.obj;
1919 request.result =
1920 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1921 notifyRequester(request);
1922 break;
1923
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 default:
1925 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1926 break;
1927 }
1928 }
Jake Hambye994d462014-02-03 13:10:13 -08001929
Pengquan Menga1bb6272018-09-06 09:59:22 -07001930 private void notifyRequester(MainThreadRequest request) {
1931 synchronized (request) {
1932 request.notifyAll();
1933 }
1934 }
1935
Jake Hambye994d462014-02-03 13:10:13 -08001936 private void handleNullReturnEvent(Message msg, String command) {
1937 AsyncResult ar = (AsyncResult) msg.obj;
1938 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1939 if (ar.exception == null) {
1940 request.result = true;
1941 } else {
1942 request.result = false;
1943 if (ar.exception instanceof CommandException) {
1944 loge(command + ": CommandException: " + ar.exception);
1945 } else {
1946 loge(command + ": Unknown exception");
1947 }
1948 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001949 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 }
1952
1953 /**
1954 * Posts the specified command to be executed on the main thread,
1955 * waits for the request to complete, and returns the result.
1956 * @see #sendRequestAsync
1957 */
1958 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001959 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1960 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001961 }
1962
1963 /**
1964 * Posts the specified command to be executed on the main thread,
1965 * waits for the request to complete, and returns the result.
1966 * @see #sendRequestAsync
1967 */
1968 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1969 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001970 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001971 }
1972
1973 /**
1974 * Posts the specified command to be executed on the main thread,
1975 * waits for the request to complete, and returns the result.
1976 * @see #sendRequestAsync
1977 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001978 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001979 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1980 }
1981
1982 /**
1983 * Posts the specified command to be executed on the main thread,
1984 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1985 * if not timeout or null otherwise.
1986 * @see #sendRequestAsync
1987 */
1988 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1989 long timeoutInMs) {
1990 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001991 }
1992
1993 /**
1994 * Posts the specified command to be executed on the main thread,
1995 * waits for the request to complete, and returns the result.
1996 * @see #sendRequestAsync
1997 */
Nathan Harold92bed182018-10-12 18:16:49 -07001998 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001999 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002000 }
2001
2002 /**
2003 * Posts the specified command to be executed on the main thread,
2004 * waits for the request to complete, and returns the result.
2005 * @see #sendRequestAsync
2006 */
2007 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002008 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2009 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002010 }
2011
2012 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002013 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2014 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2015 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002016 * @see #sendRequestAsync
2017 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002018 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2019 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2021 throw new RuntimeException("This method will deadlock if called from the main thread.");
2022 }
2023
Nathan Harold92bed182018-10-12 18:16:49 -07002024 MainThreadRequest request = null;
2025 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2026 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2027 } else if (phone != null) {
2028 request = new MainThreadRequest(argument, phone, workSource);
2029 } else {
2030 request = new MainThreadRequest(argument, subId, workSource);
2031 }
2032
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 Message msg = mMainThreadHandler.obtainMessage(command, request);
2034 msg.sendToTarget();
2035
Rambo Wang0f050d82021-02-12 11:43:36 -08002036
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002038 if (timeoutInMs >= 0) {
2039 // Wait for at least timeoutInMs before returning null request result
2040 long now = SystemClock.elapsedRealtime();
2041 long deadline = now + timeoutInMs;
2042 while (request == null && now < deadline) {
2043 try {
2044 request.wait(deadline - now);
2045 } catch (InterruptedException e) {
2046 // Do nothing, go back and check if request is completed or timeout
2047 } finally {
2048 now = SystemClock.elapsedRealtime();
2049 }
2050 }
2051 } else {
2052 // Wait for the request to complete
2053 while (request.result == null) {
2054 try {
2055 request.wait();
2056 } catch (InterruptedException e) {
2057 // Do nothing, go back and wait until the request is complete
2058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 }
2060 }
2061 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002062 if (request.result == null) {
2063 Log.wtf(LOG_TAG,
2064 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 return request.result;
2067 }
2068
2069 /**
2070 * Asynchronous ("fire and forget") version of sendRequest():
2071 * Posts the specified command to be executed on the main thread, and
2072 * returns immediately.
2073 * @see #sendRequest
2074 */
2075 private void sendRequestAsync(int command) {
2076 mMainThreadHandler.sendEmptyMessage(command);
2077 }
2078
2079 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002080 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002081 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002082 */
2083 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002084 sendRequestAsync(command, argument, null, null);
2085 }
2086
2087 /**
2088 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2089 * @see {@link #sendRequest(int,Object)}
2090 */
2091 private void sendRequestAsync(
2092 int command, Object argument, Phone phone, WorkSource workSource) {
2093 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002094 Message msg = mMainThreadHandler.obtainMessage(command, request);
2095 msg.sendToTarget();
2096 }
2097
2098 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 * Initialize the singleton PhoneInterfaceManager instance.
2100 * This is only done once, at startup, from PhoneApp.onCreate().
2101 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002102 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 synchronized (PhoneInterfaceManager.class) {
2104 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002105 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 } else {
2107 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2108 }
2109 return sInstance;
2110 }
2111 }
2112
2113 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002114 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002117 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002118 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2120 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002121 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002122 mTelephonySharedPreferences =
2123 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002124 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002125 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002126 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002127 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002128
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 publish();
2130 }
2131
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002132 private Phone getDefaultPhone() {
2133 Phone thePhone = getPhone(getDefaultSubscription());
2134 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2135 }
2136
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 private void publish() {
2138 if (DBG) log("publish: " + this);
2139
Peter Wangc035ce42020-01-08 21:00:22 -08002140 TelephonyFrameworkInitializer
2141 .getTelephonyServiceManager()
2142 .getTelephonyServiceRegisterer()
2143 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 }
2145
Stuart Scott584921c2015-01-15 17:10:34 -08002146 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002147 if (request.phone != null) {
2148 return request.phone;
2149 } else {
2150 return getPhoneFromSubId(request.subId);
2151 }
2152 }
2153
2154 private Phone getPhoneFromSubId(int subId) {
2155 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2156 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002157 }
2158
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002159 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2160 Phone phone = getPhoneFromRequest(request);
2161 return phone == null ? null :
2162 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2163 }
2164
Wink Saville36469e72014-06-11 15:17:00 -07002165 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002166 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002167 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169
Naina Nallurid63128d2019-09-17 14:10:30 -07002170 private void sendEraseModemConfig(Phone phone) {
2171 if (phone != null) {
2172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2173 mApp, phone.getSubId(), "eraseModemConfig");
2174 final long identity = Binder.clearCallingIdentity();
2175 try {
2176 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2177 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
2180 }
2181 }
2182 }
2183
Peter Wang44b186e2020-01-13 23:33:09 -08002184 private boolean isImsAvailableOnDevice() {
2185 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2186 if (pm == null) {
2187 // For some reason package manger is not available.. This will fail internally anyway,
2188 // so do not throw error and allow.
2189 return true;
2190 }
2191 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2192 }
2193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002195 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002196 }
2197
Wink Savilleb564aae2014-10-23 10:18:09 -07002198 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 if (DBG) log("dial: " + number);
2200 // No permission check needed here: This is just a wrapper around the
2201 // ACTION_DIAL intent, which is available to any app since it puts up
2202 // the UI before it does anything.
2203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002204 final long identity = Binder.clearCallingIdentity();
2205 try {
2206 String url = createTelUrl(number);
2207 if (url == null) {
2208 return;
2209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002211 // PENDING: should we just silently fail if phone is offhook or ringing?
2212 PhoneConstants.State state = mCM.getState(subId);
2213 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2214 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2215 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2216 mApp.startActivity(intent);
2217 }
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221 }
2222
2223 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002224 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002225 }
2226
Wink Savilleb564aae2014-10-23 10:18:09 -07002227 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 if (DBG) log("call: " + number);
2229
2230 // This is just a wrapper around the ACTION_CALL intent, but we still
2231 // need to do a permission check since we're calling startActivity()
2232 // from the context of the phone app.
2233 enforceCallPermission();
2234
Jordan Liu1617b712019-07-10 15:06:26 -07002235 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 != AppOpsManager.MODE_ALLOWED) {
2237 return;
2238 }
2239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240 final long identity = Binder.clearCallingIdentity();
2241 try {
2242 String url = createTelUrl(number);
2243 if (url == null) {
2244 return;
2245 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002247 boolean isValid = false;
2248 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2249 if (slist != null) {
2250 for (SubscriptionInfo subInfoRecord : slist) {
2251 if (subInfoRecord.getSubscriptionId() == subId) {
2252 isValid = true;
2253 break;
2254 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002255 }
Wink Saville08874612014-08-31 19:19:58 -07002256 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257 if (!isValid) {
2258 return;
2259 }
Wink Saville08874612014-08-31 19:19:58 -07002260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2262 intent.putExtra(SUBSCRIPTION_KEY, subId);
2263 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2264 mApp.startActivity(intent);
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
2267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269
Wink Savilleb564aae2014-10-23 10:18:09 -07002270 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002271 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002272 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2273 }
2274
Wink Savilleb564aae2014-10-23 10:18:09 -07002275 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002276 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002277 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2278 }
2279
Wink Savilleb564aae2014-10-23 10:18:09 -07002280 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282
2283 final long identity = Binder.clearCallingIdentity();
2284 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002285 Phone phone = getPhone(subId);
2286 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002287 checkSimPin.start();
2288 return checkSimPin.unlockSim(null, pin);
2289 } finally {
2290 Binder.restoreCallingIdentity(identity);
2291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 }
2293
Wink Savilleb564aae2014-10-23 10:18:09 -07002294 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296
2297 final long identity = Binder.clearCallingIdentity();
2298 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002299 Phone phone = getPhone(subId);
2300 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 checkSimPuk.start();
2302 return checkSimPuk.unlockSim(puk, pin);
2303 } finally {
2304 Binder.restoreCallingIdentity(identity);
2305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307
2308 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002309 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 * a synchronous one.
2311 */
2312 private static class UnlockSim extends Thread {
2313
2314 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002315 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316
2317 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002318 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2319 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320
2321 // For replies from SimCard interface
2322 private Handler mHandler;
2323
2324 // For async handler to identify request type
2325 private static final int SUPPLY_PIN_COMPLETE = 100;
2326
Michele Berionne5e411512020-11-13 02:36:59 +00002327 UnlockSim(int phoneId, IccCard simCard) {
2328 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 mSimCard = simCard;
2330 }
2331
2332 @Override
2333 public void run() {
2334 Looper.prepare();
2335 synchronized (UnlockSim.this) {
2336 mHandler = new Handler() {
2337 @Override
2338 public void handleMessage(Message msg) {
2339 AsyncResult ar = (AsyncResult) msg.obj;
2340 switch (msg.what) {
2341 case SUPPLY_PIN_COMPLETE:
2342 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2343 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002344 mRetryCount = msg.arg1;
2345 if (ar.exception != null) {
2346 if (ar.exception instanceof CommandException &&
2347 ((CommandException)(ar.exception)).getCommandError()
2348 == CommandException.Error.PASSWORD_INCORRECT) {
2349 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002350 } //When UiccCardApp dispose,handle message and return exception
2351 else if (ar.exception instanceof CommandException &&
2352 ((CommandException) (ar.exception)).getCommandError()
2353 == CommandException.Error.ABORTED) {
2354 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002355 } else {
2356 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2357 }
2358 } else {
2359 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 mDone = true;
2362 UnlockSim.this.notifyAll();
2363 }
2364 break;
2365 }
2366 }
2367 };
2368 UnlockSim.this.notifyAll();
2369 }
2370 Looper.loop();
2371 }
2372
2373 /*
2374 * Use PIN or PUK to unlock SIM card
2375 *
2376 * If PUK is null, unlock SIM card with PIN
2377 *
2378 * If PUK is not null, unlock SIM card with PUK and set PIN code
2379 */
Wink Saville9de0f752013-10-22 19:04:03 -07002380 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381
2382 while (mHandler == null) {
2383 try {
2384 wait();
2385 } catch (InterruptedException e) {
2386 Thread.currentThread().interrupt();
2387 }
2388 }
2389 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2390
2391 if (puk == null) {
2392 mSimCard.supplyPin(pin, callback);
2393 } else {
2394 mSimCard.supplyPuk(puk, pin, callback);
2395 }
2396
2397 while (!mDone) {
2398 try {
2399 Log.d(LOG_TAG, "wait for done");
2400 wait();
2401 } catch (InterruptedException e) {
2402 // Restore the interrupted status
2403 Thread.currentThread().interrupt();
2404 }
2405 }
2406 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002407 int[] resultArray = new int[2];
2408 resultArray[0] = mResult;
2409 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002410
2411 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2412 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2413 }
2414
Wink Saville9de0f752013-10-22 19:04:03 -07002415 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417 }
2418
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002419 /**
2420 * This method has been removed due to privacy and stability concerns.
2421 */
2422 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002424 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2425 return;
Wink Saville36469e72014-06-11 15:17:00 -07002426 }
2427
Nathan Harold1f889d82020-06-04 17:05:26 -07002428 @Override
2429 public void updateServiceLocationWithPackageName(String callingPackage) {
2430 mApp.getSystemService(AppOpsManager.class)
2431 .checkPackage(Binder.getCallingUid(), callingPackage);
2432
Nathan Haroldf096d982020-11-18 17:18:06 -08002433 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002434 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2435 // Callers targeting S have no business invoking this method.
2436 return;
2437 }
2438
2439 LocationAccessPolicy.LocationPermissionResult locationResult =
2440 LocationAccessPolicy.checkLocationPermission(mApp,
2441 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2442 .setCallingPackage(callingPackage)
2443 .setCallingFeatureId(null)
2444 .setCallingPid(Binder.getCallingPid())
2445 .setCallingUid(Binder.getCallingUid())
2446 .setMethod("updateServiceLocation")
2447 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2448 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2449 .build());
2450 // Apps that lack location permission have no business calling this method;
2451 // however, because no permission was declared in the public API, denials must
2452 // all be "soft".
2453 switch (locationResult) {
2454 case DENIED_HARD: /* fall through */
2455 case DENIED_SOFT:
2456 return;
2457 }
2458
2459 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002460 final long identity = Binder.clearCallingIdentity();
2461 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002462 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002464 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465 }
2466 } finally {
2467 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 }
2470
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002471 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002472 @Override
2473 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002474 return isRadioOnWithFeature(callingPackage, null);
2475 }
2476
2477
2478 @Override
2479 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2480 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2481 callingFeatureId);
2482 }
2483
2484 @Deprecated
2485 @Override
2486 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2487 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002488 }
2489
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002490 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002491 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2492 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002494 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002495 return false;
2496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497
2498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 return isRadioOnForSubscriber(subId);
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
2503 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002504 }
2505
2506 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 final long identity = Binder.clearCallingIdentity();
2508 try {
2509 final Phone phone = getPhone(subId);
2510 if (phone != null) {
2511 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2512 } else {
2513 return false;
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 }
2519
2520 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002521 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 }
Wink Saville36469e72014-06-11 15:17:00 -07002523
Wink Savilleb564aae2014-10-23 10:18:09 -07002524 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002526
2527 final long identity = Binder.clearCallingIdentity();
2528 try {
2529 final Phone phone = getPhone(subId);
2530 if (phone != null) {
2531 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2532 }
2533 } finally {
2534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002535 }
Wink Saville36469e72014-06-11 15:17:00 -07002536 }
2537
2538 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002539 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002540 }
2541
Wink Savilleb564aae2014-10-23 10:18:09 -07002542 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 final Phone phone = getPhone(subId);
2548 if (phone == null) {
2549 return false;
2550 }
2551 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2552 toggleRadioOnOffForSubscriber(subId);
2553 }
2554 return true;
2555 } finally {
2556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 }
Wink Saville36469e72014-06-11 15:17:00 -07002559
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002560 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002561 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002562 /*
2563 * If any of the Radios are available, it will need to be
2564 * shutdown. So return true if any Radio is available.
2565 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2569 Phone phone = PhoneFactory.getPhone(i);
2570 if (phone != null && phone.isRadioAvailable()) return true;
2571 }
2572 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2573 return false;
2574 } finally {
2575 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002576 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002577 }
2578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002580 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002581 enforceModifyPermission();
2582
2583 final long identity = Binder.clearCallingIdentity();
2584 try {
2585 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2586 logv("Shutting down Phone " + i);
2587 shutdownRadioUsingPhoneId(i);
2588 }
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002591 }
2592 }
2593
2594 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002595 Phone phone = PhoneFactory.getPhone(phoneId);
2596 if (phone != null && phone.isRadioAvailable()) {
2597 phone.shutdownRadio();
2598 }
2599 }
2600
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002602 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603
2604 final long identity = Binder.clearCallingIdentity();
2605 try {
2606 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2607 if (defaultPhone != null) {
2608 defaultPhone.setRadioPower(turnOn);
2609 return true;
2610 } else {
2611 loge("There's no default phone.");
2612 return false;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002616 }
Wink Saville36469e72014-06-11 15:17:00 -07002617 }
2618
Wink Savilleb564aae2014-10-23 10:18:09 -07002619 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621
2622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 final Phone phone = getPhone(subId);
2625 if (phone != null) {
2626 phone.setRadioPower(turnOn);
2627 return true;
2628 } else {
2629 return false;
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 }
2635
Wink Saville36469e72014-06-11 15:17:00 -07002636 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002637 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 public boolean enableDataConnectivity() {
2639 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640
2641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 int subId = mSubscriptionController.getDefaultDataSubId();
2644 final Phone phone = getPhone(subId);
2645 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002646 phone.getDataEnabledSettings().setDataEnabled(
2647 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 return true;
2649 } else {
2650 return false;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 }
2656
Wink Saville36469e72014-06-11 15:17:00 -07002657 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002658 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 public boolean disableDataConnectivity() {
2660 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661
2662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 int subId = mSubscriptionController.getDefaultDataSubId();
2665 final Phone phone = getPhone(subId);
2666 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002667 phone.getDataEnabledSettings().setDataEnabled(
2668 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669 return true;
2670 } else {
2671 return false;
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
Sanket Padawe356d7632015-06-22 14:03:32 -07002678 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002679 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680 final long identity = Binder.clearCallingIdentity();
2681 try {
2682 final Phone phone = getPhone(subId);
2683 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002684 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 } else {
2686 return false;
2687 }
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 }
2692
2693 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002694 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002695 }
2696
pkanwarae03a6b2016-11-06 20:37:09 -08002697 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 enforceCallPermission();
2699
2700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2703 return;
2704 }
2705 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2706 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2707 } finally {
2708 Binder.restoreCallingIdentity(identity);
2709 }
pkanwar32d516d2016-10-14 19:37:38 -07002710 };
2711
Wink Savilleb564aae2014-10-23 10:18:09 -07002712 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714
2715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2718 return false;
2719 }
2720 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
2725
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002727 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002728 }
2729
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002730 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 final long identity = Binder.clearCallingIdentity();
2732 try {
2733 Phone phone = PhoneFactory.getPhone(slotIndex);
2734 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2735 PhoneConstantConversions.convertCallState(phone.getState());
2736 } finally {
2737 Binder.restoreCallingIdentity(identity);
2738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 }
2740
Sanket Padawe356d7632015-06-22 14:03:32 -07002741 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002742 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002743 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2744 }
2745
2746 @Override
2747 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002748 final long identity = Binder.clearCallingIdentity();
2749 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002750 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751 if (phone != null) {
2752 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2753 } else {
2754 return PhoneConstantConversions.convertDataState(
2755 PhoneConstants.DataState.DISCONNECTED);
2756 }
2757 } finally {
2758 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 }
2761
Sanket Padawe356d7632015-06-22 14:03:32 -07002762 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002763 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002764 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2765 }
2766
2767 @Override
2768 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 final long identity = Binder.clearCallingIdentity();
2770 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002771 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 if (phone != null) {
2773 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2774 } else {
2775 return TelephonyManager.DATA_ACTIVITY_NONE;
2776 }
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
2781
2782 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002783 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002784 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002785 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002786
2787 LocationAccessPolicy.LocationPermissionResult locationResult =
2788 LocationAccessPolicy.checkLocationPermission(mApp,
2789 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2790 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002791 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002792 .setCallingPid(Binder.getCallingPid())
2793 .setCallingUid(Binder.getCallingUid())
2794 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002795 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002796 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2797 .build());
2798 switch (locationResult) {
2799 case DENIED_HARD:
2800 throw new SecurityException("Not allowed to access cell location");
2801 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002802 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2803 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002804 }
2805
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002806 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002810 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002811 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812 } finally {
2813 Binder.restoreCallingIdentity(identity);
2814 }
Svetoslav64fad262015-04-14 14:35:21 -07002815 }
2816
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002818 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002819 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2820 // registered cell info, so return a NULL country instead.
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002823 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2824 // Get default phone in this case.
2825 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2826 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002827 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002829 if (phone == null) return "";
2830 ServiceStateTracker sst = phone.getServiceStateTracker();
2831 if (sst == null) return "";
2832 LocaleTracker lt = sst.getLocaleTracker();
2833 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002834 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002835 } finally {
2836 Binder.restoreCallingIdentity(identity);
2837 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002838 }
2839
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002840 /**
2841 * This method was removed due to potential issues caused by performing partial
2842 * updates of service state, and lack of a credible use case.
2843 *
2844 * This has the ability to break the telephony implementation by disabling notification of
2845 * changes in device connectivity. DO NOT USE THIS!
2846 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002847 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 public void enableLocationUpdates() {
2849 mApp.enforceCallingOrSelfPermission(
2850 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 }
2852
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002853 /**
2854 * This method was removed due to potential issues caused by performing partial
2855 * updates of service state, and lack of a credible use case.
2856 *
2857 * This has the ability to break the telephony implementation by disabling notification of
2858 * changes in device connectivity. DO NOT USE THIS!
2859 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 @Override
2861 public void disableLocationUpdates() {
2862 mApp.enforceCallingOrSelfPermission(
2863 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 }
2865
2866 @Override
2867 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002868 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2869 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002870 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002871 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2872 throw new SecurityException(
2873 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2874 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002875
Jordan Liu1617b712019-07-10 15:06:26 -07002876 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2878 return null;
2879 }
Svetoslav64fad262015-04-14 14:35:21 -07002880
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002881 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002883 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002884 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002885
Nathan Haroldf180aac2018-06-01 18:43:55 -07002886 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2887 for (CellInfo ci : info) {
2888 if (ci instanceof CellInfoGsm) {
2889 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2890 } else if (ci instanceof CellInfoWcdma) {
2891 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002893 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002894 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
2896
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002897 private List<CellInfo> getCachedCellInfo() {
2898 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2899 for (Phone phone : PhoneFactory.getPhones()) {
2900 List<CellInfo> info = phone.getAllCellInfo();
2901 if (info != null) cellInfos.addAll(info);
2902 }
2903 return cellInfos;
2904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002905
2906 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002907 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002908 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002909 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002910
2911 LocationAccessPolicy.LocationPermissionResult locationResult =
2912 LocationAccessPolicy.checkLocationPermission(mApp,
2913 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2914 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002915 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002916 .setCallingPid(Binder.getCallingPid())
2917 .setCallingUid(Binder.getCallingUid())
2918 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002919 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002920 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2921 .build());
2922 switch (locationResult) {
2923 case DENIED_HARD:
2924 throw new SecurityException("Not allowed to access cell info");
2925 case DENIED_SOFT:
2926 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
2928
Nathan Haroldf096d982020-11-18 17:18:06 -08002929 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002930 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2931 return getCachedCellInfo();
2932 }
2933
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002934 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002935 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2939 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002940 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002941 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 if (info != null) cellInfos.addAll(info);
2943 }
2944 return cellInfos;
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 }
2948 }
2949
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002950 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002951 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2952 String callingFeatureId) {
2953 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2954 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002955 }
2956
2957 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002958 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2959 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002960 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002961 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002962 }
2963
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002964 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2965 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002966 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002967 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002968
2969 LocationAccessPolicy.LocationPermissionResult locationResult =
2970 LocationAccessPolicy.checkLocationPermission(mApp,
2971 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2972 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002973 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002974 .setCallingPid(Binder.getCallingPid())
2975 .setCallingUid(Binder.getCallingUid())
2976 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002977 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2978 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002979 .build());
2980 switch (locationResult) {
2981 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002982 if (TelephonyPermissions
2983 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002984 // Safetynet logging for b/154934934
2985 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2986 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002987 throw new SecurityException("Not allowed to access cell info");
2988 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002989 if (TelephonyPermissions
2990 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002991 // Safetynet logging for b/154934934
2992 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2993 }
Nathan Harold5320c422019-05-09 10:26:08 -07002994 try {
2995 cb.onCellInfo(new ArrayList<CellInfo>());
2996 } catch (RemoteException re) {
2997 // Drop without consequences
2998 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002999 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003000 }
3001
Nathan Harolda939a962019-05-09 10:13:47 -07003002
3003 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003004 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3005
3006 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3007 }
3008
3009 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003011 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003012 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003016 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 }
3021
Shishir Agrawala9f32182016-04-12 12:00:16 -07003022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003023 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003024 Phone phone = PhoneFactory.getPhone(slotIndex);
3025 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003026 return null;
3027 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003028 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003029 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003030 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003031 return null;
3032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 return phone.getImei();
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003040 }
3041
3042 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003043 public String getTypeAllocationCodeForSlot(int slotIndex) {
3044 Phone phone = PhoneFactory.getPhone(slotIndex);
3045 String tac = null;
3046 if (phone != null) {
3047 String imei = phone.getImei();
3048 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3049 }
3050 return tac;
3051 }
3052
3053 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003054 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003055 Phone phone = PhoneFactory.getPhone(slotIndex);
3056 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003057 return null;
3058 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003059
Jeff Davidson913390f2018-02-23 17:11:49 -08003060 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003061 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003062 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003063 return null;
3064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065
3066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 return phone.getMeid();
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Jack Yu2af8d712017-03-15 17:14:14 -07003072 }
3073
3074 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003075 public String getManufacturerCodeForSlot(int slotIndex) {
3076 Phone phone = PhoneFactory.getPhone(slotIndex);
3077 String manufacturerCode = null;
3078 if (phone != null) {
3079 String meid = phone.getMeid();
3080 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3081 }
3082 return manufacturerCode;
3083 }
3084
3085 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003086 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3087 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003088 Phone phone = PhoneFactory.getPhone(slotIndex);
3089 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003090 return null;
3091 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003092 int subId = phone.getSubId();
3093 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003094 mApp, subId, callingPackage, callingFeatureId,
3095 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003096 return null;
3097 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003098
3099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 return phone.getDeviceSvn();
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003105 }
3106
fionaxu43304da2017-11-27 22:51:16 -08003107 @Override
3108 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 final Phone phone = getPhone(subId);
3112 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
3115 }
fionaxu43304da2017-11-27 22:51:16 -08003116 }
3117
3118 @Override
3119 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120 final long identity = Binder.clearCallingIdentity();
3121 try {
3122 final Phone phone = getPhone(subId);
3123 return phone == null ? null : phone.getCarrierName();
3124 } finally {
3125 Binder.restoreCallingIdentity(identity);
3126 }
fionaxu43304da2017-11-27 22:51:16 -08003127 }
3128
calvinpanffe225e2018-11-01 19:43:06 +08003129 @Override
chen xu0026ca62019-03-06 15:28:50 -08003130 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 final Phone phone = getPhone(subId);
3134 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003135 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
3139 }
3140
3141 @Override
chen xu0026ca62019-03-06 15:28:50 -08003142 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003143 final long identity = Binder.clearCallingIdentity();
3144 try {
3145 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003146 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003147 } finally {
3148 Binder.restoreCallingIdentity(identity);
3149 }
3150 }
3151
chen xu651eec72018-11-11 19:03:44 -08003152 @Override
chen xu864e11c2018-12-06 22:10:03 -08003153 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3154 if (!isSubscriptionMccMnc) {
3155 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3156 }
chen xu651eec72018-11-11 19:03:44 -08003157 final Phone phone = PhoneFactory.getPhone(slotIndex);
3158 if (phone == null) {
3159 return TelephonyManager.UNKNOWN_CARRIER_ID;
3160 }
3161 final long identity = Binder.clearCallingIdentity();
3162 try {
3163 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3164 } finally {
3165 Binder.restoreCallingIdentity(identity);
3166 }
3167 }
3168
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 //
3170 // Internal helper methods.
3171 //
3172
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003173 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003174 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3175 *
3176 * @throws SecurityException if the caller does not have the required permission
3177 */
3178 private void enforceModifyPermission() {
3179 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3180 }
3181
Shuo Qiancd19c462020-01-16 20:51:11 -08003182 /**
3183 * Make sure the caller is system.
3184 *
3185 * @throws SecurityException if the caller is not system.
3186 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003187 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003188 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3189 throw new SecurityException("Caller must be system");
3190 }
3191 }
3192
Shuo Qian3b6ee772019-11-13 17:43:31 -08003193 private void enforceActiveEmergencySessionPermission() {
3194 mApp.enforceCallingOrSelfPermission(
3195 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3196 }
3197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 /**
3199 * Make sure the caller has the CALL_PHONE permission.
3200 *
3201 * @throws SecurityException if the caller does not have the required permission
3202 */
3203 private void enforceCallPermission() {
3204 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3205 }
3206
paulhu5a773602019-08-23 19:17:33 +08003207 private void enforceSettingsPermission() {
3208 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003209 }
3210
Michele Berionne5e411512020-11-13 02:36:59 +00003211 private void enforceRebootPermission() {
3212 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3213 }
3214
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003215 private String createTelUrl(String number) {
3216 if (TextUtils.isEmpty(number)) {
3217 return null;
3218 }
3219
Jake Hambye994d462014-02-03 13:10:13 -08003220 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 }
3222
Ihab Awadf9e92732013-12-05 18:02:52 -08003223 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3225 }
3226
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003227 private static void logv(String msg) {
3228 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3229 }
3230
Ihab Awadf9e92732013-12-05 18:02:52 -08003231 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3233 }
3234
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003235 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003237 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003238 }
3239
Sanket Padawe356d7632015-06-22 14:03:32 -07003240 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003241 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 final Phone phone = PhoneFactory.getPhone(slotIndex);
3245 if (phone == null) {
3246 return PhoneConstants.PHONE_TYPE_NONE;
3247 } else {
3248 return phone.getPhoneType();
3249 }
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 }
3254
3255 /**
3256 * Returns the CDMA ERI icon index to display
3257 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003259 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3260 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3261 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003262 }
3263
Sanket Padawe356d7632015-06-22 14:03:32 -07003264 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003265 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3266 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003268 mApp, subId, callingPackage, callingFeatureId,
3269 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003270 return -1;
3271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272
3273 final long identity = Binder.clearCallingIdentity();
3274 try {
3275 final Phone phone = getPhone(subId);
3276 if (phone != null) {
3277 return phone.getCdmaEriIconIndex();
3278 } else {
3279 return -1;
3280 }
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003284 }
3285
3286 /**
3287 * Returns the CDMA ERI icon mode,
3288 * 0 - ON
3289 * 1 - FLASHING
3290 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003291 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003292 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3293 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3294 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003295 }
3296
Sanket Padawe356d7632015-06-22 14:03:32 -07003297 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003298 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3299 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003301 mApp, subId, callingPackage, callingFeatureId,
3302 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003303 return -1;
3304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003305
3306 final long identity = Binder.clearCallingIdentity();
3307 try {
3308 final Phone phone = getPhone(subId);
3309 if (phone != null) {
3310 return phone.getCdmaEriIconMode();
3311 } else {
3312 return -1;
3313 }
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003317 }
3318
3319 /**
3320 * Returns the CDMA ERI text,
3321 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003322 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003323 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3324 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3325 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003326 }
3327
Sanket Padawe356d7632015-06-22 14:03:32 -07003328 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003329 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3330 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003331 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003332 mApp, subId, callingPackage, callingFeatureId,
3333 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003334 return null;
3335 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336
3337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 final Phone phone = getPhone(subId);
3340 if (phone != null) {
3341 return phone.getCdmaEriText();
3342 } else {
3343 return null;
3344 }
3345 } finally {
3346 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 }
3349
3350 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003351 * Returns the CDMA MDN.
3352 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003353 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003354 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3356 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357
3358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003361 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 return phone.getLine1Number();
3363 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003364 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003365 return null;
3366 }
3367 } finally {
3368 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003369 }
3370 }
3371
3372 /**
3373 * Returns the CDMA MIN.
3374 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003375 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003376 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3378 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379
3380 final long identity = Binder.clearCallingIdentity();
3381 try {
3382 final Phone phone = getPhone(subId);
3383 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3384 return phone.getCdmaMin();
3385 } else {
3386 return null;
3387 }
3388 } finally {
3389 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003390 }
3391 }
3392
Hall Liud892bec2018-11-30 14:51:45 -08003393 @Override
3394 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3395 INumberVerificationCallback callback, String callingPackage) {
3396 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3397 != PERMISSION_GRANTED) {
3398 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3399 }
3400 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3401
3402 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3403 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003404 throw new SecurityException("Calling package must be configured in the device config: "
3405 + "calling package: " + callingPackage
3406 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003407 }
3408
3409 if (range == null) {
3410 throw new NullPointerException("Range must be non-null");
3411 }
3412
3413 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003414 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003415
3416 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3417 }
3418
Junda Liuca05d5d2014-08-14 22:36:34 -07003419 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003420 * Returns true if CDMA provisioning needs to run.
3421 */
3422 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003423 final long identity = Binder.clearCallingIdentity();
3424 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003425 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003429 }
3430
3431 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003432 * Sets the voice mail number of a given subId.
3433 */
3434 @Override
3435 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003436 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3437 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003438
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
3441 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3442 new Pair<String, String>(alphaTag, number), new Integer(subId));
3443 return success;
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003447 }
3448
Ta-wei Yen87c49842016-05-13 21:19:52 -07003449 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003450 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003452 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3453 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003454 if (!TextUtils.equals(callingPackage, systemDialer)) {
3455 throw new SecurityException("caller must be system dialer");
3456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003457
3458 final long identity = Binder.clearCallingIdentity();
3459 try {
3460 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3461 if (phoneAccountHandle == null) {
3462 return null;
3463 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003467 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003468 }
3469
3470 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003471 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3472 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003475 mApp, subId, callingPackage, callingFeatureId,
3476 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003477 return null;
3478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003480 final long identity = Binder.clearCallingIdentity();
3481 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003482 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003483 } finally {
3484 Binder.restoreCallingIdentity(identity);
3485 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003486 }
3487
3488 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003489 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3490 VisualVoicemailSmsFilterSettings settings) {
3491 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003496 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003500 }
3501
3502 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003503 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3504 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003505
3506 final long identity = Binder.clearCallingIdentity();
3507 try {
3508 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003509 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003510 } finally {
3511 Binder.restoreCallingIdentity(identity);
3512 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003513 }
3514
3515 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003516 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3517 String callingPackage, int subId) {
3518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003519
3520 final long identity = Binder.clearCallingIdentity();
3521 try {
3522 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003523 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003524 } finally {
3525 Binder.restoreCallingIdentity(identity);
3526 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003527 }
3528
3529 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003530 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003531 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532
3533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003536 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003540 }
3541
3542 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003543 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3544 String callingAttributionTag, int subId, String number, int port, String text,
3545 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003546 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003547 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003548 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003549 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003550 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3551 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003552 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003553
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003554 /**
fionaxu0152e512016-11-14 13:36:14 -08003555 * Sets the voice activation state of a given subId.
3556 */
3557 @Override
3558 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3560 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003561
3562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 final Phone phone = getPhone(subId);
3565 if (phone != null) {
3566 phone.setVoiceActivationState(activationState);
3567 } else {
3568 loge("setVoiceActivationState fails with invalid subId: " + subId);
3569 }
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003572 }
3573 }
3574
3575 /**
3576 * Sets the data activation state of a given subId.
3577 */
3578 @Override
3579 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3581 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003582
3583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 final Phone phone = getPhone(subId);
3586 if (phone != null) {
3587 phone.setDataActivationState(activationState);
3588 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003589 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003590 }
3591 } finally {
3592 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003593 }
3594 }
3595
3596 /**
3597 * Returns the voice activation state of a given subId.
3598 */
3599 @Override
3600 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003601 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602
fionaxu0152e512016-11-14 13:36:14 -08003603 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 if (phone != null) {
3607 return phone.getVoiceActivationState();
3608 } else {
3609 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3610 }
3611 } finally {
3612 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003613 }
3614 }
3615
3616 /**
3617 * Returns the data activation state of a given subId.
3618 */
3619 @Override
3620 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622
fionaxu0152e512016-11-14 13:36:14 -08003623 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003624 final long identity = Binder.clearCallingIdentity();
3625 try {
3626 if (phone != null) {
3627 return phone.getDataActivationState();
3628 } else {
3629 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3630 }
3631 } finally {
3632 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003633 }
3634 }
3635
3636 /**
Wink Saville36469e72014-06-11 15:17:00 -07003637 * Returns the unread count of voicemails for a subId
3638 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003639 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003640 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3641 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003643 mApp, subId, callingPackage, callingFeatureId,
3644 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003645 return 0;
3646 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 final Phone phone = getPhone(subId);
3650 if (phone != null) {
3651 return phone.getVoiceMessageCount();
3652 } else {
3653 return 0;
3654 }
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003658 }
3659
3660 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003661 * returns true, if the device is in a state where both voice and data
3662 * are supported simultaneously. This can change based on location or network condition.
3663 */
3664 @Override
3665 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 final Phone phone = getPhone(subId);
3669 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
3672 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003673 }
3674
3675 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003676 * Send the dialer code if called from the current default dialer or the caller has
3677 * carrier privilege.
3678 * @param inputCode The dialer code to send
3679 */
3680 @Override
3681 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003682 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003684 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3685 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003686 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003687 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003688 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690
3691 final long identity = Binder.clearCallingIdentity();
3692 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003693 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
fionaxu235cc5e2017-03-06 22:25:57 -08003697 }
3698
Pengquan Menga1bb6272018-09-06 09:59:22 -07003699 @Override
3700 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003701 TelephonyPermissions
3702 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3703 mApp, subId, "getNetworkSelectionMode");
3704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 if (!isActiveSubscription(subId)) {
3707 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3708 }
3709 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3710 } finally {
3711 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003712 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003713 }
3714
Brad Ebinger35c841c2018-10-01 10:40:55 -07003715 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003716 public boolean isInEmergencySmsMode() {
3717 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 for (Phone phone : PhoneFactory.getPhones()) {
3721 if (phone.isInEmergencySmsMode()) {
3722 return true;
3723 }
3724 }
3725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
3728 return false;
3729 }
3730
shilu366312e2019-12-17 09:28:10 -08003731 /**
3732 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3733 * @param subId The subscription to use to check the configuration.
3734 * @param c The callback that will be used to send the result.
3735 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003736 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003737 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3738 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003739 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3740 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003741
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003742 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3743 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3744 "IMS not available on device.");
3745 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 final long token = Binder.clearCallingIdentity();
3747 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003748 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003749 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003751 } catch (ImsException e) {
3752 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003753 } finally {
3754 Binder.restoreCallingIdentity(token);
3755 }
3756 }
3757
shilu366312e2019-12-17 09:28:10 -08003758 /**
3759 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3760 * @param subId The subscription to use to check the configuration.
3761 * @param c The callback that will be used to send the result.
3762 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003764 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003765 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3766 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003767 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3768 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3769 }
Meng Wangafbc5852019-09-19 17:37:13 -07003770 final long token = Binder.clearCallingIdentity();
3771 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003772 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003773 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3774 .removeRegistrationCallbackForSubscription(c, subId);
3775 } catch (ImsException e) {
3776 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3777 + "is inactive, ignoring unregister.");
3778 // If the subscription is no longer active, just return, since the callback
3779 // will already have been removed internally.
3780 } finally {
3781 Binder.restoreCallingIdentity(token);
3782 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003783 }
3784
Brad Ebingera34a6c22019-10-22 17:36:18 -07003785 /**
3786 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3787 */
3788 @Override
3789 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3790 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3791 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3792 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3793 "IMS not available on device.");
3794 }
3795 final long token = Binder.clearCallingIdentity();
3796 try {
3797 Phone phone = getPhone(subId);
3798 if (phone == null) {
3799 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3800 + subId + "'");
3801 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3802 }
3803 phone.getImsRegistrationState(regState -> {
3804 try {
3805 consumer.accept((regState == null)
3806 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3807 } catch (RemoteException e) {
3808 // Ignore if the remote process is no longer available to call back.
3809 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3810 }
3811 });
3812 } finally {
3813 Binder.restoreCallingIdentity(token);
3814 }
3815 }
3816
3817 /**
3818 * Get the transport type for the IMS service registration state.
3819 */
3820 @Override
3821 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003822 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3823 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003824 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3825 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3826 "IMS not available on device.");
3827 }
3828 final long token = Binder.clearCallingIdentity();
3829 try {
3830 Phone phone = getPhone(subId);
3831 if (phone == null) {
3832 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3833 + subId + "'");
3834 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3835 }
3836 phone.getImsRegistrationTech(regTech -> {
3837 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3838 int regTechConverted = (regTech == null)
3839 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3840 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3841 regTechConverted);
3842 try {
3843 consumer.accept(regTechConverted);
3844 } catch (RemoteException e) {
3845 // Ignore if the remote process is no longer available to call back.
3846 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3847 }
3848 });
3849 } finally {
3850 Binder.restoreCallingIdentity(token);
3851 }
3852 }
3853
shilu366312e2019-12-17 09:28:10 -08003854 /**
3855 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3856 * @param subId The subscription to use to check the configuration.
3857 * @param c The callback that will be used to send the result.
3858 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003860 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3861 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003862 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3863 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003864 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3865 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3866 "IMS not available on device.");
3867 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3869 final long token = Binder.clearCallingIdentity();
3870 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003871 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003872 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003873 } catch (ImsException e) {
3874 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003875 } finally {
3876 Binder.restoreCallingIdentity(token);
3877 }
3878 }
3879
shilu366312e2019-12-17 09:28:10 -08003880 /**
3881 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3882 * @param subId The subscription to use to check the configuration.
3883 * @param c The callback that will be used to send the result.
3884 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003886 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003887 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3888 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3890 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3891 }
Meng Wangafbc5852019-09-19 17:37:13 -07003892
3893 final long token = Binder.clearCallingIdentity();
3894 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003895 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003896 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003897 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003898 } catch (ImsException e) {
3899 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3900 + "is inactive, ignoring unregister.");
3901 // If the subscription is no longer active, just return, since the callback
3902 // will already have been removed internally.
3903 } finally {
3904 Binder.restoreCallingIdentity(token);
3905 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 }
3907
3908 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003909 public boolean isCapable(int subId, int capability, int regTech) {
3910 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003911 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3912 final long token = Binder.clearCallingIdentity();
3913 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003914 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003916 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003917 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3918 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003919 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003920 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3921 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003922 } finally {
3923 Binder.restoreCallingIdentity(token);
3924 }
3925 }
3926
3927 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003928 public boolean isAvailable(int subId, int capability, int regTech) {
3929 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003930 final long token = Binder.clearCallingIdentity();
3931 try {
3932 Phone phone = getPhone(subId);
3933 if (phone == null) return false;
3934 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003935 } catch (com.android.ims.ImsException e) {
3936 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3937 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003938 } finally {
3939 Binder.restoreCallingIdentity(token);
3940 }
3941 }
3942
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003943 /**
3944 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3945 * subscription.
3946 * @param subId The subscription to use to check the configuration.
3947 * @param callback The callback that will be used to send the result.
3948 * @param capability The MmTelFeature capability that will be used to send the result.
3949 * @param transportType The transport type of the MmTelFeature capability.
3950 */
3951 @Override
3952 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3953 int transportType) {
3954 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3955 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3956 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3957 "IMS not available on device.");
3958 }
3959 final long token = Binder.clearCallingIdentity();
3960 try {
3961 int slotId = getSlotIndex(subId);
3962 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3963 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3964 + subId + "'");
3965 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3966 }
3967 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3968 transportType, aBoolean -> {
3969 try {
3970 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3971 } catch (RemoteException e) {
3972 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3973 + "running. Ignore");
3974 }
3975 });
3976 } finally {
3977 Binder.restoreCallingIdentity(token);
3978 }
3979 }
3980
shilu366312e2019-12-17 09:28:10 -08003981 /**
3982 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3983 * @param subId The subscription to use to check the configuration.
3984 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 @Override
3986 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003987 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3988 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003989
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3991 final long token = Binder.clearCallingIdentity();
3992 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003993 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003995 } catch (ImsException e) {
3996 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003997 } finally {
3998 Binder.restoreCallingIdentity(token);
3999 }
4000 }
4001
4002 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004003 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004005 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 final long identity = Binder.clearCallingIdentity();
4007 try {
4008 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004009 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004010 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004011 } catch (ImsException e) {
4012 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004013 } finally {
4014 Binder.restoreCallingIdentity(identity);
4015 }
4016 }
4017
shilu366312e2019-12-17 09:28:10 -08004018 /**
4019 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4020 * @param subId The subscription to use to check the configuration.
4021 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004023 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004024 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4025 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004026 final long identity = Binder.clearCallingIdentity();
4027 try {
4028 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004029 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4030 } catch (ImsException e) {
4031 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 } finally {
4033 Binder.restoreCallingIdentity(identity);
4034 }
4035 }
4036
4037 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004038 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004040 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004044 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004045 } catch (ImsException e) {
4046 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004047 } finally {
4048 Binder.restoreCallingIdentity(identity);
4049 }
4050 }
4051
shilu366312e2019-12-17 09:28:10 -08004052 /**
4053 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4054 * @param subId The subscription to use to check the configuration.
4055 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 @Override
4057 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004058 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4059 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 final long identity = Binder.clearCallingIdentity();
4061 try {
4062 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004063 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004064 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004065 } catch (ImsException e) {
4066 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 } finally {
4068 Binder.restoreCallingIdentity(identity);
4069 }
4070 }
4071
4072 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004073 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004075 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 final long identity = Binder.clearCallingIdentity();
4077 try {
4078 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004079 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004080 } catch (ImsException e) {
4081 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 } finally {
4083 Binder.restoreCallingIdentity(identity);
4084 }
4085 }
4086
shilu366312e2019-12-17 09:28:10 -08004087 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004088 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4089 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4090 * @param subId The subscription to use to check the configuration.
4091 */
4092 @Override
4093 public boolean isCrossSimCallingEnabledByUser(int subId) {
4094 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4095 mApp, subId, "isCrossSimCallingEnabledByUser");
4096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4099 return ImsManager.getInstance(mApp,
4100 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4101 } catch (ImsException e) {
4102 throw new ServiceSpecificException(e.getCode());
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
4105 }
4106 }
4107
4108 /**
4109 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4110 * Requires MODIFY_PHONE_STATE permission.
4111 * @param subId The subscription to use to check the configuration.
4112 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4113 * false otherwise
4114 */
4115 @Override
4116 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4118 "setCrossSimCallingEnabled");
4119 final long identity = Binder.clearCallingIdentity();
4120 try {
4121 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4122 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4123 .setCrossSimCallingEnabled(isEnabled);
4124 } catch (ImsException e) {
4125 throw new ServiceSpecificException(e.getCode());
4126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
4129 }
4130
4131 /**
shilu366312e2019-12-17 09:28:10 -08004132 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4133 * @param subId The subscription to use to check the configuration.
4134 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 @Override
4136 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004137 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4138 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 final long identity = Binder.clearCallingIdentity();
4140 try {
4141 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004142 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004144 } catch (ImsException e) {
4145 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 } finally {
4147 Binder.restoreCallingIdentity(identity);
4148 }
4149 }
4150
4151 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004152 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004154 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 final long identity = Binder.clearCallingIdentity();
4156 try {
4157 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004158 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004160 } catch (ImsException e) {
4161 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 } finally {
4163 Binder.restoreCallingIdentity(identity);
4164 }
4165 }
4166
4167 @Override
4168 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4170 "setVoWiFiNonPersistent");
4171 final long identity = Binder.clearCallingIdentity();
4172 try {
4173 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004174 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004175 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004176 } catch (ImsException e) {
4177 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004178 } finally {
4179 Binder.restoreCallingIdentity(identity);
4180 }
4181 }
4182
shilu366312e2019-12-17 09:28:10 -08004183 /**
4184 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4185 * @param subId The subscription to use to check the configuration.
4186 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004187 @Override
4188 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004189 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4190 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 final long identity = Binder.clearCallingIdentity();
4192 try {
4193 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004194 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004196 } catch (ImsException e) {
4197 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 } finally {
4199 Binder.restoreCallingIdentity(identity);
4200 }
4201 }
4202
4203 @Override
4204 public void setVoWiFiModeSetting(int subId, int mode) {
4205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4206 "setVoWiFiModeSetting");
4207 final long identity = Binder.clearCallingIdentity();
4208 try {
4209 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004210 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004212 } catch (ImsException e) {
4213 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
4217 }
4218
4219 @Override
4220 public int getVoWiFiRoamingModeSetting(int subId) {
4221 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4222 final long identity = Binder.clearCallingIdentity();
4223 try {
4224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004225 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004226 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004227 } catch (ImsException e) {
4228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 } finally {
4230 Binder.restoreCallingIdentity(identity);
4231 }
4232 }
4233
4234 @Override
4235 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4237 "setVoWiFiRoamingModeSetting");
4238 final long identity = Binder.clearCallingIdentity();
4239 try {
4240 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004241 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004242 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004243 } catch (ImsException e) {
4244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
4248 }
4249
4250 @Override
4251 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4253 "setRttCapabilityEnabled");
4254 final long identity = Binder.clearCallingIdentity();
4255 try {
4256 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004257 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4258 } catch (ImsException e) {
4259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004260 } finally {
4261 Binder.restoreCallingIdentity(identity);
4262 }
4263 }
4264
shilu366312e2019-12-17 09:28:10 -08004265 /**
4266 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4267 * @param subId The subscription to use to check the configuration.
4268 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 @Override
4270 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004271 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4272 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 final long identity = Binder.clearCallingIdentity();
4274 try {
4275 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004276 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004277 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004278 } catch (ImsException e) {
4279 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
4283 }
4284
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004285 @Override
4286 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4287 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4288 final long identity = Binder.clearCallingIdentity();
4289 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004290 if (!isImsAvailableOnDevice()) {
4291 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4292 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004293 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004294 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004295 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004296 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004297 } catch (ImsException e) {
4298 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
4302 }
4303
4304 @Override
4305 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4306 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4307 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004308 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4309 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4310 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004311 try {
4312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004313 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004314 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004315 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004316 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4317 + "is inactive, ignoring unregister.");
4318 // If the subscription is no longer active, just return, since the callback will already
4319 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
allenwtsu99c623b2020-01-03 18:24:23 +08004325
4326 private void checkModifyPhoneStatePermission(int subId, String message) {
4327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4328 message);
4329 }
4330
4331 private boolean isImsProvisioningRequired(int subId, int capability,
4332 boolean isMmtelCapability) {
4333 Phone phone = getPhone(subId);
4334 if (phone == null) {
4335 loge("phone instance null for subid " + subId);
4336 return false;
4337 }
4338 if (isMmtelCapability) {
4339 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4340 return false;
4341 }
4342 } else {
4343 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4344 return false;
4345 }
4346 }
4347 return true;
4348 }
4349
4350 @Override
4351 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4352 boolean isProvisioned) {
4353 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4354
4355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4358 if (!isImsProvisioningRequired(subId, capability, false)) {
4359 return;
4360 }
4361
4362 // this capability requires provisioning, route to the correct API.
4363 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4364 switch (capability) {
4365 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4366 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4367 ims.setEabProvisioned(isProvisioned);
4368 break;
4369 default: {
4370 throw new IllegalArgumentException("Tried to set provisioning for "
4371 + "rcs capability '" + capability + "', which does not require "
4372 + "provisioning.");
4373 }
4374 }
4375 } finally {
4376 Binder.restoreCallingIdentity(identity);
4377 }
4378
4379 }
4380
4381
4382 @Override
4383 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4384 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4385 final long identity = Binder.clearCallingIdentity();
4386 try {
4387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4388 if (!isImsProvisioningRequired(subId, capability, false)) {
4389 return true;
4390 }
4391
4392 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4393 switch (capability) {
4394 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4395 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4396 return ims.isEabProvisionedOnDevice();
4397
4398 default: {
4399 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4400 + "capability '" + capability + "', which does not require "
4401 + "provisioning.");
4402 }
4403 }
4404
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
4407 }
4408 }
4409
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004410 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004411 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4412 boolean isProvisioned) {
4413 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4414 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4415 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4416 }
allenwtsu99c623b2020-01-03 18:24:23 +08004417 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004418 final long identity = Binder.clearCallingIdentity();
4419 try {
4420 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004421 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004422 return;
4423 }
4424
4425 // this capability requires provisioning, route to the correct API.
4426 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4427 switch (capability) {
4428 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4429 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4430 ims.setVolteProvisioned(isProvisioned);
4431 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4432 ims.setWfcProvisioned(isProvisioned);
4433 }
4434 break;
4435 }
4436 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4437 // There is currently no difference in VT provisioning type.
4438 ims.setVtProvisioned(isProvisioned);
4439 break;
4440 }
4441 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4442 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4443 // change the capability of the feature instead if needed.
4444 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4445 == isProvisioned) {
4446 // No change in provisioning.
4447 return;
4448 }
4449 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4450 try {
4451 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004452 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004453 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4454 + ", Exception" + e.getMessage());
4455 }
4456 break;
4457 }
4458 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004459 throw new IllegalArgumentException("Tried to set provisioning for "
4460 + "MmTel capability '" + capability + "', which does not require "
4461 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004462 }
4463 }
4464
4465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
4468 }
4469
4470 @Override
4471 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4472 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4473 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4474 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4475 }
4476 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4477 final long identity = Binder.clearCallingIdentity();
4478 try {
4479 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004480 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004481 return true;
4482 }
4483
4484 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4485 switch (capability) {
4486 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4487 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4488 return ims.isVolteProvisionedOnDevice();
4489 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4490 return ims.isWfcProvisionedOnDevice();
4491 }
4492 // This should never happen, since we are checking tech above to make sure it
4493 // is either LTE or IWLAN.
4494 throw new IllegalArgumentException("Invalid radio technology for voice "
4495 + "capability.");
4496 }
4497 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4498 // There is currently no difference in VT provisioning type.
4499 return ims.isVtProvisionedOnDevice();
4500 }
4501 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4502 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4503 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4504 }
4505 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004506 throw new IllegalArgumentException(
4507 "Tried to get provisioning for MmTel capability '" + capability
4508 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004509 }
4510 }
4511
4512 } finally {
4513 Binder.restoreCallingIdentity(identity);
4514 }
4515 }
4516
4517 @Override
4518 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4519 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4520 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4521 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4522 }
4523 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4524 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4525 return (provisionedBits & capability) > 0;
4526 }
4527
4528 @Override
4529 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4530 boolean isProvisioned) {
4531 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4532 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4533 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4534 }
4535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4536 "setProvisioningStatusForCapability");
4537 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4538 // If the current provisioning status for capability already matches isProvisioned,
4539 // do nothing.
4540 if (((provisionedBits & capability) > 0) == isProvisioned) {
4541 return;
4542 }
4543 if (isProvisioned) {
4544 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4545 } else {
4546 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4547 }
4548 }
4549
4550 /**
4551 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4552 * technology. The bitfield should mirror the bitfield defined by
4553 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4554 */
4555 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4556 String key = getMmTelProvisioningKey(subId, tech);
4557 // Default is no capabilities are provisioned.
4558 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4559 }
4560
4561 /**
4562 * Sets the MmTel capability provisioning bitfield (defined by
4563 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4564 * technology specified.
4565 *
4566 * Note: This is a synchronous command and should not be called on UI thread.
4567 */
4568 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4569 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4570 String key = getMmTelProvisioningKey(subId, tech);
4571 editor.putInt(key, newField);
4572 editor.commit();
4573 }
4574
4575 private static String getMmTelProvisioningKey(int subId, int tech) {
4576 // resulting key is provision_ims_mmtel_{subId}_{tech}
4577 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4578 }
4579
4580 /**
4581 * Query CarrierConfig to see if the specified capability requires provisioning for the
4582 * carrier associated with the subscription id.
4583 */
4584 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4585 int capability) {
4586 CarrierConfigManager configManager = new CarrierConfigManager(context);
4587 PersistableBundle c = configManager.getConfigForSubId(subId);
4588 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004589 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004590 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4591 false);
4592 boolean requireVoiceVtProvisioning = c.getBoolean(
4593 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4594
4595 // First check to make sure that the capability requires provisioning.
4596 switch (capability) {
4597 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4598 // intentional fallthrough
4599 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4600 if (requireVoiceVtProvisioning) {
4601 // Voice and Video requires provisioning
4602 return true;
4603 }
4604 break;
4605 }
4606 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4607 if (requireUtProvisioning) {
4608 // UT requires provisioning
4609 return true;
4610 }
4611 break;
4612 }
4613 }
4614 return false;
4615 }
4616
allenwtsu99c623b2020-01-03 18:24:23 +08004617 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4618 int capability) {
4619 CarrierConfigManager configManager = new CarrierConfigManager(context);
4620 PersistableBundle c = configManager.getConfigForSubId(subId);
4621
4622 boolean requireRcsProvisioning = c.getBoolean(
4623 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4624
4625 // First check to make sure that the capability requires provisioning.
4626 switch (capability) {
4627 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4628 // intentional fallthrough
4629 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4630 if (requireRcsProvisioning) {
4631 // OPTION or PRESENCE requires provisioning
4632 return true;
4633 }
4634 break;
4635 }
4636 }
4637 return false;
4638 }
4639
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004640 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004641 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004642 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4643 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4644 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004645 enforceReadPrivilegedPermission("getImsProvisioningInt");
4646 final long identity = Binder.clearCallingIdentity();
4647 try {
4648 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004649 int slotId = getSlotIndex(subId);
4650 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4651 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4652 + subId + "' for key:" + key);
4653 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4654 }
calvinpanb5a34062021-02-08 19:59:36 +08004655 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004656 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4658 + subId + "' for key:" + key);
4659 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004660 } finally {
4661 Binder.restoreCallingIdentity(identity);
4662 }
4663 }
4664
4665 @Override
4666 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004667 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4668 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4669 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004670 enforceReadPrivilegedPermission("getImsProvisioningString");
4671 final long identity = Binder.clearCallingIdentity();
4672 try {
4673 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004674 int slotId = getSlotIndex(subId);
4675 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4676 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4677 + subId + "' for key:" + key);
4678 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4679 }
calvinpanb5a34062021-02-08 19:59:36 +08004680 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004681 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004682 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4683 + subId + "' for key:" + key);
4684 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004685 } finally {
4686 Binder.restoreCallingIdentity(identity);
4687 }
4688 }
4689
4690 @Override
4691 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4693 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4694 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4696 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004697 final long identity = Binder.clearCallingIdentity();
4698 try {
4699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004700 int slotId = getSlotIndex(subId);
4701 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4702 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4703 + subId + "' for key:" + key);
4704 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4705 }
calvinpanb5a34062021-02-08 19:59:36 +08004706 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4707 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004709 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004710 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004711 } finally {
4712 Binder.restoreCallingIdentity(identity);
4713 }
4714 }
4715
4716 @Override
4717 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004718 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4719 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4720 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4722 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004723 final long identity = Binder.clearCallingIdentity();
4724 try {
4725 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 int slotId = getSlotIndex(subId);
4727 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4728 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4729 + subId + "' for key:" + key);
4730 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4731 }
calvinpanb5a34062021-02-08 19:59:36 +08004732 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4733 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004735 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004736 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004737 } finally {
4738 Binder.restoreCallingIdentity(identity);
4739 }
4740 }
4741
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004742 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004743 int slotId = SubscriptionManager.getSlotIndex(subId);
4744 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004745 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4746 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004747 }
4748 return slotId;
4749 }
4750
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004751 private int getSlotIndex(int subId) {
4752 int slotId = SubscriptionManager.getSlotIndex(subId);
4753 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4754 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4755 }
4756 return slotId;
4757 }
4758
Wink Saville36469e72014-06-11 15:17:00 -07004759 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004760 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004761 */
4762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004763 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4764 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004765 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004766 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004767 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004768 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004769 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004770 mApp, subId, callingPackage, callingFeatureId,
4771 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004772 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4773 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004775 final long identity = Binder.clearCallingIdentity();
4776 try {
4777 final Phone phone = getPhone(subId);
4778 if (phone != null) {
4779 return phone.getServiceState().getDataNetworkType();
4780 } else {
4781 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4782 }
4783 } finally {
4784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004786 }
4787
4788 /**
4789 * Returns the data network type
4790 */
4791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004792 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4793 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4794 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004795 }
4796
4797 /**
4798 * Returns the data network type for a subId
4799 */
4800 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004801 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4802 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004804 mApp, subId, callingPackage, callingFeatureId,
4805 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004806 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4807 }
4808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 final long identity = Binder.clearCallingIdentity();
4810 try {
4811 final Phone phone = getPhone(subId);
4812 if (phone != null) {
4813 return phone.getServiceState().getDataNetworkType();
4814 } else {
4815 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4816 }
4817 } finally {
4818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004820 }
4821
4822 /**
Wink Saville36469e72014-06-11 15:17:00 -07004823 * Returns the Voice network type for a subId
4824 */
4825 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004826 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4827 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004828 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004829 mApp, subId, callingPackage, callingFeatureId,
4830 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004831 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4832 }
4833
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834 final long identity = Binder.clearCallingIdentity();
4835 try {
4836 final Phone phone = getPhone(subId);
4837 if (phone != null) {
4838 return phone.getServiceState().getVoiceNetworkType();
4839 } else {
4840 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4841 }
4842 } finally {
4843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004845 }
4846
4847 /**
4848 * @return true if a ICC card is present
4849 */
4850 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004851 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004852 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4853 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004854 }
4855
4856 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004857 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004858 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004859 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004860 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 final Phone phone = PhoneFactory.getPhone(slotIndex);
4864 if (phone != null) {
4865 return phone.getIccCard().hasIccCard();
4866 } else {
4867 return false;
4868 }
4869 } finally {
4870 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004872 }
4873
4874 /**
4875 * Return if the current radio is LTE on CDMA. This
4876 * is a tri-state return value as for a period of time
4877 * the mode may be unknown.
4878 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004879 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004880 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004881 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004882 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004883 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004884 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4885 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4886 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004887 }
4888
Sanket Padawe356d7632015-06-22 14:03:32 -07004889 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004890 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4891 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004892 try {
4893 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4894 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004895 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4896 }
4897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898 final long identity = Binder.clearCallingIdentity();
4899 try {
4900 final Phone phone = getPhone(subId);
4901 if (phone == null) {
4902 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4903 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004904 return TelephonyProperties.lte_on_cdma_device()
4905 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 }
4907 } finally {
4908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004909 }
Wink Saville36469e72014-06-11 15:17:00 -07004910 }
4911
Wink Saville36469e72014-06-11 15:17:00 -07004912 /**
4913 * {@hide}
4914 * Returns Default subId, 0 in the case of single standby.
4915 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004916 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004917 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004918 }
4919
Shishir Agrawala9f32182016-04-12 12:00:16 -07004920 private int getSlotForDefaultSubscription() {
4921 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4922 }
4923
Wink Savilleb564aae2014-10-23 10:18:09 -07004924 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004925 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004926 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004927
Pengquan Menge92a50d2018-09-21 15:54:48 -07004928 private boolean isActiveSubscription(int subId) {
4929 return mSubscriptionController.isActiveSubId(subId);
4930 }
4931
Ihab Awadf2177b72013-11-25 13:33:23 -08004932 /**
4933 * @see android.telephony.TelephonyManager.WifiCallingChoices
4934 */
4935 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 final long identity = Binder.clearCallingIdentity();
4937 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004938 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4940 getWhenToMakeWifiCallsDefaultPreference());
4941 } finally {
4942 Binder.restoreCallingIdentity(identity);
4943 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004944 }
4945
4946 /**
4947 * @see android.telephony.TelephonyManager.WifiCallingChoices
4948 */
4949 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 final long identity = Binder.clearCallingIdentity();
4951 try {
4952 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004953 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4955 } finally {
4956 Binder.restoreCallingIdentity(identity);
4957 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004958 }
4959
Sailesh Nepald1e68152013-12-12 19:08:02 -08004960 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004961 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004962 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004963 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004964
Jordan Liu4c733742019-02-28 12:03:40 -08004965 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4966 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4967 if (phoneId == -1) {
4968 throw new IllegalArgumentException("Given slot index: " + slotIndex
4969 + " does not correspond to an active phone");
4970 }
4971 return PhoneFactory.getPhone(phoneId);
4972 }
4973
Shishir Agrawal566b7612013-10-28 14:41:00 -07004974 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004975 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4976 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4978 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004979 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004980 if (DBG) {
4981 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4982 }
4983 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4984 p2);
4985 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004986
Jordan Liu4c733742019-02-28 12:03:40 -08004987
4988 @Override
4989 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4990 int slotIndex, String callingPackage, String aid, int p2) {
4991 enforceModifyPermission();
4992 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4993 if (DBG) {
4994 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4995 }
4996 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4997 callingPackage, aid, p2);
4998 }
4999
5000 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5001 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 final long identity = Binder.clearCallingIdentity();
5003 try {
5004 if (TextUtils.equals(ISDR_AID, aid)) {
5005 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005006 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5007 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008 if (bestComponent == null
5009 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5010 loge("The calling package is not allowed to access ISD-R.");
5011 throw new SecurityException(
5012 "The calling package is not allowed to access ISD-R.");
5013 }
Derek Tan740e1672017-06-27 14:56:27 -07005014 }
Derek Tan740e1672017-06-27 14:56:27 -07005015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005017 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5018 null /* workSource */);
5019 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 return response;
5021 } finally {
5022 Binder.restoreCallingIdentity(identity);
5023 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005024 }
5025
5026 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005027 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5029 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005030 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5031 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5032 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005033
Jordan Liu4c733742019-02-28 12:03:40 -08005034 @Override
5035 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5036 enforceModifyPermission();
5037 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5038 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5039 channel);
5040 }
5041
5042 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 final long identity = Binder.clearCallingIdentity();
5044 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 if (channel < 0) {
5046 return false;
5047 }
Jordan Liu4c733742019-02-28 12:03:40 -08005048 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5049 null /* workSource */);
5050 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051 return success;
5052 } finally {
5053 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005054 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005055 }
5056
5057 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005058 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005059 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5061 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005062 if (DBG) {
5063 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5064 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5065 + p3 + " data=" + data);
5066 }
5067 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5068 command, p1, p2, p3, data);
5069 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005070
Jordan Liu4c733742019-02-28 12:03:40 -08005071 @Override
5072 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5073 int command, int p1, int p2, int p3, String data) {
5074 enforceModifyPermission();
5075 if (DBG) {
5076 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5077 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5078 + p3 + " data=" + data);
5079 }
5080 return iccTransmitApduLogicalChannelWithPermission(
5081 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5082 data);
5083 }
5084
5085 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5086 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005089 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 return "";
5091 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005093 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005094 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5095 null /* workSource */);
5096 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 // Append the returned status code to the end of the response payload.
5099 String s = Integer.toHexString(
5100 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5101 if (response.payload != null) {
5102 s = IccUtils.bytesToHexString(response.payload) + s;
5103 }
5104 return s;
5105 } finally {
5106 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005107 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005108 }
Jake Hambye994d462014-02-03 13:10:13 -08005109
Evan Charltonc66da362014-05-16 14:06:40 -07005110 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005111 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5112 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5114 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005116 if (DBG) {
5117 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5118 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5119 }
5120 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5121 cla, command, p1, p2, p3, data);
5122 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005123
Jordan Liu4c733742019-02-28 12:03:40 -08005124 @Override
5125 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5126 int command, int p1, int p2, int p3, String data) {
5127 enforceModifyPermission();
5128 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5129 if (DBG) {
5130 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5131 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5132 + " data=" + data);
5133 }
5134
5135 return iccTransmitApduBasicChannelWithPermission(
5136 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5137 p2, p3, data);
5138 }
5139
5140 // open APDU basic channel assuming the caller has sufficient permissions
5141 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5142 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5146 && TextUtils.equals(ISDR_AID, data)) {
5147 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005148 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5149 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 if (bestComponent == null
5151 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5152 loge("The calling package is not allowed to select ISD-R.");
5153 throw new SecurityException(
5154 "The calling package is not allowed to select ISD-R.");
5155 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005156 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005159 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5160 null /* workSource */);
5161 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 // Append the returned status code to the end of the response payload.
5164 String s = Integer.toHexString(
5165 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5166 if (response.payload != null) {
5167 s = IccUtils.bytesToHexString(response.payload) + s;
5168 }
5169 return s;
5170 } finally {
5171 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005172 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005173 }
5174
5175 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005176 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005177 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5179 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 final long identity = Binder.clearCallingIdentity();
5182 try {
5183 if (DBG) {
5184 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5185 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5186 }
5187
5188 IccIoResult response =
5189 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5190 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5191 subId);
5192
5193 if (DBG) {
5194 log("Exchange SIM_IO [R]" + response);
5195 }
5196
5197 byte[] result = null;
5198 int length = 2;
5199 if (response.payload != null) {
5200 length = 2 + response.payload.length;
5201 result = new byte[length];
5202 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5203 } else {
5204 result = new byte[length];
5205 }
5206
5207 result[length - 1] = (byte) response.sw2;
5208 result[length - 2] = (byte) response.sw1;
5209 return result;
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005212 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005213 }
5214
Nathan Haroldb3014052017-01-25 15:57:32 -08005215 /**
5216 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5217 * on a particular subscription
5218 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005219 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5220 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005222 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005223 return null;
5224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225
5226 final long identity = Binder.clearCallingIdentity();
5227 try {
5228 if (appType != TelephonyManager.APPTYPE_USIM
5229 && appType != TelephonyManager.APPTYPE_SIM) {
5230 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5231 return null;
5232 }
5233 Object response = sendRequest(
5234 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5235 if (response instanceof String[]) {
5236 return (String[]) response;
5237 }
yincheng zhao2737e882019-09-06 17:06:54 -07005238 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005240 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 } finally {
5242 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005243 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005244 }
5245
yincheng zhao2737e882019-09-06 17:06:54 -07005246 /**
5247 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5248 * subscription.
5249 *
5250 * @param subId the id of the subscription.
5251 * @param appType the uicc app type, must be USIM or SIM.
5252 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5253 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005254 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005255 * @return number of fplmns that is successfully written to the SIM.
5256 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005257 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5258 String callingFeatureId) {
5259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5260 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005261 if (DBG) logv("no permissions for setForbiddenplmns");
5262 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5263 }
5264 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5265 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5266 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5267 }
5268 if (fplmns == null) {
5269 throw new IllegalArgumentException("Fplmn List provided is null");
5270 }
5271 for (String fplmn : fplmns) {
5272 if (!CellIdentity.isValidPlmn(fplmn)) {
5273 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5274 }
5275 }
5276 final long identity = Binder.clearCallingIdentity();
5277 try {
5278 Object response = sendRequest(
5279 CMD_SET_FORBIDDEN_PLMNS,
5280 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5281 subId);
5282 return (int) response;
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
5286 }
5287
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005288 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005289 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5291 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 final long identity = Binder.clearCallingIdentity();
5294 try {
5295 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5296 if (response.payload == null) {
5297 return "";
5298 }
Evan Charltonc66da362014-05-16 14:06:40 -07005299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 // Append the returned status code to the end of the response payload.
5301 String s = Integer.toHexString(
5302 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5303 s = IccUtils.bytesToHexString(response.payload) + s;
5304 return s;
5305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
Evan Charltonc66da362014-05-16 14:06:40 -07005308 }
5309
Jake Hambye994d462014-02-03 13:10:13 -08005310 /**
5311 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5312 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5313 *
5314 * @param itemID the ID of the item to read
5315 * @return the NV item as a String, or null on error.
5316 */
5317 @Override
5318 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5321 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322
5323 final long identity = Binder.clearCallingIdentity();
5324 try {
5325 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005326 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5328 return value;
5329 } finally {
5330 Binder.restoreCallingIdentity(identity);
5331 }
Jake Hambye994d462014-02-03 13:10:13 -08005332 }
5333
5334 /**
5335 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5336 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5337 *
5338 * @param itemID the ID of the item to read
5339 * @param itemValue the value to write, as a String
5340 * @return true on success; false on any failure
5341 */
5342 @Override
5343 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5346 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347
5348 final long identity = Binder.clearCallingIdentity();
5349 try {
5350 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5351 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005352 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5354 return success;
5355 } finally {
5356 Binder.restoreCallingIdentity(identity);
5357 }
Jake Hambye994d462014-02-03 13:10:13 -08005358 }
5359
5360 /**
5361 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5362 * Used for device configuration by some CDMA operators.
5363 *
5364 * @param preferredRoamingList byte array containing the new PRL
5365 * @return true on success; false on any failure
5366 */
5367 @Override
5368 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5370 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371
5372 final long identity = Binder.clearCallingIdentity();
5373 try {
5374 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5375 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5376 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5377 return success;
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
5380 }
Jake Hambye994d462014-02-03 13:10:13 -08005381 }
5382
5383 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005384 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005385 * Used for device configuration by some CDMA operators.
5386 *
chen xu6dac5ab2018-10-26 17:39:23 -07005387 * @param slotIndex - device slot.
5388 *
Jake Hambye994d462014-02-03 13:10:13 -08005389 * @return true on success; false on any failure
5390 */
5391 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005392 public boolean resetModemConfig(int slotIndex) {
5393 Phone phone = PhoneFactory.getPhone(slotIndex);
5394 if (phone != null) {
5395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5396 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397
chen xu6dac5ab2018-10-26 17:39:23 -07005398 final long identity = Binder.clearCallingIdentity();
5399 try {
5400 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5401 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5402 return success;
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
5405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 }
chen xu6dac5ab2018-10-26 17:39:23 -07005407 return false;
5408 }
5409
5410 /**
5411 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5412 *
5413 * @param slotIndex - device slot.
5414 *
5415 * @return true on success; false on any failure
5416 */
5417 @Override
5418 public boolean rebootModem(int slotIndex) {
5419 Phone phone = PhoneFactory.getPhone(slotIndex);
5420 if (phone != null) {
5421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5422 mApp, phone.getSubId(), "rebootModem");
5423
5424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5427 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5428 return success;
5429 } finally {
5430 Binder.restoreCallingIdentity(identity);
5431 }
5432 }
5433 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005434 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005435
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005436 public String[] getPcscfAddress(String apnType, String callingPackage,
5437 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005438 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5440 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005441 return new String[0];
5442 }
5443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444 final long identity = Binder.clearCallingIdentity();
5445 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005446 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
Wink Saville36469e72014-06-11 15:17:00 -07005450 }
5451
Brad Ebinger51f743a2017-01-23 13:50:20 -08005452 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005453 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5454 * {@link #disableIms(int)}.
5455 * @param slotIndex device slot.
5456 */
5457 public void resetIms(int slotIndex) {
5458 enforceModifyPermission();
5459
5460 final long identity = Binder.clearCallingIdentity();
5461 try {
5462 if (mImsResolver == null) {
5463 // may happen if the does not support IMS.
5464 return;
5465 }
5466 mImsResolver.disableIms(slotIndex);
5467 mImsResolver.enableIms(slotIndex);
5468 } finally {
5469 Binder.restoreCallingIdentity(identity);
5470 }
5471 }
5472
5473 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005474 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5475 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005476 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005477 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005478 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479
5480 final long identity = Binder.clearCallingIdentity();
5481 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005482 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005483 // may happen if the device does not support IMS.
5484 return;
5485 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005486 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 } finally {
5488 Binder.restoreCallingIdentity(identity);
5489 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005490 }
5491
5492 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005493 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5494 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005495 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005496 public void disableIms(int slotId) {
5497 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498
5499 final long identity = Binder.clearCallingIdentity();
5500 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005501 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005502 // may happen if the device does not support IMS.
5503 return;
5504 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005505 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 } finally {
5507 Binder.restoreCallingIdentity(identity);
5508 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005509 }
5510
5511 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005512 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5513 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005514 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005515 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005516 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005517 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518
5519 final long identity = Binder.clearCallingIdentity();
5520 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005521 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005522 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5523 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005524 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005525 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 } finally {
5527 Binder.restoreCallingIdentity(identity);
5528 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005529 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005530 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005531 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5532 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005533 @Override
5534 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005535 enforceModifyPermission();
5536
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
5539 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005540 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
5544 }
5545
5546 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005547 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005548 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005549 */
5550 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5551 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005552
5553 final long identity = Binder.clearCallingIdentity();
5554 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005555 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005556 // may happen if the device does not support IMS.
5557 return null;
5558 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005559 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005563 }
5564
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005565 /**
5566 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005567 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005568 */
5569 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005571
5572 final long identity = Binder.clearCallingIdentity();
5573 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005574 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005575 // may happen if the device does not support IMS.
5576 return null;
5577 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005578 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 } finally {
5580 Binder.restoreCallingIdentity(identity);
5581 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005582 }
5583
Brad Ebinger884c07b2018-02-15 16:17:40 -08005584 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005585 * Sets the ImsService Package Name that Telephony will bind to.
5586 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005587 * @param slotIndex the slot ID that the ImsService should bind for.
5588 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005589 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005590 * @param featureTypes An integer array of feature types associated with a packageName.
5591 * @param packageName The name of the package that the current configuration will be replaced
5592 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005593 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005594 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005595 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5596 int[] featureTypes, String packageName) {
5597 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5598 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5600 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005601 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 final long identity = Binder.clearCallingIdentity();
5604 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005605 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005606 // may happen if the device does not support IMS.
5607 return false;
5608 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005609 Map<Integer, String> featureConfig = new HashMap<>();
5610 for (int featureType : featureTypes) {
5611 featureConfig.put(featureType, packageName);
5612 }
5613 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5614 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 } finally {
5616 Binder.restoreCallingIdentity(identity);
5617 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005618 }
5619
5620 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005621 * Clears any carrier ImsService overrides for the slot index specified that were previously
5622 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5623 *
5624 * This should only be used for testing.
5625 *
5626 * @param slotIndex the slot ID that the ImsService should bind for.
5627 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5628 */
5629 @Override
5630 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5631 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5632 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5633 "clearCarrierImsServiceOverride");
5634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5635 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5636 "clearCarrierImsServiceOverride");
5637
5638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 if (mImsResolver == null) {
5641 // may happen if the device does not support IMS.
5642 return false;
5643 }
5644 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
5648 }
5649
5650 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005651 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005652 *
5653 * @param slotId The slot that the ImsService is associated with.
5654 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5655 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005656 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005657 * @return the package name of the ImsService configuration.
5658 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005659 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5660 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005661 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005662 TelephonyPermissions
5663 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5664 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5665 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 final long identity = Binder.clearCallingIdentity();
5668 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005669 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005670 // may happen if the device does not support IMS.
5671 return "";
5672 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005673 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005674 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5675 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 } finally {
5677 Binder.restoreCallingIdentity(identity);
5678 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005679 }
5680
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005681 /**
5682 * Get the MmTelFeature state associated with the requested subscription id.
5683 * @param subId The subscription that the MmTelFeature is associated with.
5684 * @param callback A callback with an integer containing the
5685 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5686 */
5687 @Override
5688 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5689 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5690 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5691 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5692 "IMS not available on device.");
5693 }
5694 final long token = Binder.clearCallingIdentity();
5695 try {
5696 int slotId = getSlotIndex(subId);
5697 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5698 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5699 + subId + "'");
5700 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5701 }
5702 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5703 try {
5704 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5705 } catch (RemoteException e) {
5706 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5707 + "Ignore");
5708 }
5709 });
5710 } finally {
5711 Binder.restoreCallingIdentity(token);
5712 }
5713 }
5714
Daniel Brightbb5840b2021-01-12 15:48:18 -08005715 /**
5716 * Sets the ims registration state on all valid {@link Phone}s.
5717 */
5718 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005719 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720
5721 final long identity = Binder.clearCallingIdentity();
5722 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005723 // NOTE: Before S, this method only set the default phone.
5724 for (final Phone phone : PhoneFactory.getPhones()) {
5725 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5726 phone.setImsRegistrationState(registered);
5727 }
5728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Wink Saville36469e72014-06-11 15:17:00 -07005732 }
5733
5734 /**
Stuart Scott54788802015-03-30 13:18:01 -07005735 * Set the network selection mode to automatic.
5736 *
5737 */
5738 @Override
5739 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5741 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742
5743 final long identity = Binder.clearCallingIdentity();
5744 try {
shilufc958392020-01-20 11:36:01 -08005745 if (!isActiveSubscription(subId)) {
5746 return;
5747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005749 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5750 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 } finally {
5752 Binder.restoreCallingIdentity(identity);
5753 }
Stuart Scott54788802015-03-30 13:18:01 -07005754 }
5755
Jack Yud10cdd42020-09-28 20:28:01 -07005756 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005757 * Ask the radio to connect to the input network and change selection mode to manual.
5758 *
5759 * @param subId the id of the subscription.
5760 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5761 * the operator to attach to.
5762 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5763 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5764 * normal network selection next time.
5765 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005766 */
5767 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005768 public boolean setNetworkSelectionModeManual(
5769 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5771 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005772
5773 if (!isActiveSubscription(subId)) {
5774 return false;
5775 }
5776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 final long identity = Binder.clearCallingIdentity();
5778 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005779 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005781 if (DBG) {
5782 log("setNetworkSelectionModeManual: subId: " + subId
5783 + " operator: " + operatorInfo);
5784 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005789 }
shilu84f6e8b2019-12-19 13:58:01 -08005790 /**
5791 * Get the manual network selection
5792 *
5793 * @param subId the id of the subscription.
5794 *
5795 * @return the previously saved user selected PLMN
5796 */
5797 @Override
5798 public String getManualNetworkSelectionPlmn(int subId) {
5799 TelephonyPermissions
5800 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5801 mApp, subId, "getManualNetworkSelectionPlmn");
5802
5803 final long identity = Binder.clearCallingIdentity();
5804 try {
5805 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005806 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005807 }
5808
5809 final Phone phone = getPhone(subId);
5810 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005811 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005812 }
5813 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5814 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5815 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5816 } finally {
5817 Binder.restoreCallingIdentity(identity);
5818 }
5819 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005820
5821 /**
5822 * Scans for available networks.
5823 */
5824 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005825 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5826 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5828 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005829 LocationAccessPolicy.LocationPermissionResult locationResult =
5830 LocationAccessPolicy.checkLocationPermission(mApp,
5831 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5832 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005833 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005834 .setCallingPid(Binder.getCallingPid())
5835 .setCallingUid(Binder.getCallingUid())
5836 .setMethod("getCellNetworkScanResults")
5837 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005838 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5839 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005840 .build());
5841 switch (locationResult) {
5842 case DENIED_HARD:
5843 throw new SecurityException("Not allowed to access scan results -- location");
5844 case DENIED_SOFT:
5845 return null;
5846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847
Pengquan Menga1bb6272018-09-06 09:59:22 -07005848 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005849 try {
5850 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005851 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853 } finally {
5854 Binder.restoreCallingIdentity(identity);
5855 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005856 }
5857
5858 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005859 * Get the call forwarding info, given the call forwarding reason.
5860 */
5861 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005862 public void getCallForwarding(int subId, int callForwardingReason,
5863 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005864 enforceReadPrivilegedPermission("getCallForwarding");
5865 long identity = Binder.clearCallingIdentity();
5866 try {
5867 if (DBG) {
5868 log("getCallForwarding: subId " + subId
5869 + " callForwardingReason" + callForwardingReason);
5870 }
Hall Liu27d24262020-09-18 19:04:59 -07005871
5872 Phone phone = getPhone(subId);
5873 if (phone == null) {
5874 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005875 callback.onError(
5876 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005877 } catch (RemoteException e) {
5878 // ignore
5879 }
5880 return;
5881 }
5882
5883 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5884 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5885 @Override
5886 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5887 try {
5888 callback.onCallForwardingInfoAvailable(info);
5889 } catch (RemoteException e) {
5890 // ignore
5891 }
5892 }
5893
5894 @Override
5895 public void onError(int error) {
5896 try {
5897 callback.onError(error);
5898 } catch (RemoteException e) {
5899 // ignore
5900 }
5901 }
5902 });
5903 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005904 } finally {
5905 Binder.restoreCallingIdentity(identity);
5906 }
5907 }
5908
5909 /**
5910 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5911 * reason, the number to forward, and the timeout before the forwarding is attempted.
5912 */
5913 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005914 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5915 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005916 enforceModifyPermission();
5917 long identity = Binder.clearCallingIdentity();
5918 try {
5919 if (DBG) {
5920 log("setCallForwarding: subId " + subId
5921 + " callForwardingInfo" + callForwardingInfo);
5922 }
Hall Liu27d24262020-09-18 19:04:59 -07005923
5924 Phone phone = getPhone(subId);
5925 if (phone == null) {
5926 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005927 callback.accept(
5928 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005929 } catch (RemoteException e) {
5930 // ignore
5931 }
5932 return;
5933 }
5934
5935 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5936 FunctionalUtils.ignoreRemoteException(callback::accept));
5937
5938 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005939 } finally {
5940 Binder.restoreCallingIdentity(identity);
5941 }
5942 }
5943
5944 /**
Hall Liu27d24262020-09-18 19:04:59 -07005945 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005946 */
5947 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005948 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005949 enforceReadPrivilegedPermission("getCallForwarding");
5950 long identity = Binder.clearCallingIdentity();
5951 try {
Hall Liu27d24262020-09-18 19:04:59 -07005952
5953 Phone phone = getPhone(subId);
5954 if (phone == null) {
5955 try {
5956 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5957 } catch (RemoteException e) {
5958 // ignore
5959 }
5960 return;
5961 }
5962
5963 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5964
Shuo Qian4a594052020-01-23 11:59:30 -08005965 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005966 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
5970 }
5971
5972 /**
Hall Liu27d24262020-09-18 19:04:59 -07005973 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005974 */
5975 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005976 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005977 enforceModifyPermission();
5978 long identity = Binder.clearCallingIdentity();
5979 try {
Hall Liu27d24262020-09-18 19:04:59 -07005980 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5981
5982 Phone phone = getPhone(subId);
5983 if (phone == null) {
5984 try {
5985 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5986 } catch (RemoteException e) {
5987 // ignore
5988 }
5989 return;
5990 }
5991
5992 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5993 FunctionalUtils.ignoreRemoteException(callback::accept));
5994
5995 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005996 } finally {
5997 Binder.restoreCallingIdentity(identity);
5998 }
5999 }
6000
6001 /**
yinxub1bed742017-04-17 11:45:04 -07006002 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006003 *
yinxub1bed742017-04-17 11:45:04 -07006004 * @param subId id of the subscription
6005 * @param request contains the radio access networks with bands/channels to scan
6006 * @param messenger callback messenger for scan results or errors
6007 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006008 * @return the id of the requested scan which can be used to stop the scan.
6009 */
6010 @Override
6011 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006012 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6014 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006015 LocationAccessPolicy.LocationPermissionResult locationResult =
6016 LocationAccessPolicy.checkLocationPermission(mApp,
6017 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6018 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006019 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006020 .setCallingPid(Binder.getCallingPid())
6021 .setCallingUid(Binder.getCallingUid())
6022 .setMethod("requestNetworkScan")
6023 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006024 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6025 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006026 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006027 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006028 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6029 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006030 if (e != null) {
6031 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6032 throw e;
6033 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006034 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006035 return TelephonyScanManager.INVALID_SCAN_ID;
6036 }
6037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 }
Hall Liu912dfd32019-04-25 14:02:26 -07006039 int callingUid = Binder.getCallingUid();
6040 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006041 final long identity = Binder.clearCallingIdentity();
6042 try {
6043 return mNetworkScanRequestTracker.startNetworkScan(
6044 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006045 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006046 } finally {
6047 Binder.restoreCallingIdentity(identity);
6048 }
yinxu504e1392017-04-12 16:03:22 -07006049 }
6050
Hall Liub2ac8ef2019-02-28 15:56:23 -08006051 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006052 NetworkScanRequest request, int subId, String callingPackage) {
6053 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006054 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6055 boolean hasNetworkScanPermission =
6056 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6057 == PERMISSION_GRANTED;
6058
6059 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6060 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6061 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006062 }
6063
6064 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6065 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006066 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6067 return new SecurityException("Specific channels must not be"
6068 + " scanned without location access.");
6069 }
6070 }
6071 }
6072
Hall Liub2ac8ef2019-02-28 15:56:23 -08006073 return null;
6074 }
6075
yinxu504e1392017-04-12 16:03:22 -07006076 /**
6077 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006078 *
6079 * @param subId id of the subscription
6080 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006081 */
6082 @Override
6083 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6085 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086
Hall Liu912dfd32019-04-25 14:02:26 -07006087 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 final long identity = Binder.clearCallingIdentity();
6089 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006090 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 } finally {
6092 Binder.restoreCallingIdentity(identity);
6093 }
yinxu504e1392017-04-12 16:03:22 -07006094 }
6095
6096 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006097 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006098 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006099 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006100 */
6101 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006102 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006103 TelephonyPermissions
6104 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006105 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106
6107 final long identity = Binder.clearCallingIdentity();
6108 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006109 if (DBG) log("getAllowedNetworkTypesBitmask");
6110 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6111 int networkTypesBitmask = (result != null ? result[0] : -1);
6112 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6113 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114 } finally {
6115 Binder.restoreCallingIdentity(identity);
6116 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006117 }
6118
6119 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006120 * Get the allowed network types for certain reason.
6121 *
6122 * @param subId the id of the subscription.
6123 * @param reason the reason the allowed network type change is taking place
6124 * @return the allowed network types.
6125 */
6126 @Override
6127 public long getAllowedNetworkTypesForReason(int subId,
6128 @TelephonyManager.AllowedNetworkTypesReason int reason) {
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006129 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6130 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006131 final long identity = Binder.clearCallingIdentity();
6132 try {
6133 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
6137 }
6138
6139 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006140 * Enable/Disable E-UTRA-NR Dual Connectivity
6141 * @param subId subscription id of the sim card
6142 * @param nrDualConnectivityState expected NR dual connectivity state
6143 * This can be passed following states
6144 * <ol>
6145 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6146 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6147 * <li>Disable NR dual connectivity and force secondary cell to be released
6148 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6149 * </ol>
6150 * @return operation result.
6151 */
6152 @Override
6153 public int setNrDualConnectivityState(int subId,
6154 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6156 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006157 if (isRadioInterfaceCapabilitySupported(
6158 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6159 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6160 }
6161
Sooraj Sasindran37444802020-08-11 10:40:43 -07006162 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6163 final long identity = Binder.clearCallingIdentity();
6164 try {
6165 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6166 nrDualConnectivityState, subId,
6167 workSource);
6168 if (DBG) log("enableNRDualConnectivity result: " + result);
6169 return result;
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
6173 }
6174
6175 /**
6176 * Is E-UTRA-NR Dual Connectivity enabled
6177 * @return true if dual connectivity is enabled else false
6178 */
6179 @Override
6180 public boolean isNrDualConnectivityEnabled(int subId) {
6181 TelephonyPermissions
6182 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6183 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006184 if (isRadioInterfaceCapabilitySupported(
6185 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6186 return false;
6187 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006188 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6192 null, subId, workSource);
6193 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6194 return isEnabled;
6195 } finally {
6196 Binder.restoreCallingIdentity(identity);
6197 }
6198 }
6199
6200 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006201 * get carrier bandwidth per primary and secondary carrier
6202 * @param subId subscription id of the sim card
6203 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6204 */
6205 @Override
6206 public CarrierBandwidth getCarrierBandwidth(int subId) {
6207 TelephonyPermissions
6208 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6209 mApp, subId, "isNRDualConnectivityEnabled");
6210 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6211 final long identity = Binder.clearCallingIdentity();
6212 try {
6213 CarrierBandwidth carrierBandwidth =
6214 getPhoneFromSubId(subId).getCarrierBandwidth();
6215 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6216 return carrierBandwidth;
6217 } finally {
6218 Binder.restoreCallingIdentity(identity);
6219 }
6220 }
6221
6222 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006223 * Set the allowed network types of the device and
6224 * provide the reason triggering the allowed network change.
6225 *
6226 * @param subId the id of the subscription.
6227 * @param reason the reason the allowed network type change is taking place
6228 * @param allowedNetworkTypes the allowed network types.
6229 * @return true on success; false on any failure.
6230 */
6231 @Override
6232 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006233 @TelephonyManager.AllowedNetworkTypesReason int reason,
6234 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6236 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006237 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6238 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6239 return false;
6240 }
6241
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006242 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6243 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6244
6245
6246 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6247 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6248 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006249 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006250
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006251 final long identity = Binder.clearCallingIdentity();
6252 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006253 Boolean success = (Boolean) sendRequest(
6254 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6255 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6256
6257 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6258 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006259 } finally {
6260 Binder.restoreCallingIdentity(identity);
6261 }
6262 }
6263
6264 /**
Miaoa84611c2019-03-15 09:21:10 +08006265 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006266 *
Miaoa84611c2019-03-15 09:21:10 +08006267 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006268 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006269 * @hide
6270 */
6271 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006272 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006273 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006275 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276 try {
Miaoa84611c2019-03-15 09:21:10 +08006277 if (phone != null) {
6278 return phone.hasMatchedTetherApnSetting();
6279 } else {
6280 return false;
6281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 } finally {
6283 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006284 }
Junda Liu475951f2014-11-07 16:45:03 -08006285 }
6286
6287 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006288 * Enable or disable always reporting signal strength changes from radio.
6289 *
6290 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6291 */
6292 @Override
6293 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6294 enforceModifyPermission();
6295 enforceSystemCaller();
6296
6297 final long identity = Binder.clearCallingIdentity();
6298 final Phone phone = getPhone(subId);
6299 try {
6300 if (phone != null) {
6301 if (DBG) {
6302 log("setAlwaysReportSignalStrength: subId=" + subId
6303 + " isEnable=" + isEnable);
6304 }
6305 phone.setAlwaysReportSignalStrength(isEnable);
6306 } else {
6307 loge("setAlwaysReportSignalStrength: no phone found for subId="
6308 + subId);
6309 }
6310 } finally {
6311 Binder.restoreCallingIdentity(identity);
6312 }
6313 }
6314
6315 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006316 * Get the user enabled state of Mobile Data.
6317 *
6318 * TODO: remove and use isUserDataEnabled.
6319 * This can't be removed now because some vendor codes
6320 * calls through ITelephony directly while they should
6321 * use TelephonyManager.
6322 *
6323 * @return true on enabled
6324 */
6325 @Override
6326 public boolean getDataEnabled(int subId) {
6327 return isUserDataEnabled(subId);
6328 }
6329
6330 /**
6331 * Get whether mobile data is enabled per user setting.
6332 *
6333 * There are other factors deciding whether mobile data is actually enabled, but they are
6334 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006335 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006336 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006337 *
6338 * @return {@code true} if data is enabled else {@code false}
6339 */
6340 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006341 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006342 try {
6343 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6344 null);
6345 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6347 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006349
6350 final long identity = Binder.clearCallingIdentity();
6351 try {
6352 int phoneId = mSubscriptionController.getPhoneId(subId);
6353 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6354 Phone phone = PhoneFactory.getPhone(phoneId);
6355 if (phone != null) {
6356 boolean retVal = phone.isUserDataEnabled();
6357 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6358 return retVal;
6359 } else {
6360 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6361 return false;
6362 }
6363 } finally {
6364 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006365 }
6366 }
6367
6368 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006369 * Checks if the device is capable of mobile data by considering whether whether the
6370 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6371 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006372 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006373 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006374 */
6375 @Override
6376 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006377 try {
6378 try {
6379 mApp.enforceCallingOrSelfPermission(
6380 android.Manifest.permission.ACCESS_NETWORK_STATE,
6381 null);
6382 } catch (Exception e) {
6383 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6384 "isDataEnabled");
6385 }
6386 } catch (Exception e) {
6387 enforceReadPrivilegedPermission("isDataEnabled");
6388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389
6390 final long identity = Binder.clearCallingIdentity();
6391 try {
6392 int phoneId = mSubscriptionController.getPhoneId(subId);
6393 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6394 Phone phone = PhoneFactory.getPhone(phoneId);
6395 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006396 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6398 return retVal;
6399 } else {
6400 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6401 return false;
6402 }
6403 } finally {
6404 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006405 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006406 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006407
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006408 /**
6409 * Check if data is enabled for a specific reason
6410 * @param subId Subscription index
6411 * @param reason the reason the data enable change is taking place
6412 * @return {@code true} if the overall data is enabled; {@code false} if not.
6413 */
6414 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006415 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006416 @TelephonyManager.DataEnabledReason int reason) {
6417 try {
6418 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6419 null);
6420 } catch (Exception e) {
6421 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006422 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006423 }
6424
6425
6426 final long identity = Binder.clearCallingIdentity();
6427 try {
6428 int phoneId = mSubscriptionController.getPhoneId(subId);
6429 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006430 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006431 + " reason=" + reason);
6432 }
6433 Phone phone = PhoneFactory.getPhone(phoneId);
6434 if (phone != null) {
6435 boolean retVal;
6436 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6437 retVal = phone.isUserDataEnabled();
6438 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006439 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006440 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006441 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006442 return retVal;
6443 } else {
6444 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006445 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006446 + subId + " retVal=false");
6447 }
6448 return false;
6449 }
6450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
6453 }
6454
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006455 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006456 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006457 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6458 // Skip the check if it's one of these special uids
6459 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6460 }
6461
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006462 //load access rules from carrier configs, and check those as well: b/139133814
6463 SubscriptionController subController = SubscriptionController.getInstance();
6464 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6465 || subController == null) return privilegeFromSim;
6466
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006467 PackageManager pkgMgr = phone.getContext().getPackageManager();
6468 String[] packages = pkgMgr.getPackagesForUid(uid);
6469
6470 final long identity = Binder.clearCallingIdentity();
6471 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006472 int subId = phone.getSubId();
6473 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6474 // A test override is in place for the privileges for this subId, so don't try to
6475 // read the subscription privileges.
6476 return privilegeFromSim;
6477 }
6478 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006479 SubscriptionManager subManager = (SubscriptionManager)
6480 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6481 for (String pkg : packages) {
6482 if (subManager.canManageSubscription(subInfo, pkg)) {
6483 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6484 }
6485 }
6486 return privilegeFromSim;
6487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
6490 }
6491
6492 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6493 String pkgName) {
6494 //load access rules from carrier configs, and check those as well: b/139133814
6495 SubscriptionController subController = SubscriptionController.getInstance();
6496 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6497 || subController == null) return privilegeFromSim;
6498
6499 final long identity = Binder.clearCallingIdentity();
6500 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006501 int subId = phone.getSubId();
6502 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6503 // A test override is in place for the privileges for this subId, so don't try to
6504 // read the subscription privileges.
6505 return privilegeFromSim;
6506 }
6507 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006508 SubscriptionManager subManager = (SubscriptionManager)
6509 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6510 return subManager.canManageSubscription(subInfo, pkgName)
6511 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6512 } finally {
6513 Binder.restoreCallingIdentity(identity);
6514 }
6515 }
6516
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006517 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006518 public int getCarrierPrivilegeStatus(int subId) {
6519 final Phone phone = getPhone(subId);
6520 if (phone == null) {
6521 loge("getCarrierPrivilegeStatus: Invalid subId");
6522 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6523 }
6524 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006525 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006526 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006527 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6528 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006529
6530 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6531 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006532 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006533 }
Junda Liu29340342014-07-10 15:23:27 -07006534
6535 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006536 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006537 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006538 final Phone phone = getPhone(subId);
6539 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006540 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006541 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6542 }
6543 UiccProfile profile =
6544 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6545 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006546 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006547 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6548 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006549 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006550 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006551 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006552 }
6553
6554 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006555 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6556 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006557 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006558 }
6559
6560 int phoneId = SubscriptionManager.getPhoneId(subId);
6561 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006562 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006563 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006564 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6565 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006566 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6567 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6568 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006569 }
6570
6571 @Override
6572 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006573 if (TextUtils.isEmpty(pkgName))
6574 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006575 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6576 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6577 UiccCard card = UiccController.getInstance().getUiccCard(i);
6578 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006579 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006580 continue;
6581 }
6582
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006583 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6584 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6585 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006586 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6587 break;
6588 }
6589 }
6590
6591 return result;
Junda Liu29340342014-07-10 15:23:27 -07006592 }
Derek Tan89e89d42014-07-08 17:00:10 -07006593
6594 @Override
Junda Liue64de782015-04-16 17:19:16 -07006595 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6596 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6597 loge("phoneId " + phoneId + " is not valid.");
6598 return null;
6599 }
6600 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006601 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006602 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006603 return null ;
6604 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006605 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006606 }
6607
Amith Yamasani6e118872016-02-19 12:53:51 -08006608 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006609 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006610 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006611 List<String> privilegedPackages = new ArrayList<>();
6612 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006613 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6614 // has UICC in that slot.
6615 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006616 if (card.hasCarrierPrivilegeRules()) {
6617 if (packages == null) {
6618 // Only check packages in user 0 for now
6619 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006620 PackageManager.MATCH_DISABLED_COMPONENTS
6621 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006622 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006623 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006624 }
6625 for (int p = packages.size() - 1; p >= 0; p--) {
6626 PackageInfo pkgInfo = packages.get(p);
6627 if (pkgInfo != null && pkgInfo.packageName != null
6628 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006629 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006630 privilegedPackages.add(pkgInfo.packageName);
6631 }
6632 }
6633 }
6634 }
6635 return privilegedPackages;
6636 }
6637
chen xuf7e9fe82019-05-09 19:31:02 -07006638 @Override
6639 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006640 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6641
6642 final long identity = Binder.clearCallingIdentity();
6643
chen xuf7e9fe82019-05-09 19:31:02 -07006644 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006645 try {
6646 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6647 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6648 }
6649 } finally {
6650 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006651 }
6652 return privilegedPackages;
6653 }
6654
Wink Savilleb564aae2014-10-23 10:18:09 -07006655 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006656 final Phone phone = getPhone(subId);
6657 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006658 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006659 return null;
6660 }
6661 String iccId = card.getIccId();
6662 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006663 return null;
6664 }
6665 return iccId;
6666 }
6667
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006668 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006669 public void setCallComposerStatus(int subId, int status) {
6670 enforceModifyPermission();
6671
6672 final long identity = Binder.clearCallingIdentity();
6673 try {
6674 Phone phone = getPhone(subId);
6675 if (phone != null) {
6676 Phone defaultPhone = phone.getImsPhone();
6677 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6678 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6679 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006680 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6681 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006682 }
6683 }
Shuo Qian284ae752020-12-22 19:10:14 -08006684 } catch (ImsException e) {
6685 throw new ServiceSpecificException(e.getCode());
6686 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006687 Binder.restoreCallingIdentity(identity);
6688 }
6689 }
6690
6691 @Override
6692 public int getCallComposerStatus(int subId) {
6693 enforceReadPrivilegedPermission("getCallComposerStatus");
6694
6695 final long identity = Binder.clearCallingIdentity();
6696 try {
6697 Phone phone = getPhone(subId);
6698 if (phone != null) {
6699 Phone defaultPhone = phone.getImsPhone();
6700 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6701 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6702 return imsPhone.getCallComposerStatus();
6703 }
6704 }
6705 } finally {
6706 Binder.restoreCallingIdentity(identity);
6707 }
6708 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6709 }
6710
6711 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006712 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6713 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006714 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006715 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717 final long identity = Binder.clearCallingIdentity();
6718 try {
6719 final String iccId = getIccId(subId);
6720 final Phone phone = getPhone(subId);
6721 if (phone == null) {
6722 return false;
6723 }
6724 final String subscriberId = phone.getSubscriberId();
6725
6726 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006727 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728 + subscriberId + " to " + number);
6729 }
6730
6731 if (TextUtils.isEmpty(iccId)) {
6732 return false;
6733 }
6734
6735 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6736
6737 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6738 if (alphaTag == null) {
6739 editor.remove(alphaTagPrefKey);
6740 } else {
6741 editor.putString(alphaTagPrefKey, alphaTag);
6742 }
6743
6744 // Record both the line number and IMSI for this ICCID, since we need to
6745 // track all merged IMSIs based on line number
6746 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6747 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6748 if (number == null) {
6749 editor.remove(numberPrefKey);
6750 editor.remove(subscriberPrefKey);
6751 } else {
6752 editor.putString(numberPrefKey, number);
6753 editor.putString(subscriberPrefKey, subscriberId);
6754 }
6755
6756 editor.commit();
6757 return true;
6758 } finally {
6759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006760 }
Derek Tan7226c842014-07-02 17:42:23 -07006761 }
6762
6763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006764 public String getLine1NumberForDisplay(int subId, String callingPackage,
6765 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006766 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006768 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006769 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006770 return null;
6771 }
Derek Tan97ebb422014-09-05 16:55:38 -07006772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006773 final long identity = Binder.clearCallingIdentity();
6774 try {
6775 String iccId = getIccId(subId);
6776 if (iccId != null) {
6777 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6778 if (DBG_MERGE) {
6779 log("getLine1NumberForDisplay returning "
6780 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6781 }
6782 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6785 return null;
6786 } finally {
6787 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006788 }
Derek Tan7226c842014-07-02 17:42:23 -07006789 }
6790
6791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006792 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6793 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006795 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006796 return null;
6797 }
Derek Tan97ebb422014-09-05 16:55:38 -07006798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799 final long identity = Binder.clearCallingIdentity();
6800 try {
6801 String iccId = getIccId(subId);
6802 if (iccId != null) {
6803 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6804 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6805 }
6806 return null;
6807 } finally {
6808 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006809 }
Derek Tan7226c842014-07-02 17:42:23 -07006810 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006811
6812 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006813 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6814 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006815 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6816 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006817 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006818 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006819 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006820 return null;
6821 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006822
Jordan Liub49b04b2019-05-06 14:45:15 -07006823 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6824 // the process, where TelephonyManager was instantiated.
6825 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006826 final long identity = Binder.clearCallingIdentity();
6827 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006828 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 final TelephonyManager tele = TelephonyManager.from(context);
6830 final SubscriptionManager sub = SubscriptionManager.from(context);
6831
6832 // Figure out what subscribers are currently active
6833 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006834
Jordan Liub49b04b2019-05-06 14:45:15 -07006835 // Only consider subs which match the current subId
6836 // This logic can be simplified. See b/131189269 for progress.
6837 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006838 activeSubscriberIds.add(tele.getSubscriberId(subId));
6839 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840
6841 // First pass, find a number override for an active subscriber
6842 String mergeNumber = null;
6843 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6844 for (String key : prefs.keySet()) {
6845 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6846 final String subscriberId = (String) prefs.get(key);
6847 if (activeSubscriberIds.contains(subscriberId)) {
6848 final String iccId = key.substring(
6849 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6850 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6851 mergeNumber = (String) prefs.get(numberKey);
6852 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006853 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854 + " for active subscriber " + subscriberId);
6855 }
6856 if (!TextUtils.isEmpty(mergeNumber)) {
6857 break;
6858 }
6859 }
6860 }
6861 }
6862
6863 // Shortcut when no active merged subscribers
6864 if (TextUtils.isEmpty(mergeNumber)) {
6865 return null;
6866 }
6867
6868 // Second pass, find all subscribers under that line override
6869 final ArraySet<String> result = new ArraySet<>();
6870 for (String key : prefs.keySet()) {
6871 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6872 final String number = (String) prefs.get(key);
6873 if (mergeNumber.equals(number)) {
6874 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6875 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6876 final String subscriberId = (String) prefs.get(subscriberKey);
6877 if (!TextUtils.isEmpty(subscriberId)) {
6878 result.add(subscriberId);
6879 }
6880 }
6881 }
6882 }
6883
6884 final String[] resultArray = result.toArray(new String[result.size()]);
6885 Arrays.sort(resultArray);
6886 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006887 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6889 }
6890 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006891 } finally {
6892 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006893 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006894 }
6895
6896 @Override
zoey chen38003472019-12-13 17:16:31 +08006897 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6898 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006899
6900 final long identity = Binder.clearCallingIdentity();
6901 try {
6902 final TelephonyManager telephonyManager = mApp.getSystemService(
6903 TelephonyManager.class);
6904 String subscriberId = telephonyManager.getSubscriberId(subId);
6905 if (subscriberId == null) {
6906 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006907 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006908 + subId);
6909 }
6910 return null;
6911 }
6912
6913 final SubscriptionInfo info = SubscriptionController.getInstance()
6914 .getSubscriptionInfo(subId);
6915 final ParcelUuid groupUuid = info.getGroupUuid();
6916 // If it doesn't belong to any group, return just subscriberId of itself.
6917 if (groupUuid == null) {
6918 return new String[]{subscriberId};
6919 }
6920
6921 // Get all subscriberIds from the group.
6922 final List<String> mergedSubscriberIds = new ArrayList<>();
6923 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006924 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006925 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006926 for (SubscriptionInfo subInfo : groupInfos) {
6927 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6928 if (subscriberId != null) {
6929 mergedSubscriberIds.add(subscriberId);
6930 }
6931 }
6932
6933 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6934 } finally {
6935 Binder.restoreCallingIdentity(identity);
6936
6937 }
6938 }
6939
6940 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006941 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006942 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006943 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944
6945 final long identity = Binder.clearCallingIdentity();
6946 try {
6947 final Phone phone = getPhone(subId);
6948 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
6951 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006952 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006953
6954 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006955 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006956 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6957 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006958 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6959 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006960
6961 final long identity = Binder.clearCallingIdentity();
6962 try {
6963 final Phone phone = getPhone(subId);
6964 if (phone == null) {
6965 return false;
6966 }
6967 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6968 cdmaNonRoamingList);
6969 } finally {
6970 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006971 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006972 }
6973
6974 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006975 @Deprecated
6976 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6977 enforceModifyPermission();
6978
6979 int returnValue = 0;
6980 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006981 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006982 if(result.exception == null) {
6983 if (result.result != null) {
6984 byte[] responseData = (byte[])(result.result);
6985 if(responseData.length > oemResp.length) {
6986 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6987 responseData.length + "bytes. Buffer Size is " +
6988 oemResp.length + "bytes.");
6989 }
6990 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6991 returnValue = responseData.length;
6992 }
6993 } else {
6994 CommandException ex = (CommandException) result.exception;
6995 returnValue = ex.getCommandError().ordinal();
6996 if(returnValue > 0) returnValue *= -1;
6997 }
6998 } catch (RuntimeException e) {
6999 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7000 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7001 if(returnValue > 0) returnValue *= -1;
7002 }
7003
7004 return returnValue;
7005 }
7006
7007 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007008 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007009 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007010 try {
7011 TelephonyPermissions
7012 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7013 mApp, phone.getSubId(), "getRadioAccessFamily");
7014 } catch (SecurityException e) {
7015 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7016 throw e;
7017 }
chen xub97461a2018-10-26 14:17:57 -07007018 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007019 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007020 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022 final long identity = Binder.clearCallingIdentity();
7023 try {
chen xub97461a2018-10-26 14:17:57 -07007024 TelephonyPermissions
7025 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7026 mApp, phone.getSubId(), "getRadioAccessFamily");
7027 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028 } finally {
7029 Binder.restoreCallingIdentity(identity);
7030 }
chen xub97461a2018-10-26 14:17:57 -07007031 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007032 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007033
7034 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007035 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007036 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007037 try {
7038 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7039 Binder.getCallingUid())) {
7040 throw new SecurityException("Package uid and package name do not match: "
7041 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7042 }
7043 } catch (PackageManager.NameNotFoundException e) {
7044 throw new SecurityException("Package name invalid:" + callingPackage);
7045 }
7046 RoleManager rm = mApp.getSystemService(RoleManager.class);
7047 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7048 if (!dialerRoleHolders.contains(callingPackage)) {
7049 throw new SecurityException("App must be the dialer role holder to"
7050 + " upload a call composer pic");
7051 }
7052
7053 Executors.newSingleThreadExecutor().execute(() -> {
7054 ByteArrayOutputStream output = new ByteArrayOutputStream(
7055 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7056 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7057 boolean readUntilEnd = false;
7058 int totalBytesRead = 0;
7059 byte[] buffer = new byte[16 * 1024];
7060 while (true) {
7061 int numRead;
7062 try {
7063 numRead = input.read(buffer);
7064 } catch (IOException e) {
7065 try {
7066 fd.checkError();
7067 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7068 null);
7069 } catch (IOException e1) {
7070 // This means that the other side closed explicitly with an error. If this
7071 // happens, log and ignore.
7072 loge("Remote end of call composer picture pipe closed: " + e1);
7073 }
7074 break;
7075 }
7076 if (numRead == -1) {
7077 readUntilEnd = true;
7078 break;
7079 }
7080 totalBytesRead += numRead;
7081 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7082 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7083 try {
7084 input.close();
7085 } catch (IOException e) {
7086 // ignore
7087 }
7088 break;
7089 }
7090 output.write(buffer, 0, numRead);
7091 }
7092 // Generally, the remote end will close the file descriptors. The only case where we
7093 // close is above, where the picture size is too big.
7094
7095 try {
7096 fd.checkError();
7097 } catch (IOException e) {
7098 loge("Remote end for call composer closed with an error: " + e);
7099 return;
7100 }
7101
Hall Liuaa4211e2021-01-20 15:43:39 -08007102 if (!readUntilEnd) {
7103 loge("Did not finish reading entire image; aborting");
7104 return;
7105 }
Hall Liu82694d52020-12-11 18:22:04 -08007106
Hall Liuaa4211e2021-01-20 15:43:39 -08007107 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7108 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7109 new CallComposerPictureTransfer.Factory() {},
7110 imageData,
7111 (result) -> {
7112 if (result.first != null) {
7113 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7114 Bundle outputResult = new Bundle();
7115 outputResult.putParcelable(
7116 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7117 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7118 outputResult);
7119 } else {
7120 callback.send(result.second, null);
7121 }
7122 }
7123 );
Hall Liu82694d52020-12-11 18:22:04 -08007124 });
7125 }
7126
7127 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007128 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007129 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007130 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131
7132 final long identity = Binder.clearCallingIdentity();
7133 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007134 ImsManager.getInstance(defaultPhone.getContext(),
7135 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007139 }
7140
7141 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007142 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007143 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7145 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007146 return false;
7147 }
Svet Ganovb320e182015-04-16 12:30:10 -07007148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 // Check the user preference and the system-level IMS setting. Even if the user has
7152 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7153 // In the long run, we may instead need to check if there exists a connection service
7154 // which can support video calling.
7155 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007156 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 return imsManager.isVtEnabledByPlatform()
7158 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7159 && imsManager.isVtEnabledByUser();
7160 } finally {
7161 Binder.restoreCallingIdentity(identity);
7162 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007163 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007164
Andrew Leea1239f22015-03-02 17:44:07 -08007165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007166 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7167 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007169 mApp, subId, callingPackage, callingFeatureId,
7170 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 return false;
7172 }
7173
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 CarrierConfigManager configManager =
7177 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007178 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
Andrew Leea1239f22015-03-02 17:44:07 -08007183 }
7184
7185 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007186 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007188 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 return false;
7190 }
7191
7192 final long identity = Binder.clearCallingIdentity();
7193 try {
7194 CarrierConfigManager configManager =
7195 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007196 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7198 } finally {
7199 Binder.restoreCallingIdentity(identity);
7200 }
Andrew Leea1239f22015-03-02 17:44:07 -08007201 }
7202
Andrew Lee9431b832015-03-09 18:46:45 -07007203 @Override
7204 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007205 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007206 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007207 }
7208
7209 @Override
7210 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 final long identity = Binder.clearCallingIdentity();
7212 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007213 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214 } finally {
7215 Binder.restoreCallingIdentity(identity);
7216 }
Andrew Lee9431b832015-03-09 18:46:45 -07007217 }
7218
Hall Liuf6668912018-10-31 17:05:23 -07007219 /**
7220 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7221 * support for the feature and device firmware support.
7222 *
7223 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7224 */
7225 @Override
7226 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007228 final Phone phone = getPhone(subscriptionId);
7229 if (phone == null) {
7230 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7231 return false;
7232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007234 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7236 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007237 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007238 return isCarrierSupported && isDeviceSupported;
7239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
Hall Liu98187582018-01-22 19:15:32 -08007242 }
7243
Hall Liuf6668912018-10-31 17:05:23 -07007244 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007245 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7246 * RTT setting, will return true if the device and carrier both support RTT.
7247 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007248 */
7249 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250 final long identity = Binder.clearCallingIdentity();
7251 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007252 boolean isRttSupported = isRttSupported(subscriptionId);
7253 boolean isUserRttSettingOn = Settings.Secure.getInt(
7254 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7255 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7256 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7257 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007258 } finally {
7259 Binder.restoreCallingIdentity(identity);
7260 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007261 }
7262
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007263 @Deprecated
7264 @Override
7265 public String getDeviceId(String callingPackage) {
7266 return getDeviceIdWithFeature(callingPackage, null);
7267 }
7268
Sanket Padawe7310cc72015-01-14 09:53:20 -08007269 /**
7270 * Returns the unique device ID of phone, for example, the IMEI for
7271 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7272 *
7273 * <p>Requires Permission:
7274 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7275 */
7276 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007277 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007278 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007279 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007280 return null;
7281 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007282 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007283 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007284 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007285 return null;
7286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007287
7288 final long identity = Binder.clearCallingIdentity();
7289 try {
7290 return phone.getDeviceId();
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
7293 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007294 }
7295
Ping Sunc67b7c22016-03-02 19:16:45 +08007296 /**
7297 * {@hide}
7298 * Returns the IMS Registration Status on a particular subid
7299 *
7300 * @param subId
7301 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007302 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007303 Phone phone = getPhone(subId);
7304 if (phone != null) {
7305 return phone.isImsRegistered();
7306 } else {
7307 return false;
7308 }
7309 }
7310
Santos Cordon7a1885b2015-02-03 11:15:19 -08007311 @Override
7312 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 final long identity = Binder.clearCallingIdentity();
7314 try {
7315 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7316 } finally {
7317 Binder.restoreCallingIdentity(identity);
7318 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007319 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007320
Tyler Gunnf70ed162019-04-03 15:28:53 -07007321 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007322 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007323 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007325 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007326 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7327 }
7328 final long identity = Binder.clearCallingIdentity();
7329 try {
7330 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7331 } finally {
7332 Binder.restoreCallingIdentity(identity);
7333 }
7334 }
7335
7336 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007337 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007338 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7339 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007340 final long identity = Binder.clearCallingIdentity();
7341 try {
7342 Phone phone = getPhone(subscriptionId);
7343 if (phone == null) {
7344 return null;
7345 }
7346 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7347 } finally {
7348 Binder.restoreCallingIdentity(identity);
7349 }
7350 }
7351
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007352 /**
7353 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007354 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007355 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 final long identity = Binder.clearCallingIdentity();
7357 try {
7358 Phone phone = getPhone(subId);
7359 if (phone != null) {
7360 return phone.isWifiCallingEnabled();
7361 } else {
7362 return false;
7363 }
7364 } finally {
7365 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007366 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007367 }
7368
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007369 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007370 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007371 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007372 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 final long identity = Binder.clearCallingIdentity();
7374 try {
7375 Phone phone = getPhone(subId);
7376 if (phone != null) {
7377 return phone.isVideoEnabled();
7378 } else {
7379 return false;
7380 }
7381 } finally {
7382 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007383 }
7384 }
7385
7386 /**
7387 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7388 * defined in {@link ImsRegistrationImplBase}.
7389 */
7390 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 final long identity = Binder.clearCallingIdentity();
7392 try {
7393 Phone phone = getPhone(subId);
7394 if (phone != null) {
7395 return phone.getImsRegistrationTech();
7396 } else {
7397 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7398 }
7399 } finally {
7400 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007401 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007402 }
7403
Stuart Scott8eef64f2015-04-08 15:13:54 -07007404 @Override
7405 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007406 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007407 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7408 return;
7409 }
7410
Svet Ganovcc087f82015-05-12 20:35:54 -07007411 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007412
Svet Ganovcc087f82015-05-12 20:35:54 -07007413 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007414 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7415 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007416 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007417 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007418 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007419 Phone phone = getPhone(subId);
7420 if (phone != null) {
7421 SubscriptionManager.setSubscriptionProperty(subId,
7422 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7423 "user=" + RadioAccessFamily.getRafFromNetworkType(
7424 RILConstants.PREFERRED_NETWORK_MODE));
7425 phone.loadAllowedNetworksFromSubscriptionDatabase();
7426 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007427 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7428 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007429 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007430 // There has been issues when Sms raw table somehow stores orphan
7431 // fragments. They lead to garbled message when new fragments come
7432 // in and combined with those stale ones. In case this happens again,
7433 // user can reset all network settings which will clean up this table.
7434 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007435 // Clean up IMS settings as well here.
7436 int slotId = getSlotIndex(subId);
7437 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7438 ImsManager.getInstance(mApp, slotId).factoryReset();
7439 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007440
7441 // Erase modem config if erase modem on network setting is enabled.
7442 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7443 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7444 if (configValue != null && Boolean.parseBoolean(configValue)) {
7445 sendEraseModemConfig(getDefaultPhone());
7446 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007447 } finally {
7448 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007449 }
7450 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007451
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007452 private void cleanUpSmsRawTable(Context context) {
7453 ContentResolver resolver = context.getContentResolver();
7454 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7455 resolver.delete(uri, null, null);
7456 }
7457
Narayan Kamath1c496c22015-04-16 14:40:19 +01007458 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007459 public String getSimLocaleForSubscriber(int subId) {
7460 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7461 final Phone phone = getPhone(subId);
7462 if (phone == null) {
7463 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007464 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 final long identity = Binder.clearCallingIdentity();
7467 try {
chen xu5d3637b2019-01-21 23:31:38 -08007468 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007469 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007470 if (info == null) {
7471 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7472 return null;
7473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 // Try and fetch the locale from the carrier properties or from the SIM language
7475 // preferences (EF-PL and EF-LI)...
7476 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007478 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7479 if (localeFromDefaultSim != null) {
7480 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7481 if (DBG) log("Using locale from subId: " + subId + " locale: "
7482 + localeFromDefaultSim);
7483 return localeFromDefaultSim.toLanguageTag();
7484 } else {
7485 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 }
7487 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 // The SIM language preferences only store a language (e.g. fr = French), not an
7490 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7491 // the SIM and carrier preferences does not include a country we add the country
7492 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007493 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007495 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 return mccLocale.toLanguageTag();
7497 }
7498
7499 if (DBG) log("No locale found - returning null");
7500 return null;
7501 } finally {
7502 Binder.restoreCallingIdentity(identity);
7503 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007504 }
7505
7506 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007507 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007508 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007509 }
7510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 /**
7512 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7513 */
7514 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007515 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007516 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007517 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007518
Chenjie Yu1ba97252018-01-11 18:16:20 -08007519 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007520 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007521
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007522 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007523 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7524 * representing the state of the modem.
7525 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007526 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7527 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007528 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007529 */
7530 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007531 public void requestModemActivityInfo(ResultReceiver result) {
7532 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007533 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534
7535 final long identity = Binder.clearCallingIdentity();
7536 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007537 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 } finally {
7539 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007540 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007541 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007542
Siddharth Rayb8114062018-06-17 15:02:38 -07007543 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7544 // less than total activity duration.
7545 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7546 if (info == null) {
7547 return false;
7548 }
7549 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007550 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7551 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7552
Siddharth Rayb8114062018-06-17 15:02:38 -07007553 return (info.isValid()
7554 && (info.getSleepTimeMillis() <= activityDurationMs)
7555 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007556 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007557 && (totalTxTimeMs <= activityDurationMs));
7558 }
7559
Jack Yu85bd38a2015-11-09 11:34:32 -08007560 /**
7561 * {@hide}
7562 * Returns the service state information on specified subscription.
7563 */
7564 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007565 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7566 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007568 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007569 return null;
7570 }
7571
Hall Liuf19c44f2018-11-27 14:38:17 -08007572 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7573 LocationAccessPolicy.checkLocationPermission(mApp,
7574 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7575 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007576 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007577 .setCallingPid(Binder.getCallingPid())
7578 .setCallingUid(Binder.getCallingUid())
7579 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007580 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007581 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007582 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7583 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007584 .build());
7585
7586 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7587 LocationAccessPolicy.checkLocationPermission(mApp,
7588 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7589 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007590 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007591 .setCallingPid(Binder.getCallingPid())
7592 .setCallingUid(Binder.getCallingUid())
7593 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007594 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007595 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007596 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7597 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007598 .build());
7599 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7600 boolean hasFinePermission =
7601 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7602 boolean hasCoarsePermission =
7603 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7604
Jack Yu479f40e2020-10-27 21:29:25 -07007605 final Phone phone = getPhone(subId);
7606 if (phone == null) {
7607 return null;
7608 }
7609
Jordan Liu0f2bc442020-11-18 16:47:37 -08007610 final long identity = Binder.clearCallingIdentity();
7611
Jack Yu479f40e2020-10-27 21:29:25 -07007612 boolean isCallingPackageDataService = phone.getDataServicePackages()
7613 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007615 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7616 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7617 Rlog.d(LOG_TAG,
7618 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7619 return null;
7620 }
7621
Hall Liuf19c44f2018-11-27 14:38:17 -08007622 ServiceState ss = phone.getServiceState();
7623
7624 // Scrub out the location info in ServiceState depending on what level of access
7625 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007626 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007627 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7628 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007629 } finally {
7630 Binder.restoreCallingIdentity(identity);
7631 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007632 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007633
7634 /**
7635 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7636 *
7637 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7638 * voicemail ringtone.
7639 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7640 * PhoneAccount.
7641 */
7642 @Override
7643 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644 final long identity = Binder.clearCallingIdentity();
7645 try {
7646 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7647 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007648 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007655 }
7656
7657 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007658 * Sets the per-account voicemail ringtone.
7659 *
7660 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7661 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7662 *
7663 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7664 * voicemail ringtone.
7665 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7666 * PhoneAccount.
7667 */
7668 @Override
7669 public void setVoicemailRingtoneUri(String callingPackage,
7670 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007671 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007672 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007673 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7674 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7676 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7677 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007678 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679
7680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7683 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007684 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 }
7686 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007689 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007690 }
7691
7692 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007693 * Returns whether vibration is set for voicemail notification in Phone settings.
7694 *
7695 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7696 * voicemail vibration setting.
7697 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7698 */
7699 @Override
7700 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7704 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007705 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007706 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7709 } finally {
7710 Binder.restoreCallingIdentity(identity);
7711 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007712 }
7713
Youhan Wange64578a2016-05-02 15:32:42 -07007714 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007715 * Sets the per-account voicemail vibration.
7716 *
7717 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7718 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7719 *
7720 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7721 * voicemail vibration setting.
7722 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7723 * specific PhoneAccount.
7724 */
7725 @Override
7726 public void setVoicemailVibrationEnabled(String callingPackage,
7727 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007728 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007729 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007730 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7731 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7733 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7734 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007735 }
7736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 final long identity = Binder.clearCallingIdentity();
7738 try {
7739 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7740 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007741 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 }
7743 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7744 } finally {
7745 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007746 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007747 }
7748
7749 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007750 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7751 *
7752 * @throws SecurityException if the caller does not have the required permission
7753 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007754 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007755 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007756 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007757 }
7758
7759 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007760 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7761 * permission.
7762 *
7763 * @throws SecurityException if the caller does not have the required permission
7764 */
7765 private void enforceSendSmsPermission() {
7766 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7767 }
7768
7769 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007770 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007771 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007772 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007773 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007774 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775 final long identity = Binder.clearCallingIdentity();
7776 try {
7777 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007778 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 if (componentName == null) {
7780 throw new SecurityException(
7781 "Caller not current active visual voicemail package[null]");
7782 }
7783 String vvmPackage = componentName.getPackageName();
7784 if (!callingPackage.equals(vvmPackage)) {
7785 throw new SecurityException("Caller not current active visual voicemail package["
7786 + vvmPackage + "]");
7787 }
7788 } finally {
7789 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007790 }
7791 }
7792
7793 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007794 * Return the application ID for the app type.
7795 *
7796 * @param subId the subscription ID that this request applies to.
7797 * @param appType the uicc app type.
7798 * @return Application ID for specificied app type, or null if no uicc.
7799 */
7800 @Override
7801 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007802 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007803 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804
7805 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007806 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007807 if (phone == null) {
7808 return null;
7809 }
7810 String aid = null;
7811 try {
7812 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7813 .getApplicationByType(appType).getAid();
7814 } catch (Exception e) {
7815 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7816 }
7817 return aid;
7818 } finally {
7819 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007820 }
Youhan Wange64578a2016-05-02 15:32:42 -07007821 }
7822
Youhan Wang4001d252016-05-11 10:29:41 -07007823 /**
7824 * Return the Electronic Serial Number.
7825 *
7826 * @param subId the subscription ID that this request applies to.
7827 * @return ESN or null if error.
7828 */
7829 @Override
7830 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007831 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007832 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007833
7834 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007835 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836 if (phone == null) {
7837 return null;
7838 }
7839 String esn = null;
7840 try {
7841 esn = phone.getEsn();
7842 } catch (Exception e) {
7843 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7844 }
7845 return esn;
7846 } finally {
7847 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007848 }
Youhan Wang4001d252016-05-11 10:29:41 -07007849 }
7850
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007851 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007852 * Return the Preferred Roaming List Version.
7853 *
7854 * @param subId the subscription ID that this request applies to.
7855 * @return PRLVersion or null if error.
7856 */
7857 @Override
7858 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007859 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007860 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861
7862 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007863 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 if (phone == null) {
7865 return null;
7866 }
7867 String cdmaPrlVersion = null;
7868 try {
7869 cdmaPrlVersion = phone.getCdmaPrlVersion();
7870 } catch (Exception e) {
7871 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7872 }
7873 return cdmaPrlVersion;
7874 } finally {
7875 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007876 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007877 }
7878
7879 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007880 * Get snapshot of Telephony histograms
7881 * @return List of Telephony histograms
7882 * @hide
7883 */
7884 @Override
7885 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7887 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888
7889 final long identity = Binder.clearCallingIdentity();
7890 try {
7891 return RIL.getTelephonyRILTimingHistograms();
7892 } finally {
7893 Binder.restoreCallingIdentity(identity);
7894 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007895 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007896
7897 /**
7898 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007899 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7900 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007901 * Require system privileges. In the future we may add this to carrier APIs.
7902 *
Michele Berionne482f8202018-11-27 18:57:59 -08007903 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007904 */
7905 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007906 @TelephonyManager.SetCarrierRestrictionResult
7907 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007908 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007909 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007910
Michele Berionne482f8202018-11-27 18:57:59 -08007911 if (carrierRestrictionRules == null) {
7912 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007913 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 final long identity = Binder.clearCallingIdentity();
7916 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007917 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007918 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007919 } finally {
7920 Binder.restoreCallingIdentity(identity);
7921 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007922 }
7923
7924 /**
7925 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007926 * Get the allowed carrier list and the excluded carrier list, including the priority between
7927 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007928 * Require system privileges. In the future we may add this to carrier APIs.
7929 *
Michele Berionne482f8202018-11-27 18:57:59 -08007930 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007931 */
7932 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007933 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007934 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007935 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936
7937 final long identity = Binder.clearCallingIdentity();
7938 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007939 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7940 if (response instanceof CarrierRestrictionRules) {
7941 return (CarrierRestrictionRules) response;
7942 }
7943 // Response is an Exception of some kind,
7944 // which is signalled to the user as a NULL retval
7945 return null;
7946 } catch (Exception e) {
7947 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7948 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007949 } finally {
7950 Binder.restoreCallingIdentity(identity);
7951 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007952 }
7953
fionaxu59545b42016-05-25 15:53:37 -07007954 /**
fionaxu59545b42016-05-25 15:53:37 -07007955 * Action set from carrier signalling broadcast receivers to enable/disable radio
7956 * @param subId the subscription ID that this action applies to.
7957 * @param enabled control enable or disable radio.
7958 * {@hide}
7959 */
7960 @Override
7961 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7962 enforceModifyPermission();
7963 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964
7965 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007966 if (phone == null) {
7967 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7968 return;
7969 }
7970 try {
7971 phone.carrierActionSetRadioEnabled(enabled);
7972 } catch (Exception e) {
7973 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007974 } finally {
7975 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007976 }
7977 }
7978
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007979 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007980 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7981 * network status based on which carrier apps could apply actions accordingly,
7982 * enable/disable default url handler for example.
7983 *
7984 * @param subId the subscription ID that this action applies to.
7985 * @param report control start/stop reporting the default network status.
7986 * {@hide}
7987 */
7988 @Override
7989 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7990 enforceModifyPermission();
7991 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992
7993 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007994 if (phone == null) {
7995 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7996 return;
7997 }
7998 try {
7999 phone.carrierActionReportDefaultNetworkStatus(report);
8000 } catch (Exception e) {
8001 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002 } finally {
8003 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008004 }
8005 }
8006
8007 /**
fionaxud9622282017-07-17 17:51:30 -07008008 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8009 * @param subId the subscription ID that this action applies to.
8010 * {@hide}
8011 */
8012 @Override
8013 public void carrierActionResetAll(int subId) {
8014 enforceModifyPermission();
8015 final Phone phone = getPhone(subId);
8016 if (phone == null) {
8017 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8018 return;
8019 }
8020 try {
8021 phone.carrierActionResetAll();
8022 } catch (Exception e) {
8023 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8024 }
8025 }
8026
8027 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008028 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8029 * bug report is being generated.
8030 */
8031 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008032 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008033 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8034 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008035 writer.println("Permission Denial: can't dump Phone from pid="
8036 + Binder.getCallingPid()
8037 + ", uid=" + Binder.getCallingUid()
8038 + "without permission "
8039 + android.Manifest.permission.DUMP);
8040 return;
8041 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008042 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008043 }
Jack Yueb89b242016-06-22 13:27:47 -07008044
Brad Ebingerdac2f002018-04-03 15:17:52 -07008045 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008046 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8047 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8048 @NonNull String[] args) {
8049 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8050 this, in.getFileDescriptor(), out.getFileDescriptor(),
8051 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008052 }
8053
Jack Yueb89b242016-06-22 13:27:47 -07008054 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008055 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008056 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008057 * @param reason the reason the data enable change is taking place
8058 * @param enabled True if enabling the data, otherwise disabling.
8059 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008060 */
8061 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008062 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008063 boolean enabled) {
8064 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8065 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8066 try {
8067 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008068 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008069 } catch (SecurityException se) {
8070 enforceModifyPermission();
8071 }
8072 } else {
8073 enforceModifyPermission();
8074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075
8076 final long identity = Binder.clearCallingIdentity();
8077 try {
8078 Phone phone = getPhone(subId);
8079 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008080 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8081 phone.carrierActionSetMeteredApnsEnabled(enabled);
8082 } else {
8083 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 }
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008088 }
8089 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008090
8091 /**
8092 * Get Client request stats
8093 * @return List of Client Request Stats
8094 * @hide
8095 */
8096 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008097 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8098 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008100 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008101 return null;
8102 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008103 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008104
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008105 final long identity = Binder.clearCallingIdentity();
8106 try {
8107 if (phone != null) {
8108 return phone.getClientRequestStats();
8109 }
8110
8111 return null;
8112 } finally {
8113 Binder.restoreCallingIdentity(identity);
8114 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008115 }
8116
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008117 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008118 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008119 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008120 }
Jack Yueb4124c2017-02-16 15:32:43 -08008121
8122 /**
Grace Chen70990072017-03-24 17:21:30 -07008123 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008124 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008125 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008126 * @param state State of SIM (power down, power up, pass through)
8127 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8128 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8129 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008130 *
8131 **/
8132 @Override
Grace Chen70990072017-03-24 17:21:30 -07008133 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008134 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008135 Phone phone = PhoneFactory.getPhone(slotIndex);
8136
vagdeviaf9a5b92018-08-15 16:01:53 -07008137 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 final long identity = Binder.clearCallingIdentity();
8140 try {
8141 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008142 phone.setSimPowerState(state, null, workSource);
8143 }
8144 } finally {
8145 Binder.restoreCallingIdentity(identity);
8146 }
8147 }
8148
8149 /**
8150 * Set SIM card power state.
8151 *
8152 * @param slotIndex SIM slot id.
8153 * @param state State of SIM (power down, power up, pass through)
8154 * @param callback callback to trigger after success or failure
8155 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8156 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8157 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8158 *
8159 **/
8160 @Override
8161 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8162 IIntegerConsumer callback) {
8163 enforceModifyPermission();
8164 Phone phone = PhoneFactory.getPhone(slotIndex);
8165
8166 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8167
8168 final long identity = Binder.clearCallingIdentity();
8169 try {
8170 if (phone != null) {
8171 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8172 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 }
8174 } finally {
8175 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008176 }
8177 }
Shuo Qiandd210312017-04-12 22:11:33 +00008178
Tyler Gunn65d45c22017-06-05 11:22:26 -07008179 private boolean isUssdApiAllowed(int subId) {
8180 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008181 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008182 if (configManager == null) {
8183 return false;
8184 }
8185 PersistableBundle pb = configManager.getConfigForSubId(subId);
8186 if (pb == null) {
8187 return false;
8188 }
8189 return pb.getBoolean(
8190 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8191 }
8192
Shuo Qiandd210312017-04-12 22:11:33 +00008193 /**
8194 * Check if phone is in emergency callback mode
8195 * @return true if phone is in emergency callback mode
8196 * @param subId sub id
8197 */
goneil9c5f4872017-12-05 14:07:56 -08008198 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008199 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008200 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008201 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008202
8203 final long identity = Binder.clearCallingIdentity();
8204 try {
8205 if (phone != null) {
8206 return phone.isInEcm();
8207 } else {
8208 return false;
8209 }
8210 } finally {
8211 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008212 }
8213 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008214
8215 /**
8216 * Get the current signal strength information for the given subscription.
8217 * Because this information is not updated when the device is in a low power state
8218 * it should not be relied-upon to be current.
8219 * @param subId Subscription index
8220 * @return the most recent cached signal strength info from the modem
8221 */
8222 @Override
8223 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 final long identity = Binder.clearCallingIdentity();
8225 try {
8226 Phone p = getPhone(subId);
8227 if (p == null) {
8228 return null;
8229 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008231 return p.getSignalStrength();
8232 } finally {
8233 Binder.restoreCallingIdentity(identity);
8234 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008235 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008236
Pengquan Meng77b7f132018-08-22 14:49:57 -07008237 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008238 * Get the current modem radio state for the given slot.
8239 * @param slotIndex slot index.
8240 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008241 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008242 * @return the current radio power state from the modem
8243 */
8244 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008245 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008246 Phone phone = PhoneFactory.getPhone(slotIndex);
8247 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8249 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008250 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8251 }
8252
8253 final long identity = Binder.clearCallingIdentity();
8254 try {
8255 return phone.getRadioPowerState();
8256 } finally {
8257 Binder.restoreCallingIdentity(identity);
8258 }
8259 }
8260 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8261 }
8262
8263 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008264 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8265 *
8266 * <p>Requires one of the following permissions:
8267 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8268 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8269 * privileges.
8270 *
8271 * @param subId subscription id
8272 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8273 * {@code false}.
8274 */
8275 @Override
8276 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008277 try {
8278 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8279 null);
8280 } catch (Exception e) {
8281 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8282 mApp, subId, "isDataRoamingEnabled");
8283 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008284
Pengquan Menga1bb6272018-09-06 09:59:22 -07008285 boolean isEnabled = false;
8286 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008287 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008288 Phone phone = getPhone(subId);
8289 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008290 } finally {
8291 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008292 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008293 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008294 }
8295
8296
8297 /**
8298 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8299 *
8300 * <p> Requires permission:
8301 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8302 * privileges.
8303 *
8304 * @param subId subscription id
8305 * @param isEnabled {@code true} means enable, {@code false} means disable.
8306 */
8307 @Override
8308 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8310 mApp, subId, "setDataRoamingEnabled");
8311
Pengquan Menga1bb6272018-09-06 09:59:22 -07008312 final long identity = Binder.clearCallingIdentity();
8313 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008314 Phone phone = getPhone(subId);
8315 if (phone != null) {
8316 phone.setDataRoamingEnabled(isEnabled);
8317 }
8318 } finally {
8319 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008320 }
8321 }
8322
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008323 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008324 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008325 TelephonyPermissions
8326 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008327 mApp, subId, "isManualNetworkSelectionAllowed");
8328
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008329 boolean isAllowed = true;
8330 final long identity = Binder.clearCallingIdentity();
8331 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008332 Phone phone = getPhone(subId);
8333 if (phone != null) {
8334 isAllowed = phone.isCspPlmnEnabled();
8335 }
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
8338 }
8339 return isAllowed;
8340 }
8341
8342 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008343 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008344 // Verify that tha callingPackage belongs to the calling UID
8345 mApp.getSystemService(AppOpsManager.class)
8346 .checkPackage(Binder.getCallingUid(), callingPackage);
8347
Jordan Liu1e142fc2019-04-22 15:10:43 -07008348 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008349 try {
8350 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008351 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008352 } catch (SecurityException e) {
8353 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8354 // has carrier privileges on an active UICC
8355 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8356 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008357 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008358 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008359 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008360
8361 final long identity = Binder.clearCallingIdentity();
8362 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008363 UiccController uiccController = UiccController.getInstance();
8364 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008365 if (hasReadPermission) {
8366 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008367 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008368
8369 // Remove private info if the caller doesn't have access
8370 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8371 for (UiccCardInfo cardInfo : cardInfos) {
8372 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8373 // is available
8374 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8375 if (card == null || card.getUiccProfile() == null) {
8376 // assume no access if the card or profile is unavailable
8377 filteredInfos.add(cardInfo.getUnprivileged());
8378 continue;
8379 }
8380 UiccProfile profile = card.getUiccProfile();
8381 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8382 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8383 filteredInfos.add(cardInfo);
8384 } else {
8385 filteredInfos.add(cardInfo.getUnprivileged());
8386 }
8387 }
8388 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008389 } finally {
8390 Binder.restoreCallingIdentity(identity);
8391 }
8392 }
8393
8394 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008395 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008396 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008398 final long identity = Binder.clearCallingIdentity();
8399 try {
8400 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8401 if (slots == null) {
8402 Rlog.i(LOG_TAG, "slots is null.");
8403 return null;
8404 }
8405
8406 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8407 for (int i = 0; i < slots.length; i++) {
8408 UiccSlot slot = slots[i];
8409 if (slot == null) {
8410 continue;
8411 }
8412
Jordan Liu7be7e652019-05-06 18:55:02 +00008413 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008414 UiccCard card = slot.getUiccCard();
8415 if (card != null) {
8416 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008417 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008418 cardId = slot.getEid();
8419 if (TextUtils.isEmpty(cardId)) {
8420 cardId = slot.getIccId();
8421 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008422 }
8423
Jordan Liu857451f2019-05-09 16:35:35 -07008424 if (cardId != null) {
8425 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8426 // if cardId is an EID, it's all digits so this is fine
8427 cardId = IccUtils.stripTrailingFs(cardId);
8428 }
8429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430 int cardState = 0;
8431 switch (slot.getCardState()) {
8432 case CARDSTATE_ABSENT:
8433 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8434 break;
8435 case CARDSTATE_PRESENT:
8436 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8437 break;
8438 case CARDSTATE_ERROR:
8439 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8440 break;
8441 case CARDSTATE_RESTRICTED:
8442 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8443 break;
8444 default:
8445 break;
8446
8447 }
8448
8449 infos[i] = new UiccSlotInfo(
8450 slot.isActive(),
8451 slot.isEuicc(),
8452 cardId,
8453 cardState,
8454 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008455 slot.isExtendedApduSupported(),
8456 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008457 }
8458 return infos;
8459 } finally {
8460 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008461 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008462 }
8463
8464 @Override
8465 public boolean switchSlots(int[] physicalSlots) {
8466 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008467
8468 final long identity = Binder.clearCallingIdentity();
8469 try {
8470 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8471 } finally {
8472 Binder.restoreCallingIdentity(identity);
8473 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008474 }
Jack Yu4c988042018-02-27 15:30:01 -08008475
8476 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008477 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008478 final long identity = Binder.clearCallingIdentity();
8479 try {
8480 return UiccController.getInstance().getCardIdForDefaultEuicc();
8481 } finally {
8482 Binder.restoreCallingIdentity(identity);
8483 }
8484 }
8485
Pengquan Meng85728fb2018-03-12 16:31:21 -07008486 /**
goneil47ffb6e2018-04-06 15:40:58 -07008487 * A test API to reload the UICC profile.
8488 *
8489 * <p>Requires that the calling app has permission
8490 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8491 * @hide
8492 */
8493 @Override
8494 public void refreshUiccProfile(int subId) {
8495 enforceModifyPermission();
8496
8497 final long identity = Binder.clearCallingIdentity();
8498 try {
8499 Phone phone = getPhone(subId);
8500 if (phone == null) {
8501 return;
8502 }
8503 UiccCard uiccCard = phone.getUiccCard();
8504 if (uiccCard == null) {
8505 return;
8506 }
8507 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8508 if (uiccProfile == null) {
8509 return;
8510 }
8511 uiccProfile.refresh();
8512 } finally {
8513 Binder.restoreCallingIdentity(identity);
8514 }
8515 }
8516
8517 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008518 * Returns false if the mobile data is disabled by default, otherwise return true.
8519 */
8520 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008521 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008522 }
8523
8524 /**
8525 * Returns true if the data roaming is enabled by default, i.e the system property
8526 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8527 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8528 */
8529 private boolean getDefaultDataRoamingEnabled(int subId) {
8530 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008531 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008532 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008533 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8534 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8535 return isDataRoamingEnabled;
8536 }
8537
8538 /**
8539 * Returns the default network type for the given {@code subId}, if the default network type is
8540 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8541 */
8542 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008543 List<Integer> list = TelephonyProperties.default_network();
8544 int phoneId = mSubscriptionController.getPhoneId(subId);
8545 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8546 return list.get(phoneId);
8547 }
8548 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008549 }
fionaxua13278b2018-03-21 00:08:13 -07008550
8551 @Override
8552 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008553 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008555
8556 final long identity = Binder.clearCallingIdentity();
8557 try {
8558 final Phone phone = getPhone(subId);
8559 if (phone == null) {
8560 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8561 return;
8562 }
chen xueaba88a2019-03-15 13:15:10 -07008563 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8564 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008565 if (carrierPrivilegeRules == null) {
8566 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8567 } else {
8568 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008570 } finally {
8571 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008572 }
fionaxua13278b2018-03-21 00:08:13 -07008573 }
8574
8575 @Override
8576 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008577 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578
8579 final long identity = Binder.clearCallingIdentity();
8580 try {
8581 final Phone phone = getPhone(subId);
8582 if (phone == null) {
8583 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8584 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8585 }
8586 return phone.getCarrierIdListVersion();
8587 } finally {
8588 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008589 }
fionaxua13278b2018-03-21 00:08:13 -07008590 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008591
8592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008593 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8594 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008596 mApp, subId, callingPackage, callingFeatureId,
8597 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008598 return -1;
8599 }
8600
8601 final long identity = Binder.clearCallingIdentity();
8602 try {
8603 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8604 } finally {
8605 Binder.restoreCallingIdentity(identity);
8606 }
8607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008608
8609 @Override
8610 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008611 TelephonyPermissions
8612 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008613 mApp, subId, "getCdmaRoamingMode");
8614
8615 final long identity = Binder.clearCallingIdentity();
8616 try {
8617 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
8620 }
8621 }
8622
8623 @Override
8624 public boolean setCdmaRoamingMode(int subId, int mode) {
8625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8626 mApp, subId, "setCdmaRoamingMode");
8627
8628 final long identity = Binder.clearCallingIdentity();
8629 try {
8630 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8631 } finally {
8632 Binder.restoreCallingIdentity(identity);
8633 }
8634 }
8635
8636 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008637 public int getCdmaSubscriptionMode(int subId) {
8638 TelephonyPermissions
8639 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8640 mApp, subId, "getCdmaSubscriptionMode");
8641
8642 final long identity = Binder.clearCallingIdentity();
8643 try {
8644 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8645 } finally {
8646 Binder.restoreCallingIdentity(identity);
8647 }
8648 }
8649
8650 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008651 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8653 mApp, subId, "setCdmaSubscriptionMode");
8654
8655 final long identity = Binder.clearCallingIdentity();
8656 try {
8657 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8658 } finally {
8659 Binder.restoreCallingIdentity(identity);
8660 }
8661 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008662
sqianc5eccab2018-10-19 18:46:41 -07008663 @Override
sqian8c685422019-02-22 15:55:18 -08008664 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008665 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008667 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8668 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008669 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8670 }
8671 final long identity = Binder.clearCallingIdentity();
8672 try {
sqian854d44b2018-12-12 16:48:18 -08008673 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8674 for (Phone phone: PhoneFactory.getPhones()) {
8675 if (phone.getEmergencyNumberTracker() != null
8676 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8677 emergencyNumberListInternal.put(
8678 phone.getSubId(),
8679 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8680 }
sqian11b7a0e2018-12-05 18:48:28 -08008681 }
sqian854d44b2018-12-12 16:48:18 -08008682 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008683 } finally {
8684 Binder.restoreCallingIdentity(identity);
8685 }
sqianc5eccab2018-10-19 18:46:41 -07008686 }
8687
8688 @Override
sqian8c685422019-02-22 15:55:18 -08008689 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008690 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008691 if (!exactMatch) {
8692 TelephonyPermissions
8693 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008694 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008695 }
8696 final long identity = Binder.clearCallingIdentity();
8697 try {
sqian854d44b2018-12-12 16:48:18 -08008698 for (Phone phone: PhoneFactory.getPhones()) {
8699 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008700 && phone.getEmergencyNumberTracker()
8701 .isEmergencyNumber(number, exactMatch)) {
8702 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008703 }
sqian11b7a0e2018-12-05 18:48:28 -08008704 }
8705 return false;
8706 } finally {
8707 Binder.restoreCallingIdentity(identity);
8708 }
8709 }
8710
sqianf4ca7ed2019-01-15 18:32:07 -08008711 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008712 * Start emergency callback mode for GsmCdmaPhone for testing.
8713 */
8714 @Override
8715 public void startEmergencyCallbackMode() {
8716 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8717 "startEmergencyCallbackMode");
8718 enforceModifyPermission();
8719 final long identity = Binder.clearCallingIdentity();
8720 try {
8721 for (Phone phone : PhoneFactory.getPhones()) {
8722 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8723 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8724 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8725 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8726 gsmCdmaPhone.obtainMessage(
8727 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8728 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8729 }
8730 }
8731 } finally {
8732 Binder.restoreCallingIdentity(identity);
8733 }
8734 }
8735
8736 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008737 * Update emergency number list for test mode.
8738 */
8739 @Override
8740 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8742 "updateEmergencyNumberListTestMode");
8743
8744 final long identity = Binder.clearCallingIdentity();
8745 try {
8746 for (Phone phone: PhoneFactory.getPhones()) {
8747 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8748 if (tracker != null) {
8749 tracker.executeEmergencyNumberTestModeCommand(action, num);
8750 }
8751 }
8752 } finally {
8753 Binder.restoreCallingIdentity(identity);
8754 }
8755 }
8756
8757 /**
8758 * Get the full emergency number list for test mode.
8759 */
8760 @Override
8761 public List<String> getEmergencyNumberListTestMode() {
8762 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8763 "getEmergencyNumberListTestMode");
8764
8765 final long identity = Binder.clearCallingIdentity();
8766 try {
8767 Set<String> emergencyNumbers = new HashSet<>();
8768 for (Phone phone: PhoneFactory.getPhones()) {
8769 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8770 if (tracker != null) {
8771 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8772 emergencyNumbers.add(num.getNumber());
8773 }
8774 }
8775 }
8776 return new ArrayList<>(emergencyNumbers);
8777 } finally {
8778 Binder.restoreCallingIdentity(identity);
8779 }
8780 }
8781
chen xud6b45bd2018-10-30 22:27:10 -07008782 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008783 public int getEmergencyNumberDbVersion(int subId) {
8784 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8785
8786 final long identity = Binder.clearCallingIdentity();
8787 try {
8788 final Phone phone = getPhone(subId);
8789 if (phone == null) {
8790 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8791 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8792 }
8793 return phone.getEmergencyNumberDbVersion();
8794 } finally {
8795 Binder.restoreCallingIdentity(identity);
8796 }
8797 }
8798
8799 @Override
8800 public void notifyOtaEmergencyNumberDbInstalled() {
8801 enforceModifyPermission();
8802
8803 final long identity = Binder.clearCallingIdentity();
8804 try {
8805 for (Phone phone: PhoneFactory.getPhones()) {
8806 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8807 if (tracker != null) {
8808 tracker.updateOtaEmergencyNumberDatabase();
8809 }
8810 }
8811 } finally {
8812 Binder.restoreCallingIdentity(identity);
8813 }
8814 }
8815
8816 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008817 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008818 enforceActiveEmergencySessionPermission();
8819
8820 final long identity = Binder.clearCallingIdentity();
8821 try {
8822 for (Phone phone: PhoneFactory.getPhones()) {
8823 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8824 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008825 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8826 }
8827 }
8828 } finally {
8829 Binder.restoreCallingIdentity(identity);
8830 }
8831 }
8832
8833 @Override
8834 public void resetOtaEmergencyNumberDbFilePath() {
8835 enforceActiveEmergencySessionPermission();
8836
8837 final long identity = Binder.clearCallingIdentity();
8838 try {
8839 for (Phone phone: PhoneFactory.getPhones()) {
8840 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8841 if (tracker != null) {
8842 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008843 }
8844 }
8845 } finally {
8846 Binder.restoreCallingIdentity(identity);
8847 }
8848 }
8849
8850 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008851 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8852 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8853 Phone phone = getPhone(subId);
8854 if (phone == null) {
8855 return null;
8856 }
8857 final long identity = Binder.clearCallingIdentity();
8858 try {
8859 UiccProfile profile = UiccController.getInstance()
8860 .getUiccProfileForPhone(phone.getPhoneId());
8861 if (profile != null) {
8862 return profile.getCertsFromCarrierPrivilegeAccessRules();
8863 }
8864 } finally {
8865 Binder.restoreCallingIdentity(identity);
8866 }
8867 return null;
8868 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008869
8870 /**
8871 * Enable or disable a modem stack.
8872 */
8873 @Override
8874 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8875 enforceModifyPermission();
8876
8877 final long identity = Binder.clearCallingIdentity();
8878 try {
8879 Phone phone = PhoneFactory.getPhone(slotIndex);
8880 if (phone == null) {
8881 return false;
8882 } else {
8883 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8884 }
8885 } finally {
8886 Binder.restoreCallingIdentity(identity);
8887 }
8888 }
Michelecea4cf22018-12-21 15:00:11 -08008889
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008890 /**
8891 * Whether a modem stack is enabled or not.
8892 */
8893 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008894 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8895 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008896 Phone phone = PhoneFactory.getPhone(slotIndex);
8897 if (phone == null) return false;
8898
8899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008900 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8901 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008902 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8903 }
8904
8905 final long identity = Binder.clearCallingIdentity();
8906 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008907 try {
8908 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8909 } catch (NoSuchElementException ex) {
8910 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8911 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008912 } finally {
8913 Binder.restoreCallingIdentity(identity);
8914 }
8915 }
8916
Michelecea4cf22018-12-21 15:00:11 -08008917 @Override
Michele0ea7d782019-03-19 14:58:42 -07008918 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008919 enforceModifyPermission();
8920
8921 final long identity = Binder.clearCallingIdentity();
8922 try {
8923 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008924 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008925 .commit();
8926 } finally {
8927 Binder.restoreCallingIdentity(identity);
8928 }
8929 }
8930
8931 @Override
Michele0ea7d782019-03-19 14:58:42 -07008932 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008933 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008935 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8936 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008937 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008938 }
Michelecea4cf22018-12-21 15:00:11 -08008939
8940 final long identity = Binder.clearCallingIdentity();
8941 try {
Michele0ea7d782019-03-19 14:58:42 -07008942 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008943 } finally {
8944 Binder.restoreCallingIdentity(identity);
8945 }
8946 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008947
Michele0ea7d782019-03-19 14:58:42 -07008948 @TelephonyManager.IsMultiSimSupportedResult
8949 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008950 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8951 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8952 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008953 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8954 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008955 }
8956 // Check if the hardware supports multisim functionality. If usage of multisim is not
8957 // supported by the modem, indicate that it is restricted.
8958 PhoneCapability staticCapability =
8959 mPhoneConfigurationManager.getStaticPhoneCapability();
8960 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008961 loge("isMultiSimSupportedInternal: no static configuration available");
8962 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008963 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008964 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008965 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8966 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008967 }
8968 // Check if support of multiple SIMs is restricted by carrier
8969 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008970 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008971 }
8972
Michele0ea7d782019-03-19 14:58:42 -07008973 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008974 }
8975
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008976 /**
8977 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008978 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8979 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8980 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008981 * @param numOfSims number of active sims we want to switch to
8982 */
8983 @Override
8984 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008985 if (numOfSims == 1) {
8986 enforceModifyPermission();
8987 } else {
8988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8989 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8990 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008991 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008992
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008993 try {
Michele30b57b22019-03-01 12:01:14 -08008994 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008995 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008996 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8997 return;
8998 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008999 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9000 } finally {
9001 Binder.restoreCallingIdentity(identity);
9002 }
9003 }
9004
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009005 @Override
9006 public boolean isApplicationOnUicc(int subId, int appType) {
9007 enforceReadPrivilegedPermission("isApplicationOnUicc");
9008 Phone phone = getPhone(subId);
9009 if (phone == null) {
9010 return false;
9011 }
9012 final long identity = Binder.clearCallingIdentity();
9013 try {
9014 UiccCard uiccCard = phone.getUiccCard();
9015 if (uiccCard == null) {
9016 return false;
9017 }
9018 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9019 if (uiccProfile == null) {
9020 return false;
9021 }
9022 if (TelephonyManager.APPTYPE_SIM <= appType
9023 && appType <= TelephonyManager.APPTYPE_ISIM) {
9024 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9025 }
9026 return false;
9027 } finally {
9028 Binder.restoreCallingIdentity(identity);
9029 }
9030 }
9031
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009032 /**
chen xub4baa772019-04-03 10:23:41 -07009033 * Get whether making changes to modem configurations will trigger reboot.
9034 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009035 */
9036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009037 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9038 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009040 mApp, subId, callingPackage, callingFeatureId,
9041 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009042 return false;
9043 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009044 final long identity = Binder.clearCallingIdentity();
9045 try {
9046 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9047 } finally {
9048 Binder.restoreCallingIdentity(identity);
9049 }
9050 }
9051
Nathan Harold29f5f052019-02-15 13:41:57 -08009052 private void updateModemStateMetrics() {
9053 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9054 // TODO: check the state for each modem if the api is ready.
9055 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9056 }
9057
Pengquan Meng3889a572019-01-23 11:16:29 -08009058 @Override
9059 public int[] getSlotsMapping() {
9060 enforceReadPrivilegedPermission("getSlotsMapping");
9061
9062 final long identity = Binder.clearCallingIdentity();
9063 try {
9064 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9065 // All logical slots should have a mapping to a physical slot.
9066 int[] logicalSlotsMapping = new int[phoneCount];
9067 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9068 for (int i = 0; i < slotInfos.length; i++) {
9069 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9070 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9071 }
9072 }
9073 return logicalSlotsMapping;
9074 } finally {
9075 Binder.restoreCallingIdentity(identity);
9076 }
9077 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009078
9079 /**
9080 * Get the IRadio HAL Version
9081 */
9082 @Override
9083 public int getRadioHalVersion() {
9084 Phone phone = getDefaultPhone();
9085 if (phone == null) return -1;
9086 HalVersion hv = phone.getHalVersion();
9087 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9088 return hv.major * 100 + hv.minor;
9089 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009090
9091 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009092 * Get the current calling package name.
9093 * @return the current calling package name
9094 */
9095 @Override
9096 public String getCurrentPackageName() {
9097 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9098 }
9099
9100 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009101 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9102 * corresponding network requests on a subId.
9103 *
9104 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009105 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009106 * 2) APN is un-metered for this subscription, or
9107 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009108 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009109 *
9110 * @return whether data is allowed for a apn type.
9111 *
9112 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009113 */
9114 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009115 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009116 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9117 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009118
9119 // Now that all security checks passes, perform the operation as ourselves.
9120 final long identity = Binder.clearCallingIdentity();
9121 try {
9122 Phone phone = getPhone(subId);
9123 if (phone == null) return false;
9124
Jack Yu41407ee2019-05-13 16:54:09 -07009125 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009126 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9127 } finally {
9128 Binder.restoreCallingIdentity(identity);
9129 }
9130 }
9131
9132 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009133 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009134 enforceReadPrivilegedPermission("isApnMetered");
9135
9136 // Now that all security checks passes, perform the operation as ourselves.
9137 final long identity = Binder.clearCallingIdentity();
9138 try {
9139 Phone phone = getPhone(subId);
9140 if (phone == null) return true; // By default return true.
9141
Jack Yu41407ee2019-05-13 16:54:09 -07009142 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009143 } finally {
9144 Binder.restoreCallingIdentity(identity);
9145 }
9146 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009147
9148 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009149 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9150 int subscriptionId, IBooleanConsumer resultCallback) {
9151 enforceModifyPermission();
9152 long token = Binder.clearCallingIdentity();
9153 try {
9154 Phone phone = getPhone(subscriptionId);
9155 if (phone == null) {
9156 try {
9157 if (resultCallback != null) {
9158 resultCallback.accept(false);
9159 }
9160 } catch (RemoteException e) {
9161 // ignore
9162 }
9163 return;
9164 }
9165 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9166 Pair.create(specifiers, (x) -> {
9167 try {
9168 if (resultCallback != null) {
9169 resultCallback.accept(x);
9170 }
9171 } catch (RemoteException e) {
9172 // ignore
9173 }
9174 });
9175 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9176 } finally {
9177 Binder.restoreCallingIdentity(token);
9178 }
9179 }
9180
9181 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009182 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9183 TelephonyPermissions
9184 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9185 mApp, subId, "getSystemSelectionChannels");
9186 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9187 final long identity = Binder.clearCallingIdentity();
9188 try {
9189 List<RadioAccessSpecifier> specifiers =
9190 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9191 null, subId, workSource);
9192 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9193 return specifiers;
9194 } finally {
9195 Binder.restoreCallingIdentity(identity);
9196 }
9197 }
9198
9199 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009200 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009201 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009202 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9203 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9204 if (iccRecords == null) {
9205 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9206 return false;
9207 }
9208 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9209 }
9210
9211 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009212 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9213 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009214 if (callingPackage == null) {
9215 callingPackage = getCurrentPackageName();
9216 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009217 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9218 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009219 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9220 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009221 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9222 }
9223 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9224 Intent intent = new Intent();
9225 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9226 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9227 // Bring up choose default SMS subscription dialog right now
9228 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9229 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9230 mApp.startActivity(intent);
9231 }
chen xud5ca2d52019-05-28 15:20:57 -07009232
9233 @Override
9234 public String getMmsUAProfUrl(int subId) {
9235 //TODO investigate if this API should require proper permission check in R b/133791609
9236 final long identity = Binder.clearCallingIdentity();
9237 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009238 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9239 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9240 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9241 return carrierUAProfUrl;
9242 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009243 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9244 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009245 } finally {
9246 Binder.restoreCallingIdentity(identity);
9247 }
9248 }
9249
9250 @Override
9251 public String getMmsUserAgent(int subId) {
9252 //TODO investigate if this API should require proper permission check in R b/133791609
9253 final long identity = Binder.clearCallingIdentity();
9254 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009255 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9256 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9257 if (!TextUtils.isEmpty(carrierUserAgent)) {
9258 return carrierUserAgent;
9259 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009260 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9261 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009262 } finally {
9263 Binder.restoreCallingIdentity(identity);
9264 }
9265 }
Jack Yub07d4972019-05-28 16:12:25 -07009266
9267 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009268 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9269 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009270
Jack Yub07d4972019-05-28 16:12:25 -07009271 final long identity = Binder.clearCallingIdentity();
9272 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009273 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009274 if (phone == null) return false;
9275
Hall Liua62f5da2020-09-25 10:42:19 -07009276 switch (policy) {
9277 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9278 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9279 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9280 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9281 default:
9282 throw new IllegalArgumentException(policy + " is not a valid policy");
9283 }
Jack Yub07d4972019-05-28 16:12:25 -07009284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 }
9288
9289 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009290 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009291 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009292 enforceModifyPermission();
9293
changbettyd5c246e2019-12-24 15:40:37 +08009294 final long identity = Binder.clearCallingIdentity();
9295 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009296 Phone phone = getPhone(subscriptionId);
9297 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009298
Hall Liua62f5da2020-09-25 10:42:19 -07009299 switch (policy) {
9300 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9301 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9302 break;
9303 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9304 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9305 break;
9306 default:
9307 throw new IllegalArgumentException(policy + " is not a valid policy");
9308 }
changbettyd5c246e2019-12-24 15:40:37 +08009309 } finally {
9310 Binder.restoreCallingIdentity(identity);
9311 }
9312 }
9313
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009314 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009315 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009316 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9317 * otherwise.
9318 */
9319 @Override
9320 public void setCepEnabled(boolean isCepEnabled) {
9321 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9322
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
9325 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9326 for (Phone phone : PhoneFactory.getPhones()) {
9327 Phone defaultPhone = phone.getImsPhone();
9328 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9329 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9330 ImsPhoneCallTracker imsPhoneCallTracker =
9331 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9332 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9333 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9334 + imsPhone.getMsisdn());
9335 }
9336 }
9337 } finally {
9338 Binder.restoreCallingIdentity(identity);
9339 }
9340 }
allenwtsu46dcc572020-01-08 18:24:03 +08009341
9342 /**
9343 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9344 *
9345 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9346 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9347 * before being read.
9348 */
9349 @Override
9350 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9351 isCompressed) {
9352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9353 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009354 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9355 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9356 }
9357 if (!isImsAvailableOnDevice()) {
9358 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9359 "IMS not available on device.");
9360 }
9361
9362 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009363 try {
Hui Wang761a6682020-10-31 05:12:53 +00009364 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9365 } finally {
9366 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009367 }
9368 }
zoey chene02881a2019-12-30 16:11:23 +08009369
9370 @Override
9371 public boolean isIccLockEnabled(int subId) {
9372 enforceReadPrivilegedPermission("isIccLockEnabled");
9373
9374 // Now that all security checks passes, perform the operation as ourselves.
9375 final long identity = Binder.clearCallingIdentity();
9376 try {
9377 Phone phone = getPhone(subId);
9378 if (phone != null && phone.getIccCard() != null) {
9379 return phone.getIccCard().getIccLockEnabled();
9380 } else {
9381 return false;
9382 }
9383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 }
9387
9388 /**
9389 * Set the ICC pin lock enabled or disabled.
9390 *
9391 * @return an integer representing the status of IccLock enabled or disabled in the following
9392 * three cases:
9393 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9394 * successfully.
9395 * - Positive number and zero for remaining password attempts.
9396 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9397 *
9398 */
9399 @Override
9400 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9401 enforceModifyPermission();
9402
9403 Phone phone = getPhone(subId);
9404 if (phone == null) {
9405 return 0;
9406 }
9407 // Now that all security checks passes, perform the operation as ourselves.
9408 final long identity = Binder.clearCallingIdentity();
9409 try {
9410 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9411 new Pair<Boolean, String>(enabled, password), phone, null);
9412 return attemptsRemaining;
9413
9414 } catch (Exception e) {
9415 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9416 } finally {
9417 Binder.restoreCallingIdentity(identity);
9418 }
9419 return 0;
9420 }
9421
9422 /**
9423 * Change the ICC password used in ICC pin lock.
9424 *
9425 * @return an integer representing the status of IccLock changed in the following three cases:
9426 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9427 * - Positive number and zero for remaining password attempts.
9428 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9429 *
9430 */
9431 @Override
9432 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9433 enforceModifyPermission();
9434
9435 Phone phone = getPhone(subId);
9436 if (phone == null) {
9437 return 0;
9438 }
9439 // Now that all security checks passes, perform the operation as ourselves.
9440 final long identity = Binder.clearCallingIdentity();
9441 try {
9442 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9443 new Pair<String, String>(oldPassword, newPassword), phone, null);
9444 return attemptsRemaining;
9445
9446 } catch (Exception e) {
9447 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9448 } finally {
9449 Binder.restoreCallingIdentity(identity);
9450 }
9451 return 0;
9452 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009453
9454 /**
9455 * Request for receiving user activity notification
9456 */
9457 @Override
9458 public void requestUserActivityNotification() {
9459 if (!mNotifyUserActivity.get()
9460 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9461 mNotifyUserActivity.set(true);
9462 }
9463 }
9464
9465 /**
9466 * Called when userActivity is signalled in the power manager.
9467 * This is safe to call from any thread, with any window manager locks held or not.
9468 */
9469 @Override
9470 public void userActivity() {
9471 // ***************************************
9472 // * Inherited from PhoneWindowManager *
9473 // ***************************************
9474 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9475 // WITH ITS LOCKS HELD.
9476 //
9477 // This code must be VERY careful about the locks
9478 // it acquires.
9479 // In fact, the current code acquires way too many,
9480 // and probably has lurking deadlocks.
9481
9482 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9483 throw new SecurityException("Only the OS may call notifyUserActivity()");
9484 }
9485
9486 if (mNotifyUserActivity.getAndSet(false)) {
9487 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9488 USER_ACTIVITY_NOTIFICATION_DELAY);
9489 }
9490 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009491
9492 @Override
9493 public boolean canConnectTo5GInDsdsMode() {
9494 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9495 }
Jack Yud10cdd42020-09-28 20:28:01 -07009496
9497 @Override
9498 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9499 String callingFeatureId) {
9500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9501 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9502 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9503 }
9504
9505 Phone phone = getPhone(subId);
9506 if (phone == null) {
9507 throw new RuntimeException("phone is not available");
9508 }
9509 // Now that all security checks passes, perform the operation as ourselves.
9510 final long identity = Binder.clearCallingIdentity();
9511 try {
9512 return phone.getEquivalentHomePlmns();
9513 } finally {
9514 Binder.restoreCallingIdentity(identity);
9515 }
9516 }
Daniel Bright59e67312020-11-13 11:49:37 -08009517
9518 @Override
9519 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009520 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9521 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009522 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009523 if (radioInterfaceCapabilities == null) {
9524 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009525 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009526 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009527 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009528
Hui Wang641e81c2020-10-12 12:14:23 -07009529 @Override
9530 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9531 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009532 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9533 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9534 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9535 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9536 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009537 if (DBG) {
9538 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9539 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9540 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9541 }
9542
9543 if (!SubscriptionManager.isValidSubscriptionId(subId)
9544 || appType < TelephonyManager.APPTYPE_UNKNOWN
9545 || appType > TelephonyManager.APPTYPE_ISIM
9546 || nafUrl == null || securityProtocol == null || callback == null) {
9547 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9548 if (callback != null) {
9549 try {
9550 callback.onAuthenticationFailure(
9551 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9552 } catch (RemoteException exception) {
9553 log("Fail to notify onAuthenticationFailure due to " + exception);
9554 }
9555 return;
9556 }
9557 }
9558
9559 final long token = Binder.clearCallingIdentity();
9560 try {
9561 getGbaManager(subId).bootstrapAuthenticationRequest(
9562 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9563 forceBootStrapping, callback));
9564 } finally {
9565 Binder.restoreCallingIdentity(token);
9566 }
9567 }
9568
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009569 /**
9570 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9571 * requested radio power state will actually be set. See {@link
9572 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9573 *
9574 * @param subId the subscription ID of the phone requesting to set the radio power state.
9575 * @param enable {@code true} if trying to turn radio on.
9576 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9577 * false}.
9578 */
9579 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9580 Phone phone = getPhone(subId);
9581 if (phone != null) {
9582 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9583 return true;
9584 }
9585 return false;
9586 }
9587
9588 private int handleDataThrottlingRequest(int subId,
9589 DataThrottlingRequest dataThrottlingRequest) {
9590 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9591 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9592 if (!setRadioPowerForThermal(subId, true)) {
9593 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9594 }
9595
9596 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9597
9598 int thermalMitigationResult =
9599 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9600 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9601 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9602 }
9603 return thermalMitigationResult;
9604 }
9605
9606 /**
9607 * Thermal mitigation request to control functionalities at modem.
9608 *
9609 * @param subId the id of the subscription.
9610 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9611 *
9612 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9613 */
9614 @Override
9615 @ThermalMitigationResult
9616 public int sendThermalMitigationRequest(
9617 int subId,
9618 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9619 enforceModifyPermission();
9620
9621 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9622 final long identity = Binder.clearCallingIdentity();
9623
9624 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9625 try {
9626 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9627 switch (thermalMitigationAction) {
9628 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9629 thermalMitigationResult =
9630 handleDataThrottlingRequest(subId,
9631 thermalMitigationRequest.getDataThrottlingRequest());
9632 break;
9633 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9634 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9635 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9636 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9637 }
9638
9639 // Ensure that radio is on. If not able to power on due to phone being
9640 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9641 if (!setRadioPowerForThermal(subId, true)) {
9642 thermalMitigationResult =
9643 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9644 break;
9645 }
9646
9647 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9648 false);
9649 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9650 break;
9651 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9652 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9653 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9654 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9655 }
9656
9657 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9658 if (registry != null) {
9659 TelephonyConnectionService service =
9660 registry.getTelephonyConnectionService();
9661 Phone phone = getPhone(subId);
9662 if (phone == null) {
9663 thermalMitigationResult =
9664 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9665 break;
9666 }
9667
9668 if (PhoneConstantConversions.convertCallState(phone.getState())
9669 != TelephonyManager.CALL_STATE_IDLE
9670 || phone.isInEmergencySmsMode() || phone.isInEcm()
9671 || (service != null && service.isEmergencyCallPending())) {
9672 String errorMessage = "Phone state is not valid. call state = "
9673 + PhoneConstantConversions.convertCallState(phone.getState())
9674 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9675 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9676 errorMessage += service == null
9677 ? " TelephonyConnectionService is null"
9678 : " isEmergencyCallPending = "
9679 + service.isEmergencyCallPending();
9680 Log.e(LOG_TAG, errorMessage);
9681 thermalMitigationResult =
9682 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9683 break;
9684 }
9685 } else {
9686 thermalMitigationResult =
9687 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9688 break;
9689 }
9690
9691 // Turn radio off. If not able to power off due to phone being unavailable,
9692 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9693 if (!setRadioPowerForThermal(subId, false)) {
9694 thermalMitigationResult =
9695 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9696 break;
9697 }
9698 thermalMitigationResult =
9699 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9700 break;
9701 default:
9702 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9703 + "not exist. Requested action: " + thermalMitigationAction);
9704 }
9705 } catch (IllegalArgumentException e) {
9706 throw e;
9707 } catch (Exception e) {
9708 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9709 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9710 } finally {
9711 Binder.restoreCallingIdentity(identity);
9712 }
9713
9714 if (DBG) {
9715 log("thermalMitigationRequest returning with thermalMitigationResult: "
9716 + thermalMitigationResult);
9717 }
9718
9719 return thermalMitigationResult;
9720 }
Hui Wang641e81c2020-10-12 12:14:23 -07009721
9722 /**
9723 * Set the GbaService Package Name that Telephony will bind to.
9724 *
9725 * @param subId The sim that the GbaService is associated with.
9726 * @param packageName The name of the package to be replaced with.
9727 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9728 */
9729 @Override
9730 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9731 enforceModifyPermission();
9732
9733 final long identity = Binder.clearCallingIdentity();
9734 try {
9735 return getGbaManager(subId).overrideServicePackage(packageName);
9736 } finally {
9737 Binder.restoreCallingIdentity(identity);
9738 }
9739 }
9740
9741 /**
9742 * Return the package name of the currently bound GbaService.
9743 *
9744 * @param subId The sim that the GbaService is associated with.
9745 * @return the package name of the GbaService configuration, null if GBA is not supported.
9746 */
9747 @Override
9748 public String getBoundGbaService(int subId) {
9749 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9750
9751 final long identity = Binder.clearCallingIdentity();
9752 try {
9753 return getGbaManager(subId).getServicePackage();
9754 } finally {
9755 Binder.restoreCallingIdentity(identity);
9756 }
9757 }
9758
9759 /**
9760 * Set the release time for telephony to unbind GbaService.
9761 *
9762 * @param subId The sim that the GbaService is associated with.
9763 * @param interval The release time to unbind GbaService by millisecond.
9764 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9765 */
9766 @Override
9767 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9768 enforceModifyPermission();
9769
9770 final long identity = Binder.clearCallingIdentity();
9771 try {
9772 return getGbaManager(subId).overrideReleaseTime(interval);
9773 } finally {
9774 Binder.restoreCallingIdentity(identity);
9775 }
9776 }
9777
9778 /**
9779 * Return the release time for telephony to unbind GbaService.
9780 *
9781 * @param subId The sim that the GbaService is associated with.
9782 * @return The release time to unbind GbaService by millisecond.
9783 */
9784 @Override
9785 public int getGbaReleaseTime(int subId) {
9786 enforceReadPrivilegedPermission("getGbaReleaseTime");
9787
9788 final long identity = Binder.clearCallingIdentity();
9789 try {
9790 return getGbaManager(subId).getReleaseTime();
9791 } finally {
9792 Binder.restoreCallingIdentity(identity);
9793 }
9794 }
9795
9796 private GbaManager getGbaManager(int subId) {
9797 GbaManager instance = GbaManager.getInstance(subId);
9798 if (instance == null) {
9799 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9800 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9801 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9802 }
9803 return instance;
9804 }
Hui Wang761a6682020-10-31 05:12:53 +00009805
9806 /**
9807 * indicate whether the device and the carrier can support
9808 * RCS VoLTE single registration.
9809 */
9810 @Override
9811 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009812 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9813 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9814 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9815 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009816
9817 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9818 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9819 }
9820
9821 final long identity = Binder.clearCallingIdentity();
9822 try {
9823 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9824 if (rpm != null) {
9825 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9826 }
9827 return false;
9828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 }
9832
9833 /**
9834 * Register RCS provisioning callback.
9835 */
9836 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009837 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009838 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009839 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009840 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009841 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9842 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009843
9844 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9845 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9846 }
9847 if (!isImsAvailableOnDevice()) {
9848 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9849 "IMS not available on device.");
9850 }
9851
9852 final long identity = Binder.clearCallingIdentity();
9853 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009854 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009855 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -08009856 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9857 "Service not available for the subscription.");
9858 }
Hui Wang761a6682020-10-31 05:12:53 +00009859 } finally {
9860 Binder.restoreCallingIdentity(identity);
9861 }
9862 }
9863
9864 /**
9865 * Unregister RCS provisioning callback.
9866 */
9867 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009868 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009869 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009870 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009871 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009872 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9873 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009874
9875 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9876 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9877 }
9878 if (!isImsAvailableOnDevice()) {
9879 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9880 "IMS not available on device.");
9881 }
9882
9883 final long identity = Binder.clearCallingIdentity();
9884 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009885 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009886 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009887 } finally {
9888 Binder.restoreCallingIdentity(identity);
9889 }
9890 }
9891
9892 /**
9893 * trigger RCS reconfiguration.
9894 */
9895 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009896 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9897 "triggerRcsReconfiguration",
9898 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009899
9900 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9901 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9902 }
9903 if (!isImsAvailableOnDevice()) {
9904 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9905 "IMS not available on device.");
9906 }
9907
9908 final long identity = Binder.clearCallingIdentity();
9909 try {
9910 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9911 } finally {
9912 Binder.restoreCallingIdentity(identity);
9913 }
9914 }
9915
9916 /**
9917 * Provide the client configuration parameters of the RCS application.
9918 */
9919 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009920 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9921 "setRcsClientConfiguration",
9922 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009923
9924 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9925 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9926 }
9927 if (!isImsAvailableOnDevice()) {
9928 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9929 "IMS not available on device.");
9930 }
9931
9932 final long identity = Binder.clearCallingIdentity();
9933
9934 try {
9935 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9936 if (configBinder == null) {
9937 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9938 } else {
9939 configBinder.setRcsClientConfiguration(rcc);
9940 }
9941 } catch (RemoteException e) {
9942 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9943 } finally {
9944 Binder.restoreCallingIdentity(identity);
9945 }
9946 }
9947
9948 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -08009949 * Enables or disables the test mode for RCS VoLTE single registration.
9950 */
9951 @Override
9952 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9954 "setRcsSingleRegistrationTestModeEnabled");
9955
9956 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9957 }
9958
9959 /**
9960 * Gets the test mode for RCS VoLTE single registration.
9961 */
9962 @Override
9963 public boolean getRcsSingleRegistrationTestModeEnabled() {
9964 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9965 "getRcsSingleRegistrationTestModeEnabled");
9966
9967 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9968 }
9969
9970 /**
Hui Wang761a6682020-10-31 05:12:53 +00009971 * Overrides the config of RCS VoLTE single registration enabled for the device.
9972 */
9973 @Override
9974 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9975 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9976 "setDeviceSingleRegistrationEnabledOverride");
9977 enforceModifyPermission();
9978
9979 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9980 : Boolean.parseBoolean(enabledStr);
9981 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009982 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +00009983 }
9984
9985 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009986 * Sends a device to device communication message. Only usable via shell.
9987 * @param message message to send.
9988 * @param value message value.
9989 */
9990 @Override
9991 public void sendDeviceToDeviceMessage(int message, int value) {
9992 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -08009993 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -08009994 enforceModifyPermission();
9995
9996 final long identity = Binder.clearCallingIdentity();
9997 try {
9998 TelephonyConnectionService service =
9999 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10000 if (service == null) {
10001 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10002 return;
10003 }
10004 service.sendTestDeviceToDeviceMessage(message, value);
10005 } finally {
10006 Binder.restoreCallingIdentity(identity);
10007 }
10008 }
10009
Tyler Gunnbabbda02021-02-10 11:05:02 -080010010 /**
10011 * Sets the specified device to device transport active.
10012 * @param transport The transport to set active.
10013 */
10014 @Override
10015 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10016 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10017 "setActiveDeviceToDeviceTransport");
10018 enforceModifyPermission();
10019
10020 final long identity = Binder.clearCallingIdentity();
10021 try {
10022 TelephonyConnectionService service =
10023 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10024 if (service == null) {
10025 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10026 return;
10027 }
10028 service.setActiveDeviceToDeviceTransport(transport);
10029 } finally {
10030 Binder.restoreCallingIdentity(identity);
10031 }
10032 }
Tyler Gunn92479152021-01-20 16:30:10 -080010033
10034 /**
Hui Wang761a6682020-10-31 05:12:53 +000010035 * Gets the config of RCS VoLTE single registration enabled for the device.
10036 */
10037 @Override
10038 public boolean getDeviceSingleRegistrationEnabled() {
10039 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10040 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10041 }
10042
10043 /**
10044 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10045 */
10046 @Override
10047 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10048 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10049 "setCarrierSingleRegistrationEnabledOverride");
10050 enforceModifyPermission();
10051
10052 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10053 : Boolean.parseBoolean(enabledStr);
10054 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10055 subId, enabled);
10056 }
10057
10058 /**
10059 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10060 */
10061 @Override
10062 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10063 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10064 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10065 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010066
10067 /**
10068 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10069 * their mobile plan.
10070 */
10071 @Override
10072 public String getMobileProvisioningUrl() {
10073 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10074 final long identity = Binder.clearCallingIdentity();
10075 try {
10076 return getDefaultPhone().getMobileProvisioningUrl();
10077 } finally {
10078 Binder.restoreCallingIdentity(identity);
10079 }
10080 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010081
James.cf Linbcdf8b32021-01-14 16:44:13 +080010082 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010083 * Get the EAB contact from the EAB database.
10084 */
10085 @Override
10086 public String getContactFromEab(String contact) {
10087 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10088 enforceModifyPermission();
10089 final long identity = Binder.clearCallingIdentity();
10090 try {
10091 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10092 } finally {
10093 Binder.restoreCallingIdentity(identity);
10094 }
10095 }
10096
10097 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010098 * Remove the EAB contacts from the EAB database.
10099 */
10100 @Override
10101 public int removeContactFromEab(int subId, String contacts) {
10102 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10103 enforceModifyPermission();
10104 final long identity = Binder.clearCallingIdentity();
10105 try {
10106 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10107 } finally {
10108 Binder.restoreCallingIdentity(identity);
10109 }
10110 }
10111
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010112 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010113 public boolean getDeviceUceEnabled() {
10114 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10115 final long identity = Binder.clearCallingIdentity();
10116 try {
10117 return mApp.getDeviceUceEnabled();
10118 } finally {
10119 Binder.restoreCallingIdentity(identity);
10120 }
10121 }
10122
10123 @Override
10124 public void setDeviceUceEnabled(boolean isEnabled) {
10125 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10126 final long identity = Binder.clearCallingIdentity();
10127 try {
10128 mApp.setDeviceUceEnabled(isEnabled);
10129 } finally {
10130 Binder.restoreCallingIdentity(identity);
10131 }
10132 }
10133
Brad Ebinger14d467f2021-02-12 06:18:28 +000010134 /**
10135 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10136 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10137 */
10138 // Used for SHELL command only right now.
10139 @Override
10140 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10141 List<String> featureTags) {
10142 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10143 "addUceRegistrationOverrideShell");
10144 final long identity = Binder.clearCallingIdentity();
10145 try {
10146 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10147 new ArraySet<>(featureTags));
10148 } catch (ImsException e) {
10149 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10150 } finally {
10151 Binder.restoreCallingIdentity(identity);
10152 }
10153 }
10154
10155 /**
10156 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10157 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10158 */
10159 // Used for SHELL command only right now.
10160 @Override
10161 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10162 List<String> featureTags) {
10163 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10164 "removeUceRegistrationOverrideShell");
10165 final long identity = Binder.clearCallingIdentity();
10166 try {
10167 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10168 new ArraySet<>(featureTags));
10169 } catch (ImsException e) {
10170 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10171 } finally {
10172 Binder.restoreCallingIdentity(identity);
10173 }
10174 }
10175
10176 /**
10177 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10178 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10179 */
10180 // Used for SHELL command only right now.
10181 @Override
10182 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10183 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10184 "clearUceRegistrationOverrideShell");
10185 final long identity = Binder.clearCallingIdentity();
10186 try {
10187 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10188 } catch (ImsException e) {
10189 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10190 } finally {
10191 Binder.restoreCallingIdentity(identity);
10192 }
10193 }
10194
10195 /**
10196 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10197 */
10198 // Used for SHELL command only right now.
10199 @Override
10200 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10201 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10202 "getLatestRcsContactUceCapabilityShell");
10203 final long identity = Binder.clearCallingIdentity();
10204 try {
10205 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10206 } catch (ImsException e) {
10207 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10208 } finally {
10209 Binder.restoreCallingIdentity(identity);
10210 }
10211 }
10212
10213 /**
10214 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10215 * device does not have an active PUBLISH.
10216 */
10217 // Used for SHELL command only right now.
10218 @Override
10219 public String getLastUcePidfXmlShell(int subId) {
10220 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10221 final long identity = Binder.clearCallingIdentity();
10222 try {
10223 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10224 } catch (ImsException e) {
10225 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10226 } finally {
10227 Binder.restoreCallingIdentity(identity);
10228 }
10229 }
10230
10231
James.cf Lin4b784aa2021-01-31 03:25:15 +080010232 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010233 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10234 String callingPackage) {
10235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10236 mApp, subId, "setSignalStrengthUpdateRequest");
10237
10238 final int callingUid = Binder.getCallingUid();
10239 // Verify that tha callingPackage belongs to the calling UID
10240 mApp.getSystemService(AppOpsManager.class)
10241 .checkPackage(callingUid, callingPackage);
10242
10243 validateSignalStrengthUpdateRequest(request, callingUid);
10244
10245 final long identity = Binder.clearCallingIdentity();
10246 try {
10247 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10248 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10249
10250 if (result instanceof IllegalStateException) {
10251 throw (IllegalStateException) result;
10252 }
10253 } finally {
10254 Binder.restoreCallingIdentity(identity);
10255 }
10256 }
10257
10258 @Override
10259 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10260 String callingPackage) {
10261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10262 mApp, subId, "clearSignalStrengthUpdateRequest");
10263
10264 final int callingUid = Binder.getCallingUid();
10265 // Verify that tha callingPackage belongs to the calling UID
10266 mApp.getSystemService(AppOpsManager.class)
10267 .checkPackage(callingUid, callingPackage);
10268
10269 final long identity = Binder.clearCallingIdentity();
10270 try {
10271 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10272 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10273
10274 if (result instanceof IllegalStateException) {
10275 throw (IllegalStateException) result;
10276 }
10277 } finally {
10278 Binder.restoreCallingIdentity(identity);
10279 }
10280 }
10281
10282 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10283 int callingUid) {
10284 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10285 // phone/system process do not have further restriction on request
10286 return;
10287 }
10288
10289 // Applications has restrictions on how to use the request:
10290 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10291 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10292 // This is not system caller which has been checked above
10293 throw new IllegalArgumentException(
10294 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10295 }
10296
10297 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10298 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10299 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10300 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10301 || info.isEnabled()) {
10302 throw new IllegalArgumentException(
10303 "Only system can set hide fields in SignalThresholdInfo");
10304 }
10305
10306 // Thresholds length for each RAN need in range. This has been validated in
10307 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10308 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10309 final int[] thresholds = info.getThresholds();
10310 Objects.requireNonNull(thresholds);
10311 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10312 || thresholds.length
10313 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10314 throw new IllegalArgumentException(
10315 "thresholds length is out of range: " + thresholds.length);
10316 }
10317 }
10318 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010319
10320 /**
10321 * Gets the current phone capability.
10322 *
10323 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10324 * @return the PhoneCapability which describes the data connection capability of modem.
10325 * It's used to evaluate possible phone config change, for example from single
10326 * SIM device to multi-SIM device.
10327 */
10328 @Override
10329 public PhoneCapability getPhoneCapability() {
10330 enforceReadPrivilegedPermission("getPhoneCapability");
10331 final long identity = Binder.clearCallingIdentity();
10332 try {
10333 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10334 } finally {
10335 Binder.restoreCallingIdentity(identity);
10336 }
10337 }
Michele Berionne5e411512020-11-13 02:36:59 +000010338
10339 /**
10340 * Prepare TelephonyManager for an unattended reboot. The reboot is
10341 * required to be done shortly after the API is invoked.
10342 */
10343 @Override
10344 @TelephonyManager.PrepareUnattendedRebootResult
10345 public int prepareForUnattendedReboot() {
10346 enforceRebootPermission();
10347
10348 final long identity = Binder.clearCallingIdentity();
10349 try {
10350 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10351 } finally {
10352 Binder.restoreCallingIdentity(identity);
10353 }
10354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010355}