blob: 3110021f654edf1dd5509d88b9ac3749ec4abc43 [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;
sandeepjs0a502c42021-09-27 15:34:44 +000030import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080032import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000033import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080034import android.app.role.RoleManager;
sandeepjs0a502c42021-09-27 15:34:44 +000035import android.compat.annotation.ChangeId;
36import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070037import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070038import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.content.Context;
40import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070041import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070042import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080043import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070044import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.net.Uri;
46import android.os.AsyncResult;
47import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080048import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Bundle;
50import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.Looper;
53import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070054import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080055import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070056import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070057import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080058import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080059import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070060import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070061import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080062import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070064import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070065import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070066import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070067import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080068import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070069import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090070import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080071import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080072import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070073import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070074import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080075import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080076import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070077import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080078import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070079import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080080import android.telephony.CellIdentityCdma;
81import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070083import android.telephony.CellInfoGsm;
84import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070085import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070087import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070088import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070089import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080090import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070091import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080092import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070093import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080094import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080095import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070096import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080097import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080099import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800100import android.telephony.SignalStrengthUpdateRequest;
101import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800102import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800103import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800104import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700105import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800107import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800108import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800109import android.telephony.UiccCardInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000110import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000111import android.telephony.UiccSlotInfo;
sandeepjs0a502c42021-09-27 15:34:44 +0000112import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700113import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700114import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800115import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800116import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800117import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700118import android.telephony.gba.GbaAuthRequest;
119import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700120import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000122import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000123import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700124import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700125import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800126import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700127import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800128import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700129import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000130import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700131import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800132import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800133import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800135import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800137import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700138import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800140import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800141
Andrew Lee312e8172014-10-23 17:01:36 -0700142import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800143import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800144import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800145import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800146import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700148import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700149import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800150import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700151import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800153import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700155import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800156import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800157import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800158import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700159import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +0000160import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700161import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800162import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800164import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700165import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700166import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700167import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700169import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800170import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700171import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700172import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700173import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700174import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800175import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800176import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700177import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700178import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700179import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800180import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800181import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800182import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700183import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800184import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700185import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800186import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700187import com.android.internal.telephony.imsphone.ImsPhone;
188import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800189import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700190import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800192import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700193import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800194import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700195import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800196import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000198import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800199import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000200import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800201import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700202import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700203import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800204import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800205import com.android.phone.callcomposer.CallComposerPictureManager;
206import com.android.phone.callcomposer.CallComposerPictureTransfer;
207import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700208import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700209import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800210import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700211import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700212import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800213import com.android.services.telephony.TelecomAccountRegistry;
214import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800215import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800216
Hall Liu82694d52020-12-11 18:22:04 -0800217import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700218import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800219import java.io.IOException;
220import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700221import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800223import java.util.Arrays;
sandeepjs0a502c42021-09-27 15:34:44 +0000224import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800225import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800226import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800227import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100228import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800229import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700230import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800231import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800232import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800233import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800234import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800235import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236
237/**
238 * Implementation of the ITelephony interface.
239 */
Santos Cordon117fee72014-05-16 17:56:12 -0700240public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241 private static final String LOG_TAG = "PhoneInterfaceManager";
242 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
243 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800244 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245
246 // Message codes used with mMainThreadHandler
247 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700248 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
249 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700250 private static final int CMD_OPEN_CHANNEL = 9;
251 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
252 private static final int CMD_CLOSE_CHANNEL = 11;
253 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800254 private static final int CMD_NV_READ_ITEM = 13;
255 private static final int EVENT_NV_READ_ITEM_DONE = 14;
256 private static final int CMD_NV_WRITE_ITEM = 15;
257 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
258 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
259 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700260 private static final int CMD_RESET_MODEM_CONFIG = 19;
261 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800262 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
263 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800264 private static final int CMD_SEND_ENVELOPE = 25;
265 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000266 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
267 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700268 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
269 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
270 private static final int CMD_EXCHANGE_SIM_IO = 31;
271 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800272 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
273 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700274 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
275 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700276 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
277 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700278 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
279 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
280 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
281 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700282 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
283 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
284 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
285 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700286 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800287 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
288 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000289 private static final int CMD_SWITCH_SLOTS = 50;
290 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700291 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
292 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
293 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
294 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
295 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
296 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
297 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
298 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700299 private static final int CMD_GET_ALL_CELL_INFO = 60;
300 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
301 private static final int CMD_GET_CELL_LOCATION = 62;
302 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700303 private static final int CMD_MODEM_REBOOT = 64;
304 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700305 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
306 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800307 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
308 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700309 private static final int CMD_GET_MODEM_STATUS = 70;
310 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700311 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
312 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700313 private static final int CMD_ERASE_MODEM_CONFIG = 74;
314 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800315 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
316 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
317 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
318 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800319 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
320 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800321 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800322 private static final int CMD_GET_CALL_FORWARDING = 83;
323 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
324 private static final int CMD_SET_CALL_FORWARDING = 85;
325 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
326 private static final int CMD_GET_CALL_WAITING = 87;
327 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
328 private static final int CMD_SET_CALL_WAITING = 89;
329 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700330 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
331 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
332 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
333 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700334 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
335 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800336 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
337 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800338 private static final int CMD_SET_DATA_THROTTLING = 99;
339 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800340 private static final int CMD_SET_SIM_POWER = 101;
341 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800342 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
343 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
344 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
345 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800346 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
347 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000348 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800349 private static final int CMD_GET_SLICING_CONFIG = 110;
350 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800351 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700352 private static final int CMD_ENABLE_VONR = 113;
353 private static final int EVENT_ENABLE_VONR_DONE = 114;
354 private static final int CMD_IS_VONR_ENABLED = 115;
355 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800357 // Parameters of select command.
358 private static final int SELECT_COMMAND = 0xA4;
359 private static final int SELECT_P1 = 0x04;
360 private static final int SELECT_P2 = 0;
361 private static final int SELECT_P3 = 0x10;
362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 /** The singleton instance. */
364 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800365 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
Wink Saville3ab207e2014-11-20 13:07:20 -0800367 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800368 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800369 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700370 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800371 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700372 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800373 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800374 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700376 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800377 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378
Peter Wangdafb9ac2020-01-15 14:13:38 -0800379 /** User Activity */
380 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800381 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
382
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700383 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
384
Derek Tan97ebb422014-09-05 16:55:38 -0700385 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
386 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800387 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800388 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700389
Michelecea4cf22018-12-21 15:00:11 -0800390 // String to store multi SIM allowed
391 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
392
Derek Tan740e1672017-06-27 14:56:27 -0700393 // The AID of ISD-R.
394 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
395
yinxub1bed742017-04-17 11:45:04 -0700396 private NetworkScanRequestTracker mNetworkScanRequestTracker;
397
David Kelly5e06a7f2018-03-12 14:10:59 +0000398 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
399 private static final int MANUFACTURER_CODE_LENGTH = 8;
400
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800401 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800402 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800403
Derek Tan89e89d42014-07-08 17:00:10 -0700404 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700405 * Experiment flag to enable erase modem config on reset network, default value is false
406 */
407 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
408 "reset_network_erase_modem_config_enabled";
409
Rambo Wang0f050d82021-02-12 11:43:36 -0800410 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjs0a502c42021-09-27 15:34:44 +0000411 /**
412 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
413 * one ICCID active at the same time.
414 * Apps should use below API signatures if targeting SDK is T and beyond.
415 *
416 * @hide
417 */
418 @ChangeId
419 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
420 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800421
Naina Nallurid63128d2019-09-17 14:10:30 -0700422 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 * A request object to use for transmitting data to an ICC.
424 */
425 private static final class IccAPDUArgument {
426 public int channel, cla, command, p1, p2, p3;
427 public String data;
428
429 public IccAPDUArgument(int channel, int cla, int command,
430 int p1, int p2, int p3, String data) {
431 this.channel = channel;
432 this.cla = cla;
433 this.command = command;
434 this.p1 = p1;
435 this.p2 = p2;
436 this.p3 = p3;
437 this.data = data;
438 }
439 }
440
441 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700442 * A request object to use for transmitting data to an ICC.
443 */
444 private static final class ManualNetworkSelectionArgument {
445 public OperatorInfo operatorInfo;
446 public boolean persistSelection;
447
448 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
449 this.operatorInfo = operatorInfo;
450 this.persistSelection = persistSelection;
451 }
452 }
453
454 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
456 * request after sending. The main thread will notify the request when it is complete.
457 */
458 private static final class MainThreadRequest {
459 /** The argument to use for the request */
460 public Object argument;
461 /** The result of the request that is run on the main thread */
462 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800463 // The subscriber id that this request applies to. Defaults to
464 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
465 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466
Nathan Harold92bed182018-10-12 18:16:49 -0700467 // In cases where subId is unavailable, the caller needs to specify the phone.
468 public Phone phone;
469
vagdeviaf9a5b92018-08-15 16:01:53 -0700470 public WorkSource workSource;
471
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 public MainThreadRequest(Object argument) {
473 this.argument = argument;
474 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800475
Nathan Harold92bed182018-10-12 18:16:49 -0700476 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
477 this.argument = argument;
478 if (phone != null) {
479 this.phone = phone;
480 }
481 this.workSource = workSource;
482 }
483
vagdeviaf9a5b92018-08-15 16:01:53 -0700484 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800485 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800486 if (subId != null) {
487 this.subId = subId;
488 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700489 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 }
492
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800493 private static final class IncomingThirdPartyCallArgs {
494 public final ComponentName component;
495 public final String callId;
496 public final String callerDisplayName;
497
498 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
499 String callerDisplayName) {
500 this.component = component;
501 this.callId = callId;
502 this.callerDisplayName = callerDisplayName;
503 }
504 }
505
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 /**
507 * A handler that processes messages on the main thread in the phone process. Since many
508 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
509 * inbound binder threads to the main thread in the phone process. The Binder thread
510 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
511 * on, which will be notified when the operation completes and will contain the result of the
512 * request.
513 *
514 * <p>If a MainThreadRequest object is provided in the msg.obj field,
515 * note that request.result must be set to something non-null for the calling thread to
516 * unblock.
517 */
518 private final class MainThreadHandler extends Handler {
519 @Override
520 public void handleMessage(Message msg) {
521 MainThreadRequest request;
522 Message onCompleted;
523 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000524 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800526 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527
528 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 case CMD_HANDLE_USSD_REQUEST: {
530 request = (MainThreadRequest) msg.obj;
531 final Phone phone = getPhoneFromRequest(request);
532 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
533 String ussdRequest = ussdObject.first;
534 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700535
Pengquan Menga1bb6272018-09-06 09:59:22 -0700536 if (!isUssdApiAllowed(request.subId)) {
537 // Carrier does not support use of this API, return failure.
538 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
539 UssdResponse response = new UssdResponse(ussdRequest, null);
540 Bundle returnData = new Bundle();
541 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
542 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700543
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 request.result = true;
545 notifyRequester(request);
546 return;
547 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700548
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 try {
550 request.result = phone != null
551 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
552 } catch (CallStateException cse) {
553 request.result = false;
554 }
555 // Wake up the requesting thread
556 notifyRequester(request);
557 break;
pkanwar32d516d2016-10-14 19:37:38 -0700558 }
559
Yorke Lee716f67e2015-06-17 15:39:16 -0700560 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700561 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700562 final Phone phone = getPhoneFromRequest(request);
563 request.result = phone != null ?
564 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
565 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700566 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000574 uiccPort = getUiccPortFromRequest(request);
575 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700576 loge("iccTransmitApduLogicalChannel: No UICC");
577 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
581 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000582 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 iccArgument.channel, iccArgument.cla, iccArgument.command,
584 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 break;
588
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 ar = (AsyncResult) msg.obj;
591 request = (MainThreadRequest) ar.userObj;
592 if (ar.exception == null && ar.result != null) {
593 request.result = ar.result;
594 } else {
595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
596 if (ar.result == null) {
597 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800598 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800600 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 } else {
602 loge("iccTransmitApduLogicalChannel: Unknown exception");
603 }
604 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
609 request = (MainThreadRequest) msg.obj;
610 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000611 uiccPort = getUiccPortFromRequest(request);
612 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 loge("iccTransmitApduBasicChannel: No UICC");
614 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 } else {
617 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
618 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000619 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
621 iccArgument.p3, iccArgument.data, onCompleted);
622 }
623 break;
624
625 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
626 ar = (AsyncResult) msg.obj;
627 request = (MainThreadRequest) ar.userObj;
628 if (ar.exception == null && ar.result != null) {
629 request.result = ar.result;
630 } else {
631 request.result = new IccIoResult(0x6F, 0, (byte[])null);
632 if (ar.result == null) {
633 loge("iccTransmitApduBasicChannel: Empty response");
634 } else if (ar.exception instanceof CommandException) {
635 loge("iccTransmitApduBasicChannel: CommandException: " +
636 ar.exception);
637 } else {
638 loge("iccTransmitApduBasicChannel: Unknown exception");
639 }
640 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 break;
643
644 case CMD_EXCHANGE_SIM_IO:
645 request = (MainThreadRequest) msg.obj;
646 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000647 uiccPort = getUiccPortFromRequest(request);
648 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700649 loge("iccExchangeSimIO: No UICC");
650 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 } else {
653 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
654 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000655 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
657 iccArgument.data, onCompleted);
658 }
659 break;
660
661 case EVENT_EXCHANGE_SIM_IO_DONE:
662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
664 if (ar.exception == null && ar.result != null) {
665 request.result = ar.result;
666 } else {
667 request.result = new IccIoResult(0x6f, 0, (byte[])null);
668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 break;
671
Derek Tan4d5e5c12014-02-04 11:54:58 -0800672 case CMD_SEND_ENVELOPE:
673 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000674 uiccPort = getUiccPortFromRequest(request);
675 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 loge("sendEnvelopeWithStatus: No UICC");
677 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 } else {
680 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000681 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800683 break;
684
685 case EVENT_SEND_ENVELOPE_DONE:
686 ar = (AsyncResult) msg.obj;
687 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700688 if (ar.exception == null && ar.result != null) {
689 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800690 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700691 request.result = new IccIoResult(0x6F, 0, (byte[])null);
692 if (ar.result == null) {
693 loge("sendEnvelopeWithStatus: Empty response");
694 } else if (ar.exception instanceof CommandException) {
695 loge("sendEnvelopeWithStatus: CommandException: " +
696 ar.exception);
697 } else {
698 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
699 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800700 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700701 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800702 break;
703
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 case CMD_OPEN_CHANNEL:
705 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000706 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800707 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000708 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700709 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800710 request.result = new IccOpenLogicalChannelResponse(-1,
711 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700712 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700713 } else {
714 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000715 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800716 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700717 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 break;
719
720 case EVENT_OPEN_CHANNEL_DONE:
721 ar = (AsyncResult) msg.obj;
722 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 int[] result = (int[]) ar.result;
726 int channelId = result[0];
727 byte[] selectResponse = null;
728 if (result.length > 1) {
729 selectResponse = new byte[result.length - 1];
730 for (int i = 1; i < result.length; ++i) {
731 selectResponse[i - 1] = (byte) result[i];
732 }
733 }
734 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700735 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700736 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 if (ar.result == null) {
738 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700740 if (ar.exception != null) {
741 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
742 }
743
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700744 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700745 if (ar.exception instanceof CommandException) {
746 CommandException.Error error =
747 ((CommandException) (ar.exception)).getCommandError();
748 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700749 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700750 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700751 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700752 }
753 }
754 openChannelResp = new IccOpenLogicalChannelResponse(
755 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700757 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700758 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 break;
760
761 case CMD_CLOSE_CHANNEL:
762 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000763 uiccPort = getUiccPortFromRequest(request);
764 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700765 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900766 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700767 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700768 } else {
769 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000770 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700771 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 break;
773
774 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800775 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
776 break;
777
778 case CMD_NV_READ_ITEM:
779 request = (MainThreadRequest) msg.obj;
780 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800781 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
782 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800783 break;
784
785 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 ar = (AsyncResult) msg.obj;
787 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800788 if (ar.exception == null && ar.result != null) {
789 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800791 request.result = "";
792 if (ar.result == null) {
793 loge("nvReadItem: Empty response");
794 } else if (ar.exception instanceof CommandException) {
795 loge("nvReadItem: CommandException: " +
796 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700797 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800798 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 }
800 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700801 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 break;
803
Jake Hambye994d462014-02-03 13:10:13 -0800804 case CMD_NV_WRITE_ITEM:
805 request = (MainThreadRequest) msg.obj;
806 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
807 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800808 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700809 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800810 break;
811
812 case EVENT_NV_WRITE_ITEM_DONE:
813 handleNullReturnEvent(msg, "nvWriteItem");
814 break;
815
816 case CMD_NV_WRITE_CDMA_PRL:
817 request = (MainThreadRequest) msg.obj;
818 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800819 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800820 break;
821
822 case EVENT_NV_WRITE_CDMA_PRL_DONE:
823 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
824 break;
825
chen xu6dac5ab2018-10-26 17:39:23 -0700826 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800827 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700828 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800829 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800830 break;
831
chen xu6dac5ab2018-10-26 17:39:23 -0700832 case EVENT_RESET_MODEM_CONFIG_DONE:
833 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800834 break;
835
Sooraj Sasindran37444802020-08-11 10:40:43 -0700836 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
837 request = (MainThreadRequest) msg.obj;
838 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
839 request);
840 Phone phone = getPhoneFromRequest(request);
841 if (phone != null) {
842 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
843 } else {
844 loge("isNRDualConnectivityEnabled: No phone object");
845 request.result = false;
846 notifyRequester(request);
847 }
848 break;
849 }
850
851 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
857 // request.result must be set to something non-null
858 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700859 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700860 request.result = ar.result;
861 } else {
862 request.result = false;
863 }
864 if (ar.result == null) {
865 loge("isNRDualConnectivityEnabled: Empty response");
866 } else if (ar.exception instanceof CommandException) {
867 loge("isNRDualConnectivityEnabled: CommandException: "
868 + ar.exception);
869 } else {
870 loge("isNRDualConnectivityEnabled: Unknown exception");
871 }
872 }
873 notifyRequester(request);
874 break;
875
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700876 case CMD_IS_VONR_ENABLED: {
877 request = (MainThreadRequest) msg.obj;
878 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
879 request);
880 Phone phone = getPhoneFromRequest(request);
881 if (phone != null) {
882 phone.isVoNrEnabled(onCompleted, request.workSource);
883 } else {
884 loge("isVoNrEnabled: No phone object");
885 request.result = false;
886 notifyRequester(request);
887 }
888 break;
889 }
890
891 case EVENT_IS_VONR_ENABLED_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result;
896 } else {
897 // request.result must be set to something non-null
898 // for the calling thread to unblock
899 if (ar.result != null) {
900 request.result = ar.result;
901 } else {
902 request.result = false;
903 }
904 if (ar.result == null) {
905 loge("isVoNrEnabled: Empty response");
906 } else if (ar.exception instanceof CommandException) {
907 loge("isVoNrEnabled: CommandException: "
908 + ar.exception);
909 } else {
910 loge("isVoNrEnabled: Unknown exception");
911 }
912 }
913 notifyRequester(request);
914 break;
915
Sooraj Sasindran37444802020-08-11 10:40:43 -0700916 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
919 Phone phone = getPhoneFromRequest(request);
920 if (phone != null) {
921 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
922 request.workSource);
923 } else {
924 loge("enableNrDualConnectivity: No phone object");
925 request.result =
926 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
927 notifyRequester(request);
928 }
929 break;
930 }
931
932 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
933 ar = (AsyncResult) msg.obj;
934 request = (MainThreadRequest) ar.userObj;
935 if (ar.exception == null) {
936 request.result =
937 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
938 } else {
939 request.result =
940 TelephonyManager
941 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
942 if (ar.exception instanceof CommandException) {
943 CommandException.Error error =
944 ((CommandException) (ar.exception)).getCommandError();
945 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
946 request.result =
947 TelephonyManager
948 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000949 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
950 request.result =
951 TelephonyManager
952 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700953 }
954 loge("enableNrDualConnectivity" + ": CommandException: "
955 + ar.exception);
956 } else {
957 loge("enableNrDualConnectivity" + ": Unknown exception");
958 }
959 }
960 notifyRequester(request);
961 break;
962 }
963
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700964 case CMD_ENABLE_VONR: {
965 request = (MainThreadRequest) msg.obj;
966 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
967 Phone phone = getPhoneFromRequest(request);
968 if (phone != null) {
969 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
970 request.workSource);
971 } else {
972 loge("setVoNrEnabled: No phone object");
973 request.result =
974 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
975 notifyRequester(request);
976 }
977 break;
978 }
979
980 case EVENT_ENABLE_VONR_DONE: {
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 if (ar.exception == null) {
984 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
985 } else {
986 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
987 if (ar.exception instanceof CommandException) {
988 CommandException.Error error =
989 ((CommandException) (ar.exception)).getCommandError();
990 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
991 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
992 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
993 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
994 } else {
995 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
996 }
997 loge("setVoNrEnabled" + ": CommandException: "
998 + ar.exception);
999 } else {
1000 loge("setVoNrEnabled" + ": Unknown exception");
1001 }
1002 }
1003 notifyRequester(request);
1004 break;
1005 }
1006
SongFerngWang3ef3e072020-12-21 16:41:52 +08001007 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001008 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001009 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1010 request);
1011 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 break;
1013
SongFerngWang3ef3e072020-12-21 16:41:52 +08001014 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
1017 if (ar.exception == null && ar.result != null) {
1018 request.result = ar.result; // Integer
1019 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301020 // request.result must be set to something non-null
1021 // for the calling thread to unblock
1022 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001023 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001024 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001025 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001026 loge("getAllowedNetworkTypesBitmask: CommandException: "
1027 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001028 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001029 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001030 }
1031 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001032 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001033 break;
1034
SongFerngWang3ef3e072020-12-21 16:41:52 +08001035 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001036 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001037 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1038 request);
1039 Pair<Integer, Long> reasonWithNetworkTypes =
1040 (Pair<Integer, Long>) request.argument;
1041 getPhoneFromRequest(request).setAllowedNetworkTypes(
1042 reasonWithNetworkTypes.first,
1043 reasonWithNetworkTypes.second,
1044 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001045 break;
1046
SongFerngWang3ef3e072020-12-21 16:41:52 +08001047 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1048 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001049 break;
1050
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001051 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1052 request = (MainThreadRequest)msg.obj;
1053 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001054 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001055 break;
1056
1057 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1058 ar = (AsyncResult)msg.obj;
1059 request = (MainThreadRequest)ar.userObj;
1060 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001061 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001062 break;
1063
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001064 case CMD_SET_VOICEMAIL_NUMBER:
1065 request = (MainThreadRequest) msg.obj;
1066 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1067 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001068 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1069 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001070 break;
1071
1072 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1073 handleNullReturnEvent(msg, "setVoicemailNumber");
1074 break;
1075
Stuart Scott54788802015-03-30 13:18:01 -07001076 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1077 request = (MainThreadRequest) msg.obj;
1078 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1079 request);
1080 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1081 break;
1082
1083 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1084 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1085 break;
1086
Shishir Agrawal302c8692015-06-19 13:49:39 -07001087 case CMD_PERFORM_NETWORK_SCAN:
1088 request = (MainThreadRequest) msg.obj;
1089 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1090 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1091 break;
1092
Hall Liu27d24262020-09-18 19:04:59 -07001093 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001094 request = (MainThreadRequest) msg.obj;
1095 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001096 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1097 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1098 request.argument;
1099 int callForwardingReason = args.first;
1100 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001101 break;
Hall Liu27d24262020-09-18 19:04:59 -07001102 }
1103 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001104 ar = (AsyncResult) msg.obj;
1105 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001106 TelephonyManager.CallForwardingInfoCallback callback =
1107 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1108 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001109 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001110 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001111 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1112 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1113 // Service Class is a bit mask per 3gpp 27.007. Search for
1114 // any service for voice call.
1115 if ((callForwardInfo.serviceClass
1116 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001117 callForwardingInfo = new CallForwardingInfo(
1118 callForwardInfo.status
1119 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001120 callForwardInfo.reason,
1121 callForwardInfo.number,
1122 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001123 break;
1124 }
1125 }
1126 // Didn't find a call forward info for voice call.
1127 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001128 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1129 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001130 }
Hall Liu27d24262020-09-18 19:04:59 -07001131 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001132 } else {
1133 if (ar.result == null) {
1134 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1135 }
1136 if (ar.exception != null) {
1137 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1138 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001139 int errorCode = TelephonyManager
1140 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001141 if (ar.exception instanceof CommandException) {
1142 CommandException.Error error =
1143 ((CommandException) (ar.exception)).getCommandError();
1144 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001145 errorCode = TelephonyManager
1146 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001147 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001148 errorCode = TelephonyManager
1149 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001150 }
1151 }
Hall Liu27d24262020-09-18 19:04:59 -07001152 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001153 }
Shuo Qian4a594052020-01-23 11:59:30 -08001154 break;
Hall Liu27d24262020-09-18 19:04:59 -07001155 }
Shuo Qian4a594052020-01-23 11:59:30 -08001156
Hall Liu27d24262020-09-18 19:04:59 -07001157 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001158 request = (MainThreadRequest) msg.obj;
1159 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001160 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001161 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001162 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1163 request.argument).first;
1164 request.phone.setCallForwardingOption(
1165 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001166 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001167 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001168 callForwardingInfoToSet.getReason(),
1169 callForwardingInfoToSet.getNumber(),
1170 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1171 break;
Hall Liu27d24262020-09-18 19:04:59 -07001172 }
Shuo Qian4a594052020-01-23 11:59:30 -08001173
Hall Liu27d24262020-09-18 19:04:59 -07001174 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001175 ar = (AsyncResult) msg.obj;
1176 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001177 Consumer<Integer> callback =
1178 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1179 request.argument).second;
1180 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001181 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001182 int errorCode = TelephonyManager.CallForwardingInfoCallback
1183 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001184 if (ar.exception instanceof CommandException) {
1185 CommandException.Error error =
1186 ((CommandException) (ar.exception)).getCommandError();
1187 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001188 errorCode = TelephonyManager.CallForwardingInfoCallback
1189 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001190 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001191 errorCode = TelephonyManager.CallForwardingInfoCallback
1192 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001193 }
1194 }
1195 callback.accept(errorCode);
1196 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001197 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001198 }
Shuo Qian4a594052020-01-23 11:59:30 -08001199 break;
Hall Liu27d24262020-09-18 19:04:59 -07001200 }
Shuo Qian4a594052020-01-23 11:59:30 -08001201
Hall Liu27d24262020-09-18 19:04:59 -07001202 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001203 request = (MainThreadRequest) msg.obj;
1204 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1205 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1206 break;
Hall Liu27d24262020-09-18 19:04:59 -07001207 }
Shuo Qian4a594052020-01-23 11:59:30 -08001208
Hall Liu27d24262020-09-18 19:04:59 -07001209 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001210 ar = (AsyncResult) msg.obj;
1211 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001212 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001213 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1214 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001215 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001216 // Service Class is a bit mask per 3gpp 27.007.
1217 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001218 if (callForwardResults.length > 1
1219 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001220 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001221 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001222 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1223 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001224 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001225 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001226 }
1227 } else {
1228 if (ar.result == null) {
1229 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1230 }
1231 if (ar.exception != null) {
1232 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1233 }
1234 if (ar.exception instanceof CommandException) {
1235 CommandException.Error error =
1236 ((CommandException) (ar.exception)).getCommandError();
1237 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1238 callForwardingStatus =
1239 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1240 }
1241 }
1242 }
Hall Liu27d24262020-09-18 19:04:59 -07001243 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001244 break;
Hall Liu27d24262020-09-18 19:04:59 -07001245 }
Shuo Qian4a594052020-01-23 11:59:30 -08001246
Hall Liu27d24262020-09-18 19:04:59 -07001247 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001248 request = (MainThreadRequest) msg.obj;
1249 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001250 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1251 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001252 break;
Hall Liu27d24262020-09-18 19:04:59 -07001253 }
Shuo Qian4a594052020-01-23 11:59:30 -08001254
Hall Liu27d24262020-09-18 19:04:59 -07001255 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001256 ar = (AsyncResult) msg.obj;
1257 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001258 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1259 Consumer<Integer> callback =
1260 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1261 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001262 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001263 if (ar.exception instanceof CommandException) {
1264 CommandException.Error error =
1265 ((CommandException) (ar.exception)).getCommandError();
1266 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1267 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1268 } else {
1269 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1270 }
1271 } else {
1272 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1273 }
1274 } else {
1275 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1276 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001277 }
Shuo Qian4a594052020-01-23 11:59:30 -08001278 break;
Hall Liu27d24262020-09-18 19:04:59 -07001279 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001280 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1281 ar = (AsyncResult) msg.obj;
1282 request = (MainThreadRequest) ar.userObj;
1283 CellNetworkScanResult cellScanResult;
1284 if (ar.exception == null && ar.result != null) {
1285 cellScanResult = new CellNetworkScanResult(
1286 CellNetworkScanResult.STATUS_SUCCESS,
1287 (List<OperatorInfo>) ar.result);
1288 } else {
1289 if (ar.result == null) {
1290 loge("getCellNetworkScanResults: Empty response");
1291 }
1292 if (ar.exception != null) {
1293 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1294 }
1295 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1296 if (ar.exception instanceof CommandException) {
1297 CommandException.Error error =
1298 ((CommandException) (ar.exception)).getCommandError();
1299 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1300 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1301 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1302 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1303 }
1304 }
1305 cellScanResult = new CellNetworkScanResult(errorCode, null);
1306 }
1307 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001308 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001309 break;
1310
1311 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1312 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001313 ManualNetworkSelectionArgument selArg =
1314 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001315 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1316 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001317 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1318 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001319 break;
1320
1321 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001322 ar = (AsyncResult) msg.obj;
1323 request = (MainThreadRequest) ar.userObj;
1324 if (ar.exception == null) {
1325 request.result = true;
1326 } else {
1327 request.result = false;
1328 loge("setNetworkSelectionModeManual " + ar.exception);
1329 }
1330 notifyRequester(request);
1331 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001332 break;
1333
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001334 case CMD_GET_MODEM_ACTIVITY_INFO:
1335 request = (MainThreadRequest) msg.obj;
1336 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001337 if (defaultPhone != null) {
1338 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001339 } else {
1340 ResultReceiver result = (ResultReceiver) request.argument;
1341 Bundle bundle = new Bundle();
1342 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001343 new ModemActivityInfo(0, 0, 0,
1344 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001345 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001346 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001347 break;
1348
Hall Liud0f208c2020-10-14 16:54:44 -07001349 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001350 ar = (AsyncResult) msg.obj;
1351 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001352 ResultReceiver result = (ResultReceiver) request.argument;
1353
Hall Liud0f208c2020-10-14 16:54:44 -07001354 ModemActivityInfo ret = null;
1355 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001356 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001357 // Update the last modem activity info and the result of the request.
1358 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1359 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001360 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001361 int[] txTimeMs = info.getTransmitTimeMillis();
1362 int[] lastModemTxTimeMs = mLastModemActivityInfo
1363 .getTransmitTimeMillis();
1364 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1365 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1366 }
Hall Liu49656c02020-10-09 19:00:11 -07001367 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001368 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1369 + mLastModemActivityInfo.getSleepTimeMillis());
1370 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1371 + mLastModemActivityInfo.getIdleTimeMillis());
1372 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1373 mLastModemActivityInfo.setReceiveTimeMillis(
1374 info.getReceiveTimeMillis()
1375 + mLastModemActivityInfo.getReceiveTimeMillis());
1376 }
Hall Liu49656c02020-10-09 19:00:11 -07001377 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001378 mLastModemActivityInfo.getSleepTimeMillis(),
1379 mLastModemActivityInfo.getIdleTimeMillis(),
1380 mLastModemActivityInfo.getTransmitTimeMillis(),
1381 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001382 } else {
1383 if (ar.result == null) {
1384 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001385 error = TelephonyManager.ModemActivityInfoException
1386 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001387 } else if (ar.exception instanceof CommandException) {
1388 loge("queryModemActivityInfo: CommandException: " +
1389 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001390 error = TelephonyManager.ModemActivityInfoException
1391 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001392 } else {
1393 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001394 error = TelephonyManager.ModemActivityInfoException
1395 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001396 }
1397 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001398 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001399 if (ret != null) {
1400 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1401 } else {
1402 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1403 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001404 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001405 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001406 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001407 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001408
Meng Wang1a7c35a2016-05-05 20:56:15 -07001409 case CMD_SET_ALLOWED_CARRIERS:
1410 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001411 CarrierRestrictionRules argument =
1412 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001413 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001414 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001415 break;
1416
1417 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1418 ar = (AsyncResult) msg.obj;
1419 request = (MainThreadRequest) ar.userObj;
1420 if (ar.exception == null && ar.result != null) {
1421 request.result = ar.result;
1422 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001423 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1424 if (ar.exception instanceof CommandException) {
1425 loge("setAllowedCarriers: CommandException: " + ar.exception);
1426 CommandException.Error error =
1427 ((CommandException) (ar.exception)).getCommandError();
1428 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1429 request.result =
1430 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1431 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001432 } else {
1433 loge("setAllowedCarriers: Unknown exception");
1434 }
1435 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001436 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001437 break;
1438
1439 case CMD_GET_ALLOWED_CARRIERS:
1440 request = (MainThreadRequest) msg.obj;
1441 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001442 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001443 break;
1444
1445 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1446 ar = (AsyncResult) msg.obj;
1447 request = (MainThreadRequest) ar.userObj;
1448 if (ar.exception == null && ar.result != null) {
1449 request.result = ar.result;
1450 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001451 request.result = new IllegalStateException(
1452 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001453 if (ar.result == null) {
1454 loge("getAllowedCarriers: Empty response");
1455 } else if (ar.exception instanceof CommandException) {
1456 loge("getAllowedCarriers: CommandException: " +
1457 ar.exception);
1458 } else {
1459 loge("getAllowedCarriers: Unknown exception");
1460 }
1461 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001462 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001463 break;
1464
Nathan Haroldb3014052017-01-25 15:57:32 -08001465 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1466 ar = (AsyncResult) msg.obj;
1467 request = (MainThreadRequest) ar.userObj;
1468 if (ar.exception == null && ar.result != null) {
1469 request.result = ar.result;
1470 } else {
1471 request.result = new IllegalArgumentException(
1472 "Failed to retrieve Forbidden Plmns");
1473 if (ar.result == null) {
1474 loge("getForbiddenPlmns: Empty response");
1475 } else {
1476 loge("getForbiddenPlmns: Unknown exception");
1477 }
1478 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001479 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001480 break;
1481
1482 case CMD_GET_FORBIDDEN_PLMNS:
1483 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001484 uiccPort = getUiccPortFromRequest(request);
1485 if (uiccPort == null) {
1486 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001487 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001488 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001489 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001490 break;
1491 }
1492 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001493 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001494 if (uiccApp == null) {
1495 loge("getForbiddenPlmns() no app with specified type -- "
1496 + appType);
1497 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001498 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001499 break;
1500 } else {
1501 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1502 + " specified type -- " + appType);
1503 }
1504 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1505 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1506 onCompleted);
1507 break;
1508
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001509 case CMD_SWITCH_SLOTS:
1510 request = (MainThreadRequest) msg.obj;
1511 int[] physicalSlots = (int[]) request.argument;
1512 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1513 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1514 break;
1515
1516 case EVENT_SWITCH_SLOTS_DONE:
1517 ar = (AsyncResult) msg.obj;
1518 request = (MainThreadRequest) ar.userObj;
1519 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001520 notifyRequester(request);
1521 break;
1522 case CMD_GET_NETWORK_SELECTION_MODE:
1523 request = (MainThreadRequest) msg.obj;
1524 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1525 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1526 break;
1527
1528 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1529 ar = (AsyncResult) msg.obj;
1530 request = (MainThreadRequest) ar.userObj;
1531 if (ar.exception != null) {
1532 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1533 } else {
1534 int mode = ((int[]) ar.result)[0];
1535 if (mode == 0) {
1536 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1537 } else {
1538 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1539 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001540 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001541 notifyRequester(request);
1542 break;
1543 case CMD_GET_CDMA_ROAMING_MODE:
1544 request = (MainThreadRequest) msg.obj;
1545 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1546 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1547 break;
1548 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 if (ar.exception != null) {
1552 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1553 } else {
1554 request.result = ((int[]) ar.result)[0];
1555 }
1556 notifyRequester(request);
1557 break;
1558 case CMD_SET_CDMA_ROAMING_MODE:
1559 request = (MainThreadRequest) msg.obj;
1560 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1561 int mode = (int) request.argument;
1562 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1563 break;
1564 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1565 ar = (AsyncResult) msg.obj;
1566 request = (MainThreadRequest) ar.userObj;
1567 request.result = ar.exception == null;
1568 notifyRequester(request);
1569 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001570 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1571 request = (MainThreadRequest) msg.obj;
1572 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1573 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1574 break;
1575 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1576 ar = (AsyncResult) msg.obj;
1577 request = (MainThreadRequest) ar.userObj;
1578 if (ar.exception != null) {
1579 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1580 } else {
1581 request.result = ((int[]) ar.result)[0];
1582 }
1583 notifyRequester(request);
1584 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001585 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1586 request = (MainThreadRequest) msg.obj;
1587 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1588 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001589 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1590 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001591 break;
1592 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1593 ar = (AsyncResult) msg.obj;
1594 request = (MainThreadRequest) ar.userObj;
1595 request.result = ar.exception == null;
1596 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001597 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001598 case CMD_GET_ALL_CELL_INFO:
1599 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001600 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001601 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001602 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001603 case EVENT_GET_ALL_CELL_INFO_DONE:
1604 ar = (AsyncResult) msg.obj;
1605 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001606 // If a timeout occurs, the response will be null
1607 request.result = (ar.exception == null && ar.result != null)
1608 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001609 synchronized (request) {
1610 request.notifyAll();
1611 }
1612 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001613 case CMD_REQUEST_CELL_INFO_UPDATE:
1614 request = (MainThreadRequest) msg.obj;
1615 request.phone.requestCellInfoUpdate(request.workSource,
1616 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1617 break;
1618 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1619 ar = (AsyncResult) msg.obj;
1620 request = (MainThreadRequest) ar.userObj;
1621 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1622 try {
1623 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001624 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001625 cb.onError(
1626 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1627 ar.exception.getClass().getName(),
1628 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001629 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001630 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001631 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001632 } else {
1633 // use the result as returned
1634 cb.onCellInfo((List<CellInfo>) ar.result);
1635 }
1636 } catch (RemoteException re) {
1637 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1638 }
1639 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001640 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001641 request = (MainThreadRequest) msg.obj;
1642 WorkSource ws = (WorkSource) request.argument;
1643 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001644 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001645 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001646 }
1647 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001648 ar = (AsyncResult) msg.obj;
1649 request = (MainThreadRequest) ar.userObj;
1650 if (ar.exception == null) {
1651 request.result = ar.result;
1652 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001653 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001654 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001655 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001656 }
1657
1658 synchronized (request) {
1659 request.notifyAll();
1660 }
1661 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001662 }
chen xu6dac5ab2018-10-26 17:39:23 -07001663 case CMD_MODEM_REBOOT:
1664 request = (MainThreadRequest) msg.obj;
1665 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001666 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001667 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001668 case EVENT_CMD_MODEM_REBOOT_DONE:
1669 handleNullReturnEvent(msg, "rebootModem");
1670 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001671 case CMD_REQUEST_ENABLE_MODEM:
1672 request = (MainThreadRequest) msg.obj;
1673 boolean enable = (boolean) request.argument;
1674 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001675 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001676 PhoneConfigurationManager.getInstance()
1677 .enablePhone(request.phone, enable, onCompleted);
1678 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001679 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001680 ar = (AsyncResult) msg.obj;
1681 request = (MainThreadRequest) ar.userObj;
1682 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001683 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001684 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001685 if ((boolean) request.result) {
1686 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1687 updateModemStateMetrics();
1688 } else {
1689 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1690 + ar.exception);
1691 }
1692 notifyRequester(request);
1693 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001694 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001695 case CMD_GET_MODEM_STATUS:
1696 request = (MainThreadRequest) msg.obj;
1697 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1698 PhoneConfigurationManager.getInstance()
1699 .getPhoneStatusFromModem(request.phone, onCompleted);
1700 break;
1701 case EVENT_GET_MODEM_STATUS_DONE:
1702 ar = (AsyncResult) msg.obj;
1703 request = (MainThreadRequest) ar.userObj;
1704 int id = request.phone.getPhoneId();
1705 if (ar.exception == null && ar.result != null) {
1706 request.result = ar.result;
1707 //update the cache as modem status has changed
1708 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1709 (boolean) request.result);
1710 } else {
1711 // Return true if modem status cannot be retrieved. For most cases,
1712 // modem status is on. And for older version modems, GET_MODEM_STATUS
1713 // and disable modem are not supported. Modem is always on.
1714 // TODO: this should be fixed in R to support a third
1715 // status UNKNOWN b/131631629
1716 request.result = true;
1717 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1718 + ar.exception);
1719 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001720 notifyRequester(request);
1721 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001722 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1725 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1726 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1727 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1728 break;
1729 }
1730 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1731 ar = (AsyncResult) msg.obj;
1732 request = (MainThreadRequest) ar.userObj;
1733 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1734 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1735 args.second.accept(ar.exception == null);
1736 notifyRequester(request);
1737 break;
1738 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001739 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1740 request = (MainThreadRequest) msg.obj;
1741 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1742 Phone phone = getPhoneFromRequest(request);
1743 if (phone != null) {
1744 phone.getSystemSelectionChannels(onCompleted);
1745 } else {
1746 loge("getSystemSelectionChannels: No phone object");
1747 request.result = new ArrayList<RadioAccessSpecifier>();
1748 notifyRequester(request);
1749 }
1750 break;
1751 }
1752 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1753 ar = (AsyncResult) msg.obj;
1754 request = (MainThreadRequest) ar.userObj;
1755 if (ar.exception == null && ar.result != null) {
1756 request.result = ar.result;
1757 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001758 request.result = new IllegalStateException(
1759 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001760 if (ar.result == null) {
1761 loge("getSystemSelectionChannels: Empty response");
1762 } else {
1763 loge("getSystemSelectionChannels: Unknown exception");
1764 }
1765 }
1766 notifyRequester(request);
1767 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001768 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1769 ar = (AsyncResult) msg.obj;
1770 request = (MainThreadRequest) ar.userObj;
1771 if (ar.exception == null && ar.result != null) {
1772 request.result = ar.result;
1773 } else {
1774 request.result = -1;
1775 loge("Failed to set Forbidden Plmns");
1776 if (ar.result == null) {
1777 loge("setForbidenPlmns: Empty response");
1778 } else if (ar.exception != null) {
1779 loge("setForbiddenPlmns: Exception: " + ar.exception);
1780 request.result = -1;
1781 } else {
1782 loge("setForbiddenPlmns: Unknown exception");
1783 }
1784 }
1785 notifyRequester(request);
1786 break;
1787 case CMD_SET_FORBIDDEN_PLMNS:
1788 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001789 uiccPort = getUiccPortFromRequest(request);
1790 if (uiccPort == null) {
1791 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001792 request.result = -1;
1793 notifyRequester(request);
1794 break;
1795 }
1796 Pair<Integer, List<String>> setFplmnsArgs =
1797 (Pair<Integer, List<String>>) request.argument;
1798 appType = setFplmnsArgs.first;
1799 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001800 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001801 if (uiccApp == null) {
1802 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1803 request.result = -1;
1804 loge("Failed to get UICC App");
1805 notifyRequester(request);
1806 } else {
1807 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1808 ((SIMRecords) uiccApp.getIccRecords())
1809 .setForbiddenPlmns(onCompleted, fplmns);
1810 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001811 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001812 case CMD_ERASE_MODEM_CONFIG:
1813 request = (MainThreadRequest) msg.obj;
1814 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1815 defaultPhone.eraseModemConfig(onCompleted);
1816 break;
1817 case EVENT_ERASE_MODEM_CONFIG_DONE:
1818 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001819 break;
zoey chene02881a2019-12-30 16:11:23 +08001820
Kai Shif70f46f2021-03-03 13:59:46 -08001821 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1822 request = (MainThreadRequest) msg.obj;
1823 request.result = defaultPhone.eraseDataInSharedPreferences();
1824 notifyRequester(request);
1825 break;
1826
zoey chene02881a2019-12-30 16:11:23 +08001827 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1828 request = (MainThreadRequest) msg.obj;
1829 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1830 Pair<String, String> changed = (Pair<String, String>) request.argument;
1831 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1832 changed.first, changed.second, onCompleted);
1833 break;
1834 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1835 ar = (AsyncResult) msg.obj;
1836 request = (MainThreadRequest) ar.userObj;
1837 if (ar.exception == null) {
1838 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001839 // If the operation is successful, update the PIN storage
1840 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1841 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001842 UiccController.getInstance().getPinStorage()
1843 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001844 } else {
1845 request.result = msg.arg1;
1846 }
1847 notifyRequester(request);
1848 break;
1849
Michele Berionne5e411512020-11-13 02:36:59 +00001850 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001851 request = (MainThreadRequest) msg.obj;
1852 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1853 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1854 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1855 enabled.first, enabled.second, onCompleted);
1856 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001857 }
zoey chene02881a2019-12-30 16:11:23 +08001858 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1859 ar = (AsyncResult) msg.obj;
1860 request = (MainThreadRequest) ar.userObj;
1861 if (ar.exception == null) {
1862 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001863 // If the operation is successful, update the PIN storage
1864 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1865 int phoneId = getPhoneFromRequest(request).getPhoneId();
1866 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001867 UiccController.getInstance().getPinStorage()
1868 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001869 } else {
1870 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1871 }
zoey chene02881a2019-12-30 16:11:23 +08001872 } else {
1873 request.result = msg.arg1;
1874 }
Michele Berionne5e411512020-11-13 02:36:59 +00001875
1876
zoey chene02881a2019-12-30 16:11:23 +08001877 notifyRequester(request);
1878 break;
1879
Peter Wangdafb9ac2020-01-15 14:13:38 -08001880 case MSG_NOTIFY_USER_ACTIVITY:
1881 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001882 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001883 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1884 getDefaultPhone().getContext().sendBroadcastAsUser(
1885 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1886 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001887
1888 case CMD_SET_DATA_THROTTLING: {
1889 request = (MainThreadRequest) msg.obj;
1890 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1891 DataThrottlingRequest dataThrottlingRequest =
1892 (DataThrottlingRequest) request.argument;
1893 Phone phone = getPhoneFromRequest(request);
1894 if (phone != null) {
1895 phone.setDataThrottling(onCompleted,
1896 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1897 dataThrottlingRequest.getCompletionDurationMillis());
1898 } else {
1899 loge("setDataThrottling: No phone object");
1900 request.result =
1901 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1902 notifyRequester(request);
1903 }
1904
1905 break;
1906 }
1907 case EVENT_SET_DATA_THROTTLING_DONE:
1908 ar = (AsyncResult) msg.obj;
1909 request = (MainThreadRequest) ar.userObj;
1910
1911 if (ar.exception == null) {
1912 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1913 } else if (ar.exception instanceof CommandException) {
1914 loge("setDataThrottling: CommandException: " + ar.exception);
1915 CommandException.Error error =
1916 ((CommandException) (ar.exception)).getCommandError();
1917
1918 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1919 request.result = TelephonyManager
1920 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1921 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1922 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001923 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1924 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001925 } else {
1926 request.result =
1927 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1928 }
1929 } else {
1930 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1931 }
1932 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1933 notifyRequester(request);
1934 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001935
1936 case CMD_SET_SIM_POWER: {
1937 request = (MainThreadRequest) msg.obj;
1938 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1939 request = (MainThreadRequest) msg.obj;
1940 int stateToSet =
1941 ((Pair<Integer, IIntegerConsumer>)
1942 request.argument).first;
1943 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1944 break;
1945 }
1946 case EVENT_SET_SIM_POWER_DONE: {
1947 ar = (AsyncResult) msg.obj;
1948 request = (MainThreadRequest) ar.userObj;
1949 IIntegerConsumer callback =
1950 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1951 if (ar.exception != null) {
1952 loge("setSimPower exception: " + ar.exception);
1953 int errorCode = TelephonyManager.CallForwardingInfoCallback
1954 .RESULT_ERROR_UNKNOWN;
1955 if (ar.exception instanceof CommandException) {
1956 CommandException.Error error =
1957 ((CommandException) (ar.exception)).getCommandError();
1958 if (error == CommandException.Error.SIM_ERR) {
1959 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1960 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1961 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1962 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1963 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1964 } else {
1965 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1966 }
1967 }
1968 try {
1969 callback.accept(errorCode);
1970 } catch (RemoteException e) {
1971 // Ignore if the remote process is no longer available to call back.
1972 Log.w(LOG_TAG, "setSimPower: callback not available.");
1973 }
1974 } else {
1975 try {
1976 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1977 } catch (RemoteException e) {
1978 // Ignore if the remote process is no longer available to call back.
1979 Log.w(LOG_TAG, "setSimPower: callback not available.");
1980 }
1981 }
1982 break;
1983 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001984 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1985 request = (MainThreadRequest) msg.obj;
1986
1987 final Phone phone = getPhoneFromRequest(request);
1988 if (phone == null || phone.getServiceStateTracker() == null) {
1989 request.result = new IllegalStateException("Phone or SST is null");
1990 notifyRequester(request);
1991 break;
1992 }
1993
1994 Pair<Integer, SignalStrengthUpdateRequest> pair =
1995 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1996 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1997 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001998 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001999 request.subId, pair.first /*callingUid*/,
2000 pair.second /*request*/, onCompleted);
2001 break;
2002 }
2003 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2004 ar = (AsyncResult) msg.obj;
2005 request = (MainThreadRequest) ar.userObj;
2006 // request.result will be the exception of ar if present, true otherwise.
2007 // Be cautious not to leave result null which will wait() forever
2008 request.result = ar.exception != null ? ar.exception : true;
2009 notifyRequester(request);
2010 break;
2011 }
2012 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2013 request = (MainThreadRequest) msg.obj;
2014
2015 Phone phone = getPhoneFromRequest(request);
2016 if (phone == null || phone.getServiceStateTracker() == null) {
2017 request.result = new IllegalStateException("Phone or SST is null");
2018 notifyRequester(request);
2019 break;
2020 }
2021
2022 Pair<Integer, SignalStrengthUpdateRequest> pair =
2023 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2024 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2025 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002026 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002027 request.subId, pair.first /*callingUid*/,
2028 pair.second /*request*/, onCompleted);
2029 break;
2030 }
2031 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2032 ar = (AsyncResult) msg.obj;
2033 request = (MainThreadRequest) ar.userObj;
2034 request.result = ar.exception != null ? ar.exception : true;
2035 notifyRequester(request);
2036 break;
2037 }
Jordan Liu109698e2020-11-24 14:50:34 -08002038
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002039 case CMD_GET_SLICING_CONFIG: {
2040 request = (MainThreadRequest) msg.obj;
2041 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2042 request.phone.getSlicingConfig(onCompleted);
2043 break;
2044 }
2045 case EVENT_GET_SLICING_CONFIG_DONE: {
2046 ar = (AsyncResult) msg.obj;
2047 request = (MainThreadRequest) ar.userObj;
2048 ResultReceiver result = (ResultReceiver) request.argument;
2049
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002050 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002051 Bundle bundle = new Bundle();
2052 int resultCode = 0;
2053 if (ar.exception != null) {
2054 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2055 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002056 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002057 } else if (ar.result == null) {
2058 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002059 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002060 } else {
2061 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002062 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2063 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002064 }
2065
2066 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002067 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002068 }
2069 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2070 result.send(resultCode, bundle);
2071 notifyRequester(request);
2072 break;
2073 }
2074
Michele Berionne5e411512020-11-13 02:36:59 +00002075 case CMD_PREPARE_UNATTENDED_REBOOT:
2076 request = (MainThreadRequest) msg.obj;
2077 request.result =
2078 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2079 notifyRequester(request);
2080 break;
2081
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 default:
2083 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2084 break;
2085 }
2086 }
Jake Hambye994d462014-02-03 13:10:13 -08002087
Pengquan Menga1bb6272018-09-06 09:59:22 -07002088 private void notifyRequester(MainThreadRequest request) {
2089 synchronized (request) {
2090 request.notifyAll();
2091 }
2092 }
2093
Jake Hambye994d462014-02-03 13:10:13 -08002094 private void handleNullReturnEvent(Message msg, String command) {
2095 AsyncResult ar = (AsyncResult) msg.obj;
2096 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2097 if (ar.exception == null) {
2098 request.result = true;
2099 } else {
2100 request.result = false;
2101 if (ar.exception instanceof CommandException) {
2102 loge(command + ": CommandException: " + ar.exception);
2103 } else {
2104 loge(command + ": Unknown exception");
2105 }
2106 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002107 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002108 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 }
2110
2111 /**
2112 * Posts the specified command to be executed on the main thread,
2113 * waits for the request to complete, and returns the result.
2114 * @see #sendRequestAsync
2115 */
2116 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002117 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2118 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002119 }
2120
2121 /**
2122 * Posts the specified command to be executed on the main thread,
2123 * waits for the request to complete, and returns the result.
2124 * @see #sendRequestAsync
2125 */
2126 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2127 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002128 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002129 }
2130
2131 /**
2132 * Posts the specified command to be executed on the main thread,
2133 * waits for the request to complete, and returns the result.
2134 * @see #sendRequestAsync
2135 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002136 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002137 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2138 }
2139
2140 /**
2141 * Posts the specified command to be executed on the main thread,
2142 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2143 * if not timeout or null otherwise.
2144 * @see #sendRequestAsync
2145 */
2146 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2147 long timeoutInMs) {
2148 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002149 }
2150
2151 /**
2152 * Posts the specified command to be executed on the main thread,
2153 * waits for the request to complete, and returns the result.
2154 * @see #sendRequestAsync
2155 */
Nathan Harold92bed182018-10-12 18:16:49 -07002156 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002157 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002158 }
2159
2160 /**
2161 * Posts the specified command to be executed on the main thread,
2162 * waits for the request to complete, and returns the result.
2163 * @see #sendRequestAsync
2164 */
2165 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002166 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2167 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002168 }
2169
2170 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002171 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2172 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2173 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002174 * @see #sendRequestAsync
2175 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002176 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2177 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2179 throw new RuntimeException("This method will deadlock if called from the main thread.");
2180 }
2181
Nathan Harold92bed182018-10-12 18:16:49 -07002182 MainThreadRequest request = null;
2183 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2184 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2185 } else if (phone != null) {
2186 request = new MainThreadRequest(argument, phone, workSource);
2187 } else {
2188 request = new MainThreadRequest(argument, subId, workSource);
2189 }
2190
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 Message msg = mMainThreadHandler.obtainMessage(command, request);
2192 msg.sendToTarget();
2193
Rambo Wang0f050d82021-02-12 11:43:36 -08002194
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002196 if (timeoutInMs >= 0) {
2197 // Wait for at least timeoutInMs before returning null request result
2198 long now = SystemClock.elapsedRealtime();
2199 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002200 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002201 try {
2202 request.wait(deadline - now);
2203 } catch (InterruptedException e) {
2204 // Do nothing, go back and check if request is completed or timeout
2205 } finally {
2206 now = SystemClock.elapsedRealtime();
2207 }
2208 }
2209 } else {
2210 // Wait for the request to complete
2211 while (request.result == null) {
2212 try {
2213 request.wait();
2214 } catch (InterruptedException e) {
2215 // Do nothing, go back and wait until the request is complete
2216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218 }
2219 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002220 if (request.result == null) {
2221 Log.wtf(LOG_TAG,
2222 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 return request.result;
2225 }
2226
2227 /**
2228 * Asynchronous ("fire and forget") version of sendRequest():
2229 * Posts the specified command to be executed on the main thread, and
2230 * returns immediately.
2231 * @see #sendRequest
2232 */
2233 private void sendRequestAsync(int command) {
2234 mMainThreadHandler.sendEmptyMessage(command);
2235 }
2236
2237 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002238 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002239 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002240 */
2241 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002242 sendRequestAsync(command, argument, null, null);
2243 }
2244
2245 /**
2246 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2247 * @see {@link #sendRequest(int,Object)}
2248 */
2249 private void sendRequestAsync(
2250 int command, Object argument, Phone phone, WorkSource workSource) {
2251 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002252 Message msg = mMainThreadHandler.obtainMessage(command, request);
2253 msg.sendToTarget();
2254 }
2255
2256 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 * Initialize the singleton PhoneInterfaceManager instance.
2258 * This is only done once, at startup, from PhoneApp.onCreate().
2259 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002260 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 synchronized (PhoneInterfaceManager.class) {
2262 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002263 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 } else {
2265 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2266 }
2267 return sInstance;
2268 }
2269 }
2270
2271 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002272 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002275 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002276 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002278 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002280 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002281 mTelephonySharedPreferences =
2282 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002283 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002284 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002285 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002286 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002287
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 publish();
2289 }
2290
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002291 private Phone getDefaultPhone() {
2292 Phone thePhone = getPhone(getDefaultSubscription());
2293 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2294 }
2295
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 private void publish() {
2297 if (DBG) log("publish: " + this);
2298
Peter Wangc035ce42020-01-08 21:00:22 -08002299 TelephonyFrameworkInitializer
2300 .getTelephonyServiceManager()
2301 .getTelephonyServiceRegisterer()
2302 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 }
2304
Stuart Scott584921c2015-01-15 17:10:34 -08002305 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002306 if (request.phone != null) {
2307 return request.phone;
2308 } else {
2309 return getPhoneFromSubId(request.subId);
2310 }
2311 }
2312
2313 private Phone getPhoneFromSubId(int subId) {
2314 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2315 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002316 }
2317
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002318 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002319 Phone phone = getPhoneFromRequest(request);
2320 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002321 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002322 }
2323
Wink Saville36469e72014-06-11 15:17:00 -07002324 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002325 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002326 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328
Kai Shif70f46f2021-03-03 13:59:46 -08002329 private void sendEraseModemConfig(@NonNull Phone phone) {
2330 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2331 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2332 }
2333
2334 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2335 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2336 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002337 }
2338
Peter Wang44b186e2020-01-13 23:33:09 -08002339 private boolean isImsAvailableOnDevice() {
2340 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2341 if (pm == null) {
2342 // For some reason package manger is not available.. This will fail internally anyway,
2343 // so do not throw error and allow.
2344 return true;
2345 }
2346 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2347 }
2348
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002350 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002351 }
2352
Wink Savilleb564aae2014-10-23 10:18:09 -07002353 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 if (DBG) log("dial: " + number);
2355 // No permission check needed here: This is just a wrapper around the
2356 // ACTION_DIAL intent, which is available to any app since it puts up
2357 // the UI before it does anything.
2358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 String url = createTelUrl(number);
2362 if (url == null) {
2363 return;
2364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002366 // PENDING: should we just silently fail if phone is offhook or ringing?
2367 PhoneConstants.State state = mCM.getState(subId);
2368 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2369 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2370 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2371 mApp.startActivity(intent);
2372 }
2373 } finally {
2374 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 }
2376 }
2377
2378 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002379 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002380 }
2381
Wink Savilleb564aae2014-10-23 10:18:09 -07002382 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 if (DBG) log("call: " + number);
2384
2385 // This is just a wrapper around the ACTION_CALL intent, but we still
2386 // need to do a permission check since we're calling startActivity()
2387 // from the context of the phone app.
2388 enforceCallPermission();
2389
Jordan Liu1617b712019-07-10 15:06:26 -07002390 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 != AppOpsManager.MODE_ALLOWED) {
2392 return;
2393 }
2394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 String url = createTelUrl(number);
2398 if (url == null) {
2399 return;
2400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002402 boolean isValid = false;
2403 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2404 if (slist != null) {
2405 for (SubscriptionInfo subInfoRecord : slist) {
2406 if (subInfoRecord.getSubscriptionId() == subId) {
2407 isValid = true;
2408 break;
2409 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002410 }
Wink Saville08874612014-08-31 19:19:58 -07002411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002412 if (!isValid) {
2413 return;
2414 }
Wink Saville08874612014-08-31 19:19:58 -07002415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002416 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2417 intent.putExtra(SUBSCRIPTION_KEY, subId);
2418 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2419 mApp.startActivity(intent);
2420 } finally {
2421 Binder.restoreCallingIdentity(identity);
2422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 }
2424
Wink Savilleb564aae2014-10-23 10:18:09 -07002425 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002426 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002427 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2428 }
2429
Wink Savilleb564aae2014-10-23 10:18:09 -07002430 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002431 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002432 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2433 }
2434
Wink Savilleb564aae2014-10-23 10:18:09 -07002435 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002440 Phone phone = getPhone(subId);
2441 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442 checkSimPin.start();
2443 return checkSimPin.unlockSim(null, pin);
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
2446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 }
2448
Wink Savilleb564aae2014-10-23 10:18:09 -07002449 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002451
2452 final long identity = Binder.clearCallingIdentity();
2453 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002454 Phone phone = getPhone(subId);
2455 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456 checkSimPuk.start();
2457 return checkSimPuk.unlockSim(puk, pin);
2458 } finally {
2459 Binder.restoreCallingIdentity(identity);
2460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 }
2462
2463 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002464 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 * a synchronous one.
2466 */
2467 private static class UnlockSim extends Thread {
2468
2469 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002470 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471
2472 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002473 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2474 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475
2476 // For replies from SimCard interface
2477 private Handler mHandler;
2478
2479 // For async handler to identify request type
2480 private static final int SUPPLY_PIN_COMPLETE = 100;
2481
Michele Berionne5e411512020-11-13 02:36:59 +00002482 UnlockSim(int phoneId, IccCard simCard) {
2483 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 mSimCard = simCard;
2485 }
2486
2487 @Override
2488 public void run() {
2489 Looper.prepare();
2490 synchronized (UnlockSim.this) {
2491 mHandler = new Handler() {
2492 @Override
2493 public void handleMessage(Message msg) {
2494 AsyncResult ar = (AsyncResult) msg.obj;
2495 switch (msg.what) {
2496 case SUPPLY_PIN_COMPLETE:
2497 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2498 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002499 mRetryCount = msg.arg1;
2500 if (ar.exception != null) {
2501 if (ar.exception instanceof CommandException &&
2502 ((CommandException)(ar.exception)).getCommandError()
2503 == CommandException.Error.PASSWORD_INCORRECT) {
2504 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002505 } //When UiccCardApp dispose,handle message and return exception
2506 else if (ar.exception instanceof CommandException &&
2507 ((CommandException) (ar.exception)).getCommandError()
2508 == CommandException.Error.ABORTED) {
2509 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002510 } else {
2511 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2512 }
2513 } else {
2514 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 mDone = true;
2517 UnlockSim.this.notifyAll();
2518 }
2519 break;
2520 }
2521 }
2522 };
2523 UnlockSim.this.notifyAll();
2524 }
2525 Looper.loop();
2526 }
2527
2528 /*
2529 * Use PIN or PUK to unlock SIM card
2530 *
2531 * If PUK is null, unlock SIM card with PIN
2532 *
2533 * If PUK is not null, unlock SIM card with PUK and set PIN code
2534 */
Wink Saville9de0f752013-10-22 19:04:03 -07002535 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536
2537 while (mHandler == null) {
2538 try {
2539 wait();
2540 } catch (InterruptedException e) {
2541 Thread.currentThread().interrupt();
2542 }
2543 }
2544 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2545
2546 if (puk == null) {
2547 mSimCard.supplyPin(pin, callback);
2548 } else {
2549 mSimCard.supplyPuk(puk, pin, callback);
2550 }
2551
2552 while (!mDone) {
2553 try {
2554 Log.d(LOG_TAG, "wait for done");
2555 wait();
2556 } catch (InterruptedException e) {
2557 // Restore the interrupted status
2558 Thread.currentThread().interrupt();
2559 }
2560 }
2561 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002562 int[] resultArray = new int[2];
2563 resultArray[0] = mResult;
2564 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002565
2566 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002567 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002568 }
2569
Wink Saville9de0f752013-10-22 19:04:03 -07002570 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 }
2572 }
2573
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002574 /**
2575 * This method has been removed due to privacy and stability concerns.
2576 */
2577 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002579 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2580 return;
Wink Saville36469e72014-06-11 15:17:00 -07002581 }
2582
Nathan Harold1f889d82020-06-04 17:05:26 -07002583 @Override
2584 public void updateServiceLocationWithPackageName(String callingPackage) {
2585 mApp.getSystemService(AppOpsManager.class)
2586 .checkPackage(Binder.getCallingUid(), callingPackage);
2587
Nathan Haroldf096d982020-11-18 17:18:06 -08002588 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002589 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2590 // Callers targeting S have no business invoking this method.
2591 return;
2592 }
2593
2594 LocationAccessPolicy.LocationPermissionResult locationResult =
2595 LocationAccessPolicy.checkLocationPermission(mApp,
2596 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2597 .setCallingPackage(callingPackage)
2598 .setCallingFeatureId(null)
2599 .setCallingPid(Binder.getCallingPid())
2600 .setCallingUid(Binder.getCallingUid())
2601 .setMethod("updateServiceLocation")
2602 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2603 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2604 .build());
2605 // Apps that lack location permission have no business calling this method;
2606 // however, because no permission was declared in the public API, denials must
2607 // all be "soft".
2608 switch (locationResult) {
2609 case DENIED_HARD: /* fall through */
2610 case DENIED_SOFT:
2611 return;
2612 }
2613
2614 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 final long identity = Binder.clearCallingIdentity();
2616 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002617 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002619 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 }
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 }
2625
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002626 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002627 @Override
2628 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002629 return isRadioOnWithFeature(callingPackage, null);
2630 }
2631
2632
2633 @Override
2634 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2635 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2636 callingFeatureId);
2637 }
2638
2639 @Deprecated
2640 @Override
2641 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2642 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002643 }
2644
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002645 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002646 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2647 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002649 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002650 return false;
2651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652
2653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 return isRadioOnForSubscriber(subId);
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
2658 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002659 }
2660
2661 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 if (phone != null) {
2666 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2667 } else {
2668 return false;
2669 }
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673 }
2674
2675 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002676 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 }
Wink Saville36469e72014-06-11 15:17:00 -07002678
Wink Savilleb564aae2014-10-23 10:18:09 -07002679 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 final Phone phone = getPhone(subId);
2685 if (phone != null) {
2686 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2687 }
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002690 }
Wink Saville36469e72014-06-11 15:17:00 -07002691 }
2692
2693 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002694 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002695 }
2696
Wink Savilleb564aae2014-10-23 10:18:09 -07002697 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002698 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699
2700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 final Phone phone = getPhone(subId);
2703 if (phone == null) {
2704 return false;
2705 }
2706 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2707 toggleRadioOnOffForSubscriber(subId);
2708 }
2709 return true;
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002712 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713 }
Wink Saville36469e72014-06-11 15:17:00 -07002714
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002715 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002716 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002717 /*
2718 * If any of the Radios are available, it will need to be
2719 * shutdown. So return true if any Radio is available.
2720 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721 final long identity = Binder.clearCallingIdentity();
2722 try {
2723 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2724 Phone phone = PhoneFactory.getPhone(i);
2725 if (phone != null && phone.isRadioAvailable()) return true;
2726 }
2727 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2728 return false;
2729 } finally {
2730 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002731 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002732 }
2733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002735 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 enforceModifyPermission();
2737
2738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2741 logv("Shutting down Phone " + i);
2742 shutdownRadioUsingPhoneId(i);
2743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002746 }
2747 }
2748
2749 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002750 Phone phone = PhoneFactory.getPhone(phoneId);
2751 if (phone != null && phone.isRadioAvailable()) {
2752 phone.shutdownRadio();
2753 }
2754 }
2755
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758
2759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2762 if (defaultPhone != null) {
2763 defaultPhone.setRadioPower(turnOn);
2764 return true;
2765 } else {
2766 loge("There's no default phone.");
2767 return false;
2768 }
2769 } finally {
2770 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002771 }
Wink Saville36469e72014-06-11 15:17:00 -07002772 }
2773
Wink Savilleb564aae2014-10-23 10:18:09 -07002774 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002776
2777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 final Phone phone = getPhone(subId);
2780 if (phone != null) {
2781 phone.setRadioPower(turnOn);
2782 return true;
2783 } else {
2784 return false;
2785 }
2786 } finally {
2787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789 }
2790
Wink Saville36469e72014-06-11 15:17:00 -07002791 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002792 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002793 public boolean enableDataConnectivity() {
2794 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795
2796 final long identity = Binder.clearCallingIdentity();
2797 try {
2798 int subId = mSubscriptionController.getDefaultDataSubId();
2799 final Phone phone = getPhone(subId);
2800 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002801 phone.getDataEnabledSettings().setDataEnabled(
2802 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803 return true;
2804 } else {
2805 return false;
2806 }
2807 } finally {
2808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002810 }
2811
Wink Saville36469e72014-06-11 15:17:00 -07002812 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 public boolean disableDataConnectivity() {
2815 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816
2817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 int subId = mSubscriptionController.getDefaultDataSubId();
2820 final Phone phone = getPhone(subId);
2821 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002822 phone.getDataEnabledSettings().setDataEnabled(
2823 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 return true;
2825 } else {
2826 return false;
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 }
2832
Sanket Padawe356d7632015-06-22 14:03:32 -07002833 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002834 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 final Phone phone = getPhone(subId);
2838 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002839 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840 } else {
2841 return false;
2842 }
2843 } finally {
2844 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 }
2847
2848 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002849 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002850 }
2851
pkanwarae03a6b2016-11-06 20:37:09 -08002852 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 enforceCallPermission();
2854
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2858 return;
2859 }
2860 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2861 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
2864 }
pkanwar32d516d2016-10-14 19:37:38 -07002865 };
2866
Wink Savilleb564aae2014-10-23 10:18:09 -07002867 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869
2870 final long identity = Binder.clearCallingIdentity();
2871 try {
2872 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2873 return false;
2874 }
2875 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2876 } finally {
2877 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879 }
2880
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002881 /**
2882 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2883 * tag on getCallState Binder call.
2884 */
2885 @Deprecated
2886 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002888 if (CompatChanges.isChangeEnabled(
2889 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2890 Binder.getCallingUid())) {
2891 // Do not allow this API to be called on API version 31+, it should only be
2892 // called on old apps using this Binder call directly.
2893 throw new SecurityException("This method can only be used for applications "
2894 + "targeting API version 30 or less.");
2895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002896 final long identity = Binder.clearCallingIdentity();
2897 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002898 Phone phone = getPhone(getDefaultSubscription());
2899 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2900 PhoneConstantConversions.convertCallState(phone.getState());
2901 } finally {
2902 Binder.restoreCallingIdentity(identity);
2903 }
2904 }
2905
2906 @Override
2907 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2908 if (CompatChanges.isChangeEnabled(
2909 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2910 Binder.getCallingUid())) {
2911 // Check READ_PHONE_STATE for API version 31+
2912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2913 featureId, "getCallStateForSubscription")) {
2914 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2915 + "targeting API level 31+.");
2916 }
2917 }
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2922 PhoneConstantConversions.convertCallState(phone.getState());
2923 } finally {
2924 Binder.restoreCallingIdentity(identity);
2925 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 }
2927
Sanket Padawe356d7632015-06-22 14:03:32 -07002928 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002929 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002930 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2931 }
2932
2933 @Override
2934 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935 final long identity = Binder.clearCallingIdentity();
2936 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002937 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 if (phone != null) {
2939 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2940 } else {
2941 return PhoneConstantConversions.convertDataState(
2942 PhoneConstants.DataState.DISCONNECTED);
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 }
2948
Sanket Padawe356d7632015-06-22 14:03:32 -07002949 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002950 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002951 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2952 }
2953
2954 @Override
2955 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 final long identity = Binder.clearCallingIdentity();
2957 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002958 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002959 if (phone != null) {
2960 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2961 } else {
2962 return TelephonyManager.DATA_ACTIVITY_NONE;
2963 }
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002967 }
2968
2969 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002970 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002971 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002972 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002973
2974 LocationAccessPolicy.LocationPermissionResult locationResult =
2975 LocationAccessPolicy.checkLocationPermission(mApp,
2976 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2977 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002978 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002979 .setCallingPid(Binder.getCallingPid())
2980 .setCallingUid(Binder.getCallingUid())
2981 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002982 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002983 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2984 .build());
2985 switch (locationResult) {
2986 case DENIED_HARD:
2987 throw new SecurityException("Not allowed to access cell location");
2988 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002989 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2990 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 }
2992
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002993 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002997 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002998 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 } finally {
3000 Binder.restoreCallingIdentity(identity);
3001 }
Svetoslav64fad262015-04-14 14:35:21 -07003002 }
3003
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003004 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003005 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003006 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3007 // registered cell info, so return a NULL country instead.
3008 final long identity = Binder.clearCallingIdentity();
3009 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003010 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3011 // Get default phone in this case.
3012 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3013 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003014 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003016 if (phone == null) return "";
3017 ServiceStateTracker sst = phone.getServiceStateTracker();
3018 if (sst == null) return "";
3019 LocaleTracker lt = sst.getLocaleTracker();
3020 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003021 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003025 }
3026
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003027 /**
3028 * This method was removed due to potential issues caused by performing partial
3029 * updates of service state, and lack of a credible use case.
3030 *
3031 * This has the ability to break the telephony implementation by disabling notification of
3032 * changes in device connectivity. DO NOT USE THIS!
3033 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003034 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003035 public void enableLocationUpdates() {
3036 mApp.enforceCallingOrSelfPermission(
3037 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003038 }
3039
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003040 /**
3041 * This method was removed due to potential issues caused by performing partial
3042 * updates of service state, and lack of a credible use case.
3043 *
3044 * This has the ability to break the telephony implementation by disabling notification of
3045 * changes in device connectivity. DO NOT USE THIS!
3046 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003047 @Override
3048 public void disableLocationUpdates() {
3049 mApp.enforceCallingOrSelfPermission(
3050 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 }
3052
3053 @Override
3054 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003055 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3056 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003057 try {
3058 mApp.getSystemService(AppOpsManager.class)
3059 .checkPackage(Binder.getCallingUid(), callingPackage);
3060 } catch (SecurityException e) {
3061 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3062 throw e;
3063 }
3064
Nathan Haroldf096d982020-11-18 17:18:06 -08003065 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003066 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3067 throw new SecurityException(
3068 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3069 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003070
Jordan Liu1617b712019-07-10 15:06:26 -07003071 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3073 return null;
3074 }
Svetoslav64fad262015-04-14 14:35:21 -07003075
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003076 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003077
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003078 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003079 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080
Nathan Haroldf180aac2018-06-01 18:43:55 -07003081 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3082 for (CellInfo ci : info) {
3083 if (ci instanceof CellInfoGsm) {
3084 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3085 } else if (ci instanceof CellInfoWcdma) {
3086 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003089 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003090 }
3091
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003092 private List<CellInfo> getCachedCellInfo() {
3093 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3094 for (Phone phone : PhoneFactory.getPhones()) {
3095 List<CellInfo> info = phone.getAllCellInfo();
3096 if (info != null) cellInfos.addAll(info);
3097 }
3098 return cellInfos;
3099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100
3101 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003102 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003103 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003104 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003105
3106 LocationAccessPolicy.LocationPermissionResult locationResult =
3107 LocationAccessPolicy.checkLocationPermission(mApp,
3108 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3109 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003110 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003111 .setCallingPid(Binder.getCallingPid())
3112 .setCallingUid(Binder.getCallingUid())
3113 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003114 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003115 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3116 .build());
3117 switch (locationResult) {
3118 case DENIED_HARD:
3119 throw new SecurityException("Not allowed to access cell info");
3120 case DENIED_SOFT:
3121 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003122 }
3123
Nathan Haroldf096d982020-11-18 17:18:06 -08003124 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003125 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3126 return getCachedCellInfo();
3127 }
3128
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003129 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003130 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3134 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003135 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003136 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 if (info != null) cellInfos.addAll(info);
3138 }
3139 return cellInfos;
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 }
3143 }
3144
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003145 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003146 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3147 String callingFeatureId) {
3148 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3149 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003150 }
3151
3152 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003153 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3154 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003155 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003156 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003157 }
3158
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003159 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3160 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003161 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003162 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003163
3164 LocationAccessPolicy.LocationPermissionResult locationResult =
3165 LocationAccessPolicy.checkLocationPermission(mApp,
3166 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3167 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003168 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003169 .setCallingPid(Binder.getCallingPid())
3170 .setCallingUid(Binder.getCallingUid())
3171 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003172 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3173 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003174 .build());
3175 switch (locationResult) {
3176 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003177 if (TelephonyPermissions
3178 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003179 // Safetynet logging for b/154934934
3180 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3181 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003182 throw new SecurityException("Not allowed to access cell info");
3183 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003184 if (TelephonyPermissions
3185 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003186 // Safetynet logging for b/154934934
3187 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3188 }
Nathan Harold5320c422019-05-09 10:26:08 -07003189 try {
3190 cb.onCellInfo(new ArrayList<CellInfo>());
3191 } catch (RemoteException re) {
3192 // Drop without consequences
3193 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003194 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003195 }
3196
Nathan Harolda939a962019-05-09 10:13:47 -07003197
3198 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003199 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3200
3201 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3202 }
3203
3204 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003206 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003207 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208
3209 final long identity = Binder.clearCallingIdentity();
3210 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003211 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003215 }
3216
Shishir Agrawala9f32182016-04-12 12:00:16 -07003217 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003218 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003219 Phone phone = PhoneFactory.getPhone(slotIndex);
3220 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003221 return null;
3222 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003223 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003224 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003225 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003226 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003227 return null;
3228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229
3230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 return phone.getImei();
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003236 }
3237
3238 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003239 public String getTypeAllocationCodeForSlot(int slotIndex) {
3240 Phone phone = PhoneFactory.getPhone(slotIndex);
3241 String tac = null;
3242 if (phone != null) {
3243 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003244 try {
3245 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3246 } catch (IndexOutOfBoundsException e) {
3247 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3248 return null;
3249 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003250 }
3251 return tac;
3252 }
3253
3254 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003255 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003256 try {
3257 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3258 } catch (SecurityException se) {
3259 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3260 throw new SecurityException("Package " + callingPackage + " does not belong to "
3261 + Binder.getCallingUid());
3262 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003263 Phone phone = PhoneFactory.getPhone(slotIndex);
3264 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003265 return null;
3266 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003267
Jeff Davidson913390f2018-02-23 17:11:49 -08003268 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003269 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003270 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003271 return null;
3272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273
3274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 return phone.getMeid();
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
Jack Yu2af8d712017-03-15 17:14:14 -07003280 }
3281
3282 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003283 public String getManufacturerCodeForSlot(int slotIndex) {
3284 Phone phone = PhoneFactory.getPhone(slotIndex);
3285 String manufacturerCode = null;
3286 if (phone != null) {
3287 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003288 try {
3289 manufacturerCode =
3290 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3291 } catch (IndexOutOfBoundsException e) {
3292 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3293 return null;
3294 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003295 }
3296 return manufacturerCode;
3297 }
3298
3299 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003300 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3301 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003302 Phone phone = PhoneFactory.getPhone(slotIndex);
3303 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003304 return null;
3305 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003306 int subId = phone.getSubId();
3307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003308 mApp, subId, callingPackage, callingFeatureId,
3309 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003310 return null;
3311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312
3313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 return phone.getDeviceSvn();
3316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003319 }
3320
fionaxu43304da2017-11-27 22:51:16 -08003321 @Override
3322 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 final Phone phone = getPhone(subId);
3326 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3327 } finally {
3328 Binder.restoreCallingIdentity(identity);
3329 }
fionaxu43304da2017-11-27 22:51:16 -08003330 }
3331
3332 @Override
3333 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 final Phone phone = getPhone(subId);
3337 return phone == null ? null : phone.getCarrierName();
3338 } finally {
3339 Binder.restoreCallingIdentity(identity);
3340 }
fionaxu43304da2017-11-27 22:51:16 -08003341 }
3342
calvinpanffe225e2018-11-01 19:43:06 +08003343 @Override
chen xu0026ca62019-03-06 15:28:50 -08003344 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 final Phone phone = getPhone(subId);
3348 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003349 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003350 } finally {
3351 Binder.restoreCallingIdentity(identity);
3352 }
3353 }
3354
3355 @Override
chen xu0026ca62019-03-06 15:28:50 -08003356 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003360 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003361 } finally {
3362 Binder.restoreCallingIdentity(identity);
3363 }
3364 }
3365
chen xu651eec72018-11-11 19:03:44 -08003366 @Override
chen xu864e11c2018-12-06 22:10:03 -08003367 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3368 if (!isSubscriptionMccMnc) {
3369 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3370 }
chen xu651eec72018-11-11 19:03:44 -08003371 final Phone phone = PhoneFactory.getPhone(slotIndex);
3372 if (phone == null) {
3373 return TelephonyManager.UNKNOWN_CARRIER_ID;
3374 }
3375 final long identity = Binder.clearCallingIdentity();
3376 try {
3377 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3378 } finally {
3379 Binder.restoreCallingIdentity(identity);
3380 }
3381 }
3382
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003383 //
3384 // Internal helper methods.
3385 //
3386
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003387 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003388 * Make sure the caller is the calling package itself
3389 *
3390 * @throws SecurityException if the caller is not the calling package
3391 */
3392 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3393 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003394 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3395 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003396 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003397 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003398 } catch (PackageManager.NameNotFoundException e) {
3399 // packageUid is -1
3400 }
3401 if (packageUid != callingUid) {
3402 throw new SecurityException(message + ": Package " + callingPackage
3403 + " does not belong to " + callingUid);
3404 }
3405 }
3406
3407 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003408 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3409 *
3410 * @throws SecurityException if the caller does not have the required permission
3411 */
3412 private void enforceModifyPermission() {
3413 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3414 }
3415
Shuo Qian3b6ee772019-11-13 17:43:31 -08003416 private void enforceActiveEmergencySessionPermission() {
3417 mApp.enforceCallingOrSelfPermission(
3418 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3419 }
3420
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003421 /**
3422 * Make sure the caller has the CALL_PHONE permission.
3423 *
3424 * @throws SecurityException if the caller does not have the required permission
3425 */
3426 private void enforceCallPermission() {
3427 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3428 }
3429
paulhu5a773602019-08-23 19:17:33 +08003430 private void enforceSettingsPermission() {
3431 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003432 }
3433
Michele Berionne5e411512020-11-13 02:36:59 +00003434 private void enforceRebootPermission() {
3435 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3436 }
3437
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003438 private String createTelUrl(String number) {
3439 if (TextUtils.isEmpty(number)) {
3440 return null;
3441 }
3442
Jake Hambye994d462014-02-03 13:10:13 -08003443 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003444 }
3445
Ihab Awadf9e92732013-12-05 18:02:52 -08003446 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003447 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3448 }
3449
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003450 private static void logv(String msg) {
3451 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3452 }
3453
Ihab Awadf9e92732013-12-05 18:02:52 -08003454 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3456 }
3457
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003458 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003459 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003460 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003461 }
3462
Sanket Padawe356d7632015-06-22 14:03:32 -07003463 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003464 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465 final long identity = Binder.clearCallingIdentity();
3466 try {
3467 final Phone phone = PhoneFactory.getPhone(slotIndex);
3468 if (phone == null) {
3469 return PhoneConstants.PHONE_TYPE_NONE;
3470 } else {
3471 return phone.getPhoneType();
3472 }
3473 } finally {
3474 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003476 }
3477
3478 /**
3479 * Returns the CDMA ERI icon index to display
3480 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003481 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003482 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3483 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3484 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003485 }
3486
Sanket Padawe356d7632015-06-22 14:03:32 -07003487 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003488 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3489 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003490 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003491 mApp, subId, callingPackage, callingFeatureId,
3492 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003493 return -1;
3494 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003495
3496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 final Phone phone = getPhone(subId);
3499 if (phone != null) {
3500 return phone.getCdmaEriIconIndex();
3501 } else {
3502 return -1;
3503 }
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507 }
3508
3509 /**
3510 * Returns the CDMA ERI icon mode,
3511 * 0 - ON
3512 * 1 - FLASHING
3513 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003515 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3516 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3517 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003518 }
3519
Sanket Padawe356d7632015-06-22 14:03:32 -07003520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003521 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3522 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003524 mApp, subId, callingPackage, callingFeatureId,
3525 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003526 return -1;
3527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 final Phone phone = getPhone(subId);
3532 if (phone != null) {
3533 return phone.getCdmaEriIconMode();
3534 } else {
3535 return -1;
3536 }
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003540 }
3541
3542 /**
3543 * Returns the CDMA ERI text,
3544 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003545 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003546 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3547 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3548 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003549 }
3550
Sanket Padawe356d7632015-06-22 14:03:32 -07003551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003552 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3553 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003554 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003555 mApp, subId, callingPackage, callingFeatureId,
3556 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003557 return null;
3558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559
3560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 final Phone phone = getPhone(subId);
3563 if (phone != null) {
3564 return phone.getCdmaEriText();
3565 } else {
3566 return null;
3567 }
3568 } finally {
3569 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003571 }
3572
3573 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003574 * Returns the CDMA MDN.
3575 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003576 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003577 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3579 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003580
3581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003584 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003585 return phone.getLine1Number();
3586 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003587 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003588 return null;
3589 }
3590 } finally {
3591 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003592 }
3593 }
3594
3595 /**
3596 * Returns the CDMA MIN.
3597 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003598 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003599 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3601 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602
3603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 final Phone phone = getPhone(subId);
3606 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3607 return phone.getCdmaMin();
3608 } else {
3609 return null;
3610 }
3611 } finally {
3612 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003613 }
3614 }
3615
Hall Liud892bec2018-11-30 14:51:45 -08003616 @Override
3617 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3618 INumberVerificationCallback callback, String callingPackage) {
3619 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3620 != PERMISSION_GRANTED) {
3621 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3622 }
3623 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3624
3625 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3626 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003627 throw new SecurityException("Calling package must be configured in the device config: "
3628 + "calling package: " + callingPackage
3629 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003630 }
3631
3632 if (range == null) {
3633 throw new NullPointerException("Range must be non-null");
3634 }
3635
3636 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003637 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003638
3639 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3640 }
3641
Junda Liuca05d5d2014-08-14 22:36:34 -07003642 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003643 * Returns true if CDMA provisioning needs to run.
3644 */
3645 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646 final long identity = Binder.clearCallingIdentity();
3647 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003648 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003652 }
3653
3654 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003655 * Sets the voice mail number of a given subId.
3656 */
3657 @Override
3658 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003659 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3660 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661
3662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3665 new Pair<String, String>(alphaTag, number), new Integer(subId));
3666 return success;
3667 } finally {
3668 Binder.restoreCallingIdentity(identity);
3669 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003670 }
3671
Ta-wei Yen87c49842016-05-13 21:19:52 -07003672 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003673 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3674 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003675 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3676 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003677 if (!TextUtils.equals(callingPackage, systemDialer)) {
3678 throw new SecurityException("caller must be system dialer");
3679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3684 if (phoneAccountHandle == null) {
3685 return null;
3686 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003687 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003690 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003691 }
3692
3693 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003694 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3695 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003698 mApp, subId, callingPackage, callingFeatureId,
3699 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003700 return null;
3701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003703 final long identity = Binder.clearCallingIdentity();
3704 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003705 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003709 }
3710
3711 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003712 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3713 VisualVoicemailSmsFilterSettings settings) {
3714 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003715
3716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003719 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003723 }
3724
3725 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003726 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3727 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728
3729 final long identity = Binder.clearCallingIdentity();
3730 try {
3731 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003732 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733 } finally {
3734 Binder.restoreCallingIdentity(identity);
3735 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003736 }
3737
3738 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003739 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3740 String callingPackage, int subId) {
3741 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742
3743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003746 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003750 }
3751
3752 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003753 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003754 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755
3756 final long identity = Binder.clearCallingIdentity();
3757 try {
3758 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003759 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003760 } finally {
3761 Binder.restoreCallingIdentity(identity);
3762 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003763 }
3764
3765 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003766 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3767 String callingAttributionTag, int subId, String number, int port, String text,
3768 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003769 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003770 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003771 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003772 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003773 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3774 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003775 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003776
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003777 /**
fionaxu0152e512016-11-14 13:36:14 -08003778 * Sets the voice activation state of a given subId.
3779 */
3780 @Override
3781 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3783 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784
3785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 final Phone phone = getPhone(subId);
3788 if (phone != null) {
3789 phone.setVoiceActivationState(activationState);
3790 } else {
3791 loge("setVoiceActivationState fails with invalid subId: " + subId);
3792 }
3793 } finally {
3794 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003795 }
3796 }
3797
3798 /**
3799 * Sets the data activation state of a given subId.
3800 */
3801 @Override
3802 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3804 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805
3806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 final Phone phone = getPhone(subId);
3809 if (phone != null) {
3810 phone.setDataActivationState(activationState);
3811 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003812 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 }
3814 } finally {
3815 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003816 }
3817 }
3818
3819 /**
3820 * Returns the voice activation state of a given subId.
3821 */
3822 @Override
3823 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825
fionaxu0152e512016-11-14 13:36:14 -08003826 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 if (phone != null) {
3830 return phone.getVoiceActivationState();
3831 } else {
3832 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3833 }
3834 } finally {
3835 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003836 }
3837 }
3838
3839 /**
3840 * Returns the data activation state of a given subId.
3841 */
3842 @Override
3843 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003844 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003845
fionaxu0152e512016-11-14 13:36:14 -08003846 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847 final long identity = Binder.clearCallingIdentity();
3848 try {
3849 if (phone != null) {
3850 return phone.getDataActivationState();
3851 } else {
3852 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3853 }
3854 } finally {
3855 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003856 }
3857 }
3858
3859 /**
Wink Saville36469e72014-06-11 15:17:00 -07003860 * Returns the unread count of voicemails for a subId
3861 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003862 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003863 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3864 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003866 mApp, subId, callingPackage, callingFeatureId,
3867 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003868 return 0;
3869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 final Phone phone = getPhone(subId);
3873 if (phone != null) {
3874 return phone.getVoiceMessageCount();
3875 } else {
3876 return 0;
3877 }
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003881 }
3882
3883 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003884 * returns true, if the device is in a state where both voice and data
3885 * are supported simultaneously. This can change based on location or network condition.
3886 */
3887 @Override
3888 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889 final long identity = Binder.clearCallingIdentity();
3890 try {
3891 final Phone phone = getPhone(subId);
3892 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3893 } finally {
3894 Binder.restoreCallingIdentity(identity);
3895 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003896 }
3897
3898 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003899 * Send the dialer code if called from the current default dialer or the caller has
3900 * carrier privilege.
3901 * @param inputCode The dialer code to send
3902 */
3903 @Override
3904 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003905 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003906 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003907 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3908 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003909 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003910 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003911 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913
3914 final long identity = Binder.clearCallingIdentity();
3915 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003916 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
fionaxu235cc5e2017-03-06 22:25:57 -08003920 }
3921
Pengquan Menga1bb6272018-09-06 09:59:22 -07003922 @Override
3923 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003924 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003925 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003926 mApp, subId, "getNetworkSelectionMode");
3927 final long identity = Binder.clearCallingIdentity();
3928 try {
3929 if (!isActiveSubscription(subId)) {
3930 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3931 }
3932 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003935 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003936 }
3937
Brad Ebinger35c841c2018-10-01 10:40:55 -07003938 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003939 public boolean isInEmergencySmsMode() {
3940 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3941 final long identity = Binder.clearCallingIdentity();
3942 try {
3943 for (Phone phone : PhoneFactory.getPhones()) {
3944 if (phone.isInEmergencySmsMode()) {
3945 return true;
3946 }
3947 }
3948 } finally {
3949 Binder.restoreCallingIdentity(identity);
3950 }
3951 return false;
3952 }
3953
shilu366312e2019-12-17 09:28:10 -08003954 /**
3955 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3956 * @param subId The subscription to use to check the configuration.
3957 * @param c The callback that will be used to send the result.
3958 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003959 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003960 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3961 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003962 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003963 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003964
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003965 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3966 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3967 "IMS not available on device.");
3968 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 final long token = Binder.clearCallingIdentity();
3970 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003971 int slotId = getSlotIndexOrException(subId);
3972 verifyImsMmTelConfiguredOrThrow(slotId);
3973 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003974 } catch (ImsException e) {
3975 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 } 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 * @param c The callback that will be used to send the result.
3985 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003987 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003988 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003989 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003990 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3991 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3992 }
Meng Wangafbc5852019-09-19 17:37:13 -07003993 final long token = Binder.clearCallingIdentity();
3994 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003995 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3996 .removeRegistrationCallbackForSubscription(c, subId);
3997 } catch (ImsException e) {
3998 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3999 + "is inactive, ignoring unregister.");
4000 // If the subscription is no longer active, just return, since the callback
4001 // will already have been removed internally.
4002 } finally {
4003 Binder.restoreCallingIdentity(token);
4004 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 }
4006
Brad Ebingera34a6c22019-10-22 17:36:18 -07004007 /**
4008 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4009 */
4010 @Override
4011 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4012 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4013 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4014 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4015 "IMS not available on device.");
4016 }
4017 final long token = Binder.clearCallingIdentity();
4018 try {
4019 Phone phone = getPhone(subId);
4020 if (phone == null) {
4021 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4022 + subId + "'");
4023 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4024 }
4025 phone.getImsRegistrationState(regState -> {
4026 try {
4027 consumer.accept((regState == null)
4028 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4029 } catch (RemoteException e) {
4030 // Ignore if the remote process is no longer available to call back.
4031 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4032 }
4033 });
4034 } finally {
4035 Binder.restoreCallingIdentity(token);
4036 }
4037 }
4038
4039 /**
4040 * Get the transport type for the IMS service registration state.
4041 */
4042 @Override
4043 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004044 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004045 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004046 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4047 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4048 "IMS not available on device.");
4049 }
4050 final long token = Binder.clearCallingIdentity();
4051 try {
4052 Phone phone = getPhone(subId);
4053 if (phone == null) {
4054 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4055 + subId + "'");
4056 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4057 }
4058 phone.getImsRegistrationTech(regTech -> {
4059 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4060 int regTechConverted = (regTech == null)
4061 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4062 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4063 regTechConverted);
4064 try {
4065 consumer.accept(regTechConverted);
4066 } catch (RemoteException e) {
4067 // Ignore if the remote process is no longer available to call back.
4068 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4069 }
4070 });
4071 } finally {
4072 Binder.restoreCallingIdentity(token);
4073 }
4074 }
4075
shilu366312e2019-12-17 09:28:10 -08004076 /**
4077 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4078 * @param subId The subscription to use to check the configuration.
4079 * @param c The callback that will be used to send the result.
4080 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004082 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4083 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004084 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004085 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004086 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4087 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4088 "IMS not available on device.");
4089 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 final long token = Binder.clearCallingIdentity();
4091 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004092 int slotId = getSlotIndexOrException(subId);
4093 verifyImsMmTelConfiguredOrThrow(slotId);
4094 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004095 } catch (ImsException e) {
4096 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004097 } finally {
4098 Binder.restoreCallingIdentity(token);
4099 }
4100 }
4101
shilu366312e2019-12-17 09:28:10 -08004102 /**
4103 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4104 * @param subId The subscription to use to check the configuration.
4105 * @param c The callback that will be used to send the result.
4106 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004108 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004109 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004110 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004111 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4112 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4113 }
Meng Wangafbc5852019-09-19 17:37:13 -07004114
4115 final long token = Binder.clearCallingIdentity();
4116 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004117 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004118 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004119 } catch (ImsException e) {
4120 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4121 + "is inactive, ignoring unregister.");
4122 // If the subscription is no longer active, just return, since the callback
4123 // will already have been removed internally.
4124 } finally {
4125 Binder.restoreCallingIdentity(token);
4126 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 }
4128
4129 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004130 public boolean isCapable(int subId, int capability, int regTech) {
4131 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004132 final long token = Binder.clearCallingIdentity();
4133 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004134 int slotId = getSlotIndexOrException(subId);
4135 verifyImsMmTelConfiguredOrThrow(slotId);
4136 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004137 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4139 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004140 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004141 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4142 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 } finally {
4144 Binder.restoreCallingIdentity(token);
4145 }
4146 }
4147
4148 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004149 public boolean isAvailable(int subId, int capability, int regTech) {
4150 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 final long token = Binder.clearCallingIdentity();
4152 try {
4153 Phone phone = getPhone(subId);
4154 if (phone == null) return false;
4155 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004156 } catch (com.android.ims.ImsException e) {
4157 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4158 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 } finally {
4160 Binder.restoreCallingIdentity(token);
4161 }
4162 }
4163
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004164 /**
4165 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4166 * subscription.
4167 * @param subId The subscription to use to check the configuration.
4168 * @param callback The callback that will be used to send the result.
4169 * @param capability The MmTelFeature capability that will be used to send the result.
4170 * @param transportType The transport type of the MmTelFeature capability.
4171 */
4172 @Override
4173 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4174 int transportType) {
4175 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4176 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4177 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4178 "IMS not available on device.");
4179 }
4180 final long token = Binder.clearCallingIdentity();
4181 try {
4182 int slotId = getSlotIndex(subId);
4183 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4184 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4185 + subId + "'");
4186 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4187 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004188 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004189 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4190 transportType, aBoolean -> {
4191 try {
4192 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4193 } catch (RemoteException e) {
4194 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4195 + "running. Ignore");
4196 }
4197 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004198 } catch (ImsException e) {
4199 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004200 } finally {
4201 Binder.restoreCallingIdentity(token);
4202 }
4203 }
4204
shilu366312e2019-12-17 09:28:10 -08004205 /**
4206 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4207 * @param subId The subscription to use to check the configuration.
4208 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 @Override
4210 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004211 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004212 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004213
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 final long token = Binder.clearCallingIdentity();
4215 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004216 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004217 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004218 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004219 } catch (ImsException e) {
4220 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 } finally {
4222 Binder.restoreCallingIdentity(token);
4223 }
4224 }
4225
4226 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004227 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004229 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004230 final long identity = Binder.clearCallingIdentity();
4231 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004232 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004233 // This setting doesn't require an active ImsService connection, so do not verify. The
4234 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004235 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004236 } catch (ImsException e) {
4237 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004238 } finally {
4239 Binder.restoreCallingIdentity(identity);
4240 }
4241 }
4242
shilu366312e2019-12-17 09:28:10 -08004243 /**
4244 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4245 * @param subId The subscription to use to check the configuration.
4246 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004247 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004248 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004249 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004250 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 final long identity = Binder.clearCallingIdentity();
4252 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004253 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004254 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004255 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004256 } catch (ImsException e) {
4257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 } finally {
4259 Binder.restoreCallingIdentity(identity);
4260 }
4261 }
4262
4263 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004264 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004266 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 final long identity = Binder.clearCallingIdentity();
4268 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004269 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004270 // This setting doesn't require an active ImsService connection, so do not verify. The
4271 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004272 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004273 } catch (ImsException e) {
4274 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 } finally {
4276 Binder.restoreCallingIdentity(identity);
4277 }
4278 }
4279
shilu366312e2019-12-17 09:28:10 -08004280 /**
4281 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4282 * @param subId The subscription to use to check the configuration.
4283 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 @Override
4285 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004286 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004287 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 final long identity = Binder.clearCallingIdentity();
4289 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004290 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004291 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004292 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004293 } catch (ImsException e) {
4294 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 } finally {
4296 Binder.restoreCallingIdentity(identity);
4297 }
4298 }
4299
4300 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004301 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004303 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 final long identity = Binder.clearCallingIdentity();
4305 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004306 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004307 // This setting doesn't require an active ImsService connection, so do not verify. The
4308 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004309 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004310 } catch (ImsException e) {
4311 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004312 } finally {
4313 Binder.restoreCallingIdentity(identity);
4314 }
4315 }
4316
shilu366312e2019-12-17 09:28:10 -08004317 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004318 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4319 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4320 * @param subId The subscription to use to check the configuration.
4321 */
4322 @Override
4323 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004324 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004325 mApp, subId, "isCrossSimCallingEnabledByUser");
4326 final long identity = Binder.clearCallingIdentity();
4327 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004328 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004329 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004330 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004331 } catch (ImsException e) {
4332 throw new ServiceSpecificException(e.getCode());
4333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
4336 }
4337
4338 /**
4339 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4340 * Requires MODIFY_PHONE_STATE permission.
4341 * @param subId The subscription to use to check the configuration.
4342 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4343 * false otherwise
4344 */
4345 @Override
4346 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4348 "setCrossSimCallingEnabled");
4349 final long identity = Binder.clearCallingIdentity();
4350 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004351 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004352 // This setting doesn't require an active ImsService connection, so do not verify. The
4353 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004354 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004355 } catch (ImsException e) {
4356 throw new ServiceSpecificException(e.getCode());
4357 } finally {
4358 Binder.restoreCallingIdentity(identity);
4359 }
4360 }
4361
4362 /**
shilu366312e2019-12-17 09:28:10 -08004363 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4364 * @param subId The subscription to use to check the configuration.
4365 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004366 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004367
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004369 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004370 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 final long identity = Binder.clearCallingIdentity();
4372 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004373 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004374 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004375 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004376 } catch (ImsException e) {
4377 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
4381 }
4382
4383 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004384 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004386 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 final long identity = Binder.clearCallingIdentity();
4388 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004389 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004390 // This setting doesn't require an active ImsService connection, so do not verify. The
4391 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004392 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004393 } catch (ImsException e) {
4394 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004395 } finally {
4396 Binder.restoreCallingIdentity(identity);
4397 }
4398 }
4399
4400 @Override
4401 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4403 "setVoWiFiNonPersistent");
4404 final long identity = Binder.clearCallingIdentity();
4405 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004406 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004407 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004408 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004409 } catch (ImsException e) {
4410 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004411 } finally {
4412 Binder.restoreCallingIdentity(identity);
4413 }
4414 }
4415
shilu366312e2019-12-17 09:28:10 -08004416 /**
4417 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4418 * @param subId The subscription to use to check the configuration.
4419 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004420 @Override
4421 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004422 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004423 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004424 final long identity = Binder.clearCallingIdentity();
4425 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004426 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004427 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004428 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004429 } catch (ImsException e) {
4430 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004431 } finally {
4432 Binder.restoreCallingIdentity(identity);
4433 }
4434 }
4435
4436 @Override
4437 public void setVoWiFiModeSetting(int subId, int mode) {
4438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4439 "setVoWiFiModeSetting");
4440 final long identity = Binder.clearCallingIdentity();
4441 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004442 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004443 // This setting doesn't require an active ImsService connection, so do not verify. The
4444 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004446 } catch (ImsException e) {
4447 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
4451 }
4452
4453 @Override
4454 public int getVoWiFiRoamingModeSetting(int subId) {
4455 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4456 final long identity = Binder.clearCallingIdentity();
4457 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004459 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004461 } catch (ImsException e) {
4462 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
4466 }
4467
4468 @Override
4469 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4471 "setVoWiFiRoamingModeSetting");
4472 final long identity = Binder.clearCallingIdentity();
4473 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004474 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004475 // This setting doesn't require an active ImsService connection, so do not verify. The
4476 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004477 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004478 } catch (ImsException e) {
4479 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
4483 }
4484
4485 @Override
4486 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4488 "setRttCapabilityEnabled");
4489 final long identity = Binder.clearCallingIdentity();
4490 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004491 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004492 // This setting doesn't require an active ImsService connection, so do not verify. The
4493 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004494 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004495 } catch (ImsException e) {
4496 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
4500 }
4501
shilu366312e2019-12-17 09:28:10 -08004502 /**
4503 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4504 * @param subId The subscription to use to check the configuration.
4505 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004506 @Override
4507 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004508 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004509 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 final long identity = Binder.clearCallingIdentity();
4511 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004512 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004513 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004514 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004515 } catch (ImsException e) {
4516 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
4520 }
4521
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004522 @Override
4523 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4524 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4525 final long identity = Binder.clearCallingIdentity();
4526 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004527 if (!isImsAvailableOnDevice()) {
4528 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4529 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004530 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004531 int slotId = getSlotIndexOrException(subId);
4532 verifyImsMmTelConfiguredOrThrow(slotId);
4533 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004534 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004535 } catch (ImsException e) {
4536 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
4540 }
4541
4542 @Override
4543 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4544 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4545 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004546 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4547 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4548 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004549 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004550 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004551 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004552 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004553 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4554 + "is inactive, ignoring unregister.");
4555 // If the subscription is no longer active, just return, since the callback will already
4556 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
4560 }
4561
allenwtsu99c623b2020-01-03 18:24:23 +08004562
4563 private void checkModifyPhoneStatePermission(int subId, String message) {
4564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4565 message);
4566 }
4567
4568 private boolean isImsProvisioningRequired(int subId, int capability,
4569 boolean isMmtelCapability) {
4570 Phone phone = getPhone(subId);
4571 if (phone == null) {
4572 loge("phone instance null for subid " + subId);
4573 return false;
4574 }
4575 if (isMmtelCapability) {
4576 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4577 return false;
4578 }
4579 } else {
4580 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4581 return false;
4582 }
4583 }
4584 return true;
4585 }
4586
4587 @Override
4588 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4589 boolean isProvisioned) {
4590 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4591
4592 final long identity = Binder.clearCallingIdentity();
4593 try {
4594 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4595 if (!isImsProvisioningRequired(subId, capability, false)) {
4596 return;
4597 }
4598
4599 // this capability requires provisioning, route to the correct API.
4600 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4601 switch (capability) {
4602 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4603 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4604 ims.setEabProvisioned(isProvisioned);
4605 break;
4606 default: {
4607 throw new IllegalArgumentException("Tried to set provisioning for "
4608 + "rcs capability '" + capability + "', which does not require "
4609 + "provisioning.");
4610 }
4611 }
4612 } finally {
4613 Binder.restoreCallingIdentity(identity);
4614 }
4615
4616 }
4617
4618
4619 @Override
4620 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4621 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4622 final long identity = Binder.clearCallingIdentity();
4623 try {
4624 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4625 if (!isImsProvisioningRequired(subId, capability, false)) {
4626 return true;
4627 }
4628
4629 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4630 switch (capability) {
4631 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4632 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4633 return ims.isEabProvisionedOnDevice();
4634
4635 default: {
4636 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4637 + "capability '" + capability + "', which does not require "
4638 + "provisioning.");
4639 }
4640 }
4641
4642 } finally {
4643 Binder.restoreCallingIdentity(identity);
4644 }
4645 }
4646
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004647 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004648 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4649 boolean isProvisioned) {
4650 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004651 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4652 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4653 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4655 }
allenwtsu99c623b2020-01-03 18:24:23 +08004656 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 final long identity = Binder.clearCallingIdentity();
4658 try {
4659 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004660 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004661 return;
4662 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004663 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4664 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4665 loge("setImsProvisioningStatusForCapability: called for technology that does "
4666 + "not support provisioning - " + tech);
4667 return;
4668 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004669
4670 // this capability requires provisioning, route to the correct API.
4671 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4672 switch (capability) {
4673 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4674 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4675 ims.setVolteProvisioned(isProvisioned);
4676 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4677 ims.setWfcProvisioned(isProvisioned);
4678 }
4679 break;
4680 }
4681 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4682 // There is currently no difference in VT provisioning type.
4683 ims.setVtProvisioned(isProvisioned);
4684 break;
4685 }
4686 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4687 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4688 // change the capability of the feature instead if needed.
4689 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4690 == isProvisioned) {
4691 // No change in provisioning.
4692 return;
4693 }
4694 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4695 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004696 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004697 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004698 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4699 + ", Exception" + e.getMessage());
4700 }
4701 break;
4702 }
4703 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004704 throw new IllegalArgumentException("Tried to set provisioning for "
4705 + "MmTel capability '" + capability + "', which does not require "
4706 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004707 }
4708 }
4709
4710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
4713 }
4714
4715 @Override
4716 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4717 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004718 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4719 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4720 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004721 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4722 }
4723 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
4726 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004727 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004728 return true;
4729 }
4730
Brad Ebinger0d79c572021-04-17 15:20:49 -07004731 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4732 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4733 loge("getImsProvisioningStatusForCapability: called for technology that does "
4734 + "not support provisioning - " + tech);
4735 return true;
4736 }
4737
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004738 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4739 switch (capability) {
4740 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4741 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4742 return ims.isVolteProvisionedOnDevice();
4743 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4744 return ims.isWfcProvisionedOnDevice();
4745 }
4746 // This should never happen, since we are checking tech above to make sure it
4747 // is either LTE or IWLAN.
4748 throw new IllegalArgumentException("Invalid radio technology for voice "
4749 + "capability.");
4750 }
4751 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4752 // There is currently no difference in VT provisioning type.
4753 return ims.isVtProvisionedOnDevice();
4754 }
4755 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4756 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4757 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4758 }
4759 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004760 throw new IllegalArgumentException(
4761 "Tried to get provisioning for MmTel capability '" + capability
4762 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004763 }
4764 }
4765
4766 } finally {
4767 Binder.restoreCallingIdentity(identity);
4768 }
4769 }
4770
4771 @Override
4772 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4773 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4774 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4775 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4776 }
4777 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4778 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4779 return (provisionedBits & capability) > 0;
4780 }
4781
4782 @Override
4783 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4784 boolean isProvisioned) {
4785 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4786 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4787 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4788 }
4789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4790 "setProvisioningStatusForCapability");
4791 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4792 // If the current provisioning status for capability already matches isProvisioned,
4793 // do nothing.
4794 if (((provisionedBits & capability) > 0) == isProvisioned) {
4795 return;
4796 }
4797 if (isProvisioned) {
4798 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4799 } else {
4800 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4801 }
4802 }
4803
4804 /**
4805 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4806 * technology. The bitfield should mirror the bitfield defined by
4807 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4808 */
4809 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4810 String key = getMmTelProvisioningKey(subId, tech);
4811 // Default is no capabilities are provisioned.
4812 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4813 }
4814
4815 /**
4816 * Sets the MmTel capability provisioning bitfield (defined by
4817 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4818 * technology specified.
4819 *
4820 * Note: This is a synchronous command and should not be called on UI thread.
4821 */
4822 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4823 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4824 String key = getMmTelProvisioningKey(subId, tech);
4825 editor.putInt(key, newField);
4826 editor.commit();
4827 }
4828
4829 private static String getMmTelProvisioningKey(int subId, int tech) {
4830 // resulting key is provision_ims_mmtel_{subId}_{tech}
4831 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4832 }
4833
4834 /**
4835 * Query CarrierConfig to see if the specified capability requires provisioning for the
4836 * carrier associated with the subscription id.
4837 */
4838 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4839 int capability) {
4840 CarrierConfigManager configManager = new CarrierConfigManager(context);
4841 PersistableBundle c = configManager.getConfigForSubId(subId);
4842 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004843 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004844 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4845 false);
4846 boolean requireVoiceVtProvisioning = c.getBoolean(
4847 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4848
4849 // First check to make sure that the capability requires provisioning.
4850 switch (capability) {
4851 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4852 // intentional fallthrough
4853 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4854 if (requireVoiceVtProvisioning) {
4855 // Voice and Video requires provisioning
4856 return true;
4857 }
4858 break;
4859 }
4860 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4861 if (requireUtProvisioning) {
4862 // UT requires provisioning
4863 return true;
4864 }
4865 break;
4866 }
4867 }
4868 return false;
4869 }
4870
allenwtsu99c623b2020-01-03 18:24:23 +08004871 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4872 int capability) {
4873 CarrierConfigManager configManager = new CarrierConfigManager(context);
4874 PersistableBundle c = configManager.getConfigForSubId(subId);
4875
4876 boolean requireRcsProvisioning = c.getBoolean(
4877 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4878
4879 // First check to make sure that the capability requires provisioning.
4880 switch (capability) {
4881 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4882 // intentional fallthrough
4883 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4884 if (requireRcsProvisioning) {
4885 // OPTION or PRESENCE requires provisioning
4886 return true;
4887 }
4888 break;
4889 }
4890 }
4891 return false;
4892 }
4893
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004894 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004895 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004896 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4897 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4898 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004899 enforceReadPrivilegedPermission("getImsProvisioningInt");
4900 final long identity = Binder.clearCallingIdentity();
4901 try {
4902 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004903 int slotId = getSlotIndex(subId);
4904 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4905 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4906 + subId + "' for key:" + key);
4907 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4908 }
calvinpanb5a34062021-02-08 19:59:36 +08004909 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004910 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004911 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4912 + subId + "' for key:" + key);
4913 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004914 } finally {
4915 Binder.restoreCallingIdentity(identity);
4916 }
4917 }
4918
4919 @Override
4920 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4922 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4923 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004924 enforceReadPrivilegedPermission("getImsProvisioningString");
4925 final long identity = Binder.clearCallingIdentity();
4926 try {
4927 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004928 int slotId = getSlotIndex(subId);
4929 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4930 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4931 + subId + "' for key:" + key);
4932 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4933 }
calvinpanb5a34062021-02-08 19:59:36 +08004934 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004935 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004936 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4937 + subId + "' for key:" + key);
4938 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004939 } finally {
4940 Binder.restoreCallingIdentity(identity);
4941 }
4942 }
4943
4944 @Override
4945 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004946 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4947 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4948 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4950 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004951 final long identity = Binder.clearCallingIdentity();
4952 try {
4953 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004954 int slotId = getSlotIndex(subId);
4955 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4956 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4957 + subId + "' for key:" + key);
4958 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4959 }
calvinpanb5a34062021-02-08 19:59:36 +08004960 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4961 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004962 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004963 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004964 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004965 } finally {
4966 Binder.restoreCallingIdentity(identity);
4967 }
4968 }
4969
4970 @Override
4971 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4973 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4974 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4976 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004977 final long identity = Binder.clearCallingIdentity();
4978 try {
4979 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004980 int slotId = getSlotIndex(subId);
4981 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4982 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4983 + subId + "' for key:" + key);
4984 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4985 }
calvinpanb5a34062021-02-08 19:59:36 +08004986 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4987 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004988 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004989 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004990 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
4994 }
4995
Brad Ebinger919631e2021-06-02 17:46:35 -07004996 /**
4997 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4998 * for the given slot ID or no ImsResolver instance has been created.
4999 * @param slotId The slot ID that the IMS service is created for.
5000 * @throws ImsException If there is no ImsService configured for this slot.
5001 */
5002 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5003 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5004 ImsFeature.FEATURE_MMTEL)) {
5005 throw new ImsException("This subscription does not support MMTEL over IMS",
5006 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5007 }
5008 }
5009
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005010 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005011 int slotId = SubscriptionManager.getSlotIndex(subId);
5012 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005013 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5014 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005015 }
5016 return slotId;
5017 }
5018
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005019 private int getSlotIndex(int subId) {
5020 int slotId = SubscriptionManager.getSlotIndex(subId);
5021 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5022 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5023 }
5024 return slotId;
5025 }
5026
Wink Saville36469e72014-06-11 15:17:00 -07005027 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005028 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005029 */
5030 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005031 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5032 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005033 try {
5034 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5035 } catch (SecurityException se) {
5036 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5037 throw new SecurityException("Package " + callingPackage + " does not belong to "
5038 + Binder.getCallingUid());
5039 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005040 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005041 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005042 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005043 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005044 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005045 mApp, subId, callingPackage, callingFeatureId,
5046 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005047 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5048 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 final long identity = Binder.clearCallingIdentity();
5051 try {
5052 final Phone phone = getPhone(subId);
5053 if (phone != null) {
5054 return phone.getServiceState().getDataNetworkType();
5055 } else {
5056 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5057 }
5058 } finally {
5059 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005061 }
5062
5063 /**
5064 * Returns the data network type
5065 */
5066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005067 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005068 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5069 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005070 }
5071
5072 /**
5073 * Returns the data network type for a subId
5074 */
5075 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005076 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5077 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005078 String functionName = "getDataNetworkTypeForSubscriber";
5079 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5080 mApp, functionName)) {
5081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5082 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5083 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5084 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005085 }
5086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 final Phone phone = getPhone(subId);
5090 if (phone != null) {
5091 return phone.getServiceState().getDataNetworkType();
5092 } else {
5093 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5094 }
5095 } finally {
5096 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005098 }
5099
5100 /**
Wink Saville36469e72014-06-11 15:17:00 -07005101 * Returns the Voice network type for a subId
5102 */
5103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005104 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5105 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005106 String functionName = "getVoiceNetworkTypeForSubscriber";
5107 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5108 mApp, functionName)) {
5109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5110 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5111 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5112 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005113 }
5114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 final Phone phone = getPhone(subId);
5118 if (phone != null) {
5119 return phone.getServiceState().getVoiceNetworkType();
5120 } else {
5121 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5122 }
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005126 }
5127
5128 /**
5129 * @return true if a ICC card is present
5130 */
5131 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005132 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005133 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5134 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005135 }
5136
5137 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005138 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005139 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005140 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005141 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 final Phone phone = PhoneFactory.getPhone(slotIndex);
5145 if (phone != null) {
5146 return phone.getIccCard().hasIccCard();
5147 } else {
5148 return false;
5149 }
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005153 }
5154
5155 /**
5156 * Return if the current radio is LTE on CDMA. This
5157 * is a tri-state return value as for a period of time
5158 * the mode may be unknown.
5159 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005160 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005161 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005162 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005163 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005164 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005165 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5166 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5167 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005168 }
5169
Sanket Padawe356d7632015-06-22 14:03:32 -07005170 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005171 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5172 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005173 try {
5174 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5175 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005176 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5177 }
5178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 final Phone phone = getPhone(subId);
5182 if (phone == null) {
5183 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5184 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005185 return TelephonyProperties.lte_on_cdma_device()
5186 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 }
5188 } finally {
5189 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005190 }
Wink Saville36469e72014-06-11 15:17:00 -07005191 }
5192
Wink Saville36469e72014-06-11 15:17:00 -07005193 /**
5194 * {@hide}
5195 * Returns Default subId, 0 in the case of single standby.
5196 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005197 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005198 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005199 }
5200
Shishir Agrawala9f32182016-04-12 12:00:16 -07005201 private int getSlotForDefaultSubscription() {
5202 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5203 }
5204
Wink Savilleb564aae2014-10-23 10:18:09 -07005205 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005206 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005207 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005208
Pengquan Menge92a50d2018-09-21 15:54:48 -07005209 private boolean isActiveSubscription(int subId) {
5210 return mSubscriptionController.isActiveSubId(subId);
5211 }
5212
Ihab Awadf2177b72013-11-25 13:33:23 -08005213 /**
5214 * @see android.telephony.TelephonyManager.WifiCallingChoices
5215 */
5216 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 final long identity = Binder.clearCallingIdentity();
5218 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005219 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5221 getWhenToMakeWifiCallsDefaultPreference());
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
5224 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005225 }
5226
5227 /**
5228 * @see android.telephony.TelephonyManager.WifiCallingChoices
5229 */
5230 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005234 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005239 }
5240
Sailesh Nepald1e68152013-12-12 19:08:02 -08005241 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005242 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005243 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005244 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005245
Jordan Liu4c733742019-02-28 12:03:40 -08005246 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5247 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5248 if (phoneId == -1) {
5249 throw new IllegalArgumentException("Given slot index: " + slotIndex
5250 + " does not correspond to an active phone");
5251 }
5252 return PhoneFactory.getPhone(phoneId);
5253 }
5254
Shishir Agrawal566b7612013-10-28 14:41:00 -07005255 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005256 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5257 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5259 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005261 if (DBG) {
5262 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5263 }
5264 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5265 p2);
5266 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005267
Jordan Liu4c733742019-02-28 12:03:40 -08005268
5269 @Override
5270 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5271 int slotIndex, String callingPackage, String aid, int p2) {
5272 enforceModifyPermission();
5273 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5274 if (DBG) {
5275 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5276 }
5277 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5278 callingPackage, aid, p2);
5279 }
5280
5281 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5282 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 if (TextUtils.equals(ISDR_AID, aid)) {
5286 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005287 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5288 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 if (bestComponent == null
5290 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5291 loge("The calling package is not allowed to access ISD-R.");
5292 throw new SecurityException(
5293 "The calling package is not allowed to access ISD-R.");
5294 }
Derek Tan740e1672017-06-27 14:56:27 -07005295 }
Derek Tan740e1672017-06-27 14:56:27 -07005296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005298 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5299 null /* workSource */);
5300 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 return response;
5302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005305 }
5306
5307 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005308 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5310 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005311 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5312 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5313 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005314
Jordan Liu4c733742019-02-28 12:03:40 -08005315 @Override
5316 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5317 enforceModifyPermission();
5318 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5319 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5320 channel);
5321 }
5322
5323 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 final long identity = Binder.clearCallingIdentity();
5325 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 if (channel < 0) {
5327 return false;
5328 }
Jordan Liu4c733742019-02-28 12:03:40 -08005329 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5330 null /* workSource */);
5331 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 return success;
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005335 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005336 }
5337
5338 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005339 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005340 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5342 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005343 if (DBG) {
5344 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5345 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5346 + p3 + " data=" + data);
5347 }
5348 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5349 command, p1, p2, p3, data);
5350 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005351
Jordan Liu4c733742019-02-28 12:03:40 -08005352 @Override
5353 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5354 int command, int p1, int p2, int p3, String data) {
5355 enforceModifyPermission();
5356 if (DBG) {
5357 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5358 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5359 + p3 + " data=" + data);
5360 }
5361 return iccTransmitApduLogicalChannelWithPermission(
5362 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5363 data);
5364 }
5365
5366 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5367 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368 final long identity = Binder.clearCallingIdentity();
5369 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005370 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 return "";
5372 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005375 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5376 null /* workSource */);
5377 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 // Append the returned status code to the end of the response payload.
5380 String s = Integer.toHexString(
5381 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5382 if (response.payload != null) {
5383 s = IccUtils.bytesToHexString(response.payload) + s;
5384 }
5385 return s;
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005388 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005389 }
Jake Hambye994d462014-02-03 13:10:13 -08005390
Evan Charltonc66da362014-05-16 14:06:40 -07005391 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005392 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5393 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5395 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005397 if (DBG) {
5398 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5399 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5400 }
5401 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5402 cla, command, p1, p2, p3, data);
5403 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005404
Jordan Liu4c733742019-02-28 12:03:40 -08005405 @Override
5406 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5407 int command, int p1, int p2, int p3, String data) {
5408 enforceModifyPermission();
5409 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5410 if (DBG) {
5411 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5412 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5413 + " data=" + data);
5414 }
5415
5416 return iccTransmitApduBasicChannelWithPermission(
5417 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5418 p2, p3, data);
5419 }
5420
5421 // open APDU basic channel assuming the caller has sufficient permissions
5422 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5423 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5427 && TextUtils.equals(ISDR_AID, data)) {
5428 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005429 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5430 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 if (bestComponent == null
5432 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5433 loge("The calling package is not allowed to select ISD-R.");
5434 throw new SecurityException(
5435 "The calling package is not allowed to select ISD-R.");
5436 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005437 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005440 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5441 null /* workSource */);
5442 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444 // Append the returned status code to the end of the response payload.
5445 String s = Integer.toHexString(
5446 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5447 if (response.payload != null) {
5448 s = IccUtils.bytesToHexString(response.payload) + s;
5449 }
5450 return s;
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005453 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005454 }
5455
5456 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005457 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005458 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5460 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462 final long identity = Binder.clearCallingIdentity();
5463 try {
5464 if (DBG) {
5465 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5466 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5467 }
5468
5469 IccIoResult response =
5470 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5471 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5472 subId);
5473
5474 if (DBG) {
5475 log("Exchange SIM_IO [R]" + response);
5476 }
5477
5478 byte[] result = null;
5479 int length = 2;
5480 if (response.payload != null) {
5481 length = 2 + response.payload.length;
5482 result = new byte[length];
5483 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5484 } else {
5485 result = new byte[length];
5486 }
5487
5488 result[length - 1] = (byte) response.sw2;
5489 result[length - 2] = (byte) response.sw1;
5490 return result;
5491 } finally {
5492 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005493 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005494 }
5495
Nathan Haroldb3014052017-01-25 15:57:32 -08005496 /**
5497 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5498 * on a particular subscription
5499 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005500 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5501 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005503 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005504 return null;
5505 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 if (appType != TelephonyManager.APPTYPE_USIM
5510 && appType != TelephonyManager.APPTYPE_SIM) {
5511 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5512 return null;
5513 }
5514 Object response = sendRequest(
5515 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5516 if (response instanceof String[]) {
5517 return (String[]) response;
5518 }
yincheng zhao2737e882019-09-06 17:06:54 -07005519 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005521 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 } finally {
5523 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005524 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005525 }
5526
yincheng zhao2737e882019-09-06 17:06:54 -07005527 /**
5528 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5529 * subscription.
5530 *
5531 * @param subId the id of the subscription.
5532 * @param appType the uicc app type, must be USIM or SIM.
5533 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5534 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005535 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005536 * @return number of fplmns that is successfully written to the SIM.
5537 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005538 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5539 String callingFeatureId) {
5540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5541 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005542 if (DBG) logv("no permissions for setForbiddenplmns");
5543 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5544 }
5545 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5546 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5547 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5548 }
5549 if (fplmns == null) {
5550 throw new IllegalArgumentException("Fplmn List provided is null");
5551 }
5552 for (String fplmn : fplmns) {
5553 if (!CellIdentity.isValidPlmn(fplmn)) {
5554 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5555 }
5556 }
5557 final long identity = Binder.clearCallingIdentity();
5558 try {
5559 Object response = sendRequest(
5560 CMD_SET_FORBIDDEN_PLMNS,
5561 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5562 subId);
5563 return (int) response;
5564 } finally {
5565 Binder.restoreCallingIdentity(identity);
5566 }
5567 }
5568
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005569 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005570 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5572 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 final long identity = Binder.clearCallingIdentity();
5575 try {
5576 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5577 if (response.payload == null) {
5578 return "";
5579 }
Evan Charltonc66da362014-05-16 14:06:40 -07005580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 // Append the returned status code to the end of the response payload.
5582 String s = Integer.toHexString(
5583 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5584 s = IccUtils.bytesToHexString(response.payload) + s;
5585 return s;
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
5588 }
Evan Charltonc66da362014-05-16 14:06:40 -07005589 }
5590
Jake Hambye994d462014-02-03 13:10:13 -08005591 /**
5592 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5593 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5594 *
5595 * @param itemID the ID of the item to read
5596 * @return the NV item as a String, or null on error.
5597 */
5598 @Override
5599 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005600 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5602 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603
5604 final long identity = Binder.clearCallingIdentity();
5605 try {
5606 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005607 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5609 return value;
5610 } finally {
5611 Binder.restoreCallingIdentity(identity);
5612 }
Jake Hambye994d462014-02-03 13:10:13 -08005613 }
5614
5615 /**
5616 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5617 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5618 *
5619 * @param itemID the ID of the item to read
5620 * @param itemValue the value to write, as a String
5621 * @return true on success; false on any failure
5622 */
5623 @Override
5624 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005625 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5627 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628
5629 final long identity = Binder.clearCallingIdentity();
5630 try {
5631 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5632 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005633 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5635 return success;
5636 } finally {
5637 Binder.restoreCallingIdentity(identity);
5638 }
Jake Hambye994d462014-02-03 13:10:13 -08005639 }
5640
5641 /**
5642 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5643 * Used for device configuration by some CDMA operators.
5644 *
5645 * @param preferredRoamingList byte array containing the new PRL
5646 * @return true on success; false on any failure
5647 */
5648 @Override
5649 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5651 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652
5653 final long identity = Binder.clearCallingIdentity();
5654 try {
5655 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5656 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5657 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5658 return success;
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
Jake Hambye994d462014-02-03 13:10:13 -08005662 }
5663
5664 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005665 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005666 * Used for device configuration by some CDMA operators.
5667 *
chen xu6dac5ab2018-10-26 17:39:23 -07005668 * @param slotIndex - device slot.
5669 *
Jake Hambye994d462014-02-03 13:10:13 -08005670 * @return true on success; false on any failure
5671 */
5672 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005673 public boolean resetModemConfig(int slotIndex) {
5674 Phone phone = PhoneFactory.getPhone(slotIndex);
5675 if (phone != null) {
5676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5677 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678
chen xu6dac5ab2018-10-26 17:39:23 -07005679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5682 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5683 return success;
5684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 }
chen xu6dac5ab2018-10-26 17:39:23 -07005688 return false;
5689 }
5690
5691 /**
5692 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5693 *
5694 * @param slotIndex - device slot.
5695 *
5696 * @return true on success; false on any failure
5697 */
5698 @Override
5699 public boolean rebootModem(int slotIndex) {
5700 Phone phone = PhoneFactory.getPhone(slotIndex);
5701 if (phone != null) {
5702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5703 mApp, phone.getSubId(), "rebootModem");
5704
5705 final long identity = Binder.clearCallingIdentity();
5706 try {
5707 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5708 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5709 return success;
5710 } finally {
5711 Binder.restoreCallingIdentity(identity);
5712 }
5713 }
5714 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005715 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005716
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005717 public String[] getPcscfAddress(String apnType, String callingPackage,
5718 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005719 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005720 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5721 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005722 return new String[0];
5723 }
5724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 final long identity = Binder.clearCallingIdentity();
5726 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005727 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 } finally {
5729 Binder.restoreCallingIdentity(identity);
5730 }
Wink Saville36469e72014-06-11 15:17:00 -07005731 }
5732
Brad Ebinger51f743a2017-01-23 13:50:20 -08005733 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005734 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5735 * {@link #disableIms(int)}.
5736 * @param slotIndex device slot.
5737 */
5738 public void resetIms(int slotIndex) {
5739 enforceModifyPermission();
5740
5741 final long identity = Binder.clearCallingIdentity();
5742 try {
5743 if (mImsResolver == null) {
5744 // may happen if the does not support IMS.
5745 return;
5746 }
5747 mImsResolver.disableIms(slotIndex);
5748 mImsResolver.enableIms(slotIndex);
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
5752 }
5753
5754 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005755 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5756 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005757 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005758 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760
5761 final long identity = Binder.clearCallingIdentity();
5762 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005763 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005764 // may happen if the device does not support IMS.
5765 return;
5766 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005767 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005771 }
5772
5773 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005774 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5775 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005776 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005777 public void disableIms(int slotId) {
5778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779
5780 final long identity = Binder.clearCallingIdentity();
5781 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005782 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005783 // may happen if the device does not support IMS.
5784 return;
5785 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005786 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005790 }
5791
5792 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005793 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5794 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005795 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005796 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005797 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799
5800 final long identity = Binder.clearCallingIdentity();
5801 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005802 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005803 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5804 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005805 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005806 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807 } finally {
5808 Binder.restoreCallingIdentity(identity);
5809 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005810 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005811 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005812 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5813 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005814 @Override
5815 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005816 enforceModifyPermission();
5817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005821 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005822 } finally {
5823 Binder.restoreCallingIdentity(identity);
5824 }
5825 }
5826
5827 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005828 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005829 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005830 */
5831 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833
5834 final long identity = Binder.clearCallingIdentity();
5835 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005836 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005837 // may happen if the device does not support IMS.
5838 return null;
5839 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005840 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005841 } finally {
5842 Binder.restoreCallingIdentity(identity);
5843 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005844 }
5845
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005846 /**
5847 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005848 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005849 */
5850 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852
5853 final long identity = Binder.clearCallingIdentity();
5854 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005855 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005856 // may happen if the device does not support IMS.
5857 return null;
5858 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005859 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005863 }
5864
Brad Ebinger884c07b2018-02-15 16:17:40 -08005865 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005866 * Sets the ImsService Package Name that Telephony will bind to.
5867 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005868 * @param slotIndex the slot ID that the ImsService should bind for.
5869 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005870 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005871 * @param featureTypes An integer array of feature types associated with a packageName.
5872 * @param packageName The name of the package that the current configuration will be replaced
5873 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005874 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005875 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005876 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5877 int[] featureTypes, String packageName) {
5878 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5879 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5881 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005882 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884 final long identity = Binder.clearCallingIdentity();
5885 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005886 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005887 // may happen if the device does not support IMS.
5888 return false;
5889 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005890 Map<Integer, String> featureConfig = new HashMap<>();
5891 for (int featureType : featureTypes) {
5892 featureConfig.put(featureType, packageName);
5893 }
5894 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5895 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005899 }
5900
5901 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005902 * Clears any carrier ImsService overrides for the slot index specified that were previously
5903 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5904 *
5905 * This should only be used for testing.
5906 *
5907 * @param slotIndex the slot ID that the ImsService should bind for.
5908 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5909 */
5910 @Override
5911 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5912 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5913 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5914 "clearCarrierImsServiceOverride");
5915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5916 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5917 "clearCarrierImsServiceOverride");
5918
5919 final long identity = Binder.clearCallingIdentity();
5920 try {
5921 if (mImsResolver == null) {
5922 // may happen if the device does not support IMS.
5923 return false;
5924 }
5925 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5926 } finally {
5927 Binder.restoreCallingIdentity(identity);
5928 }
5929 }
5930
5931 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005932 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005933 *
5934 * @param slotId The slot that the ImsService is associated with.
5935 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5936 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005937 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005938 * @return the package name of the ImsService configuration.
5939 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005940 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5941 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005942 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005943 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005944 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005945 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5946 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 final long identity = Binder.clearCallingIdentity();
5949 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005950 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005951 // may happen if the device does not support IMS.
5952 return "";
5953 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005954 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005955 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5956 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005960 }
5961
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005962 /**
5963 * Get the MmTelFeature state associated with the requested subscription id.
5964 * @param subId The subscription that the MmTelFeature is associated with.
5965 * @param callback A callback with an integer containing the
5966 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5967 */
5968 @Override
5969 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5970 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5971 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5972 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5973 "IMS not available on device.");
5974 }
5975 final long token = Binder.clearCallingIdentity();
5976 try {
5977 int slotId = getSlotIndex(subId);
5978 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5979 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5980 + subId + "'");
5981 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5982 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005983 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005984 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5985 try {
5986 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5987 } catch (RemoteException e) {
5988 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5989 + "Ignore");
5990 }
5991 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005992 } catch (ImsException e) {
5993 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005994 } finally {
5995 Binder.restoreCallingIdentity(token);
5996 }
5997 }
5998
Daniel Brightbb5840b2021-01-12 15:48:18 -08005999 /**
6000 * Sets the ims registration state on all valid {@link Phone}s.
6001 */
6002 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006003 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004
6005 final long identity = Binder.clearCallingIdentity();
6006 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006007 // NOTE: Before S, this method only set the default phone.
6008 for (final Phone phone : PhoneFactory.getPhones()) {
6009 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6010 phone.setImsRegistrationState(registered);
6011 }
6012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
Wink Saville36469e72014-06-11 15:17:00 -07006016 }
6017
6018 /**
Stuart Scott54788802015-03-30 13:18:01 -07006019 * Set the network selection mode to automatic.
6020 *
6021 */
6022 @Override
6023 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6025 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026
6027 final long identity = Binder.clearCallingIdentity();
6028 try {
shilufc958392020-01-20 11:36:01 -08006029 if (!isActiveSubscription(subId)) {
6030 return;
6031 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006032 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006033 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6034 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 } finally {
6036 Binder.restoreCallingIdentity(identity);
6037 }
Stuart Scott54788802015-03-30 13:18:01 -07006038 }
6039
Jack Yud10cdd42020-09-28 20:28:01 -07006040 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006041 * Ask the radio to connect to the input network and change selection mode to manual.
6042 *
6043 * @param subId the id of the subscription.
6044 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6045 * the operator to attach to.
6046 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6047 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6048 * normal network selection next time.
6049 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006050 */
6051 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006052 public boolean setNetworkSelectionModeManual(
6053 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6055 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006056
6057 if (!isActiveSubscription(subId)) {
6058 return false;
6059 }
6060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 final long identity = Binder.clearCallingIdentity();
6062 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006063 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006065 if (DBG) {
6066 log("setNetworkSelectionModeManual: subId: " + subId
6067 + " operator: " + operatorInfo);
6068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6070 } finally {
6071 Binder.restoreCallingIdentity(identity);
6072 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006073 }
shilu84f6e8b2019-12-19 13:58:01 -08006074 /**
6075 * Get the manual network selection
6076 *
6077 * @param subId the id of the subscription.
6078 *
6079 * @return the previously saved user selected PLMN
6080 */
6081 @Override
6082 public String getManualNetworkSelectionPlmn(int subId) {
6083 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006084 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006085 mApp, subId, "getManualNetworkSelectionPlmn");
6086
6087 final long identity = Binder.clearCallingIdentity();
6088 try {
6089 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006090 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006091 }
6092
6093 final Phone phone = getPhone(subId);
6094 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006095 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006096 }
6097 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6098 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6099 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6100 } finally {
6101 Binder.restoreCallingIdentity(identity);
6102 }
6103 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006104
6105 /**
6106 * Scans for available networks.
6107 */
6108 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006109 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6110 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6112 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006113 LocationAccessPolicy.LocationPermissionResult locationResult =
6114 LocationAccessPolicy.checkLocationPermission(mApp,
6115 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6116 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006117 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006118 .setCallingPid(Binder.getCallingPid())
6119 .setCallingUid(Binder.getCallingUid())
6120 .setMethod("getCellNetworkScanResults")
6121 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006122 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6123 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006124 .build());
6125 switch (locationResult) {
6126 case DENIED_HARD:
6127 throw new SecurityException("Not allowed to access scan results -- location");
6128 case DENIED_SOFT:
6129 return null;
6130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131
Pengquan Menga1bb6272018-09-06 09:59:22 -07006132 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 try {
6134 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006135 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 } finally {
6138 Binder.restoreCallingIdentity(identity);
6139 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006140 }
6141
6142 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006143 * Get the call forwarding info, given the call forwarding reason.
6144 */
6145 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006146 public void getCallForwarding(int subId, int callForwardingReason,
6147 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006148 enforceReadPrivilegedPermission("getCallForwarding");
6149 long identity = Binder.clearCallingIdentity();
6150 try {
6151 if (DBG) {
6152 log("getCallForwarding: subId " + subId
6153 + " callForwardingReason" + callForwardingReason);
6154 }
Hall Liu27d24262020-09-18 19:04:59 -07006155
6156 Phone phone = getPhone(subId);
6157 if (phone == null) {
6158 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006159 callback.onError(
6160 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006161 } catch (RemoteException e) {
6162 // ignore
6163 }
6164 return;
6165 }
6166
6167 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6168 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6169 @Override
6170 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6171 try {
6172 callback.onCallForwardingInfoAvailable(info);
6173 } catch (RemoteException e) {
6174 // ignore
6175 }
6176 }
6177
6178 @Override
6179 public void onError(int error) {
6180 try {
6181 callback.onError(error);
6182 } catch (RemoteException e) {
6183 // ignore
6184 }
6185 }
6186 });
6187 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006188 } finally {
6189 Binder.restoreCallingIdentity(identity);
6190 }
6191 }
6192
6193 /**
6194 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6195 * reason, the number to forward, and the timeout before the forwarding is attempted.
6196 */
6197 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006198 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6199 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006200 enforceModifyPermission();
6201 long identity = Binder.clearCallingIdentity();
6202 try {
6203 if (DBG) {
6204 log("setCallForwarding: subId " + subId
6205 + " callForwardingInfo" + callForwardingInfo);
6206 }
Hall Liu27d24262020-09-18 19:04:59 -07006207
6208 Phone phone = getPhone(subId);
6209 if (phone == null) {
6210 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006211 callback.accept(
6212 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006213 } catch (RemoteException e) {
6214 // ignore
6215 }
6216 return;
6217 }
6218
6219 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6220 FunctionalUtils.ignoreRemoteException(callback::accept));
6221
6222 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006223 } finally {
6224 Binder.restoreCallingIdentity(identity);
6225 }
6226 }
6227
6228 /**
Hall Liu27d24262020-09-18 19:04:59 -07006229 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006230 */
6231 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006232 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006233 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006234 long identity = Binder.clearCallingIdentity();
6235 try {
Hall Liu27d24262020-09-18 19:04:59 -07006236 Phone phone = getPhone(subId);
6237 if (phone == null) {
6238 try {
6239 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6240 } catch (RemoteException e) {
6241 // ignore
6242 }
6243 return;
6244 }
SongFerngWang0e767992021-03-31 22:08:45 +08006245 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6246 PersistableBundle c = configManager.getConfigForSubId(subId);
6247 boolean requireUssd = c.getBoolean(
6248 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006249
Shuo Qian4a594052020-01-23 11:59:30 -08006250 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006251 if (requireUssd) {
6252 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6253 getSubscriptionCarrierId(subId));
6254 String newUssdCommand = "";
6255 try {
6256 newUssdCommand = carrierXmlParser.getFeature(
6257 CarrierXmlParser.FEATURE_CALL_WAITING)
6258 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6259 } catch (NullPointerException e) {
6260 loge("Failed to generate USSD number" + e);
6261 }
6262 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6263 mMainThreadHandler, callback, carrierXmlParser,
6264 CarrierXmlParser.SsEntry.SSAction.QUERY);
6265 final String ussdCommand = newUssdCommand;
6266 Executors.newSingleThreadExecutor().execute(() -> {
6267 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6268 });
6269 } else {
6270 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6271 callback::accept);
6272 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6273 }
Shuo Qian4a594052020-01-23 11:59:30 -08006274 } finally {
6275 Binder.restoreCallingIdentity(identity);
6276 }
6277 }
6278
6279 /**
Hall Liu27d24262020-09-18 19:04:59 -07006280 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006281 */
6282 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006283 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006284 enforceModifyPermission();
6285 long identity = Binder.clearCallingIdentity();
6286 try {
Hall Liu27d24262020-09-18 19:04:59 -07006287 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6288
6289 Phone phone = getPhone(subId);
6290 if (phone == null) {
6291 try {
6292 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6293 } catch (RemoteException e) {
6294 // ignore
6295 }
6296 return;
6297 }
6298
SongFerngWang0e767992021-03-31 22:08:45 +08006299 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6300 PersistableBundle c = configManager.getConfigForSubId(subId);
6301 boolean requireUssd = c.getBoolean(
6302 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006303
SongFerngWang0e767992021-03-31 22:08:45 +08006304 if (DBG) log("getCallWaitingStatus: subId " + subId);
6305 if (requireUssd) {
6306 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6307 getSubscriptionCarrierId(subId));
6308 CarrierXmlParser.SsEntry.SSAction ssAction =
6309 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6310 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6311 String newUssdCommand = "";
6312 try {
6313 newUssdCommand = carrierXmlParser.getFeature(
6314 CarrierXmlParser.FEATURE_CALL_WAITING)
6315 .makeCommand(ssAction, null);
6316 } catch (NullPointerException e) {
6317 loge("Failed to generate USSD number" + e);
6318 }
6319 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6320 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6321 final String ussdCommand = newUssdCommand;
6322 Executors.newSingleThreadExecutor().execute(() -> {
6323 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6324 });
6325 } else {
6326 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6327 FunctionalUtils.ignoreRemoteException(callback::accept));
6328
6329 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6330 }
Shuo Qian4a594052020-01-23 11:59:30 -08006331 } finally {
6332 Binder.restoreCallingIdentity(identity);
6333 }
6334 }
6335
6336 /**
yinxub1bed742017-04-17 11:45:04 -07006337 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006338 *
yinxub1bed742017-04-17 11:45:04 -07006339 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006340 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6341 * location related information which will be sent if the caller already possess
6342 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006343 * @param request contains the radio access networks with bands/channels to scan
6344 * @param messenger callback messenger for scan results or errors
6345 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006346 * @return the id of the requested scan which can be used to stop the scan.
6347 */
6348 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006349 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6350 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006351 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6353 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006354 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006355 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6356 if (!renounceFineLocationAccess) {
6357 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6358 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6359 .setCallingPackage(callingPackage)
6360 .setCallingFeatureId(callingFeatureId)
6361 .setCallingPid(Binder.getCallingPid())
6362 .setCallingUid(Binder.getCallingUid())
6363 .setMethod("requestNetworkScan")
6364 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6365 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6366 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6367 .build());
6368 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006369 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006370 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6371 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006372 if (e != null) {
6373 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6374 throw e;
6375 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006376 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006377 return TelephonyScanManager.INVALID_SCAN_ID;
6378 }
6379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 }
Hall Liu912dfd32019-04-25 14:02:26 -07006381 int callingUid = Binder.getCallingUid();
6382 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006383 final long identity = Binder.clearCallingIdentity();
6384 try {
6385 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006386 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006387 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
yinxu504e1392017-04-12 16:03:22 -07006391 }
6392
Hall Liub2ac8ef2019-02-28 15:56:23 -08006393 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006394 NetworkScanRequest request, int subId, String callingPackage) {
6395 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006396 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6397 boolean hasNetworkScanPermission =
6398 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6399 == PERMISSION_GRANTED;
6400
6401 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6402 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6403 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006404 }
6405
6406 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6407 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006408 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6409 return new SecurityException("Specific channels must not be"
6410 + " scanned without location access.");
6411 }
6412 }
6413 }
6414
Hall Liub2ac8ef2019-02-28 15:56:23 -08006415 return null;
6416 }
6417
yinxu504e1392017-04-12 16:03:22 -07006418 /**
6419 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006420 *
6421 * @param subId id of the subscription
6422 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006423 */
6424 @Override
6425 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6427 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428
Hall Liu912dfd32019-04-25 14:02:26 -07006429 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006430 final long identity = Binder.clearCallingIdentity();
6431 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006432 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
yinxu504e1392017-04-12 16:03:22 -07006436 }
6437
6438 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006439 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006440 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006441 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006442 */
6443 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006444 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006445 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006446 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006447 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448
6449 final long identity = Binder.clearCallingIdentity();
6450 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006451 if (DBG) log("getAllowedNetworkTypesBitmask");
6452 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6453 int networkTypesBitmask = (result != null ? result[0] : -1);
6454 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6455 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006459 }
6460
6461 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006462 * Get the allowed network types for certain reason.
6463 *
6464 * @param subId the id of the subscription.
6465 * @param reason the reason the allowed network type change is taking place
6466 * @return the allowed network types.
6467 */
6468 @Override
6469 public long getAllowedNetworkTypesForReason(int subId,
6470 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006471 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006472 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006473 final long identity = Binder.clearCallingIdentity();
6474 try {
6475 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6476 } finally {
6477 Binder.restoreCallingIdentity(identity);
6478 }
6479 }
6480
6481 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006482 * Enable/Disable E-UTRA-NR Dual Connectivity
6483 * @param subId subscription id of the sim card
6484 * @param nrDualConnectivityState expected NR dual connectivity state
6485 * This can be passed following states
6486 * <ol>
6487 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6488 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6489 * <li>Disable NR dual connectivity and force secondary cell to be released
6490 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6491 * </ol>
6492 * @return operation result.
6493 */
6494 @Override
6495 public int setNrDualConnectivityState(int subId,
6496 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6498 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006499 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006500 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6501 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6502 }
6503
Sooraj Sasindran37444802020-08-11 10:40:43 -07006504 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6508 nrDualConnectivityState, subId,
6509 workSource);
6510 if (DBG) log("enableNRDualConnectivity result: " + result);
6511 return result;
6512 } finally {
6513 Binder.restoreCallingIdentity(identity);
6514 }
6515 }
6516
6517 /**
6518 * Is E-UTRA-NR Dual Connectivity enabled
6519 * @return true if dual connectivity is enabled else false
6520 */
6521 @Override
6522 public boolean isNrDualConnectivityEnabled(int subId) {
6523 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006524 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006525 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006526 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006527 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6528 return false;
6529 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006530 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6531 final long identity = Binder.clearCallingIdentity();
6532 try {
6533 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6534 null, subId, workSource);
6535 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6536 return isEnabled;
6537 } finally {
6538 Binder.restoreCallingIdentity(identity);
6539 }
6540 }
6541
6542 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006543 * Set the allowed network types of the device and
6544 * provide the reason triggering the allowed network change.
6545 *
6546 * @param subId the id of the subscription.
6547 * @param reason the reason the allowed network type change is taking place
6548 * @param allowedNetworkTypes the allowed network types.
6549 * @return true on success; false on any failure.
6550 */
6551 @Override
6552 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 @TelephonyManager.AllowedNetworkTypesReason int reason,
6554 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6556 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006558 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6559 return false;
6560 }
6561 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6562 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006563 return false;
6564 }
6565
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006566 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6567 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6568
6569
6570 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6571 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6572 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006573 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006574
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006575 final long identity = Binder.clearCallingIdentity();
6576 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006577 Boolean success = (Boolean) sendRequest(
6578 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6579 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6580
6581 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6582 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006583 } finally {
6584 Binder.restoreCallingIdentity(identity);
6585 }
6586 }
6587
6588 /**
Miaoa84611c2019-03-15 09:21:10 +08006589 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006590 *
Miaoa84611c2019-03-15 09:21:10 +08006591 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006592 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006593 * @hide
6594 */
6595 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006596 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006597 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006599 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600 try {
Miaoa84611c2019-03-15 09:21:10 +08006601 if (phone != null) {
6602 return phone.hasMatchedTetherApnSetting();
6603 } else {
6604 return false;
6605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606 } finally {
6607 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006608 }
Junda Liu475951f2014-11-07 16:45:03 -08006609 }
6610
6611 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006612 * Get the user enabled state of Mobile Data.
6613 *
6614 * TODO: remove and use isUserDataEnabled.
6615 * This can't be removed now because some vendor codes
6616 * calls through ITelephony directly while they should
6617 * use TelephonyManager.
6618 *
6619 * @return true on enabled
6620 */
6621 @Override
6622 public boolean getDataEnabled(int subId) {
6623 return isUserDataEnabled(subId);
6624 }
6625
6626 /**
6627 * Get whether mobile data is enabled per user setting.
6628 *
6629 * There are other factors deciding whether mobile data is actually enabled, but they are
6630 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006631 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006632 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6633 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006634 *
6635 * @return {@code true} if data is enabled else {@code false}
6636 */
6637 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006638 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006639 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006640 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006641 try {
6642 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6643 functionName);
6644 } catch (Exception e) {
6645 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6646 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006647 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006649 mApp, subId, functionName);
6650
Robert Greenwalt646120a2014-05-23 11:54:03 -07006651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652
6653 final long identity = Binder.clearCallingIdentity();
6654 try {
6655 int phoneId = mSubscriptionController.getPhoneId(subId);
6656 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6657 Phone phone = PhoneFactory.getPhone(phoneId);
6658 if (phone != null) {
6659 boolean retVal = phone.isUserDataEnabled();
6660 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6661 return retVal;
6662 } else {
6663 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6664 return false;
6665 }
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006668 }
6669 }
6670
6671 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006672 * Checks if the device is capable of mobile data by considering whether whether the
6673 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6674 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006675 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006676 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006677 */
6678 @Override
6679 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006680 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006681 try {
6682 try {
6683 mApp.enforceCallingOrSelfPermission(
6684 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006685 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006686 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006687 try {
6688 mApp.enforceCallingOrSelfPermission(
6689 android.Manifest.permission.READ_PHONE_STATE,
6690 functionName);
6691 } catch (Exception e2) {
6692 mApp.enforceCallingOrSelfPermission(
6693 permission.READ_BASIC_PHONE_STATE, functionName);
6694 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006695 }
6696 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006697 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699
6700 final long identity = Binder.clearCallingIdentity();
6701 try {
6702 int phoneId = mSubscriptionController.getPhoneId(subId);
6703 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6704 Phone phone = PhoneFactory.getPhone(phoneId);
6705 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006706 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6708 return retVal;
6709 } else {
6710 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6711 return false;
6712 }
6713 } finally {
6714 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006715 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006716 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006717
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006718 /**
6719 * Check if data is enabled for a specific reason
6720 * @param subId Subscription index
6721 * @param reason the reason the data enable change is taking place
6722 * @return {@code true} if the overall data is enabled; {@code false} if not.
6723 */
6724 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006725 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006726 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006727 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006728 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006729 try {
6730 mApp.enforceCallingOrSelfPermission(
6731 android.Manifest.permission.ACCESS_NETWORK_STATE,
6732 functionName);
6733 } catch (Exception e) {
6734 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6735 functionName);
6736 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006737 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006738 try {
6739 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006740 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006741 } catch (Exception e2) {
6742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006743 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006744 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006745 }
6746
6747
6748 final long identity = Binder.clearCallingIdentity();
6749 try {
6750 int phoneId = mSubscriptionController.getPhoneId(subId);
6751 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006752 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006753 + " reason=" + reason);
6754 }
6755 Phone phone = PhoneFactory.getPhone(phoneId);
6756 if (phone != null) {
6757 boolean retVal;
6758 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6759 retVal = phone.isUserDataEnabled();
6760 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006761 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006762 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006763 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006764 return retVal;
6765 } else {
6766 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006767 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006768 + subId + " retVal=false");
6769 }
6770 return false;
6771 }
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
6774 }
6775 }
6776
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006777 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006778 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006779 if (uid == Process.PHONE_UID) {
6780 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6781 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006782 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6783 }
6784
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006785 //load access rules from carrier configs, and check those as well: b/139133814
6786 SubscriptionController subController = SubscriptionController.getInstance();
6787 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6788 || subController == null) return privilegeFromSim;
6789
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006790 PackageManager pkgMgr = phone.getContext().getPackageManager();
6791 String[] packages = pkgMgr.getPackagesForUid(uid);
6792
6793 final long identity = Binder.clearCallingIdentity();
6794 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006795 int subId = phone.getSubId();
6796 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6797 // A test override is in place for the privileges for this subId, so don't try to
6798 // read the subscription privileges.
6799 return privilegeFromSim;
6800 }
6801 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006802 SubscriptionManager subManager = (SubscriptionManager)
6803 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6804 for (String pkg : packages) {
6805 if (subManager.canManageSubscription(subInfo, pkg)) {
6806 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6807 }
6808 }
6809 return privilegeFromSim;
6810 } finally {
6811 Binder.restoreCallingIdentity(identity);
6812 }
6813 }
6814
6815 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6816 String pkgName) {
6817 //load access rules from carrier configs, and check those as well: b/139133814
6818 SubscriptionController subController = SubscriptionController.getInstance();
6819 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6820 || subController == null) return privilegeFromSim;
6821
6822 final long identity = Binder.clearCallingIdentity();
6823 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006824 int subId = phone.getSubId();
6825 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6826 // A test override is in place for the privileges for this subId, so don't try to
6827 // read the subscription privileges.
6828 return privilegeFromSim;
6829 }
6830 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006831 SubscriptionManager subManager = (SubscriptionManager)
6832 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6833 return subManager.canManageSubscription(subInfo, pkgName)
6834 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6835 } finally {
6836 Binder.restoreCallingIdentity(identity);
6837 }
6838 }
6839
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006840 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006841 public int getCarrierPrivilegeStatus(int subId) {
6842 final Phone phone = getPhone(subId);
6843 if (phone == null) {
6844 loge("getCarrierPrivilegeStatus: Invalid subId");
6845 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6846 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006847 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6848 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006849 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6851 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006852
6853 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006854 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006855 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006856 }
Junda Liu29340342014-07-10 15:23:27 -07006857
6858 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006859 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006860 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006861 final Phone phone = getPhone(subId);
6862 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006863 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006864 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6865 }
6866 UiccProfile profile =
6867 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6868 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006869 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006870 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6871 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006872 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006873 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006874 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006875 }
6876
6877 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006878 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006879 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006880 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006881 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006882 }
6883
6884 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006885 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6886 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006887 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006888 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6889 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006890 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006891 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006892 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006893 }
6894
6895 @Override
6896 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006897 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006898 if (TextUtils.isEmpty(pkgName))
6899 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006900 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6901 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006902 UiccPort port = UiccController.getInstance().getUiccPort(i);
6903 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006904 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006905 continue;
6906 }
6907
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006908 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006909 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006910 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006911 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6912 break;
6913 }
6914 }
6915
6916 return result;
Junda Liu29340342014-07-10 15:23:27 -07006917 }
Derek Tan89e89d42014-07-08 17:00:10 -07006918
6919 @Override
Junda Liue64de782015-04-16 17:19:16 -07006920 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006921 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006922 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6923 loge("phoneId " + phoneId + " is not valid.");
6924 return null;
6925 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006926 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6927 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006928 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006929 return null ;
6930 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006931 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006932 }
6933
Amith Yamasani6e118872016-02-19 12:53:51 -08006934 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006935 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006936 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006937 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006938 List<String> privilegedPackages = new ArrayList<>();
6939 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006940 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006941 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006942 if (port != null) {
6943 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006944 if (packages == null) {
6945 // Only check packages in user 0 for now
6946 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006947 PackageManager.MATCH_DISABLED_COMPONENTS
6948 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006949 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006950 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006951 }
6952 for (int p = packages.size() - 1; p >= 0; p--) {
6953 PackageInfo pkgInfo = packages.get(p);
6954 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006955 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006956 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006957 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006958 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006959 privilegedPackages.add(pkgInfo.packageName);
6960 }
6961 }
6962 }
6963 }
6964 return privilegedPackages;
6965 }
6966
chen xuf7e9fe82019-05-09 19:31:02 -07006967 @Override
6968 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006969 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6970
6971 final long identity = Binder.clearCallingIdentity();
6972
chen xuf7e9fe82019-05-09 19:31:02 -07006973 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006974 try {
6975 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6976 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6977 }
6978 } finally {
6979 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006980 }
6981 return privilegedPackages;
6982 }
6983
Wink Savilleb564aae2014-10-23 10:18:09 -07006984 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006985 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006986 UiccPort port = phone == null ? null : phone.getUiccPort();
6987 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006988 return null;
6989 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006990 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006991 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006992 return null;
6993 }
6994 return iccId;
6995 }
6996
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006997 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006998 public void setCallComposerStatus(int subId, int status) {
6999 enforceModifyPermission();
7000
7001 final long identity = Binder.clearCallingIdentity();
7002 try {
7003 Phone phone = getPhone(subId);
7004 if (phone != null) {
7005 Phone defaultPhone = phone.getImsPhone();
7006 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7007 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7008 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007009 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7010 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007011 }
7012 }
Shuo Qian284ae752020-12-22 19:10:14 -08007013 } catch (ImsException e) {
7014 throw new ServiceSpecificException(e.getCode());
7015 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007016 Binder.restoreCallingIdentity(identity);
7017 }
7018 }
7019
7020 @Override
7021 public int getCallComposerStatus(int subId) {
7022 enforceReadPrivilegedPermission("getCallComposerStatus");
7023
7024 final long identity = Binder.clearCallingIdentity();
7025 try {
7026 Phone phone = getPhone(subId);
7027 if (phone != null) {
7028 Phone defaultPhone = phone.getImsPhone();
7029 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7030 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7031 return imsPhone.getCallComposerStatus();
7032 }
7033 }
7034 } finally {
7035 Binder.restoreCallingIdentity(identity);
7036 }
7037 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7038 }
7039
7040 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007041 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7042 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007043 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007044 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 final long identity = Binder.clearCallingIdentity();
7047 try {
7048 final String iccId = getIccId(subId);
7049 final Phone phone = getPhone(subId);
7050 if (phone == null) {
7051 return false;
7052 }
7053 final String subscriberId = phone.getSubscriberId();
7054
7055 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007056 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 + subscriberId + " to " + number);
7058 }
7059
7060 if (TextUtils.isEmpty(iccId)) {
7061 return false;
7062 }
7063
7064 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7065
7066 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7067 if (alphaTag == null) {
7068 editor.remove(alphaTagPrefKey);
7069 } else {
7070 editor.putString(alphaTagPrefKey, alphaTag);
7071 }
7072
7073 // Record both the line number and IMSI for this ICCID, since we need to
7074 // track all merged IMSIs based on line number
7075 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7076 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7077 if (number == null) {
7078 editor.remove(numberPrefKey);
7079 editor.remove(subscriberPrefKey);
7080 } else {
7081 editor.putString(numberPrefKey, number);
7082 editor.putString(subscriberPrefKey, subscriberId);
7083 }
7084
7085 editor.commit();
7086 return true;
7087 } finally {
7088 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007089 }
Derek Tan7226c842014-07-02 17:42:23 -07007090 }
7091
7092 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007093 public String getLine1NumberForDisplay(int subId, String callingPackage,
7094 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007095 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007096 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007097 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007098 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007099 return null;
7100 }
Derek Tan97ebb422014-09-05 16:55:38 -07007101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 final long identity = Binder.clearCallingIdentity();
7103 try {
7104 String iccId = getIccId(subId);
7105 if (iccId != null) {
7106 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7107 if (DBG_MERGE) {
7108 log("getLine1NumberForDisplay returning "
7109 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7110 }
7111 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7114 return null;
7115 } finally {
7116 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007117 }
Derek Tan7226c842014-07-02 17:42:23 -07007118 }
7119
7120 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007121 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7122 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007124 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007125 return null;
7126 }
Derek Tan97ebb422014-09-05 16:55:38 -07007127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 final long identity = Binder.clearCallingIdentity();
7129 try {
7130 String iccId = getIccId(subId);
7131 if (iccId != null) {
7132 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7133 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7134 }
7135 return null;
7136 } finally {
7137 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007138 }
Derek Tan7226c842014-07-02 17:42:23 -07007139 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007140
7141 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007142 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7143 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007144 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7145 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007146 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007147 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007148 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007149 return null;
7150 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007151
Jordan Liub49b04b2019-05-06 14:45:15 -07007152 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7153 // the process, where TelephonyManager was instantiated.
7154 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007155 final long identity = Binder.clearCallingIdentity();
7156 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007157 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 final TelephonyManager tele = TelephonyManager.from(context);
7159 final SubscriptionManager sub = SubscriptionManager.from(context);
7160
7161 // Figure out what subscribers are currently active
7162 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163
Jordan Liub49b04b2019-05-06 14:45:15 -07007164 // Only consider subs which match the current subId
7165 // This logic can be simplified. See b/131189269 for progress.
7166 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007167 activeSubscriberIds.add(tele.getSubscriberId(subId));
7168 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169
7170 // First pass, find a number override for an active subscriber
7171 String mergeNumber = null;
7172 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7173 for (String key : prefs.keySet()) {
7174 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7175 final String subscriberId = (String) prefs.get(key);
7176 if (activeSubscriberIds.contains(subscriberId)) {
7177 final String iccId = key.substring(
7178 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7179 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7180 mergeNumber = (String) prefs.get(numberKey);
7181 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007182 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183 + " for active subscriber " + subscriberId);
7184 }
7185 if (!TextUtils.isEmpty(mergeNumber)) {
7186 break;
7187 }
7188 }
7189 }
7190 }
7191
7192 // Shortcut when no active merged subscribers
7193 if (TextUtils.isEmpty(mergeNumber)) {
7194 return null;
7195 }
7196
7197 // Second pass, find all subscribers under that line override
7198 final ArraySet<String> result = new ArraySet<>();
7199 for (String key : prefs.keySet()) {
7200 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7201 final String number = (String) prefs.get(key);
7202 if (mergeNumber.equals(number)) {
7203 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7204 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7205 final String subscriberId = (String) prefs.get(subscriberKey);
7206 if (!TextUtils.isEmpty(subscriberId)) {
7207 result.add(subscriberId);
7208 }
7209 }
7210 }
7211 }
7212
7213 final String[] resultArray = result.toArray(new String[result.size()]);
7214 Arrays.sort(resultArray);
7215 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007216 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7218 }
7219 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007220 } finally {
7221 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007222 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007223 }
7224
7225 @Override
zoey chen38003472019-12-13 17:16:31 +08007226 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7227 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007228
7229 final long identity = Binder.clearCallingIdentity();
7230 try {
7231 final TelephonyManager telephonyManager = mApp.getSystemService(
7232 TelephonyManager.class);
7233 String subscriberId = telephonyManager.getSubscriberId(subId);
7234 if (subscriberId == null) {
7235 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007236 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007237 + subId);
7238 }
7239 return null;
7240 }
7241
7242 final SubscriptionInfo info = SubscriptionController.getInstance()
7243 .getSubscriptionInfo(subId);
7244 final ParcelUuid groupUuid = info.getGroupUuid();
7245 // If it doesn't belong to any group, return just subscriberId of itself.
7246 if (groupUuid == null) {
7247 return new String[]{subscriberId};
7248 }
7249
7250 // Get all subscriberIds from the group.
7251 final List<String> mergedSubscriberIds = new ArrayList<>();
7252 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007253 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007254 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007255 for (SubscriptionInfo subInfo : groupInfos) {
7256 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7257 if (subscriberId != null) {
7258 mergedSubscriberIds.add(subscriberId);
7259 }
7260 }
7261
7262 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7263 } finally {
7264 Binder.restoreCallingIdentity(identity);
7265
7266 }
7267 }
7268
7269 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007270 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007271 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007272 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007273
7274 final long identity = Binder.clearCallingIdentity();
7275 try {
7276 final Phone phone = getPhone(subId);
7277 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007281 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007282
7283 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007284 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007285 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7286 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007287 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7288 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007289
7290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 final Phone phone = getPhone(subId);
7293 if (phone == null) {
7294 return false;
7295 }
7296 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7297 cdmaNonRoamingList);
7298 } finally {
7299 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007300 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007301 }
7302
7303 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007304 @Deprecated
7305 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7306 enforceModifyPermission();
7307
7308 int returnValue = 0;
7309 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007310 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007311 if(result.exception == null) {
7312 if (result.result != null) {
7313 byte[] responseData = (byte[])(result.result);
7314 if(responseData.length > oemResp.length) {
7315 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7316 responseData.length + "bytes. Buffer Size is " +
7317 oemResp.length + "bytes.");
7318 }
7319 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7320 returnValue = responseData.length;
7321 }
7322 } else {
7323 CommandException ex = (CommandException) result.exception;
7324 returnValue = ex.getCommandError().ordinal();
7325 if(returnValue > 0) returnValue *= -1;
7326 }
7327 } catch (RuntimeException e) {
7328 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7329 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7330 if(returnValue > 0) returnValue *= -1;
7331 }
7332
7333 return returnValue;
7334 }
7335
7336 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007337 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007338 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007339 try {
7340 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007341 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007342 mApp, phone.getSubId(), "getRadioAccessFamily");
7343 } catch (SecurityException e) {
7344 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7345 throw e;
7346 }
chen xub97461a2018-10-26 14:17:57 -07007347 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007348 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007349 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 final long identity = Binder.clearCallingIdentity();
7352 try {
chen xub97461a2018-10-26 14:17:57 -07007353 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007354 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007355 mApp, phone.getSubId(), "getRadioAccessFamily");
7356 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357 } finally {
7358 Binder.restoreCallingIdentity(identity);
7359 }
chen xub97461a2018-10-26 14:17:57 -07007360 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007361 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007362
7363 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007364 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007365 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007366 try {
7367 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7368 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007369 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007370 }
7371 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007372 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007373 }
7374 RoleManager rm = mApp.getSystemService(RoleManager.class);
7375 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7376 if (!dialerRoleHolders.contains(callingPackage)) {
7377 throw new SecurityException("App must be the dialer role holder to"
7378 + " upload a call composer pic");
7379 }
7380
7381 Executors.newSingleThreadExecutor().execute(() -> {
7382 ByteArrayOutputStream output = new ByteArrayOutputStream(
7383 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7384 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7385 boolean readUntilEnd = false;
7386 int totalBytesRead = 0;
7387 byte[] buffer = new byte[16 * 1024];
7388 while (true) {
7389 int numRead;
7390 try {
7391 numRead = input.read(buffer);
7392 } catch (IOException e) {
7393 try {
7394 fd.checkError();
7395 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7396 null);
7397 } catch (IOException e1) {
7398 // This means that the other side closed explicitly with an error. If this
7399 // happens, log and ignore.
7400 loge("Remote end of call composer picture pipe closed: " + e1);
7401 }
7402 break;
7403 }
7404 if (numRead == -1) {
7405 readUntilEnd = true;
7406 break;
7407 }
7408 totalBytesRead += numRead;
7409 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7410 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7411 try {
7412 input.close();
7413 } catch (IOException e) {
7414 // ignore
7415 }
7416 break;
7417 }
7418 output.write(buffer, 0, numRead);
7419 }
7420 // Generally, the remote end will close the file descriptors. The only case where we
7421 // close is above, where the picture size is too big.
7422
7423 try {
7424 fd.checkError();
7425 } catch (IOException e) {
7426 loge("Remote end for call composer closed with an error: " + e);
7427 return;
7428 }
7429
Hall Liuaa4211e2021-01-20 15:43:39 -08007430 if (!readUntilEnd) {
7431 loge("Did not finish reading entire image; aborting");
7432 return;
7433 }
Hall Liu82694d52020-12-11 18:22:04 -08007434
Hall Liuaa4211e2021-01-20 15:43:39 -08007435 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7436 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7437 new CallComposerPictureTransfer.Factory() {},
7438 imageData,
7439 (result) -> {
7440 if (result.first != null) {
7441 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7442 Bundle outputResult = new Bundle();
7443 outputResult.putParcelable(
7444 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7445 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7446 outputResult);
7447 } else {
7448 callback.send(result.second, null);
7449 }
7450 }
7451 );
Hall Liu82694d52020-12-11 18:22:04 -08007452 });
7453 }
7454
7455 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007456 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007457 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007458 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459
7460 final long identity = Binder.clearCallingIdentity();
7461 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007462 ImsManager.getInstance(defaultPhone.getContext(),
7463 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007467 }
7468
7469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007470 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007471 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7473 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007474 return false;
7475 }
Svet Ganovb320e182015-04-16 12:30:10 -07007476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 final long identity = Binder.clearCallingIdentity();
7478 try {
7479 // Check the user preference and the system-level IMS setting. Even if the user has
7480 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7481 // In the long run, we may instead need to check if there exists a connection service
7482 // which can support video calling.
7483 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007484 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 return imsManager.isVtEnabledByPlatform()
7486 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7487 && imsManager.isVtEnabledByUser();
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007491 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007492
Andrew Leea1239f22015-03-02 17:44:07 -08007493 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007494 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7495 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007497 mApp, subId, callingPackage, callingFeatureId,
7498 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 return false;
7500 }
7501
7502 final long identity = Binder.clearCallingIdentity();
7503 try {
7504 CarrierConfigManager configManager =
7505 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007506 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
Andrew Leea1239f22015-03-02 17:44:07 -08007511 }
7512
7513 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007514 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007516 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 return false;
7518 }
7519
7520 final long identity = Binder.clearCallingIdentity();
7521 try {
7522 CarrierConfigManager configManager =
7523 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007524 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7526 } finally {
7527 Binder.restoreCallingIdentity(identity);
7528 }
Andrew Leea1239f22015-03-02 17:44:07 -08007529 }
7530
Andrew Lee9431b832015-03-09 18:46:45 -07007531 @Override
7532 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007533 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007534 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007535 }
7536
7537 @Override
7538 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 final long identity = Binder.clearCallingIdentity();
7540 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007541 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 } finally {
7543 Binder.restoreCallingIdentity(identity);
7544 }
Andrew Lee9431b832015-03-09 18:46:45 -07007545 }
7546
Hall Liuf6668912018-10-31 17:05:23 -07007547 /**
7548 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7549 * support for the feature and device firmware support.
7550 *
7551 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7552 */
7553 @Override
7554 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007556 final Phone phone = getPhone(subscriptionId);
7557 if (phone == null) {
7558 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7559 return false;
7560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007562 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7564 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007565 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 return isCarrierSupported && isDeviceSupported;
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
Hall Liu98187582018-01-22 19:15:32 -08007570 }
7571
Hall Liuf6668912018-10-31 17:05:23 -07007572 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007573 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7574 * RTT setting, will return true if the device and carrier both support RTT.
7575 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007576 */
7577 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007578 final long identity = Binder.clearCallingIdentity();
7579 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007580 boolean isRttSupported = isRttSupported(subscriptionId);
7581 boolean isUserRttSettingOn = Settings.Secure.getInt(
7582 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7583 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7584 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7585 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007586 } finally {
7587 Binder.restoreCallingIdentity(identity);
7588 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007589 }
7590
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007591 @Deprecated
7592 @Override
7593 public String getDeviceId(String callingPackage) {
7594 return getDeviceIdWithFeature(callingPackage, null);
7595 }
7596
Sanket Padawe7310cc72015-01-14 09:53:20 -08007597 /**
7598 * Returns the unique device ID of phone, for example, the IMEI for
7599 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7600 *
7601 * <p>Requires Permission:
7602 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7603 */
7604 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007605 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007606 try {
7607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7608 } catch (SecurityException se) {
7609 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7610 throw new SecurityException("Package " + callingPackage + " does not belong to "
7611 + Binder.getCallingUid());
7612 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007613 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007614 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007615 return null;
7616 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007617 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007618 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007619 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007620 return null;
7621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622
7623 final long identity = Binder.clearCallingIdentity();
7624 try {
7625 return phone.getDeviceId();
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
7628 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007629 }
7630
Ping Sunc67b7c22016-03-02 19:16:45 +08007631 /**
7632 * {@hide}
7633 * Returns the IMS Registration Status on a particular subid
7634 *
7635 * @param subId
7636 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007637 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007638 Phone phone = getPhone(subId);
7639 if (phone != null) {
7640 return phone.isImsRegistered();
7641 } else {
7642 return false;
7643 }
7644 }
7645
Santos Cordon7a1885b2015-02-03 11:15:19 -08007646 @Override
7647 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
7653 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007654 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007655
Tyler Gunnf70ed162019-04-03 15:28:53 -07007656 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007657 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007658 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007660 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007661 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7662 }
7663 final long identity = Binder.clearCallingIdentity();
7664 try {
7665 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7666 } finally {
7667 Binder.restoreCallingIdentity(identity);
7668 }
7669 }
7670
7671 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007672 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007673 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007674 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007675 mApp,
7676 subscriptionId,
7677 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007678 final long identity = Binder.clearCallingIdentity();
7679 try {
7680 Phone phone = getPhone(subscriptionId);
7681 if (phone == null) {
7682 return null;
7683 }
7684 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7685 } finally {
7686 Binder.restoreCallingIdentity(identity);
7687 }
7688 }
7689
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007690 /**
7691 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007692 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007693 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 final long identity = Binder.clearCallingIdentity();
7695 try {
7696 Phone phone = getPhone(subId);
7697 if (phone != null) {
7698 return phone.isWifiCallingEnabled();
7699 } else {
7700 return false;
7701 }
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007704 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007705 }
7706
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007707 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007708 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007709 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007710 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 final long identity = Binder.clearCallingIdentity();
7712 try {
7713 Phone phone = getPhone(subId);
7714 if (phone != null) {
7715 return phone.isVideoEnabled();
7716 } else {
7717 return false;
7718 }
7719 } finally {
7720 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007721 }
7722 }
7723
7724 /**
7725 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7726 * defined in {@link ImsRegistrationImplBase}.
7727 */
7728 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729 final long identity = Binder.clearCallingIdentity();
7730 try {
7731 Phone phone = getPhone(subId);
7732 if (phone != null) {
7733 return phone.getImsRegistrationTech();
7734 } else {
7735 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7736 }
7737 } finally {
7738 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007739 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007740 }
7741
Stuart Scott8eef64f2015-04-08 15:13:54 -07007742 @Override
7743 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007744 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007745 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7746 return;
7747 }
Kai Shif70f46f2021-03-03 13:59:46 -08007748 Phone defaultPhone = getDefaultPhone();
7749 if (defaultPhone != null) {
7750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7751 mApp, getDefaultPhone().getSubId(), "factoryReset");
7752 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007753 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007754
Svet Ganovcc087f82015-05-12 20:35:54 -07007755 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007756 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7757 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007758 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007759 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007760 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007761 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007762 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007763 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007764 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007765 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007766 // There has been issues when Sms raw table somehow stores orphan
7767 // fragments. They lead to garbled message when new fragments come
7768 // in and combined with those stale ones. In case this happens again,
7769 // user can reset all network settings which will clean up this table.
7770 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007771 // Clean up IMS settings as well here.
7772 int slotId = getSlotIndex(subId);
7773 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7774 ImsManager.getInstance(mApp, slotId).factoryReset();
7775 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007776
Kai Shif70f46f2021-03-03 13:59:46 -08007777 if (defaultPhone == null) {
7778 return;
7779 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007780 // Erase modem config if erase modem on network setting is enabled.
7781 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7782 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7783 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007784 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007785 }
Kai Shif70f46f2021-03-03 13:59:46 -08007786
7787 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007788 } finally {
7789 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007790 }
7791 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007792
SongFerngWangfd89b102021-05-27 22:44:54 +08007793 @VisibleForTesting
7794 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7795 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7796 return;
7797 }
7798 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7799 RILConstants.PREFERRED_NETWORK_MODE);
7800 SubscriptionManager.setSubscriptionProperty(subId,
7801 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7802 "user=" + defaultNetworkType);
7803 phone.loadAllowedNetworksFromSubscriptionDatabase();
7804 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7805 defaultNetworkType, null);
7806 }
7807
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007808 private void cleanUpSmsRawTable(Context context) {
7809 ContentResolver resolver = context.getContentResolver();
7810 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7811 resolver.delete(uri, null, null);
7812 }
7813
Narayan Kamath1c496c22015-04-16 14:40:19 +01007814 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007815 public String getSimLocaleForSubscriber(int subId) {
7816 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7817 final Phone phone = getPhone(subId);
7818 if (phone == null) {
7819 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007820 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 final long identity = Binder.clearCallingIdentity();
7823 try {
chen xu5d3637b2019-01-21 23:31:38 -08007824 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007825 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007826 if (info == null) {
7827 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7828 return null;
7829 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830 // Try and fetch the locale from the carrier properties or from the SIM language
7831 // preferences (EF-PL and EF-LI)...
7832 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007833 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007834 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7835 if (localeFromDefaultSim != null) {
7836 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7837 if (DBG) log("Using locale from subId: " + subId + " locale: "
7838 + localeFromDefaultSim);
7839 return localeFromDefaultSim.toLanguageTag();
7840 } else {
7841 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842 }
7843 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007844
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 // The SIM language preferences only store a language (e.g. fr = French), not an
7846 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7847 // the SIM and carrier preferences does not include a country we add the country
7848 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007849 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007851 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007852 return mccLocale.toLanguageTag();
7853 }
7854
7855 if (DBG) log("No locale found - returning null");
7856 return null;
7857 } finally {
7858 Binder.restoreCallingIdentity(identity);
7859 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007860 }
7861
7862 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007863 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007864 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007865 }
7866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867 /**
7868 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7869 */
7870 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007871 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007872 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007873 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007874
Chenjie Yu1ba97252018-01-11 18:16:20 -08007875 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007876 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007877
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007878 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007879 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7880 * representing the state of the modem.
7881 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007882 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7883 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007884 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007885 */
7886 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007887 public void requestModemActivityInfo(ResultReceiver result) {
7888 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007890
7891 final long identity = Binder.clearCallingIdentity();
7892 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007893 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007894 } finally {
7895 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007896 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007897 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007898
Siddharth Rayb8114062018-06-17 15:02:38 -07007899 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7900 // less than total activity duration.
7901 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7902 if (info == null) {
7903 return false;
7904 }
7905 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007906 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7907 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7908
Siddharth Rayb8114062018-06-17 15:02:38 -07007909 return (info.isValid()
7910 && (info.getSleepTimeMillis() <= activityDurationMs)
7911 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007912 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007913 && (totalTxTimeMs <= activityDurationMs));
7914 }
7915
Jack Yu85bd38a2015-11-09 11:34:32 -08007916 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007917 * Returns the service state information on specified subscription.
7918 */
7919 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007920 public ServiceState getServiceStateForSubscriber(int subId,
7921 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7922 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007924 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007925 return null;
7926 }
7927
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007928 boolean hasFinePermission = false;
7929 boolean hasCoarsePermission = false;
7930 if (!renounceFineLocationAccess) {
7931 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7932 LocationAccessPolicy.checkLocationPermission(mApp,
7933 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7934 .setCallingPackage(callingPackage)
7935 .setCallingFeatureId(callingFeatureId)
7936 .setCallingPid(Binder.getCallingPid())
7937 .setCallingUid(Binder.getCallingUid())
7938 .setMethod("getServiceStateForSubscriber")
7939 .setLogAsInfo(true)
7940 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7941 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7942 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7943 .build());
7944 hasFinePermission =
7945 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7946 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007947
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007948 if (!renounceCoarseLocationAccess) {
7949 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7950 LocationAccessPolicy.checkLocationPermission(mApp,
7951 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7952 .setCallingPackage(callingPackage)
7953 .setCallingFeatureId(callingFeatureId)
7954 .setCallingPid(Binder.getCallingPid())
7955 .setCallingUid(Binder.getCallingUid())
7956 .setMethod("getServiceStateForSubscriber")
7957 .setLogAsInfo(true)
7958 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7959 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7960 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7961 .build());
7962 hasCoarsePermission =
7963 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7964 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007965
Jack Yu479f40e2020-10-27 21:29:25 -07007966 final Phone phone = getPhone(subId);
7967 if (phone == null) {
7968 return null;
7969 }
7970
Jordan Liu0f2bc442020-11-18 16:47:37 -08007971 final long identity = Binder.clearCallingIdentity();
7972
Jack Yu479f40e2020-10-27 21:29:25 -07007973 boolean isCallingPackageDataService = phone.getDataServicePackages()
7974 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007975 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007976 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7977 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7978 Rlog.d(LOG_TAG,
7979 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7980 return null;
7981 }
7982
Hall Liuf19c44f2018-11-27 14:38:17 -08007983 ServiceState ss = phone.getServiceState();
7984
7985 // Scrub out the location info in ServiceState depending on what level of access
7986 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007987 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007988 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7989 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990 } finally {
7991 Binder.restoreCallingIdentity(identity);
7992 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007993 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007994
7995 /**
7996 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7997 *
7998 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7999 * voicemail ringtone.
8000 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8001 * PhoneAccount.
8002 */
8003 @Override
8004 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 final long identity = Binder.clearCallingIdentity();
8006 try {
8007 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8008 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008009 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8013 } finally {
8014 Binder.restoreCallingIdentity(identity);
8015 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008016 }
8017
8018 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008019 * Sets the per-account voicemail ringtone.
8020 *
8021 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8022 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8023 *
8024 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8025 * voicemail ringtone.
8026 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8027 * PhoneAccount.
8028 */
8029 @Override
8030 public void setVoicemailRingtoneUri(String callingPackage,
8031 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008032 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008033 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008034 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8035 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8037 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8038 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008040
8041 final long identity = Binder.clearCallingIdentity();
8042 try {
8043 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8044 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008045 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008046 }
8047 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8048 } finally {
8049 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008050 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008051 }
8052
8053 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008054 * Returns whether vibration is set for voicemail notification in Phone settings.
8055 *
8056 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8057 * voicemail vibration setting.
8058 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8059 */
8060 @Override
8061 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008062 final long identity = Binder.clearCallingIdentity();
8063 try {
8064 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8065 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008066 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008069 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
8072 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008073 }
8074
Youhan Wange64578a2016-05-02 15:32:42 -07008075 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008076 * Sets the per-account voicemail vibration.
8077 *
8078 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8079 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8080 *
8081 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8082 * voicemail vibration setting.
8083 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8084 * specific PhoneAccount.
8085 */
8086 @Override
8087 public void setVoicemailVibrationEnabled(String callingPackage,
8088 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008089 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008090 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008091 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8092 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8094 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8095 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008096 }
8097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098 final long identity = Binder.clearCallingIdentity();
8099 try {
8100 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8101 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008102 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008103 }
8104 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8105 } finally {
8106 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008107 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008108 }
8109
8110 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008111 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8112 *
8113 * @throws SecurityException if the caller does not have the required permission
8114 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008115 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008116 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008117 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008118 }
8119
8120 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008121 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8122 * permission.
8123 *
8124 * @throws SecurityException if the caller does not have the required permission
8125 */
8126 private void enforceSendSmsPermission() {
8127 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8128 }
8129
8130 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008131 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008132 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008133 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008134 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008135 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008136 final long identity = Binder.clearCallingIdentity();
8137 try {
8138 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008139 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008140 if (componentName == null) {
8141 throw new SecurityException(
8142 "Caller not current active visual voicemail package[null]");
8143 }
8144 String vvmPackage = componentName.getPackageName();
8145 if (!callingPackage.equals(vvmPackage)) {
8146 throw new SecurityException("Caller not current active visual voicemail package["
8147 + vvmPackage + "]");
8148 }
8149 } finally {
8150 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008151 }
8152 }
8153
8154 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008155 * Return the application ID for the app type.
8156 *
8157 * @param subId the subscription ID that this request applies to.
8158 * @param appType the uicc app type.
8159 * @return Application ID for specificied app type, or null if no uicc.
8160 */
8161 @Override
8162 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008163 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008164 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165
8166 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008167 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008168 if (phone == null) {
8169 return null;
8170 }
8171 String aid = null;
8172 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008173 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008174 .getApplicationByType(appType).getAid();
8175 } catch (Exception e) {
8176 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8177 }
8178 return aid;
8179 } finally {
8180 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008181 }
Youhan Wange64578a2016-05-02 15:32:42 -07008182 }
8183
Youhan Wang4001d252016-05-11 10:29:41 -07008184 /**
8185 * Return the Electronic Serial Number.
8186 *
8187 * @param subId the subscription ID that this request applies to.
8188 * @return ESN or null if error.
8189 */
8190 @Override
8191 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008192 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008193 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008194
8195 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008196 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008197 if (phone == null) {
8198 return null;
8199 }
8200 String esn = null;
8201 try {
8202 esn = phone.getEsn();
8203 } catch (Exception e) {
8204 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8205 }
8206 return esn;
8207 } finally {
8208 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008209 }
Youhan Wang4001d252016-05-11 10:29:41 -07008210 }
8211
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008212 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008213 * Return the Preferred Roaming List Version.
8214 *
8215 * @param subId the subscription ID that this request applies to.
8216 * @return PRLVersion or null if error.
8217 */
8218 @Override
8219 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008220 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008221 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222
8223 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008224 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 if (phone == null) {
8226 return null;
8227 }
8228 String cdmaPrlVersion = null;
8229 try {
8230 cdmaPrlVersion = phone.getCdmaPrlVersion();
8231 } catch (Exception e) {
8232 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8233 }
8234 return cdmaPrlVersion;
8235 } finally {
8236 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008237 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008238 }
8239
8240 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008241 * Get snapshot of Telephony histograms
8242 * @return List of Telephony histograms
8243 * @hide
8244 */
8245 @Override
8246 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8248 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249
8250 final long identity = Binder.clearCallingIdentity();
8251 try {
8252 return RIL.getTelephonyRILTimingHistograms();
8253 } finally {
8254 Binder.restoreCallingIdentity(identity);
8255 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008256 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008257
8258 /**
8259 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008260 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8261 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008262 * Require system privileges. In the future we may add this to carrier APIs.
8263 *
Michele Berionne482f8202018-11-27 18:57:59 -08008264 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008265 */
8266 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008267 @TelephonyManager.SetCarrierRestrictionResult
8268 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008269 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008271
Michele Berionne482f8202018-11-27 18:57:59 -08008272 if (carrierRestrictionRules == null) {
8273 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008274 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276 final long identity = Binder.clearCallingIdentity();
8277 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008278 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008279 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008280 } finally {
8281 Binder.restoreCallingIdentity(identity);
8282 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008283 }
8284
8285 /**
8286 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008287 * Get the allowed carrier list and the excluded carrier list, including the priority between
8288 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008289 * Require system privileges. In the future we may add this to carrier APIs.
8290 *
Michele Berionne482f8202018-11-27 18:57:59 -08008291 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008292 */
8293 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008294 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008295 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297
8298 final long identity = Binder.clearCallingIdentity();
8299 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008300 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8301 if (response instanceof CarrierRestrictionRules) {
8302 return (CarrierRestrictionRules) response;
8303 }
8304 // Response is an Exception of some kind,
8305 // which is signalled to the user as a NULL retval
8306 return null;
8307 } catch (Exception e) {
8308 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8309 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310 } finally {
8311 Binder.restoreCallingIdentity(identity);
8312 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008313 }
8314
fionaxu59545b42016-05-25 15:53:37 -07008315 /**
fionaxu59545b42016-05-25 15:53:37 -07008316 * Action set from carrier signalling broadcast receivers to enable/disable radio
8317 * @param subId the subscription ID that this action applies to.
8318 * @param enabled control enable or disable radio.
8319 * {@hide}
8320 */
8321 @Override
8322 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8323 enforceModifyPermission();
8324 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008325
8326 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008327 if (phone == null) {
8328 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8329 return;
8330 }
8331 try {
8332 phone.carrierActionSetRadioEnabled(enabled);
8333 } catch (Exception e) {
8334 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335 } finally {
8336 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008337 }
8338 }
8339
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008340 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008341 * Enable or disable Voice over NR (VoNR)
8342 * @param subId the subscription ID that this action applies to.
8343 * @param enabled enable or disable VoNR.
8344 * @return operation result.
8345 */
8346 @Override
8347 public int setVoNrEnabled(int subId, boolean enabled) {
8348 enforceModifyPermission();
8349 final Phone phone = getPhone(subId);
8350
8351 final long identity = Binder.clearCallingIdentity();
8352 if (phone == null) {
8353 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8354 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8355 }
8356
8357 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8358 try {
8359 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8360 workSource);
8361 if (DBG) log("setVoNrEnabled result: " + result);
8362 return result;
8363 } finally {
8364 Binder.restoreCallingIdentity(identity);
8365 }
8366 }
8367
8368 /**
8369 * Is voice over NR enabled
8370 * @return true if VoNR is enabled else false
8371 */
8372 @Override
8373 public boolean isVoNrEnabled(int subId) {
8374 enforceReadPrivilegedPermission("isVoNrEnabled");
8375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8376 final long identity = Binder.clearCallingIdentity();
8377 try {
8378 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8379 null, subId, workSource);
8380 if (DBG) log("isVoNrEnabled: " + isEnabled);
8381 return isEnabled;
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
8385 }
8386
8387 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008388 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8389 * network status based on which carrier apps could apply actions accordingly,
8390 * enable/disable default url handler for example.
8391 *
8392 * @param subId the subscription ID that this action applies to.
8393 * @param report control start/stop reporting the default network status.
8394 * {@hide}
8395 */
8396 @Override
8397 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8398 enforceModifyPermission();
8399 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008400
8401 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008402 if (phone == null) {
8403 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8404 return;
8405 }
8406 try {
8407 phone.carrierActionReportDefaultNetworkStatus(report);
8408 } catch (Exception e) {
8409 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008410 } finally {
8411 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008412 }
8413 }
8414
8415 /**
fionaxud9622282017-07-17 17:51:30 -07008416 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8417 * @param subId the subscription ID that this action applies to.
8418 * {@hide}
8419 */
8420 @Override
8421 public void carrierActionResetAll(int subId) {
8422 enforceModifyPermission();
8423 final Phone phone = getPhone(subId);
8424 if (phone == null) {
8425 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8426 return;
8427 }
8428 try {
8429 phone.carrierActionResetAll();
8430 } catch (Exception e) {
8431 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8432 }
8433 }
8434
8435 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008436 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8437 * bug report is being generated.
8438 */
8439 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008440 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008441 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8442 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008443 writer.println("Permission Denial: can't dump Phone from pid="
8444 + Binder.getCallingPid()
8445 + ", uid=" + Binder.getCallingUid()
8446 + "without permission "
8447 + android.Manifest.permission.DUMP);
8448 return;
8449 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008450 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008451 }
Jack Yueb89b242016-06-22 13:27:47 -07008452
Brad Ebingerdac2f002018-04-03 15:17:52 -07008453 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008454 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8455 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8456 @NonNull String[] args) {
8457 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8458 this, in.getFileDescriptor(), out.getFileDescriptor(),
8459 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008460 }
8461
Jack Yueb89b242016-06-22 13:27:47 -07008462 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008463 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008464 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008465 * @param reason the reason the data enable change is taking place
8466 * @param enabled True if enabling the data, otherwise disabling.
8467 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008468 */
8469 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008470 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008471 boolean enabled) {
8472 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8473 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8474 try {
8475 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008476 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008477 } catch (SecurityException se) {
8478 enforceModifyPermission();
8479 }
8480 } else {
8481 enforceModifyPermission();
8482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008483
8484 final long identity = Binder.clearCallingIdentity();
8485 try {
8486 Phone phone = getPhone(subId);
8487 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008488 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8489 phone.carrierActionSetMeteredApnsEnabled(enabled);
8490 } else {
8491 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493 }
8494 } finally {
8495 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008496 }
8497 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008498
8499 /**
8500 * Get Client request stats
8501 * @return List of Client Request Stats
8502 * @hide
8503 */
8504 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008505 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8506 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008508 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008509 return null;
8510 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008511 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 if (phone != null) {
8516 return phone.getClientRequestStats();
8517 }
8518
8519 return null;
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
8522 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008523 }
8524
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008525 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008526 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008527 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008528 }
Jack Yueb4124c2017-02-16 15:32:43 -08008529
8530 /**
Grace Chen70990072017-03-24 17:21:30 -07008531 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008532 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008533 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008534 * @param state State of SIM (power down, power up, pass through)
8535 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8536 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8537 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008538 *
8539 **/
8540 @Override
Grace Chen70990072017-03-24 17:21:30 -07008541 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008542 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008543 Phone phone = PhoneFactory.getPhone(slotIndex);
8544
vagdeviaf9a5b92018-08-15 16:01:53 -07008545 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008547 final long identity = Binder.clearCallingIdentity();
8548 try {
8549 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008550 phone.setSimPowerState(state, null, workSource);
8551 }
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
8554 }
8555 }
8556
8557 /**
8558 * Set SIM card power state.
8559 *
8560 * @param slotIndex SIM slot id.
8561 * @param state State of SIM (power down, power up, pass through)
8562 * @param callback callback to trigger after success or failure
8563 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8564 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8565 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8566 *
8567 **/
8568 @Override
8569 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8570 IIntegerConsumer callback) {
8571 enforceModifyPermission();
8572 Phone phone = PhoneFactory.getPhone(slotIndex);
8573
8574 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8575
8576 final long identity = Binder.clearCallingIdentity();
8577 try {
8578 if (phone != null) {
8579 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8580 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008581 }
8582 } finally {
8583 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008584 }
8585 }
Shuo Qiandd210312017-04-12 22:11:33 +00008586
Tyler Gunn65d45c22017-06-05 11:22:26 -07008587 private boolean isUssdApiAllowed(int subId) {
8588 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008589 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008590 if (configManager == null) {
8591 return false;
8592 }
8593 PersistableBundle pb = configManager.getConfigForSubId(subId);
8594 if (pb == null) {
8595 return false;
8596 }
8597 return pb.getBoolean(
8598 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8599 }
8600
Shuo Qiandd210312017-04-12 22:11:33 +00008601 /**
8602 * Check if phone is in emergency callback mode
8603 * @return true if phone is in emergency callback mode
8604 * @param subId sub id
8605 */
goneil9c5f4872017-12-05 14:07:56 -08008606 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008607 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008608 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008609 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008610
8611 final long identity = Binder.clearCallingIdentity();
8612 try {
8613 if (phone != null) {
8614 return phone.isInEcm();
8615 } else {
8616 return false;
8617 }
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008620 }
8621 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008622
8623 /**
8624 * Get the current signal strength information for the given subscription.
8625 * Because this information is not updated when the device is in a low power state
8626 * it should not be relied-upon to be current.
8627 * @param subId Subscription index
8628 * @return the most recent cached signal strength info from the modem
8629 */
8630 @Override
8631 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 Phone p = getPhone(subId);
8635 if (p == null) {
8636 return null;
8637 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008639 return p.getSignalStrength();
8640 } finally {
8641 Binder.restoreCallingIdentity(identity);
8642 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008643 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008644
Pengquan Meng77b7f132018-08-22 14:49:57 -07008645 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008646 * Get the current modem radio state for the given slot.
8647 * @param slotIndex slot index.
8648 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008649 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008650 * @return the current radio power state from the modem
8651 */
8652 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008653 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008654 Phone phone = PhoneFactory.getPhone(slotIndex);
8655 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8657 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008658 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8659 }
8660
8661 final long identity = Binder.clearCallingIdentity();
8662 try {
8663 return phone.getRadioPowerState();
8664 } finally {
8665 Binder.restoreCallingIdentity(identity);
8666 }
8667 }
8668 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8669 }
8670
8671 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008672 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8673 *
8674 * <p>Requires one of the following permissions:
8675 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008676 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008677 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8678 * privileges.
8679 *
8680 * @param subId subscription id
8681 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8682 * {@code false}.
8683 */
8684 @Override
8685 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008686 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008687 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008688 try {
8689 mApp.enforceCallingOrSelfPermission(
8690 android.Manifest.permission.ACCESS_NETWORK_STATE,
8691 functionName);
8692 } catch (Exception e) {
8693 mApp.enforceCallingOrSelfPermission(
8694 permission.READ_BASIC_PHONE_STATE, functionName);
8695 }
Shuo Qian093013d2020-08-13 15:42:55 -07008696 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008697 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008698 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008699 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008700
Pengquan Menga1bb6272018-09-06 09:59:22 -07008701 boolean isEnabled = false;
8702 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008703 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008704 Phone phone = getPhone(subId);
8705 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008706 } finally {
8707 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008708 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008709 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008710 }
8711
8712
8713 /**
8714 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8715 *
8716 * <p> Requires permission:
8717 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8718 * privileges.
8719 *
8720 * @param subId subscription id
8721 * @param isEnabled {@code true} means enable, {@code false} means disable.
8722 */
8723 @Override
8724 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8726 mApp, subId, "setDataRoamingEnabled");
8727
Pengquan Menga1bb6272018-09-06 09:59:22 -07008728 final long identity = Binder.clearCallingIdentity();
8729 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008730 Phone phone = getPhone(subId);
8731 if (phone != null) {
8732 phone.setDataRoamingEnabled(isEnabled);
8733 }
8734 } finally {
8735 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008736 }
8737 }
8738
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008739 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008740 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008741 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008742 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008743 mApp, subId, "isManualNetworkSelectionAllowed");
8744
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008745 boolean isAllowed = true;
8746 final long identity = Binder.clearCallingIdentity();
8747 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008748 Phone phone = getPhone(subId);
8749 if (phone != null) {
8750 isAllowed = phone.isCspPlmnEnabled();
8751 }
8752 } finally {
8753 Binder.restoreCallingIdentity(identity);
8754 }
8755 return isAllowed;
8756 }
8757
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008758 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8759 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8760 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8761 // Update each UiccPort object based on privilege access
8762 UiccPort[] uiccPorts = card.getUiccPortList();
8763 for (UiccPort port : uiccPorts) {
8764 UiccProfile profile = port.getUiccProfile();
8765 if (profile == null ||
8766 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8767 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8768 return false;
8769 }
8770 }
8771 return true;
8772 }
8773
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008774 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008775 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008776 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008777 mApp.getSystemService(AppOpsManager.class)
8778 .checkPackage(Binder.getCallingUid(), callingPackage);
8779
Jordan Liu1e142fc2019-04-22 15:10:43 -07008780 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008781 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008782 try {
8783 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008784 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008785 } catch (SecurityException e) {
8786 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8787 // has carrier privileges on an active UICC
8788 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8789 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008790 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008791 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008792 }
sandeepjs0a502c42021-09-27 15:34:44 +00008793 // checking compatibility, if calling app's target SDK is T and beyond.
8794 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8795 Binder.getCallingUid())) {
8796 isIccIdAccessRestricted = true;
8797 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008798 final long identity = Binder.clearCallingIdentity();
8799 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008800 UiccController uiccController = UiccController.getInstance();
8801 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008802 if (hasReadPermission) {
8803 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008804 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008805
8806 // Remove private info if the caller doesn't have access
8807 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8808 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008809 //setting the value after compatibility check
8810 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008811 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8812 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008813 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008814 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8815 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8816 if (card == null || card.getUiccPortList().length == 0) {
8817 // assume no access if the card or ports are unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008818 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008819 continue;
8820 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008821 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008822 filteredInfos.add(cardInfo);
8823 } else {
sandeepjs0a502c42021-09-27 15:34:44 +00008824 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008825 }
8826 }
8827 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008828 } finally {
8829 Binder.restoreCallingIdentity(identity);
8830 }
8831 }
8832
sandeepjs0a502c42021-09-27 15:34:44 +00008833 /**
8834 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8835 * generally private and require carrier privileges to view.
8836 *
8837 * @hide
8838 */
8839 @NonNull
8840 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8841 List<UiccPortInfo> portinfo = new ArrayList<>();
8842 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8843 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8844 }
8845 return new UiccCardInfo(
8846 cardInfo.isEuicc(),
8847 cardInfo.getCardId(),
8848 null,
8849 cardInfo.getPhysicalSlotIndex(),
8850 cardInfo.isRemovable(),
8851 cardInfo.isMultipleEnabledProfilesSupported(),
8852 portinfo
8853 );
8854 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008855
sandeepjs0a502c42021-09-27 15:34:44 +00008856 /**
8857 * @hide
8858 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8859 * These values are generally private and require carrier privileges to view.
8860 */
8861 @NonNull
8862 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8863 return new UiccPortInfo(
8864 UiccPortInfo.ICCID_REDACTED,
8865 portInfo.getPortIndex(),
8866 portInfo.getLogicalSlotIndex(),
8867 portInfo.isActive()
8868 );
8869 }
8870 @Override
8871 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008872 // Verify that the callingPackage belongs to the calling UID
sandeepjs0a502c42021-09-27 15:34:44 +00008873 mApp.getSystemService(AppOpsManager.class)
8874 .checkPackage(Binder.getCallingUid(), callingPackage);
8875
8876 boolean hasReadPermission = false;
8877 boolean isLogicalSlotAccessRestricted = false;
8878 String iccId;
8879
8880 try {
8881 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8882 hasReadPermission = true;
8883 } catch (SecurityException e) {
8884 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8885 // has carrier privileges on an active UICC
8886 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8887 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8888 hasReadPermission = true;
8889 }
8890 }
8891
8892 // checking compatibility, if calling app's target SDK is T and beyond.
8893 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8894 Binder.getCallingUid())) {
8895 isLogicalSlotAccessRestricted = true;
8896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008897 final long identity = Binder.clearCallingIdentity();
8898 try {
8899 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8900 if (slots == null) {
8901 Rlog.i(LOG_TAG, "slots is null.");
8902 return null;
8903 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008904 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8905 for (int i = 0; i < slots.length; i++) {
8906 UiccSlot slot = slots[i];
8907 if (slot == null) {
8908 continue;
8909 }
8910
Jordan Liu7be7e652019-05-06 18:55:02 +00008911 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008912 UiccCard card = slot.getUiccCard();
sandeepjs0a502c42021-09-27 15:34:44 +00008913 //if has read permission
8914 if (hasReadPermission) {
8915 iccId = slot.getIccId();
8916 } else {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008917 if (card != null) {
8918 // if no read permission checking carrier
8919 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
8920 iccId = slot.getIccId();
8921 } else {
8922 //if no carrier permission redact ICCID
8923 iccId = IccUtils.TEST_ICCID;
8924 }
sandeepjs0a502c42021-09-27 15:34:44 +00008925 } else {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008926 iccId = null;
sandeepjs0a502c42021-09-27 15:34:44 +00008927 }
8928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008929 if (card != null) {
8930 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008931 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008932 cardId = slot.getEid();
8933 if (TextUtils.isEmpty(cardId)) {
sandeepjs0a502c42021-09-27 15:34:44 +00008934 cardId = iccId;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008935 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008936 }
8937
Jordan Liu857451f2019-05-09 16:35:35 -07008938 if (cardId != null) {
8939 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8940 // if cardId is an EID, it's all digits so this is fine
8941 cardId = IccUtils.stripTrailingFs(cardId);
8942 }
8943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008944 int cardState = 0;
8945 switch (slot.getCardState()) {
8946 case CARDSTATE_ABSENT:
8947 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8948 break;
8949 case CARDSTATE_PRESENT:
8950 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8951 break;
8952 case CARDSTATE_ERROR:
8953 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8954 break;
8955 case CARDSTATE_RESTRICTED:
8956 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8957 break;
8958 default:
8959 break;
8960
8961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008962 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008963 slot.isEuicc(),
8964 cardId,
8965 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008966 slot.isExtendedApduSupported(),
sandeepjs0a502c42021-09-27 15:34:44 +00008967 slot.isRemovable(), Collections.singletonList(
8968 new UiccPortInfo(
8969 iccId,
8970 0 /* TODO: to use portList from UiccSlots */,
8971 slot.getPhoneId(),
8972 slot.isActive())));
8973 //setting the value after compatibility check
8974 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008975 }
8976 return infos;
8977 } finally {
8978 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008979 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008980 }
8981
8982 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008983 @Deprecated
8984 //TODO : once integrating with HAL Changes we can clean up this Internal API.
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008985 public boolean switchSlots(int[] physicalSlots) {
8986 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008987
8988 final long identity = Binder.clearCallingIdentity();
8989 try {
8990 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8991 } finally {
8992 Binder.restoreCallingIdentity(identity);
8993 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008994 }
Jack Yu4c988042018-02-27 15:30:01 -08008995
8996 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00008997 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
8998 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
8999 enforceModifyPermission();
9000
9001 final long identity = Binder.clearCallingIdentity();
9002 try {
9003 //TODO: once integrating the HAL changes we can proceed with to work on the parsing side
9004 int[] physicalSlots = new int[slotMapping.size()];
9005 for (int i = 0; i < physicalSlots.length; i++) {
9006 physicalSlots[i] = slotMapping.get(i).getPhysicalSlotIndex();
9007 }
9008 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
9009 } finally {
9010 Binder.restoreCallingIdentity(identity);
9011 }
9012 }
9013
9014 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009015 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009016 final long identity = Binder.clearCallingIdentity();
9017 try {
9018 return UiccController.getInstance().getCardIdForDefaultEuicc();
9019 } finally {
9020 Binder.restoreCallingIdentity(identity);
9021 }
9022 }
9023
Pengquan Meng85728fb2018-03-12 16:31:21 -07009024 /**
goneil47ffb6e2018-04-06 15:40:58 -07009025 * A test API to reload the UICC profile.
9026 *
9027 * <p>Requires that the calling app has permission
9028 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9029 * @hide
9030 */
9031 @Override
9032 public void refreshUiccProfile(int subId) {
9033 enforceModifyPermission();
9034
9035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 Phone phone = getPhone(subId);
9038 if (phone == null) {
9039 return;
9040 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009041 UiccPort uiccPort = phone.getUiccPort();
9042 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009043 return;
9044 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009045 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009046 if (uiccProfile == null) {
9047 return;
9048 }
9049 uiccProfile.refresh();
9050 } finally {
9051 Binder.restoreCallingIdentity(identity);
9052 }
9053 }
9054
9055 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009056 * Returns false if the mobile data is disabled by default, otherwise return true.
9057 */
9058 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009059 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009060 }
9061
9062 /**
9063 * Returns true if the data roaming is enabled by default, i.e the system property
9064 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9065 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9066 */
9067 private boolean getDefaultDataRoamingEnabled(int subId) {
9068 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009069 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009070 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009071 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9072 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9073 return isDataRoamingEnabled;
9074 }
9075
9076 /**
9077 * Returns the default network type for the given {@code subId}, if the default network type is
9078 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9079 */
9080 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009081 List<Integer> list = TelephonyProperties.default_network();
9082 int phoneId = mSubscriptionController.getPhoneId(subId);
9083 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9084 return list.get(phoneId);
9085 }
9086 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009087 }
fionaxua13278b2018-03-21 00:08:13 -07009088
9089 @Override
9090 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009091 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009092 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009093
9094 final long identity = Binder.clearCallingIdentity();
9095 try {
9096 final Phone phone = getPhone(subId);
9097 if (phone == null) {
9098 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9099 return;
9100 }
chen xueaba88a2019-03-15 13:15:10 -07009101 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9102 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009103 if (carrierPrivilegeRules == null) {
9104 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9105 } else {
9106 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009108 } finally {
9109 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009110 }
fionaxua13278b2018-03-21 00:08:13 -07009111 }
9112
9113 @Override
9114 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009115 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009116
9117 final long identity = Binder.clearCallingIdentity();
9118 try {
9119 final Phone phone = getPhone(subId);
9120 if (phone == null) {
9121 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9122 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9123 }
9124 return phone.getCarrierIdListVersion();
9125 } finally {
9126 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009127 }
fionaxua13278b2018-03-21 00:08:13 -07009128 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009129
9130 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009131 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9132 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009134 mApp, subId, callingPackage, callingFeatureId,
9135 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009136 return -1;
9137 }
9138
9139 final long identity = Binder.clearCallingIdentity();
9140 try {
9141 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9142 } finally {
9143 Binder.restoreCallingIdentity(identity);
9144 }
9145 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009146
9147 @Override
9148 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009149 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009150 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009151 mApp, subId, "getCdmaRoamingMode");
9152
9153 final long identity = Binder.clearCallingIdentity();
9154 try {
9155 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9156 } finally {
9157 Binder.restoreCallingIdentity(identity);
9158 }
9159 }
9160
9161 @Override
9162 public boolean setCdmaRoamingMode(int subId, int mode) {
9163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9164 mApp, subId, "setCdmaRoamingMode");
9165
9166 final long identity = Binder.clearCallingIdentity();
9167 try {
9168 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9169 } finally {
9170 Binder.restoreCallingIdentity(identity);
9171 }
9172 }
9173
9174 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009175 public int getCdmaSubscriptionMode(int subId) {
9176 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009177 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009178 mApp, subId, "getCdmaSubscriptionMode");
9179
9180 final long identity = Binder.clearCallingIdentity();
9181 try {
9182 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
9186 }
9187
9188 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009189 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9191 mApp, subId, "setCdmaSubscriptionMode");
9192
9193 final long identity = Binder.clearCallingIdentity();
9194 try {
9195 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9196 } finally {
9197 Binder.restoreCallingIdentity(identity);
9198 }
9199 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009200
sqianc5eccab2018-10-19 18:46:41 -07009201 @Override
sqian8c685422019-02-22 15:55:18 -08009202 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009203 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009204 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009205 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9206 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009207 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9208 }
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
sqian854d44b2018-12-12 16:48:18 -08009211 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9212 for (Phone phone: PhoneFactory.getPhones()) {
9213 if (phone.getEmergencyNumberTracker() != null
9214 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9215 emergencyNumberListInternal.put(
9216 phone.getSubId(),
9217 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9218 }
sqian11b7a0e2018-12-05 18:48:28 -08009219 }
sqian854d44b2018-12-12 16:48:18 -08009220 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
sqianc5eccab2018-10-19 18:46:41 -07009224 }
9225
9226 @Override
sqian8c685422019-02-22 15:55:18 -08009227 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009228 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009229 if (!exactMatch) {
9230 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009231 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009232 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009233 }
9234 final long identity = Binder.clearCallingIdentity();
9235 try {
sqian854d44b2018-12-12 16:48:18 -08009236 for (Phone phone: PhoneFactory.getPhones()) {
9237 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009238 && phone.getEmergencyNumberTracker()
9239 .isEmergencyNumber(number, exactMatch)) {
9240 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009241 }
sqian11b7a0e2018-12-05 18:48:28 -08009242 }
9243 return false;
9244 } finally {
9245 Binder.restoreCallingIdentity(identity);
9246 }
9247 }
9248
sqianf4ca7ed2019-01-15 18:32:07 -08009249 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009250 * Start emergency callback mode for GsmCdmaPhone for testing.
9251 */
9252 @Override
9253 public void startEmergencyCallbackMode() {
9254 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9255 "startEmergencyCallbackMode");
9256 enforceModifyPermission();
9257 final long identity = Binder.clearCallingIdentity();
9258 try {
9259 for (Phone phone : PhoneFactory.getPhones()) {
9260 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9261 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9262 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9263 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9264 gsmCdmaPhone.obtainMessage(
9265 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9266 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9267 }
9268 }
9269 } finally {
9270 Binder.restoreCallingIdentity(identity);
9271 }
9272 }
9273
9274 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009275 * Update emergency number list for test mode.
9276 */
9277 @Override
9278 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9279 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9280 "updateEmergencyNumberListTestMode");
9281
9282 final long identity = Binder.clearCallingIdentity();
9283 try {
9284 for (Phone phone: PhoneFactory.getPhones()) {
9285 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9286 if (tracker != null) {
9287 tracker.executeEmergencyNumberTestModeCommand(action, num);
9288 }
9289 }
9290 } finally {
9291 Binder.restoreCallingIdentity(identity);
9292 }
9293 }
9294
9295 /**
9296 * Get the full emergency number list for test mode.
9297 */
9298 @Override
9299 public List<String> getEmergencyNumberListTestMode() {
9300 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9301 "getEmergencyNumberListTestMode");
9302
9303 final long identity = Binder.clearCallingIdentity();
9304 try {
9305 Set<String> emergencyNumbers = new HashSet<>();
9306 for (Phone phone: PhoneFactory.getPhones()) {
9307 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9308 if (tracker != null) {
9309 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9310 emergencyNumbers.add(num.getNumber());
9311 }
9312 }
9313 }
9314 return new ArrayList<>(emergencyNumbers);
9315 } finally {
9316 Binder.restoreCallingIdentity(identity);
9317 }
9318 }
9319
chen xud6b45bd2018-10-30 22:27:10 -07009320 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009321 public int getEmergencyNumberDbVersion(int subId) {
9322 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9323
9324 final long identity = Binder.clearCallingIdentity();
9325 try {
9326 final Phone phone = getPhone(subId);
9327 if (phone == null) {
9328 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9329 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9330 }
9331 return phone.getEmergencyNumberDbVersion();
9332 } finally {
9333 Binder.restoreCallingIdentity(identity);
9334 }
9335 }
9336
9337 @Override
9338 public void notifyOtaEmergencyNumberDbInstalled() {
9339 enforceModifyPermission();
9340
9341 final long identity = Binder.clearCallingIdentity();
9342 try {
9343 for (Phone phone: PhoneFactory.getPhones()) {
9344 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9345 if (tracker != null) {
9346 tracker.updateOtaEmergencyNumberDatabase();
9347 }
9348 }
9349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 }
9353
9354 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009355 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009356 enforceActiveEmergencySessionPermission();
9357
9358 final long identity = Binder.clearCallingIdentity();
9359 try {
9360 for (Phone phone: PhoneFactory.getPhones()) {
9361 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9362 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009363 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9364 }
9365 }
9366 } finally {
9367 Binder.restoreCallingIdentity(identity);
9368 }
9369 }
9370
9371 @Override
9372 public void resetOtaEmergencyNumberDbFilePath() {
9373 enforceActiveEmergencySessionPermission();
9374
9375 final long identity = Binder.clearCallingIdentity();
9376 try {
9377 for (Phone phone: PhoneFactory.getPhones()) {
9378 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9379 if (tracker != null) {
9380 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009381 }
9382 }
9383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 }
9387
9388 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009389 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9390 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9391 Phone phone = getPhone(subId);
9392 if (phone == null) {
9393 return null;
9394 }
9395 final long identity = Binder.clearCallingIdentity();
9396 try {
9397 UiccProfile profile = UiccController.getInstance()
9398 .getUiccProfileForPhone(phone.getPhoneId());
9399 if (profile != null) {
9400 return profile.getCertsFromCarrierPrivilegeAccessRules();
9401 }
9402 } finally {
9403 Binder.restoreCallingIdentity(identity);
9404 }
9405 return null;
9406 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009407
9408 /**
9409 * Enable or disable a modem stack.
9410 */
9411 @Override
9412 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9413 enforceModifyPermission();
9414
9415 final long identity = Binder.clearCallingIdentity();
9416 try {
9417 Phone phone = PhoneFactory.getPhone(slotIndex);
9418 if (phone == null) {
9419 return false;
9420 } else {
9421 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9422 }
9423 } finally {
9424 Binder.restoreCallingIdentity(identity);
9425 }
9426 }
Michelecea4cf22018-12-21 15:00:11 -08009427
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009428 /**
9429 * Whether a modem stack is enabled or not.
9430 */
9431 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009432 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9433 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009434 Phone phone = PhoneFactory.getPhone(slotIndex);
9435 if (phone == null) return false;
9436
9437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009438 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9439 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009440 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9441 }
9442
9443 final long identity = Binder.clearCallingIdentity();
9444 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009445 try {
9446 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9447 } catch (NoSuchElementException ex) {
9448 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9449 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009450 } finally {
9451 Binder.restoreCallingIdentity(identity);
9452 }
9453 }
9454
Michelecea4cf22018-12-21 15:00:11 -08009455 @Override
Michele0ea7d782019-03-19 14:58:42 -07009456 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009457 enforceModifyPermission();
9458
9459 final long identity = Binder.clearCallingIdentity();
9460 try {
9461 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009462 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009463 .commit();
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
9468
9469 @Override
Michele0ea7d782019-03-19 14:58:42 -07009470 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009471 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009473 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9474 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009475 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009476 }
Michelecea4cf22018-12-21 15:00:11 -08009477
9478 final long identity = Binder.clearCallingIdentity();
9479 try {
Michele0ea7d782019-03-19 14:58:42 -07009480 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009481 } finally {
9482 Binder.restoreCallingIdentity(identity);
9483 }
9484 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009485
Michele0ea7d782019-03-19 14:58:42 -07009486 @TelephonyManager.IsMultiSimSupportedResult
9487 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009488 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9489 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9490 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009491 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9492 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009493 }
9494 // Check if the hardware supports multisim functionality. If usage of multisim is not
9495 // supported by the modem, indicate that it is restricted.
9496 PhoneCapability staticCapability =
9497 mPhoneConfigurationManager.getStaticPhoneCapability();
9498 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009499 loge("isMultiSimSupportedInternal: no static configuration available");
9500 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009501 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009502 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009503 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9504 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009505 }
9506 // Check if support of multiple SIMs is restricted by carrier
9507 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009508 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009509 }
9510
Michele0ea7d782019-03-19 14:58:42 -07009511 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009512 }
9513
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009514 /**
9515 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009516 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9517 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9518 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009519 * @param numOfSims number of active sims we want to switch to
9520 */
9521 @Override
9522 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009523 if (numOfSims == 1) {
9524 enforceModifyPermission();
9525 } else {
9526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9527 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9528 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009529 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009530
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009531 try {
Michele30b57b22019-03-01 12:01:14 -08009532 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009533 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009534 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9535 return;
9536 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009537 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9538 } finally {
9539 Binder.restoreCallingIdentity(identity);
9540 }
9541 }
9542
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009543 @Override
9544 public boolean isApplicationOnUicc(int subId, int appType) {
9545 enforceReadPrivilegedPermission("isApplicationOnUicc");
9546 Phone phone = getPhone(subId);
9547 if (phone == null) {
9548 return false;
9549 }
9550 final long identity = Binder.clearCallingIdentity();
9551 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009552 UiccPort uiccPort = phone.getUiccPort();
9553 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009554 return false;
9555 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009556 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009557 if (uiccProfile == null) {
9558 return false;
9559 }
9560 if (TelephonyManager.APPTYPE_SIM <= appType
9561 && appType <= TelephonyManager.APPTYPE_ISIM) {
9562 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9563 }
9564 return false;
9565 } finally {
9566 Binder.restoreCallingIdentity(identity);
9567 }
9568 }
9569
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009570 /**
chen xub4baa772019-04-03 10:23:41 -07009571 * Get whether making changes to modem configurations will trigger reboot.
9572 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009573 */
9574 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009575 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9576 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009578 mApp, subId, callingPackage, callingFeatureId,
9579 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009580 return false;
9581 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009582 final long identity = Binder.clearCallingIdentity();
9583 try {
9584 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9585 } finally {
9586 Binder.restoreCallingIdentity(identity);
9587 }
9588 }
9589
Nathan Harold29f5f052019-02-15 13:41:57 -08009590 private void updateModemStateMetrics() {
9591 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9592 // TODO: check the state for each modem if the api is ready.
9593 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9594 }
9595
Pengquan Meng3889a572019-01-23 11:16:29 -08009596 @Override
sandeepjs29b7e8e2021-11-17 04:05:58 +00009597 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009598 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjs29b7e8e2021-11-17 04:05:58 +00009599 // Verify that the callingPackage belongs to the calling UID
9600 mApp.getSystemService(AppOpsManager.class)
9601 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009602 final long identity = Binder.clearCallingIdentity();
sandeepjs29b7e8e2021-11-17 04:05:58 +00009603 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009604 try {
sandeepjs29b7e8e2021-11-17 04:05:58 +00009605 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9606 if (slotInfos != null) {
9607 for (int i = 0; i < slotInfos.length; i++) {
9608 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9609 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9610 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9611 portInfo.getLogicalSlotIndex()));
9612 }
9613 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009614 }
9615 }
sandeepjs29b7e8e2021-11-17 04:05:58 +00009616 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009617 } finally {
9618 Binder.restoreCallingIdentity(identity);
9619 }
9620 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009621
9622 /**
9623 * Get the IRadio HAL Version
9624 */
9625 @Override
9626 public int getRadioHalVersion() {
9627 Phone phone = getDefaultPhone();
9628 if (phone == null) return -1;
9629 HalVersion hv = phone.getHalVersion();
9630 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9631 return hv.major * 100 + hv.minor;
9632 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009633
9634 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009635 * Get the current calling package name.
9636 * @return the current calling package name
9637 */
9638 @Override
9639 public String getCurrentPackageName() {
9640 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9641 }
9642
9643 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009644 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9645 * corresponding network requests on a subId.
9646 *
9647 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009648 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009649 * 2) APN is un-metered for this subscription, or
9650 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009651 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009652 *
9653 * @return whether data is allowed for a apn type.
9654 *
9655 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009656 */
9657 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009658 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009659 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9660 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009661
9662 // Now that all security checks passes, perform the operation as ourselves.
9663 final long identity = Binder.clearCallingIdentity();
9664 try {
9665 Phone phone = getPhone(subId);
9666 if (phone == null) return false;
9667
Jack Yu41407ee2019-05-13 16:54:09 -07009668 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009669 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9670 } finally {
9671 Binder.restoreCallingIdentity(identity);
9672 }
9673 }
9674
9675 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009676 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009677 enforceReadPrivilegedPermission("isApnMetered");
9678
9679 // Now that all security checks passes, perform the operation as ourselves.
9680 final long identity = Binder.clearCallingIdentity();
9681 try {
9682 Phone phone = getPhone(subId);
9683 if (phone == null) return true; // By default return true.
9684
Jack Yu41407ee2019-05-13 16:54:09 -07009685 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009686 } finally {
9687 Binder.restoreCallingIdentity(identity);
9688 }
9689 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009690
9691 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009692 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9693 int subscriptionId, IBooleanConsumer resultCallback) {
9694 enforceModifyPermission();
9695 long token = Binder.clearCallingIdentity();
9696 try {
9697 Phone phone = getPhone(subscriptionId);
9698 if (phone == null) {
9699 try {
9700 if (resultCallback != null) {
9701 resultCallback.accept(false);
9702 }
9703 } catch (RemoteException e) {
9704 // ignore
9705 }
9706 return;
9707 }
9708 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9709 Pair.create(specifiers, (x) -> {
9710 try {
9711 if (resultCallback != null) {
9712 resultCallback.accept(x);
9713 }
9714 } catch (RemoteException e) {
9715 // ignore
9716 }
9717 });
9718 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9719 } finally {
9720 Binder.restoreCallingIdentity(token);
9721 }
9722 }
9723
9724 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009725 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9726 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009727 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009728 mApp, subId, "getSystemSelectionChannels");
9729 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9730 final long identity = Binder.clearCallingIdentity();
9731 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009732 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9733 if (result instanceof IllegalStateException) {
9734 throw (IllegalStateException) result;
9735 }
9736 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009737 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9738 return specifiers;
9739 } finally {
9740 Binder.restoreCallingIdentity(identity);
9741 }
9742 }
9743
9744 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009745 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009746 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009747 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9748 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9749 if (iccRecords == null) {
9750 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9751 return false;
9752 }
9753 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9754 }
9755
9756 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009757 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9758 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009759 if (callingPackage == null) {
9760 callingPackage = getCurrentPackageName();
9761 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009762 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9763 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009764 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9765 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009766 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9767 }
9768 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9769 Intent intent = new Intent();
9770 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9771 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9772 // Bring up choose default SMS subscription dialog right now
9773 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9774 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9775 mApp.startActivity(intent);
9776 }
chen xud5ca2d52019-05-28 15:20:57 -07009777
9778 @Override
9779 public String getMmsUAProfUrl(int subId) {
9780 //TODO investigate if this API should require proper permission check in R b/133791609
9781 final long identity = Binder.clearCallingIdentity();
9782 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009783 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9784 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9785 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9786 return carrierUAProfUrl;
9787 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009788 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9789 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009790 } finally {
9791 Binder.restoreCallingIdentity(identity);
9792 }
9793 }
9794
9795 @Override
9796 public String getMmsUserAgent(int subId) {
9797 //TODO investigate if this API should require proper permission check in R b/133791609
9798 final long identity = Binder.clearCallingIdentity();
9799 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009800 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9801 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9802 if (!TextUtils.isEmpty(carrierUserAgent)) {
9803 return carrierUserAgent;
9804 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009805 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9806 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009807 } finally {
9808 Binder.restoreCallingIdentity(identity);
9809 }
9810 }
Jack Yub07d4972019-05-28 16:12:25 -07009811
9812 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009813 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9814 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009815
Jack Yub07d4972019-05-28 16:12:25 -07009816 final long identity = Binder.clearCallingIdentity();
9817 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009818 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009819 if (phone == null) return false;
9820
Hall Liua62f5da2020-09-25 10:42:19 -07009821 switch (policy) {
9822 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9823 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9824 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9825 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9826 default:
9827 throw new IllegalArgumentException(policy + " is not a valid policy");
9828 }
Jack Yub07d4972019-05-28 16:12:25 -07009829 } finally {
9830 Binder.restoreCallingIdentity(identity);
9831 }
9832 }
9833
9834 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009835 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009836 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009837 enforceModifyPermission();
9838
changbettyd5c246e2019-12-24 15:40:37 +08009839 final long identity = Binder.clearCallingIdentity();
9840 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009841 Phone phone = getPhone(subscriptionId);
9842 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009843
Hall Liua62f5da2020-09-25 10:42:19 -07009844 switch (policy) {
9845 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9846 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9847 break;
9848 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9849 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9850 break;
9851 default:
9852 throw new IllegalArgumentException(policy + " is not a valid policy");
9853 }
changbettyd5c246e2019-12-24 15:40:37 +08009854 } finally {
9855 Binder.restoreCallingIdentity(identity);
9856 }
9857 }
9858
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009859 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009860 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009861 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9862 * otherwise.
9863 */
9864 @Override
9865 public void setCepEnabled(boolean isCepEnabled) {
9866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9867
9868 final long identity = Binder.clearCallingIdentity();
9869 try {
9870 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9871 for (Phone phone : PhoneFactory.getPhones()) {
9872 Phone defaultPhone = phone.getImsPhone();
9873 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9874 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9875 ImsPhoneCallTracker imsPhoneCallTracker =
9876 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9877 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9878 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9879 + imsPhone.getMsisdn());
9880 }
9881 }
9882 } finally {
9883 Binder.restoreCallingIdentity(identity);
9884 }
9885 }
allenwtsu46dcc572020-01-08 18:24:03 +08009886
9887 /**
9888 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9889 *
9890 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9891 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9892 * before being read.
9893 */
9894 @Override
9895 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9896 isCompressed) {
9897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9898 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009899 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9900 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9901 }
9902 if (!isImsAvailableOnDevice()) {
9903 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9904 "IMS not available on device.");
9905 }
9906
9907 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009908 try {
Hui Wang761a6682020-10-31 05:12:53 +00009909 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9910 } finally {
9911 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009912 }
9913 }
zoey chene02881a2019-12-30 16:11:23 +08009914
9915 @Override
9916 public boolean isIccLockEnabled(int subId) {
9917 enforceReadPrivilegedPermission("isIccLockEnabled");
9918
9919 // Now that all security checks passes, perform the operation as ourselves.
9920 final long identity = Binder.clearCallingIdentity();
9921 try {
9922 Phone phone = getPhone(subId);
9923 if (phone != null && phone.getIccCard() != null) {
9924 return phone.getIccCard().getIccLockEnabled();
9925 } else {
9926 return false;
9927 }
9928 } finally {
9929 Binder.restoreCallingIdentity(identity);
9930 }
9931 }
9932
9933 /**
9934 * Set the ICC pin lock enabled or disabled.
9935 *
9936 * @return an integer representing the status of IccLock enabled or disabled in the following
9937 * three cases:
9938 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9939 * successfully.
9940 * - Positive number and zero for remaining password attempts.
9941 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9942 *
9943 */
9944 @Override
9945 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9946 enforceModifyPermission();
9947
9948 Phone phone = getPhone(subId);
9949 if (phone == null) {
9950 return 0;
9951 }
9952 // Now that all security checks passes, perform the operation as ourselves.
9953 final long identity = Binder.clearCallingIdentity();
9954 try {
9955 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9956 new Pair<Boolean, String>(enabled, password), phone, null);
9957 return attemptsRemaining;
9958
9959 } catch (Exception e) {
9960 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9961 } finally {
9962 Binder.restoreCallingIdentity(identity);
9963 }
9964 return 0;
9965 }
9966
9967 /**
9968 * Change the ICC password used in ICC pin lock.
9969 *
9970 * @return an integer representing the status of IccLock changed in the following three cases:
9971 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9972 * - Positive number and zero for remaining password attempts.
9973 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9974 *
9975 */
9976 @Override
9977 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9978 enforceModifyPermission();
9979
9980 Phone phone = getPhone(subId);
9981 if (phone == null) {
9982 return 0;
9983 }
9984 // Now that all security checks passes, perform the operation as ourselves.
9985 final long identity = Binder.clearCallingIdentity();
9986 try {
9987 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9988 new Pair<String, String>(oldPassword, newPassword), phone, null);
9989 return attemptsRemaining;
9990
9991 } catch (Exception e) {
9992 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9993 } finally {
9994 Binder.restoreCallingIdentity(identity);
9995 }
9996 return 0;
9997 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009998
9999 /**
10000 * Request for receiving user activity notification
10001 */
10002 @Override
10003 public void requestUserActivityNotification() {
10004 if (!mNotifyUserActivity.get()
10005 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10006 mNotifyUserActivity.set(true);
10007 }
10008 }
10009
10010 /**
10011 * Called when userActivity is signalled in the power manager.
10012 * This is safe to call from any thread, with any window manager locks held or not.
10013 */
10014 @Override
10015 public void userActivity() {
10016 // ***************************************
10017 // * Inherited from PhoneWindowManager *
10018 // ***************************************
10019 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10020 // WITH ITS LOCKS HELD.
10021 //
10022 // This code must be VERY careful about the locks
10023 // it acquires.
10024 // In fact, the current code acquires way too many,
10025 // and probably has lurking deadlocks.
10026
10027 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10028 throw new SecurityException("Only the OS may call notifyUserActivity()");
10029 }
10030
10031 if (mNotifyUserActivity.getAndSet(false)) {
10032 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10033 USER_ACTIVITY_NOTIFICATION_DELAY);
10034 }
10035 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010036
10037 @Override
10038 public boolean canConnectTo5GInDsdsMode() {
10039 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10040 }
Jack Yud10cdd42020-09-28 20:28:01 -070010041
10042 @Override
10043 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10044 String callingFeatureId) {
10045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10046 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10047 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10048 }
10049
10050 Phone phone = getPhone(subId);
10051 if (phone == null) {
10052 throw new RuntimeException("phone is not available");
10053 }
10054 // Now that all security checks passes, perform the operation as ourselves.
10055 final long identity = Binder.clearCallingIdentity();
10056 try {
10057 return phone.getEquivalentHomePlmns();
10058 } finally {
10059 Binder.restoreCallingIdentity(identity);
10060 }
10061 }
Daniel Bright59e67312020-11-13 11:49:37 -080010062
10063 @Override
10064 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010065 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10066 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010067 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010068 if (radioInterfaceCapabilities == null) {
10069 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010070 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010071 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010072 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010073
Hui Wang641e81c2020-10-12 12:14:23 -070010074 @Override
10075 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10076 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010077 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10078 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10079 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10080 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10081 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010082 if (DBG) {
10083 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10084 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10085 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10086 }
10087
10088 if (!SubscriptionManager.isValidSubscriptionId(subId)
10089 || appType < TelephonyManager.APPTYPE_UNKNOWN
10090 || appType > TelephonyManager.APPTYPE_ISIM
10091 || nafUrl == null || securityProtocol == null || callback == null) {
10092 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10093 if (callback != null) {
10094 try {
10095 callback.onAuthenticationFailure(
10096 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10097 } catch (RemoteException exception) {
10098 log("Fail to notify onAuthenticationFailure due to " + exception);
10099 }
10100 return;
10101 }
10102 }
10103
10104 final long token = Binder.clearCallingIdentity();
10105 try {
10106 getGbaManager(subId).bootstrapAuthenticationRequest(
10107 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10108 forceBootStrapping, callback));
10109 } finally {
10110 Binder.restoreCallingIdentity(token);
10111 }
10112 }
10113
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010114 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010115 * Attempts to set the radio power state for all phones for thermal reason.
10116 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010117 * requested radio power state will actually be set. See {@link
10118 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10119 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010120 * @param enable {@code true} if trying to turn radio on.
10121 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10122 * false}.
10123 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010124 private boolean setRadioPowerForThermal(boolean enable) {
10125 boolean isPhoneAvailable = false;
10126 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10127 Phone phone = PhoneFactory.getPhone(i);
10128 if (phone != null) {
10129 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10130 isPhoneAvailable = true;
10131 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010132 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010133
10134 // return true if successfully informed the phone object about the thermal radio power
10135 // request.
10136 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010137 }
10138
10139 private int handleDataThrottlingRequest(int subId,
10140 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010141 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10142 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10143 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10144 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10145 throw new IllegalArgumentException("modem does not support data throttling");
10146 }
10147
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010148 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10149 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010150 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010151 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10152 }
10153
10154 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10155
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010156 if (isDataThrottlingSupported) {
10157 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010158 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010159 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10160 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10161 } else if (thermalMitigationResult
10162 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010163 log("Modem likely does not support data throttling on secondary carrier. Data " +
10164 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10165 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010166 }
10167 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010168 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010169
10170 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010171 }
10172
Jack Nudelman644b91a2021-03-12 14:09:48 -080010173 private static List<String> getThermalMitigationAllowlist(Context context) {
10174 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10175 for (String pckg : context.getResources()
10176 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10177 sThermalMitigationAllowlistedPackages.add(pckg);
10178 }
10179 }
10180
10181 return sThermalMitigationAllowlistedPackages;
10182 }
10183
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010184 private boolean isAnyPhoneInEmergencyState() {
10185 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10186 if (tm.isInEmergencyCall()) {
10187 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10188 return true;
10189 }
10190 for (Phone phone : PhoneFactory.getPhones()) {
10191 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10192 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10193 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10194 + phone.isInEcm());
10195 return true;
10196 }
10197 }
10198
10199 return false;
10200 }
10201
Jack Nudelman644b91a2021-03-12 14:09:48 -080010202 /**
10203 * Used by shell commands to add an authorized package name for thermal mitigation.
10204 * @param packageName name of package to be allowlisted
10205 * @param context
10206 */
10207 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10208 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10209 sThermalMitigationAllowlistedPackages.add(packageName);
10210 }
10211
10212 /**
10213 * Used by shell commands to remove an authorized package name for thermal mitigation.
10214 * @param packageName name of package to remove from allowlist
10215 * @param context
10216 */
10217 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10218 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10219 sThermalMitigationAllowlistedPackages.remove(packageName);
10220 }
10221
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010222 /**
10223 * Thermal mitigation request to control functionalities at modem.
10224 *
10225 * @param subId the id of the subscription.
10226 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010227 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010228 *
10229 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10230 */
10231 @Override
10232 @ThermalMitigationResult
10233 public int sendThermalMitigationRequest(
10234 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010235 ThermalMitigationRequest thermalMitigationRequest,
10236 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010237 enforceModifyPermission();
10238
Jack Nudelman644b91a2021-03-12 14:09:48 -080010239 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10240 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10241 .contains(callingPackage)) {
10242 throw new SecurityException("Calling package must be configured in the device config. "
10243 + "calling package: " + callingPackage);
10244 }
10245
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010246 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10247 final long identity = Binder.clearCallingIdentity();
10248
10249 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10250 try {
10251 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10252 switch (thermalMitigationAction) {
10253 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10254 thermalMitigationResult =
10255 handleDataThrottlingRequest(subId,
10256 thermalMitigationRequest.getDataThrottlingRequest());
10257 break;
10258 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10259 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10260 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10261 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10262 }
10263
10264 // Ensure that radio is on. If not able to power on due to phone being
10265 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010266 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010267 thermalMitigationResult =
10268 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10269 break;
10270 }
10271
10272 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10273 false);
10274 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10275 break;
10276 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10277 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10278 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10279 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10280 }
10281
10282 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10283 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010284 Phone phone = getPhone(subId);
10285 if (phone == null) {
10286 thermalMitigationResult =
10287 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10288 break;
10289 }
10290
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010291 TelephonyConnectionService service =
10292 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010293 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010294 Log.e(LOG_TAG, "An emergency call is pending");
10295 thermalMitigationResult =
10296 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10297 break;
10298 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010299 thermalMitigationResult =
10300 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10301 break;
10302 }
10303 } else {
10304 thermalMitigationResult =
10305 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10306 break;
10307 }
10308
10309 // Turn radio off. If not able to power off due to phone being unavailable,
10310 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010311 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010312 thermalMitigationResult =
10313 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10314 break;
10315 }
10316 thermalMitigationResult =
10317 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10318 break;
10319 default:
10320 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10321 + "not exist. Requested action: " + thermalMitigationAction);
10322 }
10323 } catch (IllegalArgumentException e) {
10324 throw e;
10325 } catch (Exception e) {
10326 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10327 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10328 } finally {
10329 Binder.restoreCallingIdentity(identity);
10330 }
10331
10332 if (DBG) {
10333 log("thermalMitigationRequest returning with thermalMitigationResult: "
10334 + thermalMitigationResult);
10335 }
10336
10337 return thermalMitigationResult;
10338 }
Hui Wang641e81c2020-10-12 12:14:23 -070010339
10340 /**
10341 * Set the GbaService Package Name that Telephony will bind to.
10342 *
10343 * @param subId The sim that the GbaService is associated with.
10344 * @param packageName The name of the package to be replaced with.
10345 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10346 */
10347 @Override
10348 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10349 enforceModifyPermission();
10350
10351 final long identity = Binder.clearCallingIdentity();
10352 try {
10353 return getGbaManager(subId).overrideServicePackage(packageName);
10354 } finally {
10355 Binder.restoreCallingIdentity(identity);
10356 }
10357 }
10358
10359 /**
10360 * Return the package name of the currently bound GbaService.
10361 *
10362 * @param subId The sim that the GbaService is associated with.
10363 * @return the package name of the GbaService configuration, null if GBA is not supported.
10364 */
10365 @Override
10366 public String getBoundGbaService(int subId) {
10367 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10368
10369 final long identity = Binder.clearCallingIdentity();
10370 try {
10371 return getGbaManager(subId).getServicePackage();
10372 } finally {
10373 Binder.restoreCallingIdentity(identity);
10374 }
10375 }
10376
10377 /**
10378 * Set the release time for telephony to unbind GbaService.
10379 *
10380 * @param subId The sim that the GbaService is associated with.
10381 * @param interval The release time to unbind GbaService by millisecond.
10382 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10383 */
10384 @Override
10385 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10386 enforceModifyPermission();
10387
10388 final long identity = Binder.clearCallingIdentity();
10389 try {
10390 return getGbaManager(subId).overrideReleaseTime(interval);
10391 } finally {
10392 Binder.restoreCallingIdentity(identity);
10393 }
10394 }
10395
10396 /**
10397 * Return the release time for telephony to unbind GbaService.
10398 *
10399 * @param subId The sim that the GbaService is associated with.
10400 * @return The release time to unbind GbaService by millisecond.
10401 */
10402 @Override
10403 public int getGbaReleaseTime(int subId) {
10404 enforceReadPrivilegedPermission("getGbaReleaseTime");
10405
10406 final long identity = Binder.clearCallingIdentity();
10407 try {
10408 return getGbaManager(subId).getReleaseTime();
10409 } finally {
10410 Binder.restoreCallingIdentity(identity);
10411 }
10412 }
10413
10414 private GbaManager getGbaManager(int subId) {
10415 GbaManager instance = GbaManager.getInstance(subId);
10416 if (instance == null) {
10417 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10418 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10419 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10420 }
10421 return instance;
10422 }
Hui Wang761a6682020-10-31 05:12:53 +000010423
10424 /**
10425 * indicate whether the device and the carrier can support
10426 * RCS VoLTE single registration.
10427 */
10428 @Override
10429 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010430 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10431 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10432 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10433 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010434
10435 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10436 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10437 }
10438
10439 final long identity = Binder.clearCallingIdentity();
10440 try {
10441 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10442 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010443 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10444 if (isCapable != null) {
10445 return isCapable;
10446 }
Hui Wang761a6682020-10-31 05:12:53 +000010447 }
Hui Wang67af90e2021-06-04 16:57:15 -070010448 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10449 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010450 } finally {
10451 Binder.restoreCallingIdentity(identity);
10452 }
10453 }
10454
10455 /**
10456 * Register RCS provisioning callback.
10457 */
10458 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010459 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010460 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010461 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010462 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010463 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10464 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010465
10466 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10467 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10468 }
10469 if (!isImsAvailableOnDevice()) {
10470 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10471 "IMS not available on device.");
10472 }
10473
10474 final long identity = Binder.clearCallingIdentity();
10475 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010476 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010477 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010478 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10479 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010480 }
Hui Wang761a6682020-10-31 05:12:53 +000010481 } finally {
10482 Binder.restoreCallingIdentity(identity);
10483 }
10484 }
10485
10486 /**
10487 * Unregister RCS provisioning callback.
10488 */
10489 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010490 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010491 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010492 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010493 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010494 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10495 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010496
10497 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10498 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10499 }
10500 if (!isImsAvailableOnDevice()) {
10501 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10502 "IMS not available on device.");
10503 }
10504
10505 final long identity = Binder.clearCallingIdentity();
10506 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010507 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010508 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010509 } finally {
10510 Binder.restoreCallingIdentity(identity);
10511 }
10512 }
10513
10514 /**
10515 * trigger RCS reconfiguration.
10516 */
10517 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010518 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10519 "triggerRcsReconfiguration",
10520 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010521
10522 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10523 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10524 }
10525 if (!isImsAvailableOnDevice()) {
10526 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10527 "IMS not available on device.");
10528 }
10529
10530 final long identity = Binder.clearCallingIdentity();
10531 try {
10532 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10533 } finally {
10534 Binder.restoreCallingIdentity(identity);
10535 }
10536 }
10537
10538 /**
10539 * Provide the client configuration parameters of the RCS application.
10540 */
10541 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010542 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10543 "setRcsClientConfiguration",
10544 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010545
10546 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10547 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10548 }
10549 if (!isImsAvailableOnDevice()) {
10550 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10551 "IMS not available on device.");
10552 }
10553
10554 final long identity = Binder.clearCallingIdentity();
10555
10556 try {
10557 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10558 if (configBinder == null) {
10559 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010560 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10561 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010562 } else {
10563 configBinder.setRcsClientConfiguration(rcc);
10564 }
10565 } catch (RemoteException e) {
10566 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010567 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10568 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010569 } finally {
10570 Binder.restoreCallingIdentity(identity);
10571 }
10572 }
10573
10574 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010575 * Enables or disables the test mode for RCS VoLTE single registration.
10576 */
10577 @Override
10578 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10579 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10580 "setRcsSingleRegistrationTestModeEnabled");
10581
10582 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10583 }
10584
10585 /**
10586 * Gets the test mode for RCS VoLTE single registration.
10587 */
10588 @Override
10589 public boolean getRcsSingleRegistrationTestModeEnabled() {
10590 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10591 "getRcsSingleRegistrationTestModeEnabled");
10592
10593 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10594 }
10595
10596 /**
Hui Wang761a6682020-10-31 05:12:53 +000010597 * Overrides the config of RCS VoLTE single registration enabled for the device.
10598 */
10599 @Override
10600 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10601 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10602 "setDeviceSingleRegistrationEnabledOverride");
10603 enforceModifyPermission();
10604
10605 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10606 : Boolean.parseBoolean(enabledStr);
10607 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010608 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010609 }
10610
10611 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010612 * Sends a device to device communication message. Only usable via shell.
10613 * @param message message to send.
10614 * @param value message value.
10615 */
10616 @Override
10617 public void sendDeviceToDeviceMessage(int message, int value) {
10618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010619 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010620 enforceModifyPermission();
10621
10622 final long identity = Binder.clearCallingIdentity();
10623 try {
10624 TelephonyConnectionService service =
10625 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10626 if (service == null) {
10627 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10628 return;
10629 }
10630 service.sendTestDeviceToDeviceMessage(message, value);
10631 } finally {
10632 Binder.restoreCallingIdentity(identity);
10633 }
10634 }
10635
Tyler Gunnbabbda02021-02-10 11:05:02 -080010636 /**
10637 * Sets the specified device to device transport active.
10638 * @param transport The transport to set active.
10639 */
10640 @Override
10641 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10643 "setActiveDeviceToDeviceTransport");
10644 enforceModifyPermission();
10645
10646 final long identity = Binder.clearCallingIdentity();
10647 try {
10648 TelephonyConnectionService service =
10649 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10650 if (service == null) {
10651 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10652 return;
10653 }
10654 service.setActiveDeviceToDeviceTransport(transport);
10655 } finally {
10656 Binder.restoreCallingIdentity(identity);
10657 }
10658 }
Tyler Gunn92479152021-01-20 16:30:10 -080010659
Tyler Gunnd4575212021-05-03 14:46:49 -070010660 @Override
10661 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10662 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10663 "setDeviceToDeviceForceEnabled");
10664
10665 final long identity = Binder.clearCallingIdentity();
10666 try {
10667 Arrays.stream(PhoneFactory.getPhones()).forEach(
10668 p -> {
10669 Phone thePhone = p.getImsPhone();
10670 if (thePhone != null && thePhone instanceof ImsPhone) {
10671 ImsPhone imsPhone = (ImsPhone) thePhone;
10672 CallTracker tracker = imsPhone.getCallTracker();
10673 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10674 ImsPhoneCallTracker imsPhoneCallTracker =
10675 (ImsPhoneCallTracker) tracker;
10676 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10677 }
10678 }
10679 }
10680 );
10681 } finally {
10682 Binder.restoreCallingIdentity(identity);
10683 }
10684 }
10685
Tyler Gunn92479152021-01-20 16:30:10 -080010686 /**
Hui Wang761a6682020-10-31 05:12:53 +000010687 * Gets the config of RCS VoLTE single registration enabled for the device.
10688 */
10689 @Override
10690 public boolean getDeviceSingleRegistrationEnabled() {
10691 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10692 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10693 }
10694
10695 /**
10696 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10697 */
10698 @Override
10699 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10700 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10701 "setCarrierSingleRegistrationEnabledOverride");
10702 enforceModifyPermission();
10703
10704 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10705 : Boolean.parseBoolean(enabledStr);
10706 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10707 subId, enabled);
10708 }
10709
10710 /**
10711 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10712 */
10713 @Override
10714 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10715 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10716 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10717 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010718
10719 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010720 * Overrides the ims feature validation result
10721 */
10722 @Override
10723 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10724 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10725 "setImsFeatureValidationOverride");
10726
10727 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10728 : Boolean.parseBoolean(enabledStr);
10729 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10730 subId, enabled);
10731 }
10732
10733 /**
10734 * Gets the ims feature validation override value
10735 */
10736 @Override
10737 public boolean getImsFeatureValidationOverride(int subId) {
10738 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10739 "getImsFeatureValidationOverride");
10740 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10741 }
10742
10743 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010744 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10745 * their mobile plan.
10746 */
10747 @Override
10748 public String getMobileProvisioningUrl() {
10749 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10750 final long identity = Binder.clearCallingIdentity();
10751 try {
10752 return getDefaultPhone().getMobileProvisioningUrl();
10753 } finally {
10754 Binder.restoreCallingIdentity(identity);
10755 }
10756 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010757
James.cf Linbcdf8b32021-01-14 16:44:13 +080010758 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010759 * Get the EAB contact from the EAB database.
10760 */
10761 @Override
10762 public String getContactFromEab(String contact) {
10763 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10764 enforceModifyPermission();
10765 final long identity = Binder.clearCallingIdentity();
10766 try {
10767 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10768 } finally {
10769 Binder.restoreCallingIdentity(identity);
10770 }
10771 }
10772
10773 /**
Calvin Pana1434322021-07-01 19:27:01 +080010774 * Get the EAB capability from the EAB database.
10775 */
10776 @Override
10777 public String getCapabilityFromEab(String contact) {
10778 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10779 enforceModifyPermission();
10780 final long identity = Binder.clearCallingIdentity();
10781 try {
10782 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10783 } finally {
10784 Binder.restoreCallingIdentity(identity);
10785 }
10786 }
10787
10788 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010789 * Remove the EAB contacts from the EAB database.
10790 */
10791 @Override
10792 public int removeContactFromEab(int subId, String contacts) {
10793 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10794 enforceModifyPermission();
10795 final long identity = Binder.clearCallingIdentity();
10796 try {
10797 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10798 } finally {
10799 Binder.restoreCallingIdentity(identity);
10800 }
10801 }
10802
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010803 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010804 public boolean getDeviceUceEnabled() {
10805 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10806 final long identity = Binder.clearCallingIdentity();
10807 try {
10808 return mApp.getDeviceUceEnabled();
10809 } finally {
10810 Binder.restoreCallingIdentity(identity);
10811 }
10812 }
10813
10814 @Override
10815 public void setDeviceUceEnabled(boolean isEnabled) {
10816 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10817 final long identity = Binder.clearCallingIdentity();
10818 try {
10819 mApp.setDeviceUceEnabled(isEnabled);
10820 } finally {
10821 Binder.restoreCallingIdentity(identity);
10822 }
10823 }
10824
Brad Ebinger14d467f2021-02-12 06:18:28 +000010825 /**
10826 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10827 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10828 */
10829 // Used for SHELL command only right now.
10830 @Override
10831 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10832 List<String> featureTags) {
10833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10834 "addUceRegistrationOverrideShell");
10835 final long identity = Binder.clearCallingIdentity();
10836 try {
10837 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10838 new ArraySet<>(featureTags));
10839 } catch (ImsException e) {
10840 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10841 } finally {
10842 Binder.restoreCallingIdentity(identity);
10843 }
10844 }
10845
10846 /**
10847 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10848 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10849 */
10850 // Used for SHELL command only right now.
10851 @Override
10852 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10853 List<String> featureTags) {
10854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10855 "removeUceRegistrationOverrideShell");
10856 final long identity = Binder.clearCallingIdentity();
10857 try {
10858 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10859 new ArraySet<>(featureTags));
10860 } catch (ImsException e) {
10861 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10862 } finally {
10863 Binder.restoreCallingIdentity(identity);
10864 }
10865 }
10866
10867 /**
10868 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10869 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10870 */
10871 // Used for SHELL command only right now.
10872 @Override
10873 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10874 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10875 "clearUceRegistrationOverrideShell");
10876 final long identity = Binder.clearCallingIdentity();
10877 try {
10878 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10879 } catch (ImsException e) {
10880 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10881 } finally {
10882 Binder.restoreCallingIdentity(identity);
10883 }
10884 }
10885
10886 /**
10887 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10888 */
10889 // Used for SHELL command only right now.
10890 @Override
10891 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10892 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10893 "getLatestRcsContactUceCapabilityShell");
10894 final long identity = Binder.clearCallingIdentity();
10895 try {
10896 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10897 } catch (ImsException e) {
10898 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10899 } finally {
10900 Binder.restoreCallingIdentity(identity);
10901 }
10902 }
10903
10904 /**
10905 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10906 * device does not have an active PUBLISH.
10907 */
10908 // Used for SHELL command only right now.
10909 @Override
10910 public String getLastUcePidfXmlShell(int subId) {
10911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10912 final long identity = Binder.clearCallingIdentity();
10913 try {
10914 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10915 } catch (ImsException e) {
10916 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10917 } finally {
10918 Binder.restoreCallingIdentity(identity);
10919 }
10920 }
10921
James.cf Line8713a42021-04-29 16:04:26 +080010922 /**
10923 * Remove UCE requests cannot be sent to the network status.
10924 */
10925 // Used for SHELL command only right now.
10926 @Override
10927 public boolean removeUceRequestDisallowedStatus(int subId) {
10928 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10929 final long identity = Binder.clearCallingIdentity();
10930 try {
10931 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10932 } catch (ImsException e) {
10933 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10934 } finally {
10935 Binder.restoreCallingIdentity(identity);
10936 }
10937 }
10938
James.cf Lin0fc71b02021-05-25 01:37:38 +080010939 /**
10940 * Remove UCE requests cannot be sent to the network status.
10941 */
10942 // Used for SHELL command only.
10943 @Override
10944 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10945 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10946 final long identity = Binder.clearCallingIdentity();
10947 try {
10948 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10949 } catch (ImsException e) {
10950 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10951 } finally {
10952 Binder.restoreCallingIdentity(identity);
10953 }
10954 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010955
James.cf Lin4b784aa2021-01-31 03:25:15 +080010956 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010957 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10958 String callingPackage) {
10959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10960 mApp, subId, "setSignalStrengthUpdateRequest");
10961
10962 final int callingUid = Binder.getCallingUid();
10963 // Verify that tha callingPackage belongs to the calling UID
10964 mApp.getSystemService(AppOpsManager.class)
10965 .checkPackage(callingUid, callingPackage);
10966
Rambo Wang3607f502021-02-01 21:51:40 -080010967 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010968
10969 final long identity = Binder.clearCallingIdentity();
10970 try {
10971 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10972 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10973
10974 if (result instanceof IllegalStateException) {
10975 throw (IllegalStateException) result;
10976 }
10977 } finally {
10978 Binder.restoreCallingIdentity(identity);
10979 }
10980 }
10981
10982 @Override
10983 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10984 String callingPackage) {
10985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10986 mApp, subId, "clearSignalStrengthUpdateRequest");
10987
10988 final int callingUid = Binder.getCallingUid();
10989 // Verify that tha callingPackage belongs to the calling UID
10990 mApp.getSystemService(AppOpsManager.class)
10991 .checkPackage(callingUid, callingPackage);
10992
10993 final long identity = Binder.clearCallingIdentity();
10994 try {
10995 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10996 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10997
10998 if (result instanceof IllegalStateException) {
10999 throw (IllegalStateException) result;
11000 }
11001 } finally {
11002 Binder.restoreCallingIdentity(identity);
11003 }
11004 }
11005
Rambo Wang3607f502021-02-01 21:51:40 -080011006 private static void validateSignalStrengthUpdateRequest(Context context,
11007 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011008 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11009 // phone/system process do not have further restriction on request
11010 return;
11011 }
11012
11013 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011014 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011015 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011016 context.enforceCallingOrSelfPermission(
11017 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11018 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011019 }
11020
11021 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11022 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11023 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11024 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11025 || info.isEnabled()) {
11026 throw new IllegalArgumentException(
11027 "Only system can set hide fields in SignalThresholdInfo");
11028 }
11029
11030 // Thresholds length for each RAN need in range. This has been validated in
11031 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11032 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11033 final int[] thresholds = info.getThresholds();
11034 Objects.requireNonNull(thresholds);
11035 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11036 || thresholds.length
11037 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11038 throw new IllegalArgumentException(
11039 "thresholds length is out of range: " + thresholds.length);
11040 }
11041 }
11042 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011043
11044 /**
11045 * Gets the current phone capability.
11046 *
11047 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11048 * @return the PhoneCapability which describes the data connection capability of modem.
11049 * It's used to evaluate possible phone config change, for example from single
11050 * SIM device to multi-SIM device.
11051 */
11052 @Override
11053 public PhoneCapability getPhoneCapability() {
11054 enforceReadPrivilegedPermission("getPhoneCapability");
11055 final long identity = Binder.clearCallingIdentity();
11056 try {
11057 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11058 } finally {
11059 Binder.restoreCallingIdentity(identity);
11060 }
11061 }
Michele Berionne5e411512020-11-13 02:36:59 +000011062
11063 /**
11064 * Prepare TelephonyManager for an unattended reboot. The reboot is
11065 * required to be done shortly after the API is invoked.
11066 */
11067 @Override
11068 @TelephonyManager.PrepareUnattendedRebootResult
11069 public int prepareForUnattendedReboot() {
11070 enforceRebootPermission();
11071
11072 final long identity = Binder.clearCallingIdentity();
11073 try {
11074 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
11075 } finally {
11076 Binder.restoreCallingIdentity(identity);
11077 }
11078 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011079
11080 /**
11081 * Request to get the current slicing configuration including URSP rules and
11082 * NSSAIs (configured, allowed and rejected).
11083 *
11084 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11085 */
11086 @Override
11087 public void getSlicingConfig(ResultReceiver callback) {
11088 enforceReadPrivilegedPermission("getSlicingConfig");
11089
11090 final long identity = Binder.clearCallingIdentity();
11091 try {
11092 Phone phone = getDefaultPhone();
11093 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11094 } finally {
11095 Binder.restoreCallingIdentity(identity);
11096 }
11097 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000011098
11099 /**
11100 * Register an IMS connection state callback
11101 */
11102 @Override
11103 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11104 String callingPackage) {
11105 if (feature == ImsFeature.FEATURE_MMTEL) {
11106 // ImsMmTelManager
11107 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11108 TelephonyPermissions
11109 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11110 mApp, subId, "registerImsStateCallback");
11111 } else if (feature == ImsFeature.FEATURE_RCS) {
11112 // ImsRcsManager or SipDelegateManager
11113 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11114 Binder.getCallingUid(), "registerImsStateCallback",
11115 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11116 Manifest.permission.READ_PRECISE_PHONE_STATE,
11117 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11118 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11119 }
11120
11121 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11122 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11123 "IMS not available on device.");
11124 }
11125
11126 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11127 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11128 }
11129
11130 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11131 if (controller == null) {
11132 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11133 "IMS not available on device.");
11134 }
11135
11136 if (callingPackage == null) {
11137 callingPackage = getCurrentPackageName();
11138 }
11139
11140 final long token = Binder.clearCallingIdentity();
11141 try {
11142 int slotId = getSlotIndexOrException(subId);
11143 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11144 } catch (ImsException e) {
11145 throw new ServiceSpecificException(e.getCode());
11146 } finally {
11147 Binder.restoreCallingIdentity(token);
11148 }
11149 }
11150
11151 /**
11152 * Unregister an IMS connection state callback
11153 */
11154 @Override
11155 public void unregisterImsStateCallback(IImsStateCallback cb) {
11156 final long token = Binder.clearCallingIdentity();
11157 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11158 if (controller == null) {
11159 return;
11160 }
11161 try {
11162 controller.unregisterImsStateCallback(cb);
11163 } finally {
11164 Binder.restoreCallingIdentity(token);
11165 }
11166 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011167
11168 /**
11169 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11170 *
11171 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11172 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11173 * SecurityException.
11174 * If there is current registered network this value will be same as the registered cell
11175 * identity. If the device goes out of service the previous cell identity is cached and
11176 * will be returned. If the cache age of the Cell identity is more than 24 hours
11177 * it will be cleared and null will be returned.
11178 *
11179 */
11180 @Override
11181 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11182 String callingFeatureId) {
11183 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11184 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11185 LocationAccessPolicy.checkLocationPermission(mApp,
11186 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11187 .setCallingPackage(callingPackage)
11188 .setCallingFeatureId(callingFeatureId)
11189 .setCallingPid(Binder.getCallingPid())
11190 .setCallingUid(Binder.getCallingUid())
11191 .setMethod("getLastKnownCellIdentity")
11192 .setLogAsInfo(true)
11193 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11194 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11195 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11196 .build());
11197
11198 boolean hasFinePermission =
11199 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11200 if (!hasFinePermission
11201 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11202 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11203 + "and BIND_CONNECTION_SERVICE permission.");
11204 }
11205
11206 final long identity = Binder.clearCallingIdentity();
11207 try {
11208 Phone phone = getPhone(subId);
11209 if (phone == null) return null;
11210 ServiceStateTracker sst = phone.getServiceStateTracker();
11211 if (sst == null) return null;
11212 return sst.getLastKnownCellIdentity();
11213 } finally {
11214 Binder.restoreCallingIdentity(identity);
11215 }
11216 }
jimsun38340bf2021-10-26 15:01:23 +080011217
11218 /**
11219 * Sets the modem service class Name that Telephony will bind to.
11220 *
11221 * @param serviceName The class name of the modem service.
11222 * @return true if the operation is succeed, otherwise false.
11223 */
11224 public boolean setModemService(String serviceName) {
11225 Log.d(LOG_TAG, "setModemService - " + serviceName);
11226 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11228 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11229 "setModemService");
11230 return mPhoneConfigurationManager.setModemService(serviceName);
11231 }
11232
11233 /**
11234 * Return the class name of the currently bounded modem service.
11235 *
11236 * @return the class name of the modem service.
11237 */
11238 public String getModemService() {
11239 String result;
11240 Log.d(LOG_TAG, "getModemService");
11241 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11242 TelephonyPermissions
11243 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11244 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11245 "getModemService");
11246 result = mPhoneConfigurationManager.getModemService();
11247 Log.d(LOG_TAG, "result = " + result);
11248 return result;
11249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011250}