blob: a807b11fc602d1b430f41d803b7636bb460d3c7d [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;
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +0000224import java.util.Collection;
sandeepjs0a502c42021-09-27 15:34:44 +0000225import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800226import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800227import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800228import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100229import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800230import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700231import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800232import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800233import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800234import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800235import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800236import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
238/**
239 * Implementation of the ITelephony interface.
240 */
Santos Cordon117fee72014-05-16 17:56:12 -0700241public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242 private static final String LOG_TAG = "PhoneInterfaceManager";
243 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
244 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800245 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246
247 // Message codes used with mMainThreadHandler
248 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700249 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
250 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700251 private static final int CMD_OPEN_CHANNEL = 9;
252 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
253 private static final int CMD_CLOSE_CHANNEL = 11;
254 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800255 private static final int CMD_NV_READ_ITEM = 13;
256 private static final int EVENT_NV_READ_ITEM_DONE = 14;
257 private static final int CMD_NV_WRITE_ITEM = 15;
258 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
259 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
260 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700261 private static final int CMD_RESET_MODEM_CONFIG = 19;
262 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800263 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
264 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800265 private static final int CMD_SEND_ENVELOPE = 25;
266 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000267 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
268 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700269 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
270 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
271 private static final int CMD_EXCHANGE_SIM_IO = 31;
272 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800273 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
274 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700275 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
276 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700277 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
278 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700279 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
280 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
281 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
282 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700283 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
284 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
285 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
286 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700287 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800288 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
289 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000290 private static final int CMD_SWITCH_SLOTS = 50;
291 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700292 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
293 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
294 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
295 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
296 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
297 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
298 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
299 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700300 private static final int CMD_GET_ALL_CELL_INFO = 60;
301 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
302 private static final int CMD_GET_CELL_LOCATION = 62;
303 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700304 private static final int CMD_MODEM_REBOOT = 64;
305 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700306 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
307 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800308 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
309 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700310 private static final int CMD_GET_MODEM_STATUS = 70;
311 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700312 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
313 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700314 private static final int CMD_ERASE_MODEM_CONFIG = 74;
315 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800316 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
317 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
318 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
319 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800320 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
321 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800322 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800323 private static final int CMD_GET_CALL_FORWARDING = 83;
324 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
325 private static final int CMD_SET_CALL_FORWARDING = 85;
326 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
327 private static final int CMD_GET_CALL_WAITING = 87;
328 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
329 private static final int CMD_SET_CALL_WAITING = 89;
330 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700331 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
332 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
333 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
334 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700335 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
336 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800337 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
338 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800339 private static final int CMD_SET_DATA_THROTTLING = 99;
340 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800341 private static final int CMD_SET_SIM_POWER = 101;
342 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800343 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
344 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
345 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
346 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800347 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
348 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000349 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800350 private static final int CMD_GET_SLICING_CONFIG = 110;
351 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800352 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700353 private static final int CMD_ENABLE_VONR = 113;
354 private static final int EVENT_ENABLE_VONR_DONE = 114;
355 private static final int CMD_IS_VONR_ENABLED = 115;
356 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800358 // Parameters of select command.
359 private static final int SELECT_COMMAND = 0xA4;
360 private static final int SELECT_P1 = 0x04;
361 private static final int SELECT_P2 = 0;
362 private static final int SELECT_P3 = 0x10;
363
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 /** The singleton instance. */
365 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800366 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367
Wink Saville3ab207e2014-11-20 13:07:20 -0800368 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800370 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700371 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800372 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700373 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800375 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700377 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800378 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379
Peter Wangdafb9ac2020-01-15 14:13:38 -0800380 /** User Activity */
381 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800382 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
383
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700384 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
385
Derek Tan97ebb422014-09-05 16:55:38 -0700386 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
387 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800388 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800389 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700390
Michelecea4cf22018-12-21 15:00:11 -0800391 // String to store multi SIM allowed
392 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
393
Derek Tan740e1672017-06-27 14:56:27 -0700394 // The AID of ISD-R.
395 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
396
yinxub1bed742017-04-17 11:45:04 -0700397 private NetworkScanRequestTracker mNetworkScanRequestTracker;
398
David Kelly5e06a7f2018-03-12 14:10:59 +0000399 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
400 private static final int MANUFACTURER_CODE_LENGTH = 8;
401
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800402 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800403 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800404
Derek Tan89e89d42014-07-08 17:00:10 -0700405 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700406 * Experiment flag to enable erase modem config on reset network, default value is false
407 */
408 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
409 "reset_network_erase_modem_config_enabled";
410
Rambo Wang0f050d82021-02-12 11:43:36 -0800411 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
sandeepjs0a502c42021-09-27 15:34:44 +0000412 /**
413 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
414 * one ICCID active at the same time.
415 * Apps should use below API signatures if targeting SDK is T and beyond.
416 *
417 * @hide
418 */
419 @ChangeId
420 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
421 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800422
Naina Nallurid63128d2019-09-17 14:10:30 -0700423 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 * A request object to use for transmitting data to an ICC.
425 */
426 private static final class IccAPDUArgument {
427 public int channel, cla, command, p1, p2, p3;
428 public String data;
429
430 public IccAPDUArgument(int channel, int cla, int command,
431 int p1, int p2, int p3, String data) {
432 this.channel = channel;
433 this.cla = cla;
434 this.command = command;
435 this.p1 = p1;
436 this.p2 = p2;
437 this.p3 = p3;
438 this.data = data;
439 }
440 }
441
442 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700443 * A request object to use for transmitting data to an ICC.
444 */
445 private static final class ManualNetworkSelectionArgument {
446 public OperatorInfo operatorInfo;
447 public boolean persistSelection;
448
449 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
450 this.operatorInfo = operatorInfo;
451 this.persistSelection = persistSelection;
452 }
453 }
454
455 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
457 * request after sending. The main thread will notify the request when it is complete.
458 */
459 private static final class MainThreadRequest {
460 /** The argument to use for the request */
461 public Object argument;
462 /** The result of the request that is run on the main thread */
463 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800464 // The subscriber id that this request applies to. Defaults to
465 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
466 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467
Nathan Harold92bed182018-10-12 18:16:49 -0700468 // In cases where subId is unavailable, the caller needs to specify the phone.
469 public Phone phone;
470
vagdeviaf9a5b92018-08-15 16:01:53 -0700471 public WorkSource workSource;
472
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 public MainThreadRequest(Object argument) {
474 this.argument = argument;
475 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800476
Nathan Harold92bed182018-10-12 18:16:49 -0700477 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
478 this.argument = argument;
479 if (phone != null) {
480 this.phone = phone;
481 }
482 this.workSource = workSource;
483 }
484
vagdeviaf9a5b92018-08-15 16:01:53 -0700485 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800486 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800487 if (subId != null) {
488 this.subId = subId;
489 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700490 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492 }
493
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800494 private static final class IncomingThirdPartyCallArgs {
495 public final ComponentName component;
496 public final String callId;
497 public final String callerDisplayName;
498
499 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
500 String callerDisplayName) {
501 this.component = component;
502 this.callId = callId;
503 this.callerDisplayName = callerDisplayName;
504 }
505 }
506
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 /**
508 * A handler that processes messages on the main thread in the phone process. Since many
509 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
510 * inbound binder threads to the main thread in the phone process. The Binder thread
511 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
512 * on, which will be notified when the operation completes and will contain the result of the
513 * request.
514 *
515 * <p>If a MainThreadRequest object is provided in the msg.obj field,
516 * note that request.result must be set to something non-null for the calling thread to
517 * unblock.
518 */
519 private final class MainThreadHandler extends Handler {
520 @Override
521 public void handleMessage(Message msg) {
522 MainThreadRequest request;
523 Message onCompleted;
524 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000525 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800527 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528
529 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 case CMD_HANDLE_USSD_REQUEST: {
531 request = (MainThreadRequest) msg.obj;
532 final Phone phone = getPhoneFromRequest(request);
533 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
534 String ussdRequest = ussdObject.first;
535 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700536
Pengquan Menga1bb6272018-09-06 09:59:22 -0700537 if (!isUssdApiAllowed(request.subId)) {
538 // Carrier does not support use of this API, return failure.
539 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
540 UssdResponse response = new UssdResponse(ussdRequest, null);
541 Bundle returnData = new Bundle();
542 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
543 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700544
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 request.result = true;
546 notifyRequester(request);
547 return;
548 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700549
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 try {
551 request.result = phone != null
552 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
553 } catch (CallStateException cse) {
554 request.result = false;
555 }
556 // Wake up the requesting thread
557 notifyRequester(request);
558 break;
pkanwar32d516d2016-10-14 19:37:38 -0700559 }
560
Yorke Lee716f67e2015-06-17 15:39:16 -0700561 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700563 final Phone phone = getPhoneFromRequest(request);
564 request.result = phone != null ?
565 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
566 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000575 uiccPort = getUiccPortFromRequest(request);
576 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 loge("iccTransmitApduLogicalChannel: No UICC");
578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
582 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000583 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 iccArgument.channel, iccArgument.cla, iccArgument.command,
585 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 ar = (AsyncResult) msg.obj;
592 request = (MainThreadRequest) ar.userObj;
593 if (ar.exception == null && ar.result != null) {
594 request.result = ar.result;
595 } else {
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
597 if (ar.result == null) {
598 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800599 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800601 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 } else {
603 loge("iccTransmitApduLogicalChannel: Unknown exception");
604 }
605 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 break;
608
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
610 request = (MainThreadRequest) msg.obj;
611 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000612 uiccPort = getUiccPortFromRequest(request);
613 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 loge("iccTransmitApduBasicChannel: No UICC");
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 } else {
618 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
619 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000620 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
622 iccArgument.p3, iccArgument.data, onCompleted);
623 }
624 break;
625
626 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
627 ar = (AsyncResult) msg.obj;
628 request = (MainThreadRequest) ar.userObj;
629 if (ar.exception == null && ar.result != null) {
630 request.result = ar.result;
631 } else {
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
633 if (ar.result == null) {
634 loge("iccTransmitApduBasicChannel: Empty response");
635 } else if (ar.exception instanceof CommandException) {
636 loge("iccTransmitApduBasicChannel: CommandException: " +
637 ar.exception);
638 } else {
639 loge("iccTransmitApduBasicChannel: Unknown exception");
640 }
641 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 break;
644
645 case CMD_EXCHANGE_SIM_IO:
646 request = (MainThreadRequest) msg.obj;
647 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000648 uiccPort = getUiccPortFromRequest(request);
649 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 loge("iccExchangeSimIO: No UICC");
651 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 } else {
654 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
655 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000656 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
658 iccArgument.data, onCompleted);
659 }
660 break;
661
662 case EVENT_EXCHANGE_SIM_IO_DONE:
663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result;
667 } else {
668 request.result = new IccIoResult(0x6f, 0, (byte[])null);
669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 break;
672
Derek Tan4d5e5c12014-02-04 11:54:58 -0800673 case CMD_SEND_ENVELOPE:
674 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000675 uiccPort = getUiccPortFromRequest(request);
676 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 loge("sendEnvelopeWithStatus: No UICC");
678 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 } else {
681 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000682 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 break;
685
686 case EVENT_SEND_ENVELOPE_DONE:
687 ar = (AsyncResult) msg.obj;
688 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700689 if (ar.exception == null && ar.result != null) {
690 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800691 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700692 request.result = new IccIoResult(0x6F, 0, (byte[])null);
693 if (ar.result == null) {
694 loge("sendEnvelopeWithStatus: Empty response");
695 } else if (ar.exception instanceof CommandException) {
696 loge("sendEnvelopeWithStatus: CommandException: " +
697 ar.exception);
698 } else {
699 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
700 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800701 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700702 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800703 break;
704
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 case CMD_OPEN_CHANNEL:
706 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000707 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800708 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000709 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700710 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800711 request.result = new IccOpenLogicalChannelResponse(-1,
712 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700713 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700714 } else {
715 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000716 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800717 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 break;
720
721 case EVENT_OPEN_CHANNEL_DONE:
722 ar = (AsyncResult) msg.obj;
723 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700725 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 int[] result = (int[]) ar.result;
727 int channelId = result[0];
728 byte[] selectResponse = null;
729 if (result.length > 1) {
730 selectResponse = new byte[result.length - 1];
731 for (int i = 1; i < result.length; ++i) {
732 selectResponse[i - 1] = (byte) result[i];
733 }
734 }
735 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700736 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 if (ar.result == null) {
739 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700741 if (ar.exception != null) {
742 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
743 }
744
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700745 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700746 if (ar.exception instanceof CommandException) {
747 CommandException.Error error =
748 ((CommandException) (ar.exception)).getCommandError();
749 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700750 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700751 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700752 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700753 }
754 }
755 openChannelResp = new IccOpenLogicalChannelResponse(
756 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700758 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700759 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 break;
761
762 case CMD_CLOSE_CHANNEL:
763 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000764 uiccPort = getUiccPortFromRequest(request);
765 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700766 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900767 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700768 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 } else {
770 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000771 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700772 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 break;
774
775 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800776 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
777 break;
778
779 case CMD_NV_READ_ITEM:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
783 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800784 break;
785
786 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800789 if (ar.exception == null && ar.result != null) {
790 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700791 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800792 request.result = "";
793 if (ar.result == null) {
794 loge("nvReadItem: Empty response");
795 } else if (ar.exception instanceof CommandException) {
796 loge("nvReadItem: CommandException: " +
797 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800799 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 }
801 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700802 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 break;
804
Jake Hambye994d462014-02-03 13:10:13 -0800805 case CMD_NV_WRITE_ITEM:
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
808 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800809 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700810 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800811 break;
812
813 case EVENT_NV_WRITE_ITEM_DONE:
814 handleNullReturnEvent(msg, "nvWriteItem");
815 break;
816
817 case CMD_NV_WRITE_CDMA_PRL:
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800820 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800821 break;
822
823 case EVENT_NV_WRITE_CDMA_PRL_DONE:
824 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
825 break;
826
chen xu6dac5ab2018-10-26 17:39:23 -0700827 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800828 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700829 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800830 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800831 break;
832
chen xu6dac5ab2018-10-26 17:39:23 -0700833 case EVENT_RESET_MODEM_CONFIG_DONE:
834 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800835 break;
836
Sooraj Sasindran37444802020-08-11 10:40:43 -0700837 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
838 request = (MainThreadRequest) msg.obj;
839 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
840 request);
841 Phone phone = getPhoneFromRequest(request);
842 if (phone != null) {
843 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
844 } else {
845 loge("isNRDualConnectivityEnabled: No phone object");
846 request.result = false;
847 notifyRequester(request);
848 }
849 break;
850 }
851
852 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result;
857 } else {
858 // request.result must be set to something non-null
859 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700860 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700861 request.result = ar.result;
862 } else {
863 request.result = false;
864 }
865 if (ar.result == null) {
866 loge("isNRDualConnectivityEnabled: Empty response");
867 } else if (ar.exception instanceof CommandException) {
868 loge("isNRDualConnectivityEnabled: CommandException: "
869 + ar.exception);
870 } else {
871 loge("isNRDualConnectivityEnabled: Unknown exception");
872 }
873 }
874 notifyRequester(request);
875 break;
876
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700877 case CMD_IS_VONR_ENABLED: {
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
880 request);
881 Phone phone = getPhoneFromRequest(request);
882 if (phone != null) {
883 phone.isVoNrEnabled(onCompleted, request.workSource);
884 } else {
885 loge("isVoNrEnabled: No phone object");
886 request.result = false;
887 notifyRequester(request);
888 }
889 break;
890 }
891
892 case EVENT_IS_VONR_ENABLED_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result;
897 } else {
898 // request.result must be set to something non-null
899 // for the calling thread to unblock
900 if (ar.result != null) {
901 request.result = ar.result;
902 } else {
903 request.result = false;
904 }
905 if (ar.result == null) {
906 loge("isVoNrEnabled: Empty response");
907 } else if (ar.exception instanceof CommandException) {
908 loge("isVoNrEnabled: CommandException: "
909 + ar.exception);
910 } else {
911 loge("isVoNrEnabled: Unknown exception");
912 }
913 }
914 notifyRequester(request);
915 break;
916
Sooraj Sasindran37444802020-08-11 10:40:43 -0700917 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
918 request = (MainThreadRequest) msg.obj;
919 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
920 Phone phone = getPhoneFromRequest(request);
921 if (phone != null) {
922 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
923 request.workSource);
924 } else {
925 loge("enableNrDualConnectivity: No phone object");
926 request.result =
927 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
928 notifyRequester(request);
929 }
930 break;
931 }
932
933 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
936 if (ar.exception == null) {
937 request.result =
938 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
939 } else {
940 request.result =
941 TelephonyManager
942 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
943 if (ar.exception instanceof CommandException) {
944 CommandException.Error error =
945 ((CommandException) (ar.exception)).getCommandError();
946 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
947 request.result =
948 TelephonyManager
949 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000950 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
951 request.result =
952 TelephonyManager
953 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700954 }
955 loge("enableNrDualConnectivity" + ": CommandException: "
956 + ar.exception);
957 } else {
958 loge("enableNrDualConnectivity" + ": Unknown exception");
959 }
960 }
961 notifyRequester(request);
962 break;
963 }
964
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700965 case CMD_ENABLE_VONR: {
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
968 Phone phone = getPhoneFromRequest(request);
969 if (phone != null) {
970 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
971 request.workSource);
972 } else {
973 loge("setVoNrEnabled: No phone object");
974 request.result =
975 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
976 notifyRequester(request);
977 }
978 break;
979 }
980
981 case EVENT_ENABLE_VONR_DONE: {
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception == null) {
985 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
986 } else {
987 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
988 if (ar.exception instanceof CommandException) {
989 CommandException.Error error =
990 ((CommandException) (ar.exception)).getCommandError();
991 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
992 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
993 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
994 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
995 } else {
996 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
997 }
998 loge("setVoNrEnabled" + ": CommandException: "
999 + ar.exception);
1000 } else {
1001 loge("setVoNrEnabled" + ": Unknown exception");
1002 }
1003 }
1004 notifyRequester(request);
1005 break;
1006 }
1007
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001009 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1011 request);
1012 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001013 break;
1014
SongFerngWang3ef3e072020-12-21 16:41:52 +08001015 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception == null && ar.result != null) {
1019 request.result = ar.result; // Integer
1020 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301021 // request.result must be set to something non-null
1022 // for the calling thread to unblock
1023 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001024 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001025 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001026 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001027 loge("getAllowedNetworkTypesBitmask: CommandException: "
1028 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 }
1032 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001033 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001034 break;
1035
SongFerngWang3ef3e072020-12-21 16:41:52 +08001036 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001037 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001038 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1039 request);
1040 Pair<Integer, Long> reasonWithNetworkTypes =
1041 (Pair<Integer, Long>) request.argument;
1042 getPhoneFromRequest(request).setAllowedNetworkTypes(
1043 reasonWithNetworkTypes.first,
1044 reasonWithNetworkTypes.second,
1045 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001046 break;
1047
SongFerngWang3ef3e072020-12-21 16:41:52 +08001048 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1049 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001050 break;
1051
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001052 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1053 request = (MainThreadRequest)msg.obj;
1054 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001055 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001056 break;
1057
1058 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1059 ar = (AsyncResult)msg.obj;
1060 request = (MainThreadRequest)ar.userObj;
1061 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001062 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001063 break;
1064
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001065 case CMD_SET_VOICEMAIL_NUMBER:
1066 request = (MainThreadRequest) msg.obj;
1067 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1068 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001069 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1070 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001071 break;
1072
1073 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1074 handleNullReturnEvent(msg, "setVoicemailNumber");
1075 break;
1076
Stuart Scott54788802015-03-30 13:18:01 -07001077 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1080 request);
1081 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1082 break;
1083
1084 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1085 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1086 break;
1087
Shishir Agrawal302c8692015-06-19 13:49:39 -07001088 case CMD_PERFORM_NETWORK_SCAN:
1089 request = (MainThreadRequest) msg.obj;
1090 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1091 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1092 break;
1093
Hall Liu27d24262020-09-18 19:04:59 -07001094 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001095 request = (MainThreadRequest) msg.obj;
1096 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001097 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1098 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1099 request.argument;
1100 int callForwardingReason = args.first;
1101 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001102 break;
Hall Liu27d24262020-09-18 19:04:59 -07001103 }
1104 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001105 ar = (AsyncResult) msg.obj;
1106 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001107 TelephonyManager.CallForwardingInfoCallback callback =
1108 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1109 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001110 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001111 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001112 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1113 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1114 // Service Class is a bit mask per 3gpp 27.007. Search for
1115 // any service for voice call.
1116 if ((callForwardInfo.serviceClass
1117 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001118 callForwardingInfo = new CallForwardingInfo(
1119 callForwardInfo.status
1120 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001121 callForwardInfo.reason,
1122 callForwardInfo.number,
1123 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001124 break;
1125 }
1126 }
1127 // Didn't find a call forward info for voice call.
1128 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001129 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1130 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001131 }
Hall Liu27d24262020-09-18 19:04:59 -07001132 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 } else {
1134 if (ar.result == null) {
1135 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1136 }
1137 if (ar.exception != null) {
1138 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1139 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001140 int errorCode = TelephonyManager
1141 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001142 if (ar.exception instanceof CommandException) {
1143 CommandException.Error error =
1144 ((CommandException) (ar.exception)).getCommandError();
1145 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001146 errorCode = TelephonyManager
1147 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001148 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001149 errorCode = TelephonyManager
1150 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001151 }
1152 }
Hall Liu27d24262020-09-18 19:04:59 -07001153 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001154 }
Shuo Qian4a594052020-01-23 11:59:30 -08001155 break;
Hall Liu27d24262020-09-18 19:04:59 -07001156 }
Shuo Qian4a594052020-01-23 11:59:30 -08001157
Hall Liu27d24262020-09-18 19:04:59 -07001158 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001159 request = (MainThreadRequest) msg.obj;
1160 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001161 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001162 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001163 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1164 request.argument).first;
1165 request.phone.setCallForwardingOption(
1166 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001167 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001168 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001169 callForwardingInfoToSet.getReason(),
1170 callForwardingInfoToSet.getNumber(),
1171 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1172 break;
Hall Liu27d24262020-09-18 19:04:59 -07001173 }
Shuo Qian4a594052020-01-23 11:59:30 -08001174
Hall Liu27d24262020-09-18 19:04:59 -07001175 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001176 ar = (AsyncResult) msg.obj;
1177 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001178 Consumer<Integer> callback =
1179 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1180 request.argument).second;
1181 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001182 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001183 int errorCode = TelephonyManager.CallForwardingInfoCallback
1184 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001185 if (ar.exception instanceof CommandException) {
1186 CommandException.Error error =
1187 ((CommandException) (ar.exception)).getCommandError();
1188 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001189 errorCode = TelephonyManager.CallForwardingInfoCallback
1190 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001191 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001192 errorCode = TelephonyManager.CallForwardingInfoCallback
1193 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001194 }
1195 }
1196 callback.accept(errorCode);
1197 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001198 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001199 }
Shuo Qian4a594052020-01-23 11:59:30 -08001200 break;
Hall Liu27d24262020-09-18 19:04:59 -07001201 }
Shuo Qian4a594052020-01-23 11:59:30 -08001202
Hall Liu27d24262020-09-18 19:04:59 -07001203 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1206 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1207 break;
Hall Liu27d24262020-09-18 19:04:59 -07001208 }
Shuo Qian4a594052020-01-23 11:59:30 -08001209
Hall Liu27d24262020-09-18 19:04:59 -07001210 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001213 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001214 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1215 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001216 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001217 // Service Class is a bit mask per 3gpp 27.007.
1218 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001219 if (callForwardResults.length > 1
1220 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001221 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001222 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001223 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1224 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001225 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001226 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 }
1228 } else {
1229 if (ar.result == null) {
1230 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1231 }
1232 if (ar.exception != null) {
1233 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1234 }
1235 if (ar.exception instanceof CommandException) {
1236 CommandException.Error error =
1237 ((CommandException) (ar.exception)).getCommandError();
1238 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1239 callForwardingStatus =
1240 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1241 }
1242 }
1243 }
Hall Liu27d24262020-09-18 19:04:59 -07001244 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001245 break;
Hall Liu27d24262020-09-18 19:04:59 -07001246 }
Shuo Qian4a594052020-01-23 11:59:30 -08001247
Hall Liu27d24262020-09-18 19:04:59 -07001248 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001249 request = (MainThreadRequest) msg.obj;
1250 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001251 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1252 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001253 break;
Hall Liu27d24262020-09-18 19:04:59 -07001254 }
Shuo Qian4a594052020-01-23 11:59:30 -08001255
Hall Liu27d24262020-09-18 19:04:59 -07001256 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001257 ar = (AsyncResult) msg.obj;
1258 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001259 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1260 Consumer<Integer> callback =
1261 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1262 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001263 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001264 if (ar.exception instanceof CommandException) {
1265 CommandException.Error error =
1266 ((CommandException) (ar.exception)).getCommandError();
1267 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1268 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1269 } else {
1270 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1271 }
1272 } else {
1273 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1274 }
1275 } else {
1276 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1277 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279 break;
Hall Liu27d24262020-09-18 19:04:59 -07001280 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001281 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 CellNetworkScanResult cellScanResult;
1285 if (ar.exception == null && ar.result != null) {
1286 cellScanResult = new CellNetworkScanResult(
1287 CellNetworkScanResult.STATUS_SUCCESS,
1288 (List<OperatorInfo>) ar.result);
1289 } else {
1290 if (ar.result == null) {
1291 loge("getCellNetworkScanResults: Empty response");
1292 }
1293 if (ar.exception != null) {
1294 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1295 }
1296 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1297 if (ar.exception instanceof CommandException) {
1298 CommandException.Error error =
1299 ((CommandException) (ar.exception)).getCommandError();
1300 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1301 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1302 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1303 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1304 }
1305 }
1306 cellScanResult = new CellNetworkScanResult(errorCode, null);
1307 }
1308 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001309 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001310 break;
1311
1312 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1313 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001314 ManualNetworkSelectionArgument selArg =
1315 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001316 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1317 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001318 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1319 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001320 break;
1321
1322 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001323 ar = (AsyncResult) msg.obj;
1324 request = (MainThreadRequest) ar.userObj;
1325 if (ar.exception == null) {
1326 request.result = true;
1327 } else {
1328 request.result = false;
1329 loge("setNetworkSelectionModeManual " + ar.exception);
1330 }
1331 notifyRequester(request);
1332 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001333 break;
1334
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001335 case CMD_GET_MODEM_ACTIVITY_INFO:
1336 request = (MainThreadRequest) msg.obj;
1337 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001338 if (defaultPhone != null) {
1339 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001340 } else {
1341 ResultReceiver result = (ResultReceiver) request.argument;
1342 Bundle bundle = new Bundle();
1343 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001344 new ModemActivityInfo(0, 0, 0,
1345 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001346 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001347 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001348 break;
1349
Hall Liud0f208c2020-10-14 16:54:44 -07001350 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001351 ar = (AsyncResult) msg.obj;
1352 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001353 ResultReceiver result = (ResultReceiver) request.argument;
1354
Hall Liud0f208c2020-10-14 16:54:44 -07001355 ModemActivityInfo ret = null;
1356 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001357 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001358 // Update the last modem activity info and the result of the request.
1359 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1360 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001361 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001362 int[] txTimeMs = info.getTransmitTimeMillis();
1363 int[] lastModemTxTimeMs = mLastModemActivityInfo
1364 .getTransmitTimeMillis();
1365 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1366 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1367 }
Hall Liu49656c02020-10-09 19:00:11 -07001368 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001369 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1370 + mLastModemActivityInfo.getSleepTimeMillis());
1371 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1372 + mLastModemActivityInfo.getIdleTimeMillis());
1373 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1374 mLastModemActivityInfo.setReceiveTimeMillis(
1375 info.getReceiveTimeMillis()
1376 + mLastModemActivityInfo.getReceiveTimeMillis());
1377 }
Hall Liu49656c02020-10-09 19:00:11 -07001378 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001379 mLastModemActivityInfo.getSleepTimeMillis(),
1380 mLastModemActivityInfo.getIdleTimeMillis(),
1381 mLastModemActivityInfo.getTransmitTimeMillis(),
1382 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001383 } else {
1384 if (ar.result == null) {
1385 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001386 error = TelephonyManager.ModemActivityInfoException
1387 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388 } else if (ar.exception instanceof CommandException) {
1389 loge("queryModemActivityInfo: CommandException: " +
1390 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001391 error = TelephonyManager.ModemActivityInfoException
1392 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001393 } else {
1394 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001395 error = TelephonyManager.ModemActivityInfoException
1396 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001397 }
1398 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001399 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001400 if (ret != null) {
1401 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1402 } else {
1403 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1404 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001405 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001406 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001407 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001408 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001409
Meng Wang1a7c35a2016-05-05 20:56:15 -07001410 case CMD_SET_ALLOWED_CARRIERS:
1411 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001412 CarrierRestrictionRules argument =
1413 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001414 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001415 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001416 break;
1417
1418 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception == null && ar.result != null) {
1422 request.result = ar.result;
1423 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001424 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1425 if (ar.exception instanceof CommandException) {
1426 loge("setAllowedCarriers: CommandException: " + ar.exception);
1427 CommandException.Error error =
1428 ((CommandException) (ar.exception)).getCommandError();
1429 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1430 request.result =
1431 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1432 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001433 } else {
1434 loge("setAllowedCarriers: Unknown exception");
1435 }
1436 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001437 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001438 break;
1439
1440 case CMD_GET_ALLOWED_CARRIERS:
1441 request = (MainThreadRequest) msg.obj;
1442 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001443 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001444 break;
1445
1446 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 if (ar.exception == null && ar.result != null) {
1450 request.result = ar.result;
1451 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001452 request.result = new IllegalStateException(
1453 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001454 if (ar.result == null) {
1455 loge("getAllowedCarriers: Empty response");
1456 } else if (ar.exception instanceof CommandException) {
1457 loge("getAllowedCarriers: CommandException: " +
1458 ar.exception);
1459 } else {
1460 loge("getAllowedCarriers: Unknown exception");
1461 }
1462 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001463 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001464 break;
1465
Nathan Haroldb3014052017-01-25 15:57:32 -08001466 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
1469 if (ar.exception == null && ar.result != null) {
1470 request.result = ar.result;
1471 } else {
1472 request.result = new IllegalArgumentException(
1473 "Failed to retrieve Forbidden Plmns");
1474 if (ar.result == null) {
1475 loge("getForbiddenPlmns: Empty response");
1476 } else {
1477 loge("getForbiddenPlmns: Unknown exception");
1478 }
1479 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001480 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001481 break;
1482
1483 case CMD_GET_FORBIDDEN_PLMNS:
1484 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001485 uiccPort = getUiccPortFromRequest(request);
1486 if (uiccPort == null) {
1487 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001488 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001489 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001490 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001491 break;
1492 }
1493 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001494 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001495 if (uiccApp == null) {
1496 loge("getForbiddenPlmns() no app with specified type -- "
1497 + appType);
1498 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001499 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001500 break;
1501 } else {
1502 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1503 + " specified type -- " + appType);
1504 }
1505 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1506 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1507 onCompleted);
1508 break;
1509
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001510 case CMD_SWITCH_SLOTS:
1511 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001512 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001513 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00001514 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001515 break;
1516
1517 case EVENT_SWITCH_SLOTS_DONE:
1518 ar = (AsyncResult) msg.obj;
1519 request = (MainThreadRequest) ar.userObj;
1520 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
1522 break;
1523 case CMD_GET_NETWORK_SELECTION_MODE:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1526 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1527 break;
1528
1529 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 if (ar.exception != null) {
1533 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1534 } else {
1535 int mode = ((int[]) ar.result)[0];
1536 if (mode == 0) {
1537 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1538 } else {
1539 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1540 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001541 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001542 notifyRequester(request);
1543 break;
1544 case CMD_GET_CDMA_ROAMING_MODE:
1545 request = (MainThreadRequest) msg.obj;
1546 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1547 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1548 break;
1549 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1550 ar = (AsyncResult) msg.obj;
1551 request = (MainThreadRequest) ar.userObj;
1552 if (ar.exception != null) {
1553 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1554 } else {
1555 request.result = ((int[]) ar.result)[0];
1556 }
1557 notifyRequester(request);
1558 break;
1559 case CMD_SET_CDMA_ROAMING_MODE:
1560 request = (MainThreadRequest) msg.obj;
1561 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1562 int mode = (int) request.argument;
1563 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1564 break;
1565 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 request.result = ar.exception == null;
1569 notifyRequester(request);
1570 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001571 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1574 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1575 break;
1576 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 if (ar.exception != null) {
1580 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1581 } else {
1582 request.result = ((int[]) ar.result)[0];
1583 }
1584 notifyRequester(request);
1585 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001586 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1587 request = (MainThreadRequest) msg.obj;
1588 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1589 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001590 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1591 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001592 break;
1593 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1594 ar = (AsyncResult) msg.obj;
1595 request = (MainThreadRequest) ar.userObj;
1596 request.result = ar.exception == null;
1597 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001598 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001599 case CMD_GET_ALL_CELL_INFO:
1600 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001601 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001602 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001603 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001604 case EVENT_GET_ALL_CELL_INFO_DONE:
1605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001607 // If a timeout occurs, the response will be null
1608 request.result = (ar.exception == null && ar.result != null)
1609 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001610 synchronized (request) {
1611 request.notifyAll();
1612 }
1613 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001614 case CMD_REQUEST_CELL_INFO_UPDATE:
1615 request = (MainThreadRequest) msg.obj;
1616 request.phone.requestCellInfoUpdate(request.workSource,
1617 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1618 break;
1619 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1623 try {
1624 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001625 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001626 cb.onError(
1627 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1628 ar.exception.getClass().getName(),
1629 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001630 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001631 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001632 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001633 } else {
1634 // use the result as returned
1635 cb.onCellInfo((List<CellInfo>) ar.result);
1636 }
1637 } catch (RemoteException re) {
1638 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1639 }
1640 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001641 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001642 request = (MainThreadRequest) msg.obj;
1643 WorkSource ws = (WorkSource) request.argument;
1644 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001645 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001646 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001647 }
1648 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001649 ar = (AsyncResult) msg.obj;
1650 request = (MainThreadRequest) ar.userObj;
1651 if (ar.exception == null) {
1652 request.result = ar.result;
1653 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001654 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001655 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001656 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001657 }
1658
1659 synchronized (request) {
1660 request.notifyAll();
1661 }
1662 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001663 }
chen xu6dac5ab2018-10-26 17:39:23 -07001664 case CMD_MODEM_REBOOT:
1665 request = (MainThreadRequest) msg.obj;
1666 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001667 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001668 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001669 case EVENT_CMD_MODEM_REBOOT_DONE:
1670 handleNullReturnEvent(msg, "rebootModem");
1671 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001672 case CMD_REQUEST_ENABLE_MODEM:
1673 request = (MainThreadRequest) msg.obj;
1674 boolean enable = (boolean) request.argument;
1675 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001676 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001677 PhoneConfigurationManager.getInstance()
1678 .enablePhone(request.phone, enable, onCompleted);
1679 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001680 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001684 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001685 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001686 if ((boolean) request.result) {
1687 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1688 updateModemStateMetrics();
1689 } else {
1690 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1691 + ar.exception);
1692 }
1693 notifyRequester(request);
1694 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001695 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001696 case CMD_GET_MODEM_STATUS:
1697 request = (MainThreadRequest) msg.obj;
1698 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1699 PhoneConfigurationManager.getInstance()
1700 .getPhoneStatusFromModem(request.phone, onCompleted);
1701 break;
1702 case EVENT_GET_MODEM_STATUS_DONE:
1703 ar = (AsyncResult) msg.obj;
1704 request = (MainThreadRequest) ar.userObj;
1705 int id = request.phone.getPhoneId();
1706 if (ar.exception == null && ar.result != null) {
1707 request.result = ar.result;
1708 //update the cache as modem status has changed
1709 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1710 (boolean) request.result);
1711 } else {
1712 // Return true if modem status cannot be retrieved. For most cases,
1713 // modem status is on. And for older version modems, GET_MODEM_STATUS
1714 // and disable modem are not supported. Modem is always on.
1715 // TODO: this should be fixed in R to support a third
1716 // status UNKNOWN b/131631629
1717 request.result = true;
1718 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1719 + ar.exception);
1720 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001721 notifyRequester(request);
1722 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001723 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1726 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1727 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1728 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1729 break;
1730 }
1731 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1732 ar = (AsyncResult) msg.obj;
1733 request = (MainThreadRequest) ar.userObj;
1734 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1735 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1736 args.second.accept(ar.exception == null);
1737 notifyRequester(request);
1738 break;
1739 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001740 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1741 request = (MainThreadRequest) msg.obj;
1742 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1743 Phone phone = getPhoneFromRequest(request);
1744 if (phone != null) {
1745 phone.getSystemSelectionChannels(onCompleted);
1746 } else {
1747 loge("getSystemSelectionChannels: No phone object");
1748 request.result = new ArrayList<RadioAccessSpecifier>();
1749 notifyRequester(request);
1750 }
1751 break;
1752 }
1753 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
1756 if (ar.exception == null && ar.result != null) {
1757 request.result = ar.result;
1758 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001759 request.result = new IllegalStateException(
1760 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001761 if (ar.result == null) {
1762 loge("getSystemSelectionChannels: Empty response");
1763 } else {
1764 loge("getSystemSelectionChannels: Unknown exception");
1765 }
1766 }
1767 notifyRequester(request);
1768 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001769 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1770 ar = (AsyncResult) msg.obj;
1771 request = (MainThreadRequest) ar.userObj;
1772 if (ar.exception == null && ar.result != null) {
1773 request.result = ar.result;
1774 } else {
1775 request.result = -1;
1776 loge("Failed to set Forbidden Plmns");
1777 if (ar.result == null) {
1778 loge("setForbidenPlmns: Empty response");
1779 } else if (ar.exception != null) {
1780 loge("setForbiddenPlmns: Exception: " + ar.exception);
1781 request.result = -1;
1782 } else {
1783 loge("setForbiddenPlmns: Unknown exception");
1784 }
1785 }
1786 notifyRequester(request);
1787 break;
1788 case CMD_SET_FORBIDDEN_PLMNS:
1789 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001790 uiccPort = getUiccPortFromRequest(request);
1791 if (uiccPort == null) {
1792 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001793 request.result = -1;
1794 notifyRequester(request);
1795 break;
1796 }
1797 Pair<Integer, List<String>> setFplmnsArgs =
1798 (Pair<Integer, List<String>>) request.argument;
1799 appType = setFplmnsArgs.first;
1800 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001801 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001802 if (uiccApp == null) {
1803 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1804 request.result = -1;
1805 loge("Failed to get UICC App");
1806 notifyRequester(request);
1807 } else {
1808 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1809 ((SIMRecords) uiccApp.getIccRecords())
1810 .setForbiddenPlmns(onCompleted, fplmns);
1811 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001812 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001813 case CMD_ERASE_MODEM_CONFIG:
1814 request = (MainThreadRequest) msg.obj;
1815 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1816 defaultPhone.eraseModemConfig(onCompleted);
1817 break;
1818 case EVENT_ERASE_MODEM_CONFIG_DONE:
1819 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001820 break;
zoey chene02881a2019-12-30 16:11:23 +08001821
Kai Shif70f46f2021-03-03 13:59:46 -08001822 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1823 request = (MainThreadRequest) msg.obj;
1824 request.result = defaultPhone.eraseDataInSharedPreferences();
1825 notifyRequester(request);
1826 break;
1827
zoey chene02881a2019-12-30 16:11:23 +08001828 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1829 request = (MainThreadRequest) msg.obj;
1830 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1831 Pair<String, String> changed = (Pair<String, String>) request.argument;
1832 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1833 changed.first, changed.second, onCompleted);
1834 break;
1835 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1836 ar = (AsyncResult) msg.obj;
1837 request = (MainThreadRequest) ar.userObj;
1838 if (ar.exception == null) {
1839 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001840 // If the operation is successful, update the PIN storage
1841 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1842 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001843 UiccController.getInstance().getPinStorage()
1844 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001845 } else {
1846 request.result = msg.arg1;
1847 }
1848 notifyRequester(request);
1849 break;
1850
Michele Berionne5e411512020-11-13 02:36:59 +00001851 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001852 request = (MainThreadRequest) msg.obj;
1853 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1854 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1855 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1856 enabled.first, enabled.second, onCompleted);
1857 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001858 }
zoey chene02881a2019-12-30 16:11:23 +08001859 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1860 ar = (AsyncResult) msg.obj;
1861 request = (MainThreadRequest) ar.userObj;
1862 if (ar.exception == null) {
1863 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001864 // If the operation is successful, update the PIN storage
1865 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1866 int phoneId = getPhoneFromRequest(request).getPhoneId();
1867 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001868 UiccController.getInstance().getPinStorage()
1869 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001870 } else {
1871 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1872 }
zoey chene02881a2019-12-30 16:11:23 +08001873 } else {
1874 request.result = msg.arg1;
1875 }
Michele Berionne5e411512020-11-13 02:36:59 +00001876
1877
zoey chene02881a2019-12-30 16:11:23 +08001878 notifyRequester(request);
1879 break;
1880
Peter Wangdafb9ac2020-01-15 14:13:38 -08001881 case MSG_NOTIFY_USER_ACTIVITY:
1882 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001883 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001884 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1885 getDefaultPhone().getContext().sendBroadcastAsUser(
1886 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1887 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001888
1889 case CMD_SET_DATA_THROTTLING: {
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1892 DataThrottlingRequest dataThrottlingRequest =
1893 (DataThrottlingRequest) request.argument;
1894 Phone phone = getPhoneFromRequest(request);
1895 if (phone != null) {
1896 phone.setDataThrottling(onCompleted,
1897 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1898 dataThrottlingRequest.getCompletionDurationMillis());
1899 } else {
1900 loge("setDataThrottling: No phone object");
1901 request.result =
1902 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1903 notifyRequester(request);
1904 }
1905
1906 break;
1907 }
1908 case EVENT_SET_DATA_THROTTLING_DONE:
1909 ar = (AsyncResult) msg.obj;
1910 request = (MainThreadRequest) ar.userObj;
1911
1912 if (ar.exception == null) {
1913 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1914 } else if (ar.exception instanceof CommandException) {
1915 loge("setDataThrottling: CommandException: " + ar.exception);
1916 CommandException.Error error =
1917 ((CommandException) (ar.exception)).getCommandError();
1918
1919 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1920 request.result = TelephonyManager
1921 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1922 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1923 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001924 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1925 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001926 } else {
1927 request.result =
1928 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1929 }
1930 } else {
1931 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1932 }
1933 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1934 notifyRequester(request);
1935 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001936
1937 case CMD_SET_SIM_POWER: {
1938 request = (MainThreadRequest) msg.obj;
1939 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1940 request = (MainThreadRequest) msg.obj;
1941 int stateToSet =
1942 ((Pair<Integer, IIntegerConsumer>)
1943 request.argument).first;
1944 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1945 break;
1946 }
1947 case EVENT_SET_SIM_POWER_DONE: {
1948 ar = (AsyncResult) msg.obj;
1949 request = (MainThreadRequest) ar.userObj;
1950 IIntegerConsumer callback =
1951 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1952 if (ar.exception != null) {
1953 loge("setSimPower exception: " + ar.exception);
1954 int errorCode = TelephonyManager.CallForwardingInfoCallback
1955 .RESULT_ERROR_UNKNOWN;
1956 if (ar.exception instanceof CommandException) {
1957 CommandException.Error error =
1958 ((CommandException) (ar.exception)).getCommandError();
1959 if (error == CommandException.Error.SIM_ERR) {
1960 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1961 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1962 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1963 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1964 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1965 } else {
1966 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1967 }
1968 }
1969 try {
1970 callback.accept(errorCode);
1971 } catch (RemoteException e) {
1972 // Ignore if the remote process is no longer available to call back.
1973 Log.w(LOG_TAG, "setSimPower: callback not available.");
1974 }
1975 } else {
1976 try {
1977 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1978 } catch (RemoteException e) {
1979 // Ignore if the remote process is no longer available to call back.
1980 Log.w(LOG_TAG, "setSimPower: callback not available.");
1981 }
1982 }
1983 break;
1984 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001985 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1986 request = (MainThreadRequest) msg.obj;
1987
1988 final Phone phone = getPhoneFromRequest(request);
1989 if (phone == null || phone.getServiceStateTracker() == null) {
1990 request.result = new IllegalStateException("Phone or SST is null");
1991 notifyRequester(request);
1992 break;
1993 }
1994
1995 Pair<Integer, SignalStrengthUpdateRequest> pair =
1996 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1997 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1998 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001999 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002000 request.subId, pair.first /*callingUid*/,
2001 pair.second /*request*/, onCompleted);
2002 break;
2003 }
2004 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2005 ar = (AsyncResult) msg.obj;
2006 request = (MainThreadRequest) ar.userObj;
2007 // request.result will be the exception of ar if present, true otherwise.
2008 // Be cautious not to leave result null which will wait() forever
2009 request.result = ar.exception != null ? ar.exception : true;
2010 notifyRequester(request);
2011 break;
2012 }
2013 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2014 request = (MainThreadRequest) msg.obj;
2015
2016 Phone phone = getPhoneFromRequest(request);
2017 if (phone == null || phone.getServiceStateTracker() == null) {
2018 request.result = new IllegalStateException("Phone or SST is null");
2019 notifyRequester(request);
2020 break;
2021 }
2022
2023 Pair<Integer, SignalStrengthUpdateRequest> pair =
2024 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2025 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2026 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002027 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002028 request.subId, pair.first /*callingUid*/,
2029 pair.second /*request*/, onCompleted);
2030 break;
2031 }
2032 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2033 ar = (AsyncResult) msg.obj;
2034 request = (MainThreadRequest) ar.userObj;
2035 request.result = ar.exception != null ? ar.exception : true;
2036 notifyRequester(request);
2037 break;
2038 }
Jordan Liu109698e2020-11-24 14:50:34 -08002039
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002040 case CMD_GET_SLICING_CONFIG: {
2041 request = (MainThreadRequest) msg.obj;
2042 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2043 request.phone.getSlicingConfig(onCompleted);
2044 break;
2045 }
2046 case EVENT_GET_SLICING_CONFIG_DONE: {
2047 ar = (AsyncResult) msg.obj;
2048 request = (MainThreadRequest) ar.userObj;
2049 ResultReceiver result = (ResultReceiver) request.argument;
2050
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002051 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002052 Bundle bundle = new Bundle();
2053 int resultCode = 0;
2054 if (ar.exception != null) {
2055 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2056 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002057 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002058 } else if (ar.result == null) {
2059 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002060 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002061 } else {
2062 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002063 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2064 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002065 }
2066
2067 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002068 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002069 }
2070 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2071 result.send(resultCode, bundle);
2072 notifyRequester(request);
2073 break;
2074 }
2075
Michele Berionne5e411512020-11-13 02:36:59 +00002076 case CMD_PREPARE_UNATTENDED_REBOOT:
2077 request = (MainThreadRequest) msg.obj;
2078 request.result =
2079 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2080 notifyRequester(request);
2081 break;
2082
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 default:
2084 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2085 break;
2086 }
2087 }
Jake Hambye994d462014-02-03 13:10:13 -08002088
Pengquan Menga1bb6272018-09-06 09:59:22 -07002089 private void notifyRequester(MainThreadRequest request) {
2090 synchronized (request) {
2091 request.notifyAll();
2092 }
2093 }
2094
Jake Hambye994d462014-02-03 13:10:13 -08002095 private void handleNullReturnEvent(Message msg, String command) {
2096 AsyncResult ar = (AsyncResult) msg.obj;
2097 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2098 if (ar.exception == null) {
2099 request.result = true;
2100 } else {
2101 request.result = false;
2102 if (ar.exception instanceof CommandException) {
2103 loge(command + ": CommandException: " + ar.exception);
2104 } else {
2105 loge(command + ": Unknown exception");
2106 }
2107 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002108 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111
2112 /**
2113 * Posts the specified command to be executed on the main thread,
2114 * waits for the request to complete, and returns the result.
2115 * @see #sendRequestAsync
2116 */
2117 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002118 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2119 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002120 }
2121
2122 /**
2123 * Posts the specified command to be executed on the main thread,
2124 * waits for the request to complete, and returns the result.
2125 * @see #sendRequestAsync
2126 */
2127 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2128 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002129 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002130 }
2131
2132 /**
2133 * Posts the specified command to be executed on the main thread,
2134 * waits for the request to complete, and returns the result.
2135 * @see #sendRequestAsync
2136 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002137 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002138 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2139 }
2140
2141 /**
2142 * Posts the specified command to be executed on the main thread,
2143 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2144 * if not timeout or null otherwise.
2145 * @see #sendRequestAsync
2146 */
2147 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2148 long timeoutInMs) {
2149 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002150 }
2151
2152 /**
2153 * Posts the specified command to be executed on the main thread,
2154 * waits for the request to complete, and returns the result.
2155 * @see #sendRequestAsync
2156 */
Nathan Harold92bed182018-10-12 18:16:49 -07002157 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002158 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002159 }
2160
2161 /**
2162 * Posts the specified command to be executed on the main thread,
2163 * waits for the request to complete, and returns the result.
2164 * @see #sendRequestAsync
2165 */
2166 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002167 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2168 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002169 }
2170
2171 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002172 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2173 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2174 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002175 * @see #sendRequestAsync
2176 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002177 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2178 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2180 throw new RuntimeException("This method will deadlock if called from the main thread.");
2181 }
2182
Nathan Harold92bed182018-10-12 18:16:49 -07002183 MainThreadRequest request = null;
2184 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2185 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2186 } else if (phone != null) {
2187 request = new MainThreadRequest(argument, phone, workSource);
2188 } else {
2189 request = new MainThreadRequest(argument, subId, workSource);
2190 }
2191
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 Message msg = mMainThreadHandler.obtainMessage(command, request);
2193 msg.sendToTarget();
2194
Rambo Wang0f050d82021-02-12 11:43:36 -08002195
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002197 if (timeoutInMs >= 0) {
2198 // Wait for at least timeoutInMs before returning null request result
2199 long now = SystemClock.elapsedRealtime();
2200 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002201 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002202 try {
2203 request.wait(deadline - now);
2204 } catch (InterruptedException e) {
2205 // Do nothing, go back and check if request is completed or timeout
2206 } finally {
2207 now = SystemClock.elapsedRealtime();
2208 }
2209 }
2210 } else {
2211 // Wait for the request to complete
2212 while (request.result == null) {
2213 try {
2214 request.wait();
2215 } catch (InterruptedException e) {
2216 // Do nothing, go back and wait until the request is complete
2217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
2219 }
2220 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002221 if (request.result == null) {
2222 Log.wtf(LOG_TAG,
2223 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 return request.result;
2226 }
2227
2228 /**
2229 * Asynchronous ("fire and forget") version of sendRequest():
2230 * Posts the specified command to be executed on the main thread, and
2231 * returns immediately.
2232 * @see #sendRequest
2233 */
2234 private void sendRequestAsync(int command) {
2235 mMainThreadHandler.sendEmptyMessage(command);
2236 }
2237
2238 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002239 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002240 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002241 */
2242 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 sendRequestAsync(command, argument, null, null);
2244 }
2245
2246 /**
2247 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2248 * @see {@link #sendRequest(int,Object)}
2249 */
2250 private void sendRequestAsync(
2251 int command, Object argument, Phone phone, WorkSource workSource) {
2252 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002253 Message msg = mMainThreadHandler.obtainMessage(command, request);
2254 msg.sendToTarget();
2255 }
2256
2257 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 * Initialize the singleton PhoneInterfaceManager instance.
2259 * This is only done once, at startup, from PhoneApp.onCreate().
2260 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002261 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 synchronized (PhoneInterfaceManager.class) {
2263 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002264 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 } else {
2266 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2267 }
2268 return sInstance;
2269 }
2270 }
2271
2272 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002273 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002276 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002277 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002279 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002281 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002282 mTelephonySharedPreferences =
2283 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002284 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002285 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002286 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002287 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002288
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 publish();
2290 }
2291
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002292 private Phone getDefaultPhone() {
2293 Phone thePhone = getPhone(getDefaultSubscription());
2294 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2295 }
2296
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 private void publish() {
2298 if (DBG) log("publish: " + this);
2299
Peter Wangc035ce42020-01-08 21:00:22 -08002300 TelephonyFrameworkInitializer
2301 .getTelephonyServiceManager()
2302 .getTelephonyServiceRegisterer()
2303 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 }
2305
Stuart Scott584921c2015-01-15 17:10:34 -08002306 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002307 if (request.phone != null) {
2308 return request.phone;
2309 } else {
2310 return getPhoneFromSubId(request.subId);
2311 }
2312 }
2313
2314 private Phone getPhoneFromSubId(int subId) {
2315 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2316 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002317 }
2318
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002319 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002320 Phone phone = getPhoneFromRequest(request);
2321 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002322 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002323 }
2324
Wink Saville36469e72014-06-11 15:17:00 -07002325 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002326 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002327 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329
Kai Shif70f46f2021-03-03 13:59:46 -08002330 private void sendEraseModemConfig(@NonNull Phone phone) {
2331 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2332 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2333 }
2334
2335 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2336 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2337 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002338 }
2339
Peter Wang44b186e2020-01-13 23:33:09 -08002340 private boolean isImsAvailableOnDevice() {
2341 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2342 if (pm == null) {
2343 // For some reason package manger is not available.. This will fail internally anyway,
2344 // so do not throw error and allow.
2345 return true;
2346 }
2347 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2348 }
2349
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002351 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002352 }
2353
Wink Savilleb564aae2014-10-23 10:18:09 -07002354 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 if (DBG) log("dial: " + number);
2356 // No permission check needed here: This is just a wrapper around the
2357 // ACTION_DIAL intent, which is available to any app since it puts up
2358 // the UI before it does anything.
2359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 String url = createTelUrl(number);
2363 if (url == null) {
2364 return;
2365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367 // PENDING: should we just silently fail if phone is offhook or ringing?
2368 PhoneConstants.State state = mCM.getState(subId);
2369 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2370 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2371 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2372 mApp.startActivity(intent);
2373 }
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 }
2377 }
2378
2379 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002380 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002381 }
2382
Wink Savilleb564aae2014-10-23 10:18:09 -07002383 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 if (DBG) log("call: " + number);
2385
2386 // This is just a wrapper around the ACTION_CALL intent, but we still
2387 // need to do a permission check since we're calling startActivity()
2388 // from the context of the phone app.
2389 enforceCallPermission();
2390
Jordan Liu1617b712019-07-10 15:06:26 -07002391 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 != AppOpsManager.MODE_ALLOWED) {
2393 return;
2394 }
2395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 String url = createTelUrl(number);
2399 if (url == null) {
2400 return;
2401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002403 boolean isValid = false;
2404 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2405 if (slist != null) {
2406 for (SubscriptionInfo subInfoRecord : slist) {
2407 if (subInfoRecord.getSubscriptionId() == subId) {
2408 isValid = true;
2409 break;
2410 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002411 }
Wink Saville08874612014-08-31 19:19:58 -07002412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002413 if (!isValid) {
2414 return;
2415 }
Wink Saville08874612014-08-31 19:19:58 -07002416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2418 intent.putExtra(SUBSCRIPTION_KEY, subId);
2419 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2420 mApp.startActivity(intent);
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
2423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 }
2425
Wink Savilleb564aae2014-10-23 10:18:09 -07002426 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002427 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002428 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2429 }
2430
Wink Savilleb564aae2014-10-23 10:18:09 -07002431 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002432 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002433 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2434 }
2435
Wink Savilleb564aae2014-10-23 10:18:09 -07002436 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002438
2439 final long identity = Binder.clearCallingIdentity();
2440 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002441 Phone phone = getPhone(subId);
2442 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443 checkSimPin.start();
2444 return checkSimPin.unlockSim(null, pin);
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
2447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 }
2449
Wink Savilleb564aae2014-10-23 10:18:09 -07002450 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002455 Phone phone = getPhone(subId);
2456 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 checkSimPuk.start();
2458 return checkSimPuk.unlockSim(puk, pin);
2459 } finally {
2460 Binder.restoreCallingIdentity(identity);
2461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463
2464 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002465 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 * a synchronous one.
2467 */
2468 private static class UnlockSim extends Thread {
2469
2470 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002471 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472
2473 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002474 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2475 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476
2477 // For replies from SimCard interface
2478 private Handler mHandler;
2479
2480 // For async handler to identify request type
2481 private static final int SUPPLY_PIN_COMPLETE = 100;
2482
Michele Berionne5e411512020-11-13 02:36:59 +00002483 UnlockSim(int phoneId, IccCard simCard) {
2484 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 mSimCard = simCard;
2486 }
2487
2488 @Override
2489 public void run() {
2490 Looper.prepare();
2491 synchronized (UnlockSim.this) {
2492 mHandler = new Handler() {
2493 @Override
2494 public void handleMessage(Message msg) {
2495 AsyncResult ar = (AsyncResult) msg.obj;
2496 switch (msg.what) {
2497 case SUPPLY_PIN_COMPLETE:
2498 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2499 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002500 mRetryCount = msg.arg1;
2501 if (ar.exception != null) {
2502 if (ar.exception instanceof CommandException &&
2503 ((CommandException)(ar.exception)).getCommandError()
2504 == CommandException.Error.PASSWORD_INCORRECT) {
2505 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002506 } //When UiccCardApp dispose,handle message and return exception
2507 else if (ar.exception instanceof CommandException &&
2508 ((CommandException) (ar.exception)).getCommandError()
2509 == CommandException.Error.ABORTED) {
2510 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002511 } else {
2512 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2513 }
2514 } else {
2515 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 mDone = true;
2518 UnlockSim.this.notifyAll();
2519 }
2520 break;
2521 }
2522 }
2523 };
2524 UnlockSim.this.notifyAll();
2525 }
2526 Looper.loop();
2527 }
2528
2529 /*
2530 * Use PIN or PUK to unlock SIM card
2531 *
2532 * If PUK is null, unlock SIM card with PIN
2533 *
2534 * If PUK is not null, unlock SIM card with PUK and set PIN code
2535 */
Wink Saville9de0f752013-10-22 19:04:03 -07002536 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537
2538 while (mHandler == null) {
2539 try {
2540 wait();
2541 } catch (InterruptedException e) {
2542 Thread.currentThread().interrupt();
2543 }
2544 }
2545 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2546
2547 if (puk == null) {
2548 mSimCard.supplyPin(pin, callback);
2549 } else {
2550 mSimCard.supplyPuk(puk, pin, callback);
2551 }
2552
2553 while (!mDone) {
2554 try {
2555 Log.d(LOG_TAG, "wait for done");
2556 wait();
2557 } catch (InterruptedException e) {
2558 // Restore the interrupted status
2559 Thread.currentThread().interrupt();
2560 }
2561 }
2562 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002563 int[] resultArray = new int[2];
2564 resultArray[0] = mResult;
2565 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002566
2567 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002568 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002569 }
2570
Wink Saville9de0f752013-10-22 19:04:03 -07002571 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 }
2573 }
2574
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002575 /**
2576 * This method has been removed due to privacy and stability concerns.
2577 */
2578 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002580 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2581 return;
Wink Saville36469e72014-06-11 15:17:00 -07002582 }
2583
Nathan Harold1f889d82020-06-04 17:05:26 -07002584 @Override
2585 public void updateServiceLocationWithPackageName(String callingPackage) {
2586 mApp.getSystemService(AppOpsManager.class)
2587 .checkPackage(Binder.getCallingUid(), callingPackage);
2588
Nathan Haroldf096d982020-11-18 17:18:06 -08002589 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002590 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2591 // Callers targeting S have no business invoking this method.
2592 return;
2593 }
2594
2595 LocationAccessPolicy.LocationPermissionResult locationResult =
2596 LocationAccessPolicy.checkLocationPermission(mApp,
2597 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2598 .setCallingPackage(callingPackage)
2599 .setCallingFeatureId(null)
2600 .setCallingPid(Binder.getCallingPid())
2601 .setCallingUid(Binder.getCallingUid())
2602 .setMethod("updateServiceLocation")
2603 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2604 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2605 .build());
2606 // Apps that lack location permission have no business calling this method;
2607 // however, because no permission was declared in the public API, denials must
2608 // all be "soft".
2609 switch (locationResult) {
2610 case DENIED_HARD: /* fall through */
2611 case DENIED_SOFT:
2612 return;
2613 }
2614
2615 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002618 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002620 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002627 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002628 @Override
2629 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002630 return isRadioOnWithFeature(callingPackage, null);
2631 }
2632
2633
2634 @Override
2635 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2636 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2637 callingFeatureId);
2638 }
2639
2640 @Deprecated
2641 @Override
2642 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2643 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002644 }
2645
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002646 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002647 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2648 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002650 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002651 return false;
2652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653
2654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 return isRadioOnForSubscriber(subId);
2657 } finally {
2658 Binder.restoreCallingIdentity(identity);
2659 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002660 }
2661
2662 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
2666 if (phone != null) {
2667 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2668 } else {
2669 return false;
2670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
Wink Saville36469e72014-06-11 15:17:00 -07002679
Wink Savilleb564aae2014-10-23 10:18:09 -07002680 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 final Phone phone = getPhone(subId);
2686 if (phone != null) {
2687 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2688 }
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002691 }
Wink Saville36469e72014-06-11 15:17:00 -07002692 }
2693
2694 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002695 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002696 }
2697
Wink Savilleb564aae2014-10-23 10:18:09 -07002698 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 final Phone phone = getPhone(subId);
2704 if (phone == null) {
2705 return false;
2706 }
2707 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2708 toggleRadioOnOffForSubscriber(subId);
2709 }
2710 return true;
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
Wink Saville36469e72014-06-11 15:17:00 -07002715
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002716 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002717 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002718 /*
2719 * If any of the Radios are available, it will need to be
2720 * shutdown. So return true if any Radio is available.
2721 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2725 Phone phone = PhoneFactory.getPhone(i);
2726 if (phone != null && phone.isRadioAvailable()) return true;
2727 }
2728 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2729 return false;
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002732 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002733 }
2734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002736 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 enforceModifyPermission();
2738
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2742 logv("Shutting down Phone " + i);
2743 shutdownRadioUsingPhoneId(i);
2744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002747 }
2748 }
2749
2750 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002751 Phone phone = PhoneFactory.getPhone(phoneId);
2752 if (phone != null && phone.isRadioAvailable()) {
2753 phone.shutdownRadio();
2754 }
2755 }
2756
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759
2760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2763 if (defaultPhone != null) {
2764 defaultPhone.setRadioPower(turnOn);
2765 return true;
2766 } else {
2767 loge("There's no default phone.");
2768 return false;
2769 }
2770 } finally {
2771 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002772 }
Wink Saville36469e72014-06-11 15:17:00 -07002773 }
2774
Wink Savilleb564aae2014-10-23 10:18:09 -07002775 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777
2778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 final Phone phone = getPhone(subId);
2781 if (phone != null) {
2782 phone.setRadioPower(turnOn);
2783 return true;
2784 } else {
2785 return false;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
Wink Saville36469e72014-06-11 15:17:00 -07002792 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 public boolean enableDataConnectivity() {
2795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 int subId = mSubscriptionController.getDefaultDataSubId();
2800 final Phone phone = getPhone(subId);
2801 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002802 phone.getDataEnabledSettings().setDataEnabled(
2803 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 return true;
2805 } else {
2806 return false;
2807 }
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
Wink Saville36469e72014-06-11 15:17:00 -07002813 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 public boolean disableDataConnectivity() {
2816 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817
2818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 int subId = mSubscriptionController.getDefaultDataSubId();
2821 final Phone phone = getPhone(subId);
2822 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002823 phone.getDataEnabledSettings().setDataEnabled(
2824 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 return true;
2826 } else {
2827 return false;
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 }
2833
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002835 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 final Phone phone = getPhone(subId);
2839 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002840 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002841 } else {
2842 return false;
2843 }
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
2849 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002850 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002851 }
2852
pkanwarae03a6b2016-11-06 20:37:09 -08002853 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854 enforceCallPermission();
2855
2856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2859 return;
2860 }
2861 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2862 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2863 } finally {
2864 Binder.restoreCallingIdentity(identity);
2865 }
pkanwar32d516d2016-10-14 19:37:38 -07002866 };
2867
Wink Savilleb564aae2014-10-23 10:18:09 -07002868 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2874 return false;
2875 }
2876 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2877 } finally {
2878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 }
2881
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002882 /**
2883 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2884 * tag on getCallState Binder call.
2885 */
2886 @Deprecated
2887 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002889 if (CompatChanges.isChangeEnabled(
2890 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2891 Binder.getCallingUid())) {
2892 // Do not allow this API to be called on API version 31+, it should only be
2893 // called on old apps using this Binder call directly.
2894 throw new SecurityException("This method can only be used for applications "
2895 + "targeting API version 30 or less.");
2896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897 final long identity = Binder.clearCallingIdentity();
2898 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002899 Phone phone = getPhone(getDefaultSubscription());
2900 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2901 PhoneConstantConversions.convertCallState(phone.getState());
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
2904 }
2905 }
2906
2907 @Override
2908 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2909 if (CompatChanges.isChangeEnabled(
2910 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2911 Binder.getCallingUid())) {
2912 // Check READ_PHONE_STATE for API version 31+
2913 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2914 featureId, "getCallStateForSubscription")) {
2915 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2916 + "targeting API level 31+.");
2917 }
2918 }
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2923 PhoneConstantConversions.convertCallState(phone.getState());
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
2928
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002930 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002931 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2932 }
2933
2934 @Override
2935 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002938 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 if (phone != null) {
2940 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2941 } else {
2942 return PhoneConstantConversions.convertDataState(
2943 PhoneConstants.DataState.DISCONNECTED);
2944 }
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 }
2949
Sanket Padawe356d7632015-06-22 14:03:32 -07002950 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002951 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002952 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2953 }
2954
2955 @Override
2956 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957 final long identity = Binder.clearCallingIdentity();
2958 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002959 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 if (phone != null) {
2961 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2962 } else {
2963 return TelephonyManager.DATA_ACTIVITY_NONE;
2964 }
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002968 }
2969
2970 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002971 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002972 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002973 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002974
2975 LocationAccessPolicy.LocationPermissionResult locationResult =
2976 LocationAccessPolicy.checkLocationPermission(mApp,
2977 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2978 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002979 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002980 .setCallingPid(Binder.getCallingPid())
2981 .setCallingUid(Binder.getCallingUid())
2982 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002983 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002984 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2985 .build());
2986 switch (locationResult) {
2987 case DENIED_HARD:
2988 throw new SecurityException("Not allowed to access cell location");
2989 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002990 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2991 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 }
2993
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002994 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002998 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002999 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
Svetoslav64fad262015-04-14 14:35:21 -07003003 }
3004
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003006 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003007 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3008 // registered cell info, so return a NULL country instead.
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003011 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3012 // Get default phone in this case.
3013 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3014 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003015 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003017 if (phone == null) return "";
3018 ServiceStateTracker sst = phone.getServiceStateTracker();
3019 if (sst == null) return "";
3020 LocaleTracker lt = sst.getLocaleTracker();
3021 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003022 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003026 }
3027
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003028 /**
3029 * This method was removed due to potential issues caused by performing partial
3030 * updates of service state, and lack of a credible use case.
3031 *
3032 * This has the ability to break the telephony implementation by disabling notification of
3033 * changes in device connectivity. DO NOT USE THIS!
3034 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003035 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003036 public void enableLocationUpdates() {
3037 mApp.enforceCallingOrSelfPermission(
3038 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003039 }
3040
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003041 /**
3042 * This method was removed due to potential issues caused by performing partial
3043 * updates of service state, and lack of a credible use case.
3044 *
3045 * This has the ability to break the telephony implementation by disabling notification of
3046 * changes in device connectivity. DO NOT USE THIS!
3047 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 @Override
3049 public void disableLocationUpdates() {
3050 mApp.enforceCallingOrSelfPermission(
3051 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003052 }
3053
3054 @Override
3055 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003056 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3057 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003058 try {
3059 mApp.getSystemService(AppOpsManager.class)
3060 .checkPackage(Binder.getCallingUid(), callingPackage);
3061 } catch (SecurityException e) {
3062 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3063 throw e;
3064 }
3065
Nathan Haroldf096d982020-11-18 17:18:06 -08003066 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003067 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3068 throw new SecurityException(
3069 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3070 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003071
Jordan Liu1617b712019-07-10 15:06:26 -07003072 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3074 return null;
3075 }
Svetoslav64fad262015-04-14 14:35:21 -07003076
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003077 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003078
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003079 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003080 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081
Nathan Haroldf180aac2018-06-01 18:43:55 -07003082 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3083 for (CellInfo ci : info) {
3084 if (ci instanceof CellInfoGsm) {
3085 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3086 } else if (ci instanceof CellInfoWcdma) {
3087 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003090 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 }
3092
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003093 private List<CellInfo> getCachedCellInfo() {
3094 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3095 for (Phone phone : PhoneFactory.getPhones()) {
3096 List<CellInfo> info = phone.getAllCellInfo();
3097 if (info != null) cellInfos.addAll(info);
3098 }
3099 return cellInfos;
3100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003101
3102 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003103 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003104 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003105 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003106
3107 LocationAccessPolicy.LocationPermissionResult locationResult =
3108 LocationAccessPolicy.checkLocationPermission(mApp,
3109 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3110 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003111 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003112 .setCallingPid(Binder.getCallingPid())
3113 .setCallingUid(Binder.getCallingUid())
3114 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003115 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003116 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3117 .build());
3118 switch (locationResult) {
3119 case DENIED_HARD:
3120 throw new SecurityException("Not allowed to access cell info");
3121 case DENIED_SOFT:
3122 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 }
3124
Nathan Haroldf096d982020-11-18 17:18:06 -08003125 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003126 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3127 return getCachedCellInfo();
3128 }
3129
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003130 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003131 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3135 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003136 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003137 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 if (info != null) cellInfos.addAll(info);
3139 }
3140 return cellInfos;
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 }
3144 }
3145
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003146 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003147 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3148 String callingFeatureId) {
3149 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3150 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003151 }
3152
3153 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003154 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3155 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003156 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003157 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003158 }
3159
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003160 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3161 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003162 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003163 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003164
3165 LocationAccessPolicy.LocationPermissionResult locationResult =
3166 LocationAccessPolicy.checkLocationPermission(mApp,
3167 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3168 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003169 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003170 .setCallingPid(Binder.getCallingPid())
3171 .setCallingUid(Binder.getCallingUid())
3172 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003173 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3174 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003175 .build());
3176 switch (locationResult) {
3177 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003178 if (TelephonyPermissions
3179 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003180 // Safetynet logging for b/154934934
3181 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3182 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003183 throw new SecurityException("Not allowed to access cell info");
3184 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003185 if (TelephonyPermissions
3186 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003187 // Safetynet logging for b/154934934
3188 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3189 }
Nathan Harold5320c422019-05-09 10:26:08 -07003190 try {
3191 cb.onCellInfo(new ArrayList<CellInfo>());
3192 } catch (RemoteException re) {
3193 // Drop without consequences
3194 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003195 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003196 }
3197
Nathan Harolda939a962019-05-09 10:13:47 -07003198
3199 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003200 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3201
3202 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3203 }
3204
3205 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003207 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003212 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 }
3217
Shishir Agrawala9f32182016-04-12 12:00:16 -07003218 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003219 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003220 Phone phone = PhoneFactory.getPhone(slotIndex);
3221 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003222 return null;
3223 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003224 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003225 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003226 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003227 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003228 return null;
3229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230
3231 final long identity = Binder.clearCallingIdentity();
3232 try {
3233 return phone.getImei();
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003237 }
3238
3239 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003240 public String getTypeAllocationCodeForSlot(int slotIndex) {
3241 Phone phone = PhoneFactory.getPhone(slotIndex);
3242 String tac = null;
3243 if (phone != null) {
3244 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003245 try {
3246 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3247 } catch (IndexOutOfBoundsException e) {
3248 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3249 return null;
3250 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003251 }
3252 return tac;
3253 }
3254
3255 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003256 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003257 try {
3258 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3259 } catch (SecurityException se) {
3260 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3261 throw new SecurityException("Package " + callingPackage + " does not belong to "
3262 + Binder.getCallingUid());
3263 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003264 Phone phone = PhoneFactory.getPhone(slotIndex);
3265 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003266 return null;
3267 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003268
Jeff Davidson913390f2018-02-23 17:11:49 -08003269 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003270 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003271 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003272 return null;
3273 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274
3275 final long identity = Binder.clearCallingIdentity();
3276 try {
3277 return phone.getMeid();
3278 } finally {
3279 Binder.restoreCallingIdentity(identity);
3280 }
Jack Yu2af8d712017-03-15 17:14:14 -07003281 }
3282
3283 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003284 public String getManufacturerCodeForSlot(int slotIndex) {
3285 Phone phone = PhoneFactory.getPhone(slotIndex);
3286 String manufacturerCode = null;
3287 if (phone != null) {
3288 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003289 try {
3290 manufacturerCode =
3291 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3292 } catch (IndexOutOfBoundsException e) {
3293 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3294 return null;
3295 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003296 }
3297 return manufacturerCode;
3298 }
3299
3300 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003301 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3302 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003303 Phone phone = PhoneFactory.getPhone(slotIndex);
3304 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003305 return null;
3306 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003307 int subId = phone.getSubId();
3308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003309 mApp, subId, callingPackage, callingFeatureId,
3310 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003311 return null;
3312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 return phone.getDeviceSvn();
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003320 }
3321
fionaxu43304da2017-11-27 22:51:16 -08003322 @Override
3323 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 final Phone phone = getPhone(subId);
3327 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
3330 }
fionaxu43304da2017-11-27 22:51:16 -08003331 }
3332
3333 @Override
3334 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 final Phone phone = getPhone(subId);
3338 return phone == null ? null : phone.getCarrierName();
3339 } finally {
3340 Binder.restoreCallingIdentity(identity);
3341 }
fionaxu43304da2017-11-27 22:51:16 -08003342 }
3343
calvinpanffe225e2018-11-01 19:43:06 +08003344 @Override
chen xu0026ca62019-03-06 15:28:50 -08003345 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 final Phone phone = getPhone(subId);
3349 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003350 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
3354 }
3355
3356 @Override
chen xu0026ca62019-03-06 15:28:50 -08003357 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003361 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
3365 }
3366
chen xu651eec72018-11-11 19:03:44 -08003367 @Override
chen xu864e11c2018-12-06 22:10:03 -08003368 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3369 if (!isSubscriptionMccMnc) {
3370 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3371 }
chen xu651eec72018-11-11 19:03:44 -08003372 final Phone phone = PhoneFactory.getPhone(slotIndex);
3373 if (phone == null) {
3374 return TelephonyManager.UNKNOWN_CARRIER_ID;
3375 }
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3379 } finally {
3380 Binder.restoreCallingIdentity(identity);
3381 }
3382 }
3383
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003384 //
3385 // Internal helper methods.
3386 //
3387
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003388 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003389 * Make sure the caller is the calling package itself
3390 *
3391 * @throws SecurityException if the caller is not the calling package
3392 */
3393 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3394 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003395 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3396 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003397 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003398 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003399 } catch (PackageManager.NameNotFoundException e) {
3400 // packageUid is -1
3401 }
3402 if (packageUid != callingUid) {
3403 throw new SecurityException(message + ": Package " + callingPackage
3404 + " does not belong to " + callingUid);
3405 }
3406 }
3407
3408 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003409 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3410 *
3411 * @throws SecurityException if the caller does not have the required permission
3412 */
3413 private void enforceModifyPermission() {
3414 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3415 }
3416
Shuo Qian3b6ee772019-11-13 17:43:31 -08003417 private void enforceActiveEmergencySessionPermission() {
3418 mApp.enforceCallingOrSelfPermission(
3419 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3420 }
3421
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003422 /**
3423 * Make sure the caller has the CALL_PHONE permission.
3424 *
3425 * @throws SecurityException if the caller does not have the required permission
3426 */
3427 private void enforceCallPermission() {
3428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3429 }
3430
paulhu5a773602019-08-23 19:17:33 +08003431 private void enforceSettingsPermission() {
3432 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003433 }
3434
Michele Berionne5e411512020-11-13 02:36:59 +00003435 private void enforceRebootPermission() {
3436 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3437 }
3438
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003439 private String createTelUrl(String number) {
3440 if (TextUtils.isEmpty(number)) {
3441 return null;
3442 }
3443
Jake Hambye994d462014-02-03 13:10:13 -08003444 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 }
3446
Ihab Awadf9e92732013-12-05 18:02:52 -08003447 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3449 }
3450
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003451 private static void logv(String msg) {
3452 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3453 }
3454
Ihab Awadf9e92732013-12-05 18:02:52 -08003455 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003456 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3457 }
3458
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003459 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003460 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003461 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003462 }
3463
Sanket Padawe356d7632015-06-22 14:03:32 -07003464 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003465 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 final Phone phone = PhoneFactory.getPhone(slotIndex);
3469 if (phone == null) {
3470 return PhoneConstants.PHONE_TYPE_NONE;
3471 } else {
3472 return phone.getPhoneType();
3473 }
3474 } finally {
3475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003477 }
3478
3479 /**
3480 * Returns the CDMA ERI icon index to display
3481 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003482 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003483 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3484 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3485 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003486 }
3487
Sanket Padawe356d7632015-06-22 14:03:32 -07003488 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003489 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3490 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003492 mApp, subId, callingPackage, callingFeatureId,
3493 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003494 return -1;
3495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003496
3497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 final Phone phone = getPhone(subId);
3500 if (phone != null) {
3501 return phone.getCdmaEriIconIndex();
3502 } else {
3503 return -1;
3504 }
3505 } finally {
3506 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 }
3509
3510 /**
3511 * Returns the CDMA ERI icon mode,
3512 * 0 - ON
3513 * 1 - FLASHING
3514 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003515 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003516 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3517 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3518 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003519 }
3520
Sanket Padawe356d7632015-06-22 14:03:32 -07003521 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003522 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3523 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003525 mApp, subId, callingPackage, callingFeatureId,
3526 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003527 return -1;
3528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529
3530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 final Phone phone = getPhone(subId);
3533 if (phone != null) {
3534 return phone.getCdmaEriIconMode();
3535 } else {
3536 return -1;
3537 }
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003541 }
3542
3543 /**
3544 * Returns the CDMA ERI text,
3545 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003546 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003547 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3548 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3549 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003550 }
3551
Sanket Padawe356d7632015-06-22 14:03:32 -07003552 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003553 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3554 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003556 mApp, subId, callingPackage, callingFeatureId,
3557 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003558 return null;
3559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 final Phone phone = getPhone(subId);
3564 if (phone != null) {
3565 return phone.getCdmaEriText();
3566 } else {
3567 return null;
3568 }
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003572 }
3573
3574 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003575 * Returns the CDMA MDN.
3576 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003577 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003578 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3580 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581
3582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003585 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586 return phone.getLine1Number();
3587 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003588 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589 return null;
3590 }
3591 } finally {
3592 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003593 }
3594 }
3595
3596 /**
3597 * Returns the CDMA MIN.
3598 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003599 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003600 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3602 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603
3604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 final Phone phone = getPhone(subId);
3607 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3608 return phone.getCdmaMin();
3609 } else {
3610 return null;
3611 }
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003614 }
3615 }
3616
Hall Liud892bec2018-11-30 14:51:45 -08003617 @Override
3618 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3619 INumberVerificationCallback callback, String callingPackage) {
3620 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3621 != PERMISSION_GRANTED) {
3622 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3623 }
3624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3625
3626 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3627 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003628 throw new SecurityException("Calling package must be configured in the device config: "
3629 + "calling package: " + callingPackage
3630 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003631 }
3632
3633 if (range == null) {
3634 throw new NullPointerException("Range must be non-null");
3635 }
3636
3637 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003638 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003639
3640 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3641 }
3642
Junda Liuca05d5d2014-08-14 22:36:34 -07003643 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003644 * Returns true if CDMA provisioning needs to run.
3645 */
3646 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647 final long identity = Binder.clearCallingIdentity();
3648 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003649 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003653 }
3654
3655 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003656 * Sets the voice mail number of a given subId.
3657 */
3658 @Override
3659 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003660 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3661 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662
3663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3666 new Pair<String, String>(alphaTag, number), new Integer(subId));
3667 return success;
3668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003671 }
3672
Ta-wei Yen87c49842016-05-13 21:19:52 -07003673 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003674 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3675 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003676 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3677 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003678 if (!TextUtils.equals(callingPackage, systemDialer)) {
3679 throw new SecurityException("caller must be system dialer");
3680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681
3682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3685 if (phoneAccountHandle == null) {
3686 return null;
3687 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003688 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689 } finally {
3690 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003691 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003692 }
3693
3694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003695 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3696 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003697 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003699 mApp, subId, callingPackage, callingFeatureId,
3700 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003701 return null;
3702 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003703
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003704 final long identity = Binder.clearCallingIdentity();
3705 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003710 }
3711
3712 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003713 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3714 VisualVoicemailSmsFilterSettings settings) {
3715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716
3717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003720 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003724 }
3725
3726 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003727 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729
3730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003733 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003737 }
3738
3739 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003740 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3741 String callingPackage, int subId) {
3742 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743
3744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003747 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748 } finally {
3749 Binder.restoreCallingIdentity(identity);
3750 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003751 }
3752
3753 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003754 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756
3757 final long identity = Binder.clearCallingIdentity();
3758 try {
3759 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003764 }
3765
3766 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003767 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3768 String callingAttributionTag, int subId, String number, int port, String text,
3769 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003770 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003771 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003772 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003773 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003774 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3775 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003776 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003777
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003778 /**
fionaxu0152e512016-11-14 13:36:14 -08003779 * Sets the voice activation state of a given subId.
3780 */
3781 @Override
3782 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3784 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 final Phone phone = getPhone(subId);
3789 if (phone != null) {
3790 phone.setVoiceActivationState(activationState);
3791 } else {
3792 loge("setVoiceActivationState fails with invalid subId: " + subId);
3793 }
3794 } finally {
3795 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003796 }
3797 }
3798
3799 /**
3800 * Sets the data activation state of a given subId.
3801 */
3802 @Override
3803 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3805 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806
3807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 final Phone phone = getPhone(subId);
3810 if (phone != null) {
3811 phone.setDataActivationState(activationState);
3812 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003813 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 }
3815 } finally {
3816 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003817 }
3818 }
3819
3820 /**
3821 * Returns the voice activation state of a given subId.
3822 */
3823 @Override
3824 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826
fionaxu0152e512016-11-14 13:36:14 -08003827 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 if (phone != null) {
3831 return phone.getVoiceActivationState();
3832 } else {
3833 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3834 }
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003837 }
3838 }
3839
3840 /**
3841 * Returns the data activation state of a given subId.
3842 */
3843 @Override
3844 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003846
fionaxu0152e512016-11-14 13:36:14 -08003847 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 if (phone != null) {
3851 return phone.getDataActivationState();
3852 } else {
3853 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3854 }
3855 } finally {
3856 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003857 }
3858 }
3859
3860 /**
Wink Saville36469e72014-06-11 15:17:00 -07003861 * Returns the unread count of voicemails for a subId
3862 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003863 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003864 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3865 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003867 mApp, subId, callingPackage, callingFeatureId,
3868 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003869 return 0;
3870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 final Phone phone = getPhone(subId);
3874 if (phone != null) {
3875 return phone.getVoiceMessageCount();
3876 } else {
3877 return 0;
3878 }
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003882 }
3883
3884 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003885 * returns true, if the device is in a state where both voice and data
3886 * are supported simultaneously. This can change based on location or network condition.
3887 */
3888 @Override
3889 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890 final long identity = Binder.clearCallingIdentity();
3891 try {
3892 final Phone phone = getPhone(subId);
3893 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
3896 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003897 }
3898
3899 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003900 * Send the dialer code if called from the current default dialer or the caller has
3901 * carrier privilege.
3902 * @param inputCode The dialer code to send
3903 */
3904 @Override
3905 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003906 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003907 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003908 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3909 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003910 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003911 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003912 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914
3915 final long identity = Binder.clearCallingIdentity();
3916 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003917 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
fionaxu235cc5e2017-03-06 22:25:57 -08003921 }
3922
Pengquan Menga1bb6272018-09-06 09:59:22 -07003923 @Override
3924 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003925 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003926 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003927 mApp, subId, "getNetworkSelectionMode");
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 if (!isActiveSubscription(subId)) {
3931 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3932 }
3933 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003936 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003937 }
3938
Brad Ebinger35c841c2018-10-01 10:40:55 -07003939 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003940 public boolean isInEmergencySmsMode() {
3941 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 for (Phone phone : PhoneFactory.getPhones()) {
3945 if (phone.isInEmergencySmsMode()) {
3946 return true;
3947 }
3948 }
3949 } finally {
3950 Binder.restoreCallingIdentity(identity);
3951 }
3952 return false;
3953 }
3954
shilu366312e2019-12-17 09:28:10 -08003955 /**
3956 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3957 * @param subId The subscription to use to check the configuration.
3958 * @param c The callback that will be used to send the result.
3959 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003960 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003961 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3962 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003963 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003964 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003965
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003966 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3967 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3968 "IMS not available on device.");
3969 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 final long token = Binder.clearCallingIdentity();
3971 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003972 int slotId = getSlotIndexOrException(subId);
3973 verifyImsMmTelConfiguredOrThrow(slotId);
3974 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003975 } catch (ImsException e) {
3976 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 } finally {
3978 Binder.restoreCallingIdentity(token);
3979 }
3980 }
3981
shilu366312e2019-12-17 09:28:10 -08003982 /**
3983 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3984 * @param subId The subscription to use to check the configuration.
3985 * @param c The callback that will be used to send the result.
3986 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003988 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003989 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003990 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003991 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3992 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3993 }
Meng Wangafbc5852019-09-19 17:37:13 -07003994 final long token = Binder.clearCallingIdentity();
3995 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003996 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3997 .removeRegistrationCallbackForSubscription(c, subId);
3998 } catch (ImsException e) {
3999 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4000 + "is inactive, ignoring unregister.");
4001 // If the subscription is no longer active, just return, since the callback
4002 // will already have been removed internally.
4003 } finally {
4004 Binder.restoreCallingIdentity(token);
4005 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 }
4007
Brad Ebingera34a6c22019-10-22 17:36:18 -07004008 /**
4009 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4010 */
4011 @Override
4012 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4013 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4014 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4015 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4016 "IMS not available on device.");
4017 }
4018 final long token = Binder.clearCallingIdentity();
4019 try {
4020 Phone phone = getPhone(subId);
4021 if (phone == null) {
4022 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4023 + subId + "'");
4024 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4025 }
4026 phone.getImsRegistrationState(regState -> {
4027 try {
4028 consumer.accept((regState == null)
4029 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4030 } catch (RemoteException e) {
4031 // Ignore if the remote process is no longer available to call back.
4032 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4033 }
4034 });
4035 } finally {
4036 Binder.restoreCallingIdentity(token);
4037 }
4038 }
4039
4040 /**
4041 * Get the transport type for the IMS service registration state.
4042 */
4043 @Override
4044 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004045 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004046 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004047 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4048 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4049 "IMS not available on device.");
4050 }
4051 final long token = Binder.clearCallingIdentity();
4052 try {
4053 Phone phone = getPhone(subId);
4054 if (phone == null) {
4055 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4056 + subId + "'");
4057 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4058 }
4059 phone.getImsRegistrationTech(regTech -> {
4060 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4061 int regTechConverted = (regTech == null)
4062 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4063 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4064 regTechConverted);
4065 try {
4066 consumer.accept(regTechConverted);
4067 } catch (RemoteException e) {
4068 // Ignore if the remote process is no longer available to call back.
4069 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4070 }
4071 });
4072 } finally {
4073 Binder.restoreCallingIdentity(token);
4074 }
4075 }
4076
shilu366312e2019-12-17 09:28:10 -08004077 /**
4078 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4079 * @param subId The subscription to use to check the configuration.
4080 * @param c The callback that will be used to send the result.
4081 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004083 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4084 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004085 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004086 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004087 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4088 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4089 "IMS not available on device.");
4090 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 final long token = Binder.clearCallingIdentity();
4092 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004093 int slotId = getSlotIndexOrException(subId);
4094 verifyImsMmTelConfiguredOrThrow(slotId);
4095 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004096 } catch (ImsException e) {
4097 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 } finally {
4099 Binder.restoreCallingIdentity(token);
4100 }
4101 }
4102
shilu366312e2019-12-17 09:28:10 -08004103 /**
4104 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4105 * @param subId The subscription to use to check the configuration.
4106 * @param c The callback that will be used to send the result.
4107 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004109 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004110 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004111 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004112 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4113 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4114 }
Meng Wangafbc5852019-09-19 17:37:13 -07004115
4116 final long token = Binder.clearCallingIdentity();
4117 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004118 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004119 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004120 } catch (ImsException e) {
4121 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4122 + "is inactive, ignoring unregister.");
4123 // If the subscription is no longer active, just return, since the callback
4124 // will already have been removed internally.
4125 } finally {
4126 Binder.restoreCallingIdentity(token);
4127 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 }
4129
4130 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004131 public boolean isCapable(int subId, int capability, int regTech) {
4132 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 final long token = Binder.clearCallingIdentity();
4134 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004135 int slotId = getSlotIndexOrException(subId);
4136 verifyImsMmTelConfiguredOrThrow(slotId);
4137 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004138 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4140 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004141 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004142 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4143 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 } finally {
4145 Binder.restoreCallingIdentity(token);
4146 }
4147 }
4148
4149 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004150 public boolean isAvailable(int subId, int capability, int regTech) {
4151 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 final long token = Binder.clearCallingIdentity();
4153 try {
4154 Phone phone = getPhone(subId);
4155 if (phone == null) return false;
4156 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004157 } catch (com.android.ims.ImsException e) {
4158 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4159 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 } finally {
4161 Binder.restoreCallingIdentity(token);
4162 }
4163 }
4164
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004165 /**
4166 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4167 * subscription.
4168 * @param subId The subscription to use to check the configuration.
4169 * @param callback The callback that will be used to send the result.
4170 * @param capability The MmTelFeature capability that will be used to send the result.
4171 * @param transportType The transport type of the MmTelFeature capability.
4172 */
4173 @Override
4174 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4175 int transportType) {
4176 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4177 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4178 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4179 "IMS not available on device.");
4180 }
4181 final long token = Binder.clearCallingIdentity();
4182 try {
4183 int slotId = getSlotIndex(subId);
4184 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4185 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4186 + subId + "'");
4187 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4188 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004189 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004190 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4191 transportType, aBoolean -> {
4192 try {
4193 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4194 } catch (RemoteException e) {
4195 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4196 + "running. Ignore");
4197 }
4198 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004199 } catch (ImsException e) {
4200 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004201 } finally {
4202 Binder.restoreCallingIdentity(token);
4203 }
4204 }
4205
shilu366312e2019-12-17 09:28:10 -08004206 /**
4207 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4208 * @param subId The subscription to use to check the configuration.
4209 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 @Override
4211 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004212 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004213 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004214
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 final long token = Binder.clearCallingIdentity();
4216 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004217 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004218 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004219 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004220 } catch (ImsException e) {
4221 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 } finally {
4223 Binder.restoreCallingIdentity(token);
4224 }
4225 }
4226
4227 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004228 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004230 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 final long identity = Binder.clearCallingIdentity();
4232 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004233 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004234 // This setting doesn't require an active ImsService connection, so do not verify. The
4235 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004236 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004237 } catch (ImsException e) {
4238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
4242 }
4243
shilu366312e2019-12-17 09:28:10 -08004244 /**
4245 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4246 * @param subId The subscription to use to check the configuration.
4247 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004248 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004249 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004250 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004251 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004252 final long identity = Binder.clearCallingIdentity();
4253 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004254 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004255 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004256 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004257 } catch (ImsException e) {
4258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
4262 }
4263
4264 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004265 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004267 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 final long identity = Binder.clearCallingIdentity();
4269 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004270 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004271 // This setting doesn't require an active ImsService connection, so do not verify. The
4272 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004273 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004274 } catch (ImsException e) {
4275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
4279 }
4280
shilu366312e2019-12-17 09:28:10 -08004281 /**
4282 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4283 * @param subId The subscription to use to check the configuration.
4284 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 @Override
4286 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004287 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004288 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 final long identity = Binder.clearCallingIdentity();
4290 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004291 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004292 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004293 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004294 } catch (ImsException e) {
4295 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
4299 }
4300
4301 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004302 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004304 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 final long identity = Binder.clearCallingIdentity();
4306 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004307 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004308 // This setting doesn't require an active ImsService connection, so do not verify. The
4309 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004310 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004311 } catch (ImsException e) {
4312 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
4316 }
4317
shilu366312e2019-12-17 09:28:10 -08004318 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004319 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4320 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4321 * @param subId The subscription to use to check the configuration.
4322 */
4323 @Override
4324 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004325 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004326 mApp, subId, "isCrossSimCallingEnabledByUser");
4327 final long identity = Binder.clearCallingIdentity();
4328 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004329 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004330 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004331 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004332 } catch (ImsException e) {
4333 throw new ServiceSpecificException(e.getCode());
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
4337 }
4338
4339 /**
4340 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4341 * Requires MODIFY_PHONE_STATE permission.
4342 * @param subId The subscription to use to check the configuration.
4343 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4344 * false otherwise
4345 */
4346 @Override
4347 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4349 "setCrossSimCallingEnabled");
4350 final long identity = Binder.clearCallingIdentity();
4351 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004352 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004353 // This setting doesn't require an active ImsService connection, so do not verify. The
4354 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004355 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004356 } catch (ImsException e) {
4357 throw new ServiceSpecificException(e.getCode());
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
4361 }
4362
4363 /**
shilu366312e2019-12-17 09:28:10 -08004364 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4365 * @param subId The subscription to use to check the configuration.
4366 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004368
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004370 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004371 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 final long identity = Binder.clearCallingIdentity();
4373 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004375 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004376 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004377 } catch (ImsException e) {
4378 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
4382 }
4383
4384 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004385 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004387 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004388 final long identity = Binder.clearCallingIdentity();
4389 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004390 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004391 // This setting doesn't require an active ImsService connection, so do not verify. The
4392 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004394 } catch (ImsException e) {
4395 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004396 } finally {
4397 Binder.restoreCallingIdentity(identity);
4398 }
4399 }
4400
4401 @Override
4402 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4404 "setVoWiFiNonPersistent");
4405 final long identity = Binder.clearCallingIdentity();
4406 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004407 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004408 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004409 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004410 } catch (ImsException e) {
4411 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
4415 }
4416
shilu366312e2019-12-17 09:28:10 -08004417 /**
4418 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4419 * @param subId The subscription to use to check the configuration.
4420 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004421 @Override
4422 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004423 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004424 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004425 final long identity = Binder.clearCallingIdentity();
4426 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004427 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004428 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004429 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004430 } catch (ImsException e) {
4431 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
4435 }
4436
4437 @Override
4438 public void setVoWiFiModeSetting(int subId, int mode) {
4439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4440 "setVoWiFiModeSetting");
4441 final long identity = Binder.clearCallingIdentity();
4442 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004444 // This setting doesn't require an active ImsService connection, so do not verify. The
4445 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004446 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004447 } catch (ImsException e) {
4448 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
4452 }
4453
4454 @Override
4455 public int getVoWiFiRoamingModeSetting(int subId) {
4456 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4457 final long identity = Binder.clearCallingIdentity();
4458 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004460 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004462 } catch (ImsException e) {
4463 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
4467 }
4468
4469 @Override
4470 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4472 "setVoWiFiRoamingModeSetting");
4473 final long identity = Binder.clearCallingIdentity();
4474 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004475 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004476 // This setting doesn't require an active ImsService connection, so do not verify. The
4477 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004479 } catch (ImsException e) {
4480 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
4484 }
4485
4486 @Override
4487 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4489 "setRttCapabilityEnabled");
4490 final long identity = Binder.clearCallingIdentity();
4491 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004492 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004493 // This setting doesn't require an active ImsService connection, so do not verify. The
4494 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004496 } catch (ImsException e) {
4497 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
4501 }
4502
shilu366312e2019-12-17 09:28:10 -08004503 /**
4504 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4505 * @param subId The subscription to use to check the configuration.
4506 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004507 @Override
4508 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004509 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004510 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004511 final long identity = Binder.clearCallingIdentity();
4512 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004513 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004514 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004516 } catch (ImsException e) {
4517 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
4521 }
4522
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004523 @Override
4524 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4525 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4526 final long identity = Binder.clearCallingIdentity();
4527 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004528 if (!isImsAvailableOnDevice()) {
4529 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4530 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004531 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004532 int slotId = getSlotIndexOrException(subId);
4533 verifyImsMmTelConfiguredOrThrow(slotId);
4534 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004535 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004536 } catch (ImsException e) {
4537 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
4541 }
4542
4543 @Override
4544 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4545 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4546 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004547 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4548 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4549 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004550 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004551 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004552 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004553 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004554 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4555 + "is inactive, ignoring unregister.");
4556 // If the subscription is no longer active, just return, since the callback will already
4557 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004558 } finally {
4559 Binder.restoreCallingIdentity(identity);
4560 }
4561 }
4562
allenwtsu99c623b2020-01-03 18:24:23 +08004563
4564 private void checkModifyPhoneStatePermission(int subId, String message) {
4565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4566 message);
4567 }
4568
4569 private boolean isImsProvisioningRequired(int subId, int capability,
4570 boolean isMmtelCapability) {
4571 Phone phone = getPhone(subId);
4572 if (phone == null) {
4573 loge("phone instance null for subid " + subId);
4574 return false;
4575 }
4576 if (isMmtelCapability) {
4577 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4578 return false;
4579 }
4580 } else {
4581 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4582 return false;
4583 }
4584 }
4585 return true;
4586 }
4587
4588 @Override
4589 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4590 boolean isProvisioned) {
4591 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4592
4593 final long identity = Binder.clearCallingIdentity();
4594 try {
4595 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4596 if (!isImsProvisioningRequired(subId, capability, false)) {
4597 return;
4598 }
4599
4600 // this capability requires provisioning, route to the correct API.
4601 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4602 switch (capability) {
4603 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4604 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4605 ims.setEabProvisioned(isProvisioned);
4606 break;
4607 default: {
4608 throw new IllegalArgumentException("Tried to set provisioning for "
4609 + "rcs capability '" + capability + "', which does not require "
4610 + "provisioning.");
4611 }
4612 }
4613 } finally {
4614 Binder.restoreCallingIdentity(identity);
4615 }
4616
4617 }
4618
4619
4620 @Override
4621 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4622 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4623 final long identity = Binder.clearCallingIdentity();
4624 try {
4625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4626 if (!isImsProvisioningRequired(subId, capability, false)) {
4627 return true;
4628 }
4629
4630 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4631 switch (capability) {
4632 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4633 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4634 return ims.isEabProvisionedOnDevice();
4635
4636 default: {
4637 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4638 + "capability '" + capability + "', which does not require "
4639 + "provisioning.");
4640 }
4641 }
4642
4643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
4646 }
4647
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004648 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004649 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4650 boolean isProvisioned) {
4651 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004652 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4653 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4654 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004655 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4656 }
allenwtsu99c623b2020-01-03 18:24:23 +08004657 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004658 final long identity = Binder.clearCallingIdentity();
4659 try {
4660 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004661 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662 return;
4663 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004664 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4665 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4666 loge("setImsProvisioningStatusForCapability: called for technology that does "
4667 + "not support provisioning - " + tech);
4668 return;
4669 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004670
4671 // this capability requires provisioning, route to the correct API.
4672 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4673 switch (capability) {
4674 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4675 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4676 ims.setVolteProvisioned(isProvisioned);
4677 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4678 ims.setWfcProvisioned(isProvisioned);
4679 }
4680 break;
4681 }
4682 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4683 // There is currently no difference in VT provisioning type.
4684 ims.setVtProvisioned(isProvisioned);
4685 break;
4686 }
4687 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4688 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4689 // change the capability of the feature instead if needed.
4690 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4691 == isProvisioned) {
4692 // No change in provisioning.
4693 return;
4694 }
4695 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4696 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004697 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004698 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004699 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4700 + ", Exception" + e.getMessage());
4701 }
4702 break;
4703 }
4704 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004705 throw new IllegalArgumentException("Tried to set provisioning for "
4706 + "MmTel capability '" + capability + "', which does not require "
4707 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 }
4709 }
4710
4711 } finally {
4712 Binder.restoreCallingIdentity(identity);
4713 }
4714 }
4715
4716 @Override
4717 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4718 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004719 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4720 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4721 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004722 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4723 }
4724 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4725 final long identity = Binder.clearCallingIdentity();
4726 try {
4727 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004728 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004729 return true;
4730 }
4731
Brad Ebinger0d79c572021-04-17 15:20:49 -07004732 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4733 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4734 loge("getImsProvisioningStatusForCapability: called for technology that does "
4735 + "not support provisioning - " + tech);
4736 return true;
4737 }
4738
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004739 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4740 switch (capability) {
4741 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4742 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4743 return ims.isVolteProvisionedOnDevice();
4744 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4745 return ims.isWfcProvisionedOnDevice();
4746 }
4747 // This should never happen, since we are checking tech above to make sure it
4748 // is either LTE or IWLAN.
4749 throw new IllegalArgumentException("Invalid radio technology for voice "
4750 + "capability.");
4751 }
4752 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4753 // There is currently no difference in VT provisioning type.
4754 return ims.isVtProvisionedOnDevice();
4755 }
4756 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4757 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4758 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4759 }
4760 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004761 throw new IllegalArgumentException(
4762 "Tried to get provisioning for MmTel capability '" + capability
4763 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004764 }
4765 }
4766
4767 } finally {
4768 Binder.restoreCallingIdentity(identity);
4769 }
4770 }
4771
4772 @Override
4773 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4774 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4775 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4776 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4777 }
4778 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4779 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4780 return (provisionedBits & capability) > 0;
4781 }
4782
4783 @Override
4784 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4785 boolean isProvisioned) {
4786 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4787 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4788 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4789 }
4790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4791 "setProvisioningStatusForCapability");
4792 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4793 // If the current provisioning status for capability already matches isProvisioned,
4794 // do nothing.
4795 if (((provisionedBits & capability) > 0) == isProvisioned) {
4796 return;
4797 }
4798 if (isProvisioned) {
4799 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4800 } else {
4801 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4802 }
4803 }
4804
4805 /**
4806 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4807 * technology. The bitfield should mirror the bitfield defined by
4808 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4809 */
4810 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4811 String key = getMmTelProvisioningKey(subId, tech);
4812 // Default is no capabilities are provisioned.
4813 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4814 }
4815
4816 /**
4817 * Sets the MmTel capability provisioning bitfield (defined by
4818 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4819 * technology specified.
4820 *
4821 * Note: This is a synchronous command and should not be called on UI thread.
4822 */
4823 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4824 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4825 String key = getMmTelProvisioningKey(subId, tech);
4826 editor.putInt(key, newField);
4827 editor.commit();
4828 }
4829
4830 private static String getMmTelProvisioningKey(int subId, int tech) {
4831 // resulting key is provision_ims_mmtel_{subId}_{tech}
4832 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4833 }
4834
4835 /**
4836 * Query CarrierConfig to see if the specified capability requires provisioning for the
4837 * carrier associated with the subscription id.
4838 */
4839 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4840 int capability) {
4841 CarrierConfigManager configManager = new CarrierConfigManager(context);
4842 PersistableBundle c = configManager.getConfigForSubId(subId);
4843 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004844 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004845 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4846 false);
4847 boolean requireVoiceVtProvisioning = c.getBoolean(
4848 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4849
4850 // First check to make sure that the capability requires provisioning.
4851 switch (capability) {
4852 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4853 // intentional fallthrough
4854 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4855 if (requireVoiceVtProvisioning) {
4856 // Voice and Video requires provisioning
4857 return true;
4858 }
4859 break;
4860 }
4861 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4862 if (requireUtProvisioning) {
4863 // UT requires provisioning
4864 return true;
4865 }
4866 break;
4867 }
4868 }
4869 return false;
4870 }
4871
allenwtsu99c623b2020-01-03 18:24:23 +08004872 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4873 int capability) {
4874 CarrierConfigManager configManager = new CarrierConfigManager(context);
4875 PersistableBundle c = configManager.getConfigForSubId(subId);
4876
4877 boolean requireRcsProvisioning = c.getBoolean(
4878 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4879
4880 // First check to make sure that the capability requires provisioning.
4881 switch (capability) {
4882 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4883 // intentional fallthrough
4884 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4885 if (requireRcsProvisioning) {
4886 // OPTION or PRESENCE requires provisioning
4887 return true;
4888 }
4889 break;
4890 }
4891 }
4892 return false;
4893 }
4894
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004895 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004896 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4898 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4899 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004900 enforceReadPrivilegedPermission("getImsProvisioningInt");
4901 final long identity = Binder.clearCallingIdentity();
4902 try {
4903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004904 int slotId = getSlotIndex(subId);
4905 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4906 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4907 + subId + "' for key:" + key);
4908 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4909 }
calvinpanb5a34062021-02-08 19:59:36 +08004910 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004911 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004912 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4913 + subId + "' for key:" + key);
4914 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004915 } finally {
4916 Binder.restoreCallingIdentity(identity);
4917 }
4918 }
4919
4920 @Override
4921 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004922 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4923 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4924 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004925 enforceReadPrivilegedPermission("getImsProvisioningString");
4926 final long identity = Binder.clearCallingIdentity();
4927 try {
4928 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 int slotId = getSlotIndex(subId);
4930 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4931 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4932 + subId + "' for key:" + key);
4933 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4934 }
calvinpanb5a34062021-02-08 19:59:36 +08004935 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004936 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004937 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4938 + subId + "' for key:" + key);
4939 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004940 } finally {
4941 Binder.restoreCallingIdentity(identity);
4942 }
4943 }
4944
4945 @Override
4946 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4948 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4949 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4951 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004952 final long identity = Binder.clearCallingIdentity();
4953 try {
4954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 int slotId = getSlotIndex(subId);
4956 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4957 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4958 + subId + "' for key:" + key);
4959 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4960 }
calvinpanb5a34062021-02-08 19:59:36 +08004961 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4962 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004963 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004964 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004965 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004966 } finally {
4967 Binder.restoreCallingIdentity(identity);
4968 }
4969 }
4970
4971 @Override
4972 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004973 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4974 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4975 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4977 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004978 final long identity = Binder.clearCallingIdentity();
4979 try {
4980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004981 int slotId = getSlotIndex(subId);
4982 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4983 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4984 + subId + "' for key:" + key);
4985 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4986 }
calvinpanb5a34062021-02-08 19:59:36 +08004987 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4988 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004989 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004990 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004991 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004992 } finally {
4993 Binder.restoreCallingIdentity(identity);
4994 }
4995 }
4996
Brad Ebinger919631e2021-06-02 17:46:35 -07004997 /**
4998 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4999 * for the given slot ID or no ImsResolver instance has been created.
5000 * @param slotId The slot ID that the IMS service is created for.
5001 * @throws ImsException If there is no ImsService configured for this slot.
5002 */
5003 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5004 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5005 ImsFeature.FEATURE_MMTEL)) {
5006 throw new ImsException("This subscription does not support MMTEL over IMS",
5007 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5008 }
5009 }
5010
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005011 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005012 int slotId = SubscriptionManager.getSlotIndex(subId);
5013 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005014 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5015 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005016 }
5017 return slotId;
5018 }
5019
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005020 private int getSlotIndex(int subId) {
5021 int slotId = SubscriptionManager.getSlotIndex(subId);
5022 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5023 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5024 }
5025 return slotId;
5026 }
5027
Wink Saville36469e72014-06-11 15:17:00 -07005028 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005029 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005030 */
5031 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005032 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5033 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005034 try {
5035 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5036 } catch (SecurityException se) {
5037 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5038 throw new SecurityException("Package " + callingPackage + " does not belong to "
5039 + Binder.getCallingUid());
5040 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005041 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005042 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005043 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005044 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005045 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005046 mApp, subId, callingPackage, callingFeatureId,
5047 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005048 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5049 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051 final long identity = Binder.clearCallingIdentity();
5052 try {
5053 final Phone phone = getPhone(subId);
5054 if (phone != null) {
5055 return phone.getServiceState().getDataNetworkType();
5056 } else {
5057 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5058 }
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005062 }
5063
5064 /**
5065 * Returns the data network type
5066 */
5067 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005068 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005069 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5070 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005071 }
5072
5073 /**
5074 * Returns the data network type for a subId
5075 */
5076 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005077 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5078 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005079 String functionName = "getDataNetworkTypeForSubscriber";
5080 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5081 mApp, functionName)) {
5082 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5083 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5084 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5085 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005086 }
5087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 final long identity = Binder.clearCallingIdentity();
5089 try {
5090 final Phone phone = getPhone(subId);
5091 if (phone != null) {
5092 return phone.getServiceState().getDataNetworkType();
5093 } else {
5094 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5095 }
5096 } finally {
5097 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005098 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005099 }
5100
5101 /**
Wink Saville36469e72014-06-11 15:17:00 -07005102 * Returns the Voice network type for a subId
5103 */
5104 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005105 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5106 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005107 String functionName = "getVoiceNetworkTypeForSubscriber";
5108 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5109 mApp, functionName)) {
5110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5111 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5112 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5113 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005114 }
5115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 final long identity = Binder.clearCallingIdentity();
5117 try {
5118 final Phone phone = getPhone(subId);
5119 if (phone != null) {
5120 return phone.getServiceState().getVoiceNetworkType();
5121 } else {
5122 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5123 }
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005127 }
5128
5129 /**
5130 * @return true if a ICC card is present
5131 */
5132 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005133 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005134 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5135 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005136 }
5137
5138 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005139 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005140 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005141 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005142 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 final Phone phone = PhoneFactory.getPhone(slotIndex);
5146 if (phone != null) {
5147 return phone.getIccCard().hasIccCard();
5148 } else {
5149 return false;
5150 }
5151 } finally {
5152 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005154 }
5155
5156 /**
5157 * Return if the current radio is LTE on CDMA. This
5158 * is a tri-state return value as for a period of time
5159 * the mode may be unknown.
5160 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005161 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005162 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005163 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005164 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005166 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5167 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5168 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005169 }
5170
Sanket Padawe356d7632015-06-22 14:03:32 -07005171 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005172 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5173 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005174 try {
5175 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5176 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005177 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5178 }
5179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 final long identity = Binder.clearCallingIdentity();
5181 try {
5182 final Phone phone = getPhone(subId);
5183 if (phone == null) {
5184 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5185 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005186 return TelephonyProperties.lte_on_cdma_device()
5187 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 }
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005191 }
Wink Saville36469e72014-06-11 15:17:00 -07005192 }
5193
Wink Saville36469e72014-06-11 15:17:00 -07005194 /**
5195 * {@hide}
5196 * Returns Default subId, 0 in the case of single standby.
5197 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005198 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005199 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005200 }
5201
Shishir Agrawala9f32182016-04-12 12:00:16 -07005202 private int getSlotForDefaultSubscription() {
5203 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5204 }
5205
Wink Savilleb564aae2014-10-23 10:18:09 -07005206 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005207 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005208 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005209
Pengquan Menge92a50d2018-09-21 15:54:48 -07005210 private boolean isActiveSubscription(int subId) {
5211 return mSubscriptionController.isActiveSubId(subId);
5212 }
5213
Ihab Awadf2177b72013-11-25 13:33:23 -08005214 /**
5215 * @see android.telephony.TelephonyManager.WifiCallingChoices
5216 */
5217 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
5219 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005220 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5222 getWhenToMakeWifiCallsDefaultPreference());
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005226 }
5227
5228 /**
5229 * @see android.telephony.TelephonyManager.WifiCallingChoices
5230 */
5231 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 final long identity = Binder.clearCallingIdentity();
5233 try {
5234 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005235 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005240 }
5241
Sailesh Nepald1e68152013-12-12 19:08:02 -08005242 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005243 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005244 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005245 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005246
Jordan Liu4c733742019-02-28 12:03:40 -08005247 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5248 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5249 if (phoneId == -1) {
5250 throw new IllegalArgumentException("Given slot index: " + slotIndex
5251 + " does not correspond to an active phone");
5252 }
5253 return PhoneFactory.getPhone(phoneId);
5254 }
5255
Shishir Agrawal566b7612013-10-28 14:41:00 -07005256 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005257 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5258 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5260 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005262 if (DBG) {
5263 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5264 }
5265 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5266 p2);
5267 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005268
Jordan Liu4c733742019-02-28 12:03:40 -08005269
5270 @Override
5271 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5272 int slotIndex, String callingPackage, String aid, int p2) {
5273 enforceModifyPermission();
5274 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5275 if (DBG) {
5276 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5277 }
5278 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5279 callingPackage, aid, p2);
5280 }
5281
5282 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5283 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 final long identity = Binder.clearCallingIdentity();
5285 try {
5286 if (TextUtils.equals(ISDR_AID, aid)) {
5287 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005288 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5289 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 if (bestComponent == null
5291 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5292 loge("The calling package is not allowed to access ISD-R.");
5293 throw new SecurityException(
5294 "The calling package is not allowed to access ISD-R.");
5295 }
Derek Tan740e1672017-06-27 14:56:27 -07005296 }
Derek Tan740e1672017-06-27 14:56:27 -07005297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005299 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5300 null /* workSource */);
5301 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 return response;
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005306 }
5307
5308 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005309 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5311 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005312 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5313 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5314 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005315
Jordan Liu4c733742019-02-28 12:03:40 -08005316 @Override
5317 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5318 enforceModifyPermission();
5319 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5320 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5321 channel);
5322 }
5323
5324 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 final long identity = Binder.clearCallingIdentity();
5326 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 if (channel < 0) {
5328 return false;
5329 }
Jordan Liu4c733742019-02-28 12:03:40 -08005330 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5331 null /* workSource */);
5332 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 return success;
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005337 }
5338
5339 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005340 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005341 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5343 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005344 if (DBG) {
5345 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5346 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5347 + p3 + " data=" + data);
5348 }
5349 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5350 command, p1, p2, p3, data);
5351 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005352
Jordan Liu4c733742019-02-28 12:03:40 -08005353 @Override
5354 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5355 int command, int p1, int p2, int p3, String data) {
5356 enforceModifyPermission();
5357 if (DBG) {
5358 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5359 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5360 + p3 + " data=" + data);
5361 }
5362 return iccTransmitApduLogicalChannelWithPermission(
5363 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5364 data);
5365 }
5366
5367 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5368 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 final long identity = Binder.clearCallingIdentity();
5370 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005371 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 return "";
5373 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005376 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5377 null /* workSource */);
5378 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 // Append the returned status code to the end of the response payload.
5381 String s = Integer.toHexString(
5382 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5383 if (response.payload != null) {
5384 s = IccUtils.bytesToHexString(response.payload) + s;
5385 }
5386 return s;
5387 } finally {
5388 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005389 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005390 }
Jake Hambye994d462014-02-03 13:10:13 -08005391
Evan Charltonc66da362014-05-16 14:06:40 -07005392 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005393 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5394 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5396 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005398 if (DBG) {
5399 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5400 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5401 }
5402 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5403 cla, command, p1, p2, p3, data);
5404 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005405
Jordan Liu4c733742019-02-28 12:03:40 -08005406 @Override
5407 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5408 int command, int p1, int p2, int p3, String data) {
5409 enforceModifyPermission();
5410 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5411 if (DBG) {
5412 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5413 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5414 + " data=" + data);
5415 }
5416
5417 return iccTransmitApduBasicChannelWithPermission(
5418 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5419 p2, p3, data);
5420 }
5421
5422 // open APDU basic channel assuming the caller has sufficient permissions
5423 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5424 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5428 && TextUtils.equals(ISDR_AID, data)) {
5429 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005430 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5431 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432 if (bestComponent == null
5433 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5434 loge("The calling package is not allowed to select ISD-R.");
5435 throw new SecurityException(
5436 "The calling package is not allowed to select ISD-R.");
5437 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005438 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005441 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5442 null /* workSource */);
5443 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 // Append the returned status code to the end of the response payload.
5446 String s = Integer.toHexString(
5447 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5448 if (response.payload != null) {
5449 s = IccUtils.bytesToHexString(response.payload) + s;
5450 }
5451 return s;
5452 } finally {
5453 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005454 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005455 }
5456
5457 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005458 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005459 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5461 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463 final long identity = Binder.clearCallingIdentity();
5464 try {
5465 if (DBG) {
5466 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5467 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5468 }
5469
5470 IccIoResult response =
5471 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5472 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5473 subId);
5474
5475 if (DBG) {
5476 log("Exchange SIM_IO [R]" + response);
5477 }
5478
5479 byte[] result = null;
5480 int length = 2;
5481 if (response.payload != null) {
5482 length = 2 + response.payload.length;
5483 result = new byte[length];
5484 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5485 } else {
5486 result = new byte[length];
5487 }
5488
5489 result[length - 1] = (byte) response.sw2;
5490 result[length - 2] = (byte) response.sw1;
5491 return result;
5492 } finally {
5493 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005494 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005495 }
5496
Nathan Haroldb3014052017-01-25 15:57:32 -08005497 /**
5498 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5499 * on a particular subscription
5500 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005501 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5502 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005504 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005505 return null;
5506 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507
5508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 if (appType != TelephonyManager.APPTYPE_USIM
5511 && appType != TelephonyManager.APPTYPE_SIM) {
5512 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5513 return null;
5514 }
5515 Object response = sendRequest(
5516 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5517 if (response instanceof String[]) {
5518 return (String[]) response;
5519 }
yincheng zhao2737e882019-09-06 17:06:54 -07005520 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005522 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 } finally {
5524 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005525 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005526 }
5527
yincheng zhao2737e882019-09-06 17:06:54 -07005528 /**
5529 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5530 * subscription.
5531 *
5532 * @param subId the id of the subscription.
5533 * @param appType the uicc app type, must be USIM or SIM.
5534 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5535 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005536 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005537 * @return number of fplmns that is successfully written to the SIM.
5538 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005539 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5540 String callingFeatureId) {
5541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5542 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005543 if (DBG) logv("no permissions for setForbiddenplmns");
5544 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5545 }
5546 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5547 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5548 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5549 }
5550 if (fplmns == null) {
5551 throw new IllegalArgumentException("Fplmn List provided is null");
5552 }
5553 for (String fplmn : fplmns) {
5554 if (!CellIdentity.isValidPlmn(fplmn)) {
5555 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5556 }
5557 }
5558 final long identity = Binder.clearCallingIdentity();
5559 try {
5560 Object response = sendRequest(
5561 CMD_SET_FORBIDDEN_PLMNS,
5562 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5563 subId);
5564 return (int) response;
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
5568 }
5569
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005570 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005571 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5573 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 final long identity = Binder.clearCallingIdentity();
5576 try {
5577 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5578 if (response.payload == null) {
5579 return "";
5580 }
Evan Charltonc66da362014-05-16 14:06:40 -07005581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 // Append the returned status code to the end of the response payload.
5583 String s = Integer.toHexString(
5584 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5585 s = IccUtils.bytesToHexString(response.payload) + s;
5586 return s;
5587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
Evan Charltonc66da362014-05-16 14:06:40 -07005590 }
5591
Jake Hambye994d462014-02-03 13:10:13 -08005592 /**
5593 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5594 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5595 *
5596 * @param itemID the ID of the item to read
5597 * @return the NV item as a String, or null on error.
5598 */
5599 @Override
5600 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005601 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5603 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604
5605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005608 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5610 return value;
5611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
Jake Hambye994d462014-02-03 13:10:13 -08005614 }
5615
5616 /**
5617 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5618 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5619 *
5620 * @param itemID the ID of the item to read
5621 * @param itemValue the value to write, as a String
5622 * @return true on success; false on any failure
5623 */
5624 @Override
5625 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005626 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5628 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629
5630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5633 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005634 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5636 return success;
5637 } finally {
5638 Binder.restoreCallingIdentity(identity);
5639 }
Jake Hambye994d462014-02-03 13:10:13 -08005640 }
5641
5642 /**
5643 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5644 * Used for device configuration by some CDMA operators.
5645 *
5646 * @param preferredRoamingList byte array containing the new PRL
5647 * @return true on success; false on any failure
5648 */
5649 @Override
5650 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5652 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653
5654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5657 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5658 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5659 return success;
5660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
Jake Hambye994d462014-02-03 13:10:13 -08005663 }
5664
5665 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005666 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005667 * Used for device configuration by some CDMA operators.
5668 *
chen xu6dac5ab2018-10-26 17:39:23 -07005669 * @param slotIndex - device slot.
5670 *
Jake Hambye994d462014-02-03 13:10:13 -08005671 * @return true on success; false on any failure
5672 */
5673 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005674 public boolean resetModemConfig(int slotIndex) {
5675 Phone phone = PhoneFactory.getPhone(slotIndex);
5676 if (phone != null) {
5677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5678 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679
chen xu6dac5ab2018-10-26 17:39:23 -07005680 final long identity = Binder.clearCallingIdentity();
5681 try {
5682 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5683 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5684 return success;
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 }
chen xu6dac5ab2018-10-26 17:39:23 -07005689 return false;
5690 }
5691
5692 /**
5693 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5694 *
5695 * @param slotIndex - device slot.
5696 *
5697 * @return true on success; false on any failure
5698 */
5699 @Override
5700 public boolean rebootModem(int slotIndex) {
5701 Phone phone = PhoneFactory.getPhone(slotIndex);
5702 if (phone != null) {
5703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5704 mApp, phone.getSubId(), "rebootModem");
5705
5706 final long identity = Binder.clearCallingIdentity();
5707 try {
5708 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5709 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5710 return success;
5711 } finally {
5712 Binder.restoreCallingIdentity(identity);
5713 }
5714 }
5715 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005716 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005717
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005718 public String[] getPcscfAddress(String apnType, String callingPackage,
5719 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005720 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005721 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5722 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005723 return new String[0];
5724 }
5725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 final long identity = Binder.clearCallingIdentity();
5727 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005728 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Wink Saville36469e72014-06-11 15:17:00 -07005732 }
5733
Brad Ebinger51f743a2017-01-23 13:50:20 -08005734 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005735 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5736 * {@link #disableIms(int)}.
5737 * @param slotIndex device slot.
5738 */
5739 public void resetIms(int slotIndex) {
5740 enforceModifyPermission();
5741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
5744 if (mImsResolver == null) {
5745 // may happen if the does not support IMS.
5746 return;
5747 }
5748 mImsResolver.disableIms(slotIndex);
5749 mImsResolver.enableIms(slotIndex);
5750 } finally {
5751 Binder.restoreCallingIdentity(identity);
5752 }
5753 }
5754
5755 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005756 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5757 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005758 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005759 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761
5762 final long identity = Binder.clearCallingIdentity();
5763 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005764 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005765 // may happen if the device does not support IMS.
5766 return;
5767 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005768 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005772 }
5773
5774 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005775 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5776 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005777 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005778 public void disableIms(int slotId) {
5779 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005783 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005784 // may happen if the device does not support IMS.
5785 return;
5786 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005787 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788 } finally {
5789 Binder.restoreCallingIdentity(identity);
5790 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005791 }
5792
5793 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005794 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5795 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005796 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005797 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005798 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800
5801 final long identity = Binder.clearCallingIdentity();
5802 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005803 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005804 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5805 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005806 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005807 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005811 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005812 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005813 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5814 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005815 @Override
5816 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005817 enforceModifyPermission();
5818
5819 final long identity = Binder.clearCallingIdentity();
5820 try {
5821 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005822 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
5826 }
5827
5828 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005829 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005830 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005831 */
5832 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005834
5835 final long identity = Binder.clearCallingIdentity();
5836 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005837 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005838 // may happen if the device does not support IMS.
5839 return null;
5840 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005841 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 } finally {
5843 Binder.restoreCallingIdentity(identity);
5844 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005845 }
5846
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005847 /**
5848 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005849 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005850 */
5851 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5852 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853
5854 final long identity = Binder.clearCallingIdentity();
5855 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005856 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005857 // may happen if the device does not support IMS.
5858 return null;
5859 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005860 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005864 }
5865
Brad Ebinger884c07b2018-02-15 16:17:40 -08005866 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005867 * Sets the ImsService Package Name that Telephony will bind to.
5868 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005869 * @param slotIndex the slot ID that the ImsService should bind for.
5870 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005871 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005872 * @param featureTypes An integer array of feature types associated with a packageName.
5873 * @param packageName The name of the package that the current configuration will be replaced
5874 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005875 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005876 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005877 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5878 int[] featureTypes, String packageName) {
5879 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5880 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5882 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005883 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885 final long identity = Binder.clearCallingIdentity();
5886 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005887 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005888 // may happen if the device does not support IMS.
5889 return false;
5890 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005891 Map<Integer, String> featureConfig = new HashMap<>();
5892 for (int featureType : featureTypes) {
5893 featureConfig.put(featureType, packageName);
5894 }
5895 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5896 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 } finally {
5898 Binder.restoreCallingIdentity(identity);
5899 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005900 }
5901
5902 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005903 * Clears any carrier ImsService overrides for the slot index specified that were previously
5904 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5905 *
5906 * This should only be used for testing.
5907 *
5908 * @param slotIndex the slot ID that the ImsService should bind for.
5909 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5910 */
5911 @Override
5912 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5913 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5914 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5915 "clearCarrierImsServiceOverride");
5916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5917 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5918 "clearCarrierImsServiceOverride");
5919
5920 final long identity = Binder.clearCallingIdentity();
5921 try {
5922 if (mImsResolver == null) {
5923 // may happen if the device does not support IMS.
5924 return false;
5925 }
5926 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5927 } finally {
5928 Binder.restoreCallingIdentity(identity);
5929 }
5930 }
5931
5932 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005933 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005934 *
5935 * @param slotId The slot that the ImsService is associated with.
5936 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5937 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005938 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005939 * @return the package name of the ImsService configuration.
5940 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5942 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005943 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005944 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005945 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005946 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5947 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 final long identity = Binder.clearCallingIdentity();
5950 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005951 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005952 // may happen if the device does not support IMS.
5953 return "";
5954 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005955 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005956 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5957 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 } finally {
5959 Binder.restoreCallingIdentity(identity);
5960 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005961 }
5962
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005963 /**
5964 * Get the MmTelFeature state associated with the requested subscription id.
5965 * @param subId The subscription that the MmTelFeature is associated with.
5966 * @param callback A callback with an integer containing the
5967 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5968 */
5969 @Override
5970 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5971 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5972 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5973 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5974 "IMS not available on device.");
5975 }
5976 final long token = Binder.clearCallingIdentity();
5977 try {
5978 int slotId = getSlotIndex(subId);
5979 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5980 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5981 + subId + "'");
5982 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5983 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005984 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005985 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5986 try {
5987 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5988 } catch (RemoteException e) {
5989 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5990 + "Ignore");
5991 }
5992 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005993 } catch (ImsException e) {
5994 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005995 } finally {
5996 Binder.restoreCallingIdentity(token);
5997 }
5998 }
5999
Daniel Brightbb5840b2021-01-12 15:48:18 -08006000 /**
6001 * Sets the ims registration state on all valid {@link Phone}s.
6002 */
6003 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005
6006 final long identity = Binder.clearCallingIdentity();
6007 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006008 // NOTE: Before S, this method only set the default phone.
6009 for (final Phone phone : PhoneFactory.getPhones()) {
6010 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6011 phone.setImsRegistrationState(registered);
6012 }
6013 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 } finally {
6015 Binder.restoreCallingIdentity(identity);
6016 }
Wink Saville36469e72014-06-11 15:17:00 -07006017 }
6018
6019 /**
Stuart Scott54788802015-03-30 13:18:01 -07006020 * Set the network selection mode to automatic.
6021 *
6022 */
6023 @Override
6024 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6026 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027
6028 final long identity = Binder.clearCallingIdentity();
6029 try {
shilufc958392020-01-20 11:36:01 -08006030 if (!isActiveSubscription(subId)) {
6031 return;
6032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006034 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6035 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 } finally {
6037 Binder.restoreCallingIdentity(identity);
6038 }
Stuart Scott54788802015-03-30 13:18:01 -07006039 }
6040
Jack Yud10cdd42020-09-28 20:28:01 -07006041 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006042 * Ask the radio to connect to the input network and change selection mode to manual.
6043 *
6044 * @param subId the id of the subscription.
6045 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6046 * the operator to attach to.
6047 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6048 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6049 * normal network selection next time.
6050 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006051 */
6052 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006053 public boolean setNetworkSelectionModeManual(
6054 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6056 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006057
6058 if (!isActiveSubscription(subId)) {
6059 return false;
6060 }
6061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 final long identity = Binder.clearCallingIdentity();
6063 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006064 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006066 if (DBG) {
6067 log("setNetworkSelectionModeManual: subId: " + subId
6068 + " operator: " + operatorInfo);
6069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6071 } finally {
6072 Binder.restoreCallingIdentity(identity);
6073 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006074 }
shilu84f6e8b2019-12-19 13:58:01 -08006075 /**
6076 * Get the manual network selection
6077 *
6078 * @param subId the id of the subscription.
6079 *
6080 * @return the previously saved user selected PLMN
6081 */
6082 @Override
6083 public String getManualNetworkSelectionPlmn(int subId) {
6084 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006085 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006086 mApp, subId, "getManualNetworkSelectionPlmn");
6087
6088 final long identity = Binder.clearCallingIdentity();
6089 try {
6090 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006091 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006092 }
6093
6094 final Phone phone = getPhone(subId);
6095 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006096 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006097 }
6098 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6099 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6100 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
6104 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006105
6106 /**
6107 * Scans for available networks.
6108 */
6109 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006110 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6111 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6113 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006114 LocationAccessPolicy.LocationPermissionResult locationResult =
6115 LocationAccessPolicy.checkLocationPermission(mApp,
6116 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6117 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006118 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006119 .setCallingPid(Binder.getCallingPid())
6120 .setCallingUid(Binder.getCallingUid())
6121 .setMethod("getCellNetworkScanResults")
6122 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006123 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6124 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006125 .build());
6126 switch (locationResult) {
6127 case DENIED_HARD:
6128 throw new SecurityException("Not allowed to access scan results -- location");
6129 case DENIED_SOFT:
6130 return null;
6131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132
Pengquan Menga1bb6272018-09-06 09:59:22 -07006133 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 try {
6135 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006136 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 } finally {
6139 Binder.restoreCallingIdentity(identity);
6140 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006141 }
6142
6143 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006144 * Get the call forwarding info, given the call forwarding reason.
6145 */
6146 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006147 public void getCallForwarding(int subId, int callForwardingReason,
6148 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006149 enforceReadPrivilegedPermission("getCallForwarding");
6150 long identity = Binder.clearCallingIdentity();
6151 try {
6152 if (DBG) {
6153 log("getCallForwarding: subId " + subId
6154 + " callForwardingReason" + callForwardingReason);
6155 }
Hall Liu27d24262020-09-18 19:04:59 -07006156
6157 Phone phone = getPhone(subId);
6158 if (phone == null) {
6159 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006160 callback.onError(
6161 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006162 } catch (RemoteException e) {
6163 // ignore
6164 }
6165 return;
6166 }
6167
6168 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6169 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6170 @Override
6171 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6172 try {
6173 callback.onCallForwardingInfoAvailable(info);
6174 } catch (RemoteException e) {
6175 // ignore
6176 }
6177 }
6178
6179 @Override
6180 public void onError(int error) {
6181 try {
6182 callback.onError(error);
6183 } catch (RemoteException e) {
6184 // ignore
6185 }
6186 }
6187 });
6188 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
6192 }
6193
6194 /**
6195 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6196 * reason, the number to forward, and the timeout before the forwarding is attempted.
6197 */
6198 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006199 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6200 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006201 enforceModifyPermission();
6202 long identity = Binder.clearCallingIdentity();
6203 try {
6204 if (DBG) {
6205 log("setCallForwarding: subId " + subId
6206 + " callForwardingInfo" + callForwardingInfo);
6207 }
Hall Liu27d24262020-09-18 19:04:59 -07006208
6209 Phone phone = getPhone(subId);
6210 if (phone == null) {
6211 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006212 callback.accept(
6213 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006214 } catch (RemoteException e) {
6215 // ignore
6216 }
6217 return;
6218 }
6219
6220 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6221 FunctionalUtils.ignoreRemoteException(callback::accept));
6222
6223 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006224 } finally {
6225 Binder.restoreCallingIdentity(identity);
6226 }
6227 }
6228
6229 /**
Hall Liu27d24262020-09-18 19:04:59 -07006230 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006231 */
6232 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006233 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006234 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006235 long identity = Binder.clearCallingIdentity();
6236 try {
Hall Liu27d24262020-09-18 19:04:59 -07006237 Phone phone = getPhone(subId);
6238 if (phone == null) {
6239 try {
6240 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6241 } catch (RemoteException e) {
6242 // ignore
6243 }
6244 return;
6245 }
SongFerngWang0e767992021-03-31 22:08:45 +08006246 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6247 PersistableBundle c = configManager.getConfigForSubId(subId);
6248 boolean requireUssd = c.getBoolean(
6249 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006250
Shuo Qian4a594052020-01-23 11:59:30 -08006251 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006252 if (requireUssd) {
6253 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6254 getSubscriptionCarrierId(subId));
6255 String newUssdCommand = "";
6256 try {
6257 newUssdCommand = carrierXmlParser.getFeature(
6258 CarrierXmlParser.FEATURE_CALL_WAITING)
6259 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6260 } catch (NullPointerException e) {
6261 loge("Failed to generate USSD number" + e);
6262 }
6263 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6264 mMainThreadHandler, callback, carrierXmlParser,
6265 CarrierXmlParser.SsEntry.SSAction.QUERY);
6266 final String ussdCommand = newUssdCommand;
6267 Executors.newSingleThreadExecutor().execute(() -> {
6268 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6269 });
6270 } else {
6271 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6272 callback::accept);
6273 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6274 }
Shuo Qian4a594052020-01-23 11:59:30 -08006275 } finally {
6276 Binder.restoreCallingIdentity(identity);
6277 }
6278 }
6279
6280 /**
Hall Liu27d24262020-09-18 19:04:59 -07006281 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006282 */
6283 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006284 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006285 enforceModifyPermission();
6286 long identity = Binder.clearCallingIdentity();
6287 try {
Hall Liu27d24262020-09-18 19:04:59 -07006288 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6289
6290 Phone phone = getPhone(subId);
6291 if (phone == null) {
6292 try {
6293 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6294 } catch (RemoteException e) {
6295 // ignore
6296 }
6297 return;
6298 }
6299
SongFerngWang0e767992021-03-31 22:08:45 +08006300 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6301 PersistableBundle c = configManager.getConfigForSubId(subId);
6302 boolean requireUssd = c.getBoolean(
6303 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006304
SongFerngWang0e767992021-03-31 22:08:45 +08006305 if (DBG) log("getCallWaitingStatus: subId " + subId);
6306 if (requireUssd) {
6307 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6308 getSubscriptionCarrierId(subId));
6309 CarrierXmlParser.SsEntry.SSAction ssAction =
6310 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6311 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6312 String newUssdCommand = "";
6313 try {
6314 newUssdCommand = carrierXmlParser.getFeature(
6315 CarrierXmlParser.FEATURE_CALL_WAITING)
6316 .makeCommand(ssAction, null);
6317 } catch (NullPointerException e) {
6318 loge("Failed to generate USSD number" + e);
6319 }
6320 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6321 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6322 final String ussdCommand = newUssdCommand;
6323 Executors.newSingleThreadExecutor().execute(() -> {
6324 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6325 });
6326 } else {
6327 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6328 FunctionalUtils.ignoreRemoteException(callback::accept));
6329
6330 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6331 }
Shuo Qian4a594052020-01-23 11:59:30 -08006332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
6335 }
6336
6337 /**
yinxub1bed742017-04-17 11:45:04 -07006338 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006339 *
yinxub1bed742017-04-17 11:45:04 -07006340 * @param subId id of the subscription
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006341 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6342 * location related information which will be sent if the caller already possess
6343 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006344 * @param request contains the radio access networks with bands/channels to scan
6345 * @param messenger callback messenger for scan results or errors
6346 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006347 * @return the id of the requested scan which can be used to stop the scan.
6348 */
6349 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006350 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6351 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006352 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6354 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006355 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006356 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6357 if (!renounceFineLocationAccess) {
6358 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6359 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6360 .setCallingPackage(callingPackage)
6361 .setCallingFeatureId(callingFeatureId)
6362 .setCallingPid(Binder.getCallingPid())
6363 .setCallingUid(Binder.getCallingUid())
6364 .setMethod("requestNetworkScan")
6365 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6366 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6367 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6368 .build());
6369 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006370 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006371 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6372 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006373 if (e != null) {
6374 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6375 throw e;
6376 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006377 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006378 return TelephonyScanManager.INVALID_SCAN_ID;
6379 }
6380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 }
Hall Liu912dfd32019-04-25 14:02:26 -07006382 int callingUid = Binder.getCallingUid();
6383 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006384 final long identity = Binder.clearCallingIdentity();
6385 try {
6386 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08006387 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006388 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006389 } finally {
6390 Binder.restoreCallingIdentity(identity);
6391 }
yinxu504e1392017-04-12 16:03:22 -07006392 }
6393
Hall Liub2ac8ef2019-02-28 15:56:23 -08006394 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006395 NetworkScanRequest request, int subId, String callingPackage) {
6396 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006397 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6398 boolean hasNetworkScanPermission =
6399 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6400 == PERMISSION_GRANTED;
6401
6402 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6403 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6404 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006405 }
6406
6407 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6408 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006409 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6410 return new SecurityException("Specific channels must not be"
6411 + " scanned without location access.");
6412 }
6413 }
6414 }
6415
Hall Liub2ac8ef2019-02-28 15:56:23 -08006416 return null;
6417 }
6418
yinxu504e1392017-04-12 16:03:22 -07006419 /**
6420 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006421 *
6422 * @param subId id of the subscription
6423 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006424 */
6425 @Override
6426 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6428 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429
Hall Liu912dfd32019-04-25 14:02:26 -07006430 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006431 final long identity = Binder.clearCallingIdentity();
6432 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006433 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434 } finally {
6435 Binder.restoreCallingIdentity(identity);
6436 }
yinxu504e1392017-04-12 16:03:22 -07006437 }
6438
6439 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006440 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006441 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006442 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006443 */
6444 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006445 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006446 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006447 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006448 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449
6450 final long identity = Binder.clearCallingIdentity();
6451 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006452 if (DBG) log("getAllowedNetworkTypesBitmask");
6453 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6454 int networkTypesBitmask = (result != null ? result[0] : -1);
6455 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6456 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006460 }
6461
6462 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006463 * Get the allowed network types for certain reason.
6464 *
6465 * @param subId the id of the subscription.
6466 * @param reason the reason the allowed network type change is taking place
6467 * @return the allowed network types.
6468 */
6469 @Override
6470 public long getAllowedNetworkTypesForReason(int subId,
6471 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006472 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006473 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006474 final long identity = Binder.clearCallingIdentity();
6475 try {
6476 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6477 } finally {
6478 Binder.restoreCallingIdentity(identity);
6479 }
6480 }
6481
6482 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006483 * Enable/Disable E-UTRA-NR Dual Connectivity
6484 * @param subId subscription id of the sim card
6485 * @param nrDualConnectivityState expected NR dual connectivity state
6486 * This can be passed following states
6487 * <ol>
6488 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6489 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6490 * <li>Disable NR dual connectivity and force secondary cell to be released
6491 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6492 * </ol>
6493 * @return operation result.
6494 */
6495 @Override
6496 public int setNrDualConnectivityState(int subId,
6497 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6499 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006500 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006501 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6502 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6503 }
6504
Sooraj Sasindran37444802020-08-11 10:40:43 -07006505 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6509 nrDualConnectivityState, subId,
6510 workSource);
6511 if (DBG) log("enableNRDualConnectivity result: " + result);
6512 return result;
6513 } finally {
6514 Binder.restoreCallingIdentity(identity);
6515 }
6516 }
6517
6518 /**
6519 * Is E-UTRA-NR Dual Connectivity enabled
6520 * @return true if dual connectivity is enabled else false
6521 */
6522 @Override
6523 public boolean isNrDualConnectivityEnabled(int subId) {
6524 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006525 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006526 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006527 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006528 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6529 return false;
6530 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006531 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6535 null, subId, workSource);
6536 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6537 return isEnabled;
6538 } finally {
6539 Binder.restoreCallingIdentity(identity);
6540 }
6541 }
6542
6543 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006544 * Set the allowed network types of the device and
6545 * provide the reason triggering the allowed network change.
6546 *
6547 * @param subId the id of the subscription.
6548 * @param reason the reason the allowed network type change is taking place
6549 * @param allowedNetworkTypes the allowed network types.
6550 * @return true on success; false on any failure.
6551 */
6552 @Override
6553 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006554 @TelephonyManager.AllowedNetworkTypesReason int reason,
6555 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6557 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006558 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006559 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6560 return false;
6561 }
6562 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6563 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006564 return false;
6565 }
6566
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006567 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6568 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6569
6570
6571 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6572 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6573 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006574 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006575
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006576 final long identity = Binder.clearCallingIdentity();
6577 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006578 Boolean success = (Boolean) sendRequest(
6579 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6580 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6581
6582 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6583 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006584 } finally {
6585 Binder.restoreCallingIdentity(identity);
6586 }
6587 }
6588
6589 /**
Miaoa84611c2019-03-15 09:21:10 +08006590 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006591 *
Miaoa84611c2019-03-15 09:21:10 +08006592 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006593 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006594 * @hide
6595 */
6596 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006597 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006598 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006600 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 try {
Miaoa84611c2019-03-15 09:21:10 +08006602 if (phone != null) {
6603 return phone.hasMatchedTetherApnSetting();
6604 } else {
6605 return false;
6606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 } finally {
6608 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006609 }
Junda Liu475951f2014-11-07 16:45:03 -08006610 }
6611
6612 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006613 * Get the user enabled state of Mobile Data.
6614 *
6615 * TODO: remove and use isUserDataEnabled.
6616 * This can't be removed now because some vendor codes
6617 * calls through ITelephony directly while they should
6618 * use TelephonyManager.
6619 *
6620 * @return true on enabled
6621 */
6622 @Override
6623 public boolean getDataEnabled(int subId) {
6624 return isUserDataEnabled(subId);
6625 }
6626
6627 /**
6628 * Get whether mobile data is enabled per user setting.
6629 *
6630 * There are other factors deciding whether mobile data is actually enabled, but they are
6631 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006632 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006633 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6634 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006635 *
6636 * @return {@code true} if data is enabled else {@code false}
6637 */
6638 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006639 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006640 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006641 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006642 try {
6643 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6644 functionName);
6645 } catch (Exception e) {
6646 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6647 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006648 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006650 mApp, subId, functionName);
6651
Robert Greenwalt646120a2014-05-23 11:54:03 -07006652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653
6654 final long identity = Binder.clearCallingIdentity();
6655 try {
6656 int phoneId = mSubscriptionController.getPhoneId(subId);
6657 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6658 Phone phone = PhoneFactory.getPhone(phoneId);
6659 if (phone != null) {
6660 boolean retVal = phone.isUserDataEnabled();
6661 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6662 return retVal;
6663 } else {
6664 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6665 return false;
6666 }
6667 } finally {
6668 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006669 }
6670 }
6671
6672 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006673 * Checks if the device is capable of mobile data by considering whether whether the
6674 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6675 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006676 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006677 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006678 */
6679 @Override
6680 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006681 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006682 try {
6683 try {
6684 mApp.enforceCallingOrSelfPermission(
6685 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006686 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006687 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006688 try {
6689 mApp.enforceCallingOrSelfPermission(
6690 android.Manifest.permission.READ_PHONE_STATE,
6691 functionName);
6692 } catch (Exception e2) {
6693 mApp.enforceCallingOrSelfPermission(
6694 permission.READ_BASIC_PHONE_STATE, functionName);
6695 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006696 }
6697 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006698 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700
6701 final long identity = Binder.clearCallingIdentity();
6702 try {
6703 int phoneId = mSubscriptionController.getPhoneId(subId);
6704 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6705 Phone phone = PhoneFactory.getPhone(phoneId);
6706 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006707 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6709 return retVal;
6710 } else {
6711 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6712 return false;
6713 }
6714 } finally {
6715 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006716 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006717 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006718
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006719 /**
6720 * Check if data is enabled for a specific reason
6721 * @param subId Subscription index
6722 * @param reason the reason the data enable change is taking place
6723 * @return {@code true} if the overall data is enabled; {@code false} if not.
6724 */
6725 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006726 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006727 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006728 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006729 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006730 try {
6731 mApp.enforceCallingOrSelfPermission(
6732 android.Manifest.permission.ACCESS_NETWORK_STATE,
6733 functionName);
6734 } catch (Exception e) {
6735 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6736 functionName);
6737 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006738 } catch (Exception e) {
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006739 try {
6740 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006741 functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006742 } catch (Exception e2) {
6743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006744 mApp, subId, functionName);
Sooraj Sasindran72a22762021-11-08 12:01:16 -08006745 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006746 }
6747
6748
6749 final long identity = Binder.clearCallingIdentity();
6750 try {
6751 int phoneId = mSubscriptionController.getPhoneId(subId);
6752 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006753 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006754 + " reason=" + reason);
6755 }
6756 Phone phone = PhoneFactory.getPhone(phoneId);
6757 if (phone != null) {
6758 boolean retVal;
6759 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6760 retVal = phone.isUserDataEnabled();
6761 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006762 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006763 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006764 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006765 return retVal;
6766 } else {
6767 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006768 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006769 + subId + " retVal=false");
6770 }
6771 return false;
6772 }
6773 } finally {
6774 Binder.restoreCallingIdentity(identity);
6775 }
6776 }
6777
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006778 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006779 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006780 if (uid == Process.PHONE_UID) {
6781 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6782 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006783 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6784 }
6785
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006786 //load access rules from carrier configs, and check those as well: b/139133814
6787 SubscriptionController subController = SubscriptionController.getInstance();
6788 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6789 || subController == null) return privilegeFromSim;
6790
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006791 PackageManager pkgMgr = phone.getContext().getPackageManager();
6792 String[] packages = pkgMgr.getPackagesForUid(uid);
6793
6794 final long identity = Binder.clearCallingIdentity();
6795 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006796 int subId = phone.getSubId();
6797 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6798 // A test override is in place for the privileges for this subId, so don't try to
6799 // read the subscription privileges.
6800 return privilegeFromSim;
6801 }
6802 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006803 SubscriptionManager subManager = (SubscriptionManager)
6804 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6805 for (String pkg : packages) {
6806 if (subManager.canManageSubscription(subInfo, pkg)) {
6807 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6808 }
6809 }
6810 return privilegeFromSim;
6811 } finally {
6812 Binder.restoreCallingIdentity(identity);
6813 }
6814 }
6815
6816 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6817 String pkgName) {
6818 //load access rules from carrier configs, and check those as well: b/139133814
6819 SubscriptionController subController = SubscriptionController.getInstance();
6820 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6821 || subController == null) return privilegeFromSim;
6822
6823 final long identity = Binder.clearCallingIdentity();
6824 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006825 int subId = phone.getSubId();
6826 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6827 // A test override is in place for the privileges for this subId, so don't try to
6828 // read the subscription privileges.
6829 return privilegeFromSim;
6830 }
6831 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006832 SubscriptionManager subManager = (SubscriptionManager)
6833 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6834 return subManager.canManageSubscription(subInfo, pkgName)
6835 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6836 } finally {
6837 Binder.restoreCallingIdentity(identity);
6838 }
6839 }
6840
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006841 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006842 public int getCarrierPrivilegeStatus(int subId) {
6843 final Phone phone = getPhone(subId);
6844 if (phone == null) {
6845 loge("getCarrierPrivilegeStatus: Invalid subId");
6846 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6847 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006848 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6849 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006850 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006851 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6852 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006853
6854 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006855 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006856 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006857 }
Junda Liu29340342014-07-10 15:23:27 -07006858
6859 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006860 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006861 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006862 final Phone phone = getPhone(subId);
6863 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006864 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006865 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6866 }
6867 UiccProfile profile =
6868 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6869 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006870 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006871 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6872 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006873 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006874 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006875 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006876 }
6877
6878 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006879 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006880 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006881 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006882 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006883 }
6884
6885 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006886 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6887 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006888 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006889 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6890 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006891 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006892 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006893 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006894 }
6895
6896 @Override
6897 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006898 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006899 if (TextUtils.isEmpty(pkgName))
6900 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006901 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6902 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006903 UiccPort port = UiccController.getInstance().getUiccPort(i);
6904 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006905 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006906 continue;
6907 }
6908
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006909 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006910 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006911 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006912 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6913 break;
6914 }
6915 }
6916
6917 return result;
Junda Liu29340342014-07-10 15:23:27 -07006918 }
Derek Tan89e89d42014-07-08 17:00:10 -07006919
6920 @Override
Junda Liue64de782015-04-16 17:19:16 -07006921 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006922 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006923 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6924 loge("phoneId " + phoneId + " is not valid.");
6925 return null;
6926 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006927 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6928 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006929 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006930 return null ;
6931 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006932 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006933 }
6934
Amith Yamasani6e118872016-02-19 12:53:51 -08006935 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006936 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006937 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006938 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006939 List<String> privilegedPackages = new ArrayList<>();
6940 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006941 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006942 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006943 if (port != null) {
6944 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006945 if (packages == null) {
6946 // Only check packages in user 0 for now
6947 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006948 PackageManager.MATCH_DISABLED_COMPONENTS
6949 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006950 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006951 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006952 }
6953 for (int p = packages.size() - 1; p >= 0; p--) {
6954 PackageInfo pkgInfo = packages.get(p);
6955 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006956 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006957 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006958 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006959 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006960 privilegedPackages.add(pkgInfo.packageName);
6961 }
6962 }
6963 }
6964 }
6965 return privilegedPackages;
6966 }
6967
chen xuf7e9fe82019-05-09 19:31:02 -07006968 @Override
6969 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006970 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6971
6972 final long identity = Binder.clearCallingIdentity();
6973
chen xuf7e9fe82019-05-09 19:31:02 -07006974 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006975 try {
6976 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6977 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6978 }
6979 } finally {
6980 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006981 }
6982 return privilegedPackages;
6983 }
6984
Wink Savilleb564aae2014-10-23 10:18:09 -07006985 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006986 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006987 UiccPort port = phone == null ? null : phone.getUiccPort();
6988 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006989 return null;
6990 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006991 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006992 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006993 return null;
6994 }
6995 return iccId;
6996 }
6997
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006998 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006999 public void setCallComposerStatus(int subId, int status) {
7000 enforceModifyPermission();
7001
7002 final long identity = Binder.clearCallingIdentity();
7003 try {
7004 Phone phone = getPhone(subId);
7005 if (phone != null) {
7006 Phone defaultPhone = phone.getImsPhone();
7007 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7008 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7009 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007010 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7011 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007012 }
7013 }
Shuo Qian284ae752020-12-22 19:10:14 -08007014 } catch (ImsException e) {
7015 throw new ServiceSpecificException(e.getCode());
7016 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007017 Binder.restoreCallingIdentity(identity);
7018 }
7019 }
7020
7021 @Override
7022 public int getCallComposerStatus(int subId) {
7023 enforceReadPrivilegedPermission("getCallComposerStatus");
7024
7025 final long identity = Binder.clearCallingIdentity();
7026 try {
7027 Phone phone = getPhone(subId);
7028 if (phone != null) {
7029 Phone defaultPhone = phone.getImsPhone();
7030 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7031 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7032 return imsPhone.getCallComposerStatus();
7033 }
7034 }
7035 } finally {
7036 Binder.restoreCallingIdentity(identity);
7037 }
7038 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7039 }
7040
7041 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007042 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7043 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007044 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007045 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047 final long identity = Binder.clearCallingIdentity();
7048 try {
7049 final String iccId = getIccId(subId);
7050 final Phone phone = getPhone(subId);
7051 if (phone == null) {
7052 return false;
7053 }
7054 final String subscriberId = phone.getSubscriberId();
7055
7056 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007057 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 + subscriberId + " to " + number);
7059 }
7060
7061 if (TextUtils.isEmpty(iccId)) {
7062 return false;
7063 }
7064
7065 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7066
7067 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7068 if (alphaTag == null) {
7069 editor.remove(alphaTagPrefKey);
7070 } else {
7071 editor.putString(alphaTagPrefKey, alphaTag);
7072 }
7073
7074 // Record both the line number and IMSI for this ICCID, since we need to
7075 // track all merged IMSIs based on line number
7076 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7077 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7078 if (number == null) {
7079 editor.remove(numberPrefKey);
7080 editor.remove(subscriberPrefKey);
7081 } else {
7082 editor.putString(numberPrefKey, number);
7083 editor.putString(subscriberPrefKey, subscriberId);
7084 }
7085
7086 editor.commit();
7087 return true;
7088 } finally {
7089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007090 }
Derek Tan7226c842014-07-02 17:42:23 -07007091 }
7092
7093 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007094 public String getLine1NumberForDisplay(int subId, String callingPackage,
7095 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007096 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007098 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007099 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007100 return null;
7101 }
Derek Tan97ebb422014-09-05 16:55:38 -07007102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103 final long identity = Binder.clearCallingIdentity();
7104 try {
7105 String iccId = getIccId(subId);
7106 if (iccId != null) {
7107 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7108 if (DBG_MERGE) {
7109 log("getLine1NumberForDisplay returning "
7110 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7111 }
7112 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007113 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7115 return null;
7116 } finally {
7117 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007118 }
Derek Tan7226c842014-07-02 17:42:23 -07007119 }
7120
7121 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007122 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7123 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007125 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007126 return null;
7127 }
Derek Tan97ebb422014-09-05 16:55:38 -07007128
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129 final long identity = Binder.clearCallingIdentity();
7130 try {
7131 String iccId = getIccId(subId);
7132 if (iccId != null) {
7133 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7134 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7135 }
7136 return null;
7137 } finally {
7138 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007139 }
Derek Tan7226c842014-07-02 17:42:23 -07007140 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007141
7142 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007143 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7144 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007145 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7146 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007147 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007148 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007149 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007150 return null;
7151 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007152
Jordan Liub49b04b2019-05-06 14:45:15 -07007153 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7154 // the process, where TelephonyManager was instantiated.
7155 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007156 final long identity = Binder.clearCallingIdentity();
7157 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007158 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 final TelephonyManager tele = TelephonyManager.from(context);
7160 final SubscriptionManager sub = SubscriptionManager.from(context);
7161
7162 // Figure out what subscribers are currently active
7163 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164
Jordan Liub49b04b2019-05-06 14:45:15 -07007165 // Only consider subs which match the current subId
7166 // This logic can be simplified. See b/131189269 for progress.
7167 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007168 activeSubscriberIds.add(tele.getSubscriberId(subId));
7169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170
7171 // First pass, find a number override for an active subscriber
7172 String mergeNumber = null;
7173 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7174 for (String key : prefs.keySet()) {
7175 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7176 final String subscriberId = (String) prefs.get(key);
7177 if (activeSubscriberIds.contains(subscriberId)) {
7178 final String iccId = key.substring(
7179 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7180 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7181 mergeNumber = (String) prefs.get(numberKey);
7182 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007183 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 + " for active subscriber " + subscriberId);
7185 }
7186 if (!TextUtils.isEmpty(mergeNumber)) {
7187 break;
7188 }
7189 }
7190 }
7191 }
7192
7193 // Shortcut when no active merged subscribers
7194 if (TextUtils.isEmpty(mergeNumber)) {
7195 return null;
7196 }
7197
7198 // Second pass, find all subscribers under that line override
7199 final ArraySet<String> result = new ArraySet<>();
7200 for (String key : prefs.keySet()) {
7201 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7202 final String number = (String) prefs.get(key);
7203 if (mergeNumber.equals(number)) {
7204 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7205 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7206 final String subscriberId = (String) prefs.get(subscriberKey);
7207 if (!TextUtils.isEmpty(subscriberId)) {
7208 result.add(subscriberId);
7209 }
7210 }
7211 }
7212 }
7213
7214 final String[] resultArray = result.toArray(new String[result.size()]);
7215 Arrays.sort(resultArray);
7216 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007217 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007218 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7219 }
7220 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007221 } finally {
7222 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007223 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007224 }
7225
7226 @Override
zoey chen38003472019-12-13 17:16:31 +08007227 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7228 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007229
7230 final long identity = Binder.clearCallingIdentity();
7231 try {
7232 final TelephonyManager telephonyManager = mApp.getSystemService(
7233 TelephonyManager.class);
7234 String subscriberId = telephonyManager.getSubscriberId(subId);
7235 if (subscriberId == null) {
7236 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007237 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007238 + subId);
7239 }
7240 return null;
7241 }
7242
7243 final SubscriptionInfo info = SubscriptionController.getInstance()
7244 .getSubscriptionInfo(subId);
7245 final ParcelUuid groupUuid = info.getGroupUuid();
7246 // If it doesn't belong to any group, return just subscriberId of itself.
7247 if (groupUuid == null) {
7248 return new String[]{subscriberId};
7249 }
7250
7251 // Get all subscriberIds from the group.
7252 final List<String> mergedSubscriberIds = new ArrayList<>();
7253 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007254 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007255 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007256 for (SubscriptionInfo subInfo : groupInfos) {
7257 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7258 if (subscriberId != null) {
7259 mergedSubscriberIds.add(subscriberId);
7260 }
7261 }
7262
7263 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266
7267 }
7268 }
7269
7270 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007271 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007272 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007273 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274
7275 final long identity = Binder.clearCallingIdentity();
7276 try {
7277 final Phone phone = getPhone(subId);
7278 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7279 } finally {
7280 Binder.restoreCallingIdentity(identity);
7281 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007282 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007283
7284 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007285 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007286 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7287 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007288 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7289 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290
7291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 final Phone phone = getPhone(subId);
7294 if (phone == null) {
7295 return false;
7296 }
7297 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7298 cdmaNonRoamingList);
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007301 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007302 }
7303
7304 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007305 @Deprecated
7306 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7307 enforceModifyPermission();
7308
7309 int returnValue = 0;
7310 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007311 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007312 if(result.exception == null) {
7313 if (result.result != null) {
7314 byte[] responseData = (byte[])(result.result);
7315 if(responseData.length > oemResp.length) {
7316 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7317 responseData.length + "bytes. Buffer Size is " +
7318 oemResp.length + "bytes.");
7319 }
7320 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7321 returnValue = responseData.length;
7322 }
7323 } else {
7324 CommandException ex = (CommandException) result.exception;
7325 returnValue = ex.getCommandError().ordinal();
7326 if(returnValue > 0) returnValue *= -1;
7327 }
7328 } catch (RuntimeException e) {
7329 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7330 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7331 if(returnValue > 0) returnValue *= -1;
7332 }
7333
7334 return returnValue;
7335 }
7336
7337 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007338 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007339 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007340 try {
7341 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007342 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007343 mApp, phone.getSubId(), "getRadioAccessFamily");
7344 } catch (SecurityException e) {
7345 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7346 throw e;
7347 }
chen xub97461a2018-10-26 14:17:57 -07007348 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007349 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007350 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352 final long identity = Binder.clearCallingIdentity();
7353 try {
chen xub97461a2018-10-26 14:17:57 -07007354 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007355 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007356 mApp, phone.getSubId(), "getRadioAccessFamily");
7357 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358 } finally {
7359 Binder.restoreCallingIdentity(identity);
7360 }
chen xub97461a2018-10-26 14:17:57 -07007361 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007362 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007363
7364 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007365 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007366 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007367 try {
7368 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7369 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007370 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007371 }
7372 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007373 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007374 }
7375 RoleManager rm = mApp.getSystemService(RoleManager.class);
7376 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7377 if (!dialerRoleHolders.contains(callingPackage)) {
7378 throw new SecurityException("App must be the dialer role holder to"
7379 + " upload a call composer pic");
7380 }
7381
7382 Executors.newSingleThreadExecutor().execute(() -> {
7383 ByteArrayOutputStream output = new ByteArrayOutputStream(
7384 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7385 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7386 boolean readUntilEnd = false;
7387 int totalBytesRead = 0;
7388 byte[] buffer = new byte[16 * 1024];
7389 while (true) {
7390 int numRead;
7391 try {
7392 numRead = input.read(buffer);
7393 } catch (IOException e) {
7394 try {
7395 fd.checkError();
7396 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7397 null);
7398 } catch (IOException e1) {
7399 // This means that the other side closed explicitly with an error. If this
7400 // happens, log and ignore.
7401 loge("Remote end of call composer picture pipe closed: " + e1);
7402 }
7403 break;
7404 }
7405 if (numRead == -1) {
7406 readUntilEnd = true;
7407 break;
7408 }
7409 totalBytesRead += numRead;
7410 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7411 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7412 try {
7413 input.close();
7414 } catch (IOException e) {
7415 // ignore
7416 }
7417 break;
7418 }
7419 output.write(buffer, 0, numRead);
7420 }
7421 // Generally, the remote end will close the file descriptors. The only case where we
7422 // close is above, where the picture size is too big.
7423
7424 try {
7425 fd.checkError();
7426 } catch (IOException e) {
7427 loge("Remote end for call composer closed with an error: " + e);
7428 return;
7429 }
7430
Hall Liuaa4211e2021-01-20 15:43:39 -08007431 if (!readUntilEnd) {
7432 loge("Did not finish reading entire image; aborting");
7433 return;
7434 }
Hall Liu82694d52020-12-11 18:22:04 -08007435
Hall Liuaa4211e2021-01-20 15:43:39 -08007436 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7437 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7438 new CallComposerPictureTransfer.Factory() {},
7439 imageData,
7440 (result) -> {
7441 if (result.first != null) {
7442 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7443 Bundle outputResult = new Bundle();
7444 outputResult.putParcelable(
7445 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7446 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7447 outputResult);
7448 } else {
7449 callback.send(result.second, null);
7450 }
7451 }
7452 );
Hall Liu82694d52020-12-11 18:22:04 -08007453 });
7454 }
7455
7456 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007457 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007458 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007459 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460
7461 final long identity = Binder.clearCallingIdentity();
7462 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007463 ImsManager.getInstance(defaultPhone.getContext(),
7464 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 } finally {
7466 Binder.restoreCallingIdentity(identity);
7467 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007468 }
7469
7470 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007471 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007472 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7474 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007475 return false;
7476 }
Svet Ganovb320e182015-04-16 12:30:10 -07007477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 final long identity = Binder.clearCallingIdentity();
7479 try {
7480 // Check the user preference and the system-level IMS setting. Even if the user has
7481 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7482 // In the long run, we may instead need to check if there exists a connection service
7483 // which can support video calling.
7484 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007485 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 return imsManager.isVtEnabledByPlatform()
7487 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7488 && imsManager.isVtEnabledByUser();
7489 } finally {
7490 Binder.restoreCallingIdentity(identity);
7491 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007492 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007493
Andrew Leea1239f22015-03-02 17:44:07 -08007494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007495 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7496 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007498 mApp, subId, callingPackage, callingFeatureId,
7499 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 return false;
7501 }
7502
7503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 CarrierConfigManager configManager =
7506 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007507 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Andrew Leea1239f22015-03-02 17:44:07 -08007512 }
7513
7514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007515 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007517 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 return false;
7519 }
7520
7521 final long identity = Binder.clearCallingIdentity();
7522 try {
7523 CarrierConfigManager configManager =
7524 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007525 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7527 } finally {
7528 Binder.restoreCallingIdentity(identity);
7529 }
Andrew Leea1239f22015-03-02 17:44:07 -08007530 }
7531
Andrew Lee9431b832015-03-09 18:46:45 -07007532 @Override
7533 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007534 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007535 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007536 }
7537
7538 @Override
7539 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 final long identity = Binder.clearCallingIdentity();
7541 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007542 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 } finally {
7544 Binder.restoreCallingIdentity(identity);
7545 }
Andrew Lee9431b832015-03-09 18:46:45 -07007546 }
7547
Hall Liuf6668912018-10-31 17:05:23 -07007548 /**
7549 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7550 * support for the feature and device firmware support.
7551 *
7552 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7553 */
7554 @Override
7555 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007557 final Phone phone = getPhone(subscriptionId);
7558 if (phone == null) {
7559 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7560 return false;
7561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007563 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7565 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007566 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567 return isCarrierSupported && isDeviceSupported;
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
Hall Liu98187582018-01-22 19:15:32 -08007571 }
7572
Hall Liuf6668912018-10-31 17:05:23 -07007573 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007574 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7575 * RTT setting, will return true if the device and carrier both support RTT.
7576 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007577 */
7578 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 final long identity = Binder.clearCallingIdentity();
7580 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007581 boolean isRttSupported = isRttSupported(subscriptionId);
7582 boolean isUserRttSettingOn = Settings.Secure.getInt(
7583 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7584 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7585 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7586 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007590 }
7591
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007592 @Deprecated
7593 @Override
7594 public String getDeviceId(String callingPackage) {
7595 return getDeviceIdWithFeature(callingPackage, null);
7596 }
7597
Sanket Padawe7310cc72015-01-14 09:53:20 -08007598 /**
7599 * Returns the unique device ID of phone, for example, the IMEI for
7600 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7601 *
7602 * <p>Requires Permission:
7603 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7604 */
7605 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007606 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007607 try {
7608 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7609 } catch (SecurityException se) {
7610 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7611 throw new SecurityException("Package " + callingPackage + " does not belong to "
7612 + Binder.getCallingUid());
7613 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007614 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007615 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007616 return null;
7617 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007618 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007619 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007620 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007621 return null;
7622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623
7624 final long identity = Binder.clearCallingIdentity();
7625 try {
7626 return phone.getDeviceId();
7627 } finally {
7628 Binder.restoreCallingIdentity(identity);
7629 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007630 }
7631
Ping Sunc67b7c22016-03-02 19:16:45 +08007632 /**
7633 * {@hide}
7634 * Returns the IMS Registration Status on a particular subid
7635 *
7636 * @param subId
7637 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007638 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007639 Phone phone = getPhone(subId);
7640 if (phone != null) {
7641 return phone.isImsRegistered();
7642 } else {
7643 return false;
7644 }
7645 }
7646
Santos Cordon7a1885b2015-02-03 11:15:19 -08007647 @Override
7648 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649 final long identity = Binder.clearCallingIdentity();
7650 try {
7651 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007655 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007656
Tyler Gunnf70ed162019-04-03 15:28:53 -07007657 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007658 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007659 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007661 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007662 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7663 }
7664 final long identity = Binder.clearCallingIdentity();
7665 try {
7666 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7667 } finally {
7668 Binder.restoreCallingIdentity(identity);
7669 }
7670 }
7671
7672 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007673 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007674 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007675 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007676 mApp,
7677 subscriptionId,
7678 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 Phone phone = getPhone(subscriptionId);
7682 if (phone == null) {
7683 return null;
7684 }
7685 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
7688 }
7689 }
7690
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007691 /**
7692 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007693 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007694 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 final long identity = Binder.clearCallingIdentity();
7696 try {
7697 Phone phone = getPhone(subId);
7698 if (phone != null) {
7699 return phone.isWifiCallingEnabled();
7700 } else {
7701 return false;
7702 }
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007705 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007706 }
7707
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007708 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007709 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007710 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007711 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712 final long identity = Binder.clearCallingIdentity();
7713 try {
7714 Phone phone = getPhone(subId);
7715 if (phone != null) {
7716 return phone.isVideoEnabled();
7717 } else {
7718 return false;
7719 }
7720 } finally {
7721 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007722 }
7723 }
7724
7725 /**
7726 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7727 * defined in {@link ImsRegistrationImplBase}.
7728 */
7729 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730 final long identity = Binder.clearCallingIdentity();
7731 try {
7732 Phone phone = getPhone(subId);
7733 if (phone != null) {
7734 return phone.getImsRegistrationTech();
7735 } else {
7736 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7737 }
7738 } finally {
7739 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007740 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007741 }
7742
Stuart Scott8eef64f2015-04-08 15:13:54 -07007743 @Override
7744 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007745 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007746 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7747 return;
7748 }
Kai Shif70f46f2021-03-03 13:59:46 -08007749 Phone defaultPhone = getDefaultPhone();
7750 if (defaultPhone != null) {
7751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7752 mApp, getDefaultPhone().getSubId(), "factoryReset");
7753 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007754 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007755
Svet Ganovcc087f82015-05-12 20:35:54 -07007756 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007757 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7758 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007759 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007760 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007761 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007762 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007763 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007764 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007765 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007766 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007767 // There has been issues when Sms raw table somehow stores orphan
7768 // fragments. They lead to garbled message when new fragments come
7769 // in and combined with those stale ones. In case this happens again,
7770 // user can reset all network settings which will clean up this table.
7771 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007772 // Clean up IMS settings as well here.
7773 int slotId = getSlotIndex(subId);
7774 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7775 ImsManager.getInstance(mApp, slotId).factoryReset();
7776 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007777
Kai Shif70f46f2021-03-03 13:59:46 -08007778 if (defaultPhone == null) {
7779 return;
7780 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007781 // Erase modem config if erase modem on network setting is enabled.
7782 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7783 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7784 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007785 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007786 }
Kai Shif70f46f2021-03-03 13:59:46 -08007787
7788 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007789 } finally {
7790 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007791 }
7792 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007793
SongFerngWangfd89b102021-05-27 22:44:54 +08007794 @VisibleForTesting
7795 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7796 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7797 return;
7798 }
7799 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7800 RILConstants.PREFERRED_NETWORK_MODE);
7801 SubscriptionManager.setSubscriptionProperty(subId,
7802 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7803 "user=" + defaultNetworkType);
7804 phone.loadAllowedNetworksFromSubscriptionDatabase();
7805 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7806 defaultNetworkType, null);
7807 }
7808
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007809 private void cleanUpSmsRawTable(Context context) {
7810 ContentResolver resolver = context.getContentResolver();
7811 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7812 resolver.delete(uri, null, null);
7813 }
7814
Narayan Kamath1c496c22015-04-16 14:40:19 +01007815 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007816 public String getSimLocaleForSubscriber(int subId) {
7817 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7818 final Phone phone = getPhone(subId);
7819 if (phone == null) {
7820 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007821 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007822 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 final long identity = Binder.clearCallingIdentity();
7824 try {
chen xu5d3637b2019-01-21 23:31:38 -08007825 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007826 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007827 if (info == null) {
7828 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7829 return null;
7830 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007831 // Try and fetch the locale from the carrier properties or from the SIM language
7832 // preferences (EF-PL and EF-LI)...
7833 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007835 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7836 if (localeFromDefaultSim != null) {
7837 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7838 if (DBG) log("Using locale from subId: " + subId + " locale: "
7839 + localeFromDefaultSim);
7840 return localeFromDefaultSim.toLanguageTag();
7841 } else {
7842 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007843 }
7844 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 // The SIM language preferences only store a language (e.g. fr = French), not an
7847 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7848 // the SIM and carrier preferences does not include a country we add the country
7849 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007850 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007852 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 return mccLocale.toLanguageTag();
7854 }
7855
7856 if (DBG) log("No locale found - returning null");
7857 return null;
7858 } finally {
7859 Binder.restoreCallingIdentity(identity);
7860 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007861 }
7862
7863 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007864 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007865 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007866 }
7867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 /**
7869 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7870 */
7871 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007872 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007873 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007874 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007875
Chenjie Yu1ba97252018-01-11 18:16:20 -08007876 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007877 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007878
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007879 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007880 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7881 * representing the state of the modem.
7882 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007883 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7884 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007885 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007886 */
7887 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007888 public void requestModemActivityInfo(ResultReceiver result) {
7889 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007890 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891
7892 final long identity = Binder.clearCallingIdentity();
7893 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007894 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007895 } finally {
7896 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007897 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007898 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007899
Siddharth Rayb8114062018-06-17 15:02:38 -07007900 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7901 // less than total activity duration.
7902 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7903 if (info == null) {
7904 return false;
7905 }
7906 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007907 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7908 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7909
Siddharth Rayb8114062018-06-17 15:02:38 -07007910 return (info.isValid()
7911 && (info.getSleepTimeMillis() <= activityDurationMs)
7912 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007913 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007914 && (totalTxTimeMs <= activityDurationMs));
7915 }
7916
Jack Yu85bd38a2015-11-09 11:34:32 -08007917 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007918 * Returns the service state information on specified subscription.
7919 */
7920 @Override
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007921 public ServiceState getServiceStateForSubscriber(int subId,
7922 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7923 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007925 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007926 return null;
7927 }
7928
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007929 boolean hasFinePermission = false;
7930 boolean hasCoarsePermission = false;
7931 if (!renounceFineLocationAccess) {
7932 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7933 LocationAccessPolicy.checkLocationPermission(mApp,
7934 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7935 .setCallingPackage(callingPackage)
7936 .setCallingFeatureId(callingFeatureId)
7937 .setCallingPid(Binder.getCallingPid())
7938 .setCallingUid(Binder.getCallingUid())
7939 .setMethod("getServiceStateForSubscriber")
7940 .setLogAsInfo(true)
7941 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7942 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7943 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7944 .build());
7945 hasFinePermission =
7946 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7947 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007948
Sooraj Sasindran37bb1a72021-11-10 16:42:01 -08007949 if (!renounceCoarseLocationAccess) {
7950 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7951 LocationAccessPolicy.checkLocationPermission(mApp,
7952 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7953 .setCallingPackage(callingPackage)
7954 .setCallingFeatureId(callingFeatureId)
7955 .setCallingPid(Binder.getCallingPid())
7956 .setCallingUid(Binder.getCallingUid())
7957 .setMethod("getServiceStateForSubscriber")
7958 .setLogAsInfo(true)
7959 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7960 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7961 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7962 .build());
7963 hasCoarsePermission =
7964 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7965 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007966
Jack Yu479f40e2020-10-27 21:29:25 -07007967 final Phone phone = getPhone(subId);
7968 if (phone == null) {
7969 return null;
7970 }
7971
Jordan Liu0f2bc442020-11-18 16:47:37 -08007972 final long identity = Binder.clearCallingIdentity();
7973
Jack Yu479f40e2020-10-27 21:29:25 -07007974 boolean isCallingPackageDataService = phone.getDataServicePackages()
7975 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007976 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007977 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7978 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7979 Rlog.d(LOG_TAG,
7980 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7981 return null;
7982 }
7983
Hall Liuf19c44f2018-11-27 14:38:17 -08007984 ServiceState ss = phone.getServiceState();
7985
7986 // Scrub out the location info in ServiceState depending on what level of access
7987 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007988 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007989 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7990 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007991 } finally {
7992 Binder.restoreCallingIdentity(identity);
7993 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007994 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007995
7996 /**
7997 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7998 *
7999 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8000 * voicemail ringtone.
8001 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8002 * PhoneAccount.
8003 */
8004 @Override
8005 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008006 final long identity = Binder.clearCallingIdentity();
8007 try {
8008 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8009 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008010 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8014 } finally {
8015 Binder.restoreCallingIdentity(identity);
8016 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008017 }
8018
8019 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008020 * Sets the per-account voicemail ringtone.
8021 *
8022 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8023 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8024 *
8025 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8026 * voicemail ringtone.
8027 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8028 * PhoneAccount.
8029 */
8030 @Override
8031 public void setVoicemailRingtoneUri(String callingPackage,
8032 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008033 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008034 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008035 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8036 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8038 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8039 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008041
8042 final long identity = Binder.clearCallingIdentity();
8043 try {
8044 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8045 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008046 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 }
8048 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8049 } finally {
8050 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008051 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008052 }
8053
8054 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008055 * Returns whether vibration is set for voicemail notification in Phone settings.
8056 *
8057 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8058 * voicemail vibration setting.
8059 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8060 */
8061 @Override
8062 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063 final long identity = Binder.clearCallingIdentity();
8064 try {
8065 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8066 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008067 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008068 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8071 } finally {
8072 Binder.restoreCallingIdentity(identity);
8073 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008074 }
8075
Youhan Wange64578a2016-05-02 15:32:42 -07008076 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008077 * Sets the per-account voicemail vibration.
8078 *
8079 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8080 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8081 *
8082 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8083 * voicemail vibration setting.
8084 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8085 * specific PhoneAccount.
8086 */
8087 @Override
8088 public void setVoicemailVibrationEnabled(String callingPackage,
8089 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008090 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008091 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008092 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8093 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8095 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8096 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008097 }
8098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008099 final long identity = Binder.clearCallingIdentity();
8100 try {
8101 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8102 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008103 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 }
8105 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8106 } finally {
8107 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008108 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008109 }
8110
8111 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008112 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8113 *
8114 * @throws SecurityException if the caller does not have the required permission
8115 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008116 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008117 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008118 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008119 }
8120
8121 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008122 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8123 * permission.
8124 *
8125 * @throws SecurityException if the caller does not have the required permission
8126 */
8127 private void enforceSendSmsPermission() {
8128 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8129 }
8130
8131 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008132 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008133 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008134 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008135 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008136 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008137 final long identity = Binder.clearCallingIdentity();
8138 try {
8139 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008140 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141 if (componentName == null) {
8142 throw new SecurityException(
8143 "Caller not current active visual voicemail package[null]");
8144 }
8145 String vvmPackage = componentName.getPackageName();
8146 if (!callingPackage.equals(vvmPackage)) {
8147 throw new SecurityException("Caller not current active visual voicemail package["
8148 + vvmPackage + "]");
8149 }
8150 } finally {
8151 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008152 }
8153 }
8154
8155 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008156 * Return the application ID for the app type.
8157 *
8158 * @param subId the subscription ID that this request applies to.
8159 * @param appType the uicc app type.
8160 * @return Application ID for specificied app type, or null if no uicc.
8161 */
8162 @Override
8163 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008164 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008165 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166
8167 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008168 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008169 if (phone == null) {
8170 return null;
8171 }
8172 String aid = null;
8173 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008174 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175 .getApplicationByType(appType).getAid();
8176 } catch (Exception e) {
8177 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8178 }
8179 return aid;
8180 } finally {
8181 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008182 }
Youhan Wange64578a2016-05-02 15:32:42 -07008183 }
8184
Youhan Wang4001d252016-05-11 10:29:41 -07008185 /**
8186 * Return the Electronic Serial Number.
8187 *
8188 * @param subId the subscription ID that this request applies to.
8189 * @return ESN or null if error.
8190 */
8191 @Override
8192 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008193 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008194 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008195
8196 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008197 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008198 if (phone == null) {
8199 return null;
8200 }
8201 String esn = null;
8202 try {
8203 esn = phone.getEsn();
8204 } catch (Exception e) {
8205 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8206 }
8207 return esn;
8208 } finally {
8209 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008210 }
Youhan Wang4001d252016-05-11 10:29:41 -07008211 }
8212
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008213 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008214 * Return the Preferred Roaming List Version.
8215 *
8216 * @param subId the subscription ID that this request applies to.
8217 * @return PRLVersion or null if error.
8218 */
8219 @Override
8220 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008221 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008222 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008223
8224 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008225 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226 if (phone == null) {
8227 return null;
8228 }
8229 String cdmaPrlVersion = null;
8230 try {
8231 cdmaPrlVersion = phone.getCdmaPrlVersion();
8232 } catch (Exception e) {
8233 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8234 }
8235 return cdmaPrlVersion;
8236 } finally {
8237 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008238 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008239 }
8240
8241 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008242 * Get snapshot of Telephony histograms
8243 * @return List of Telephony histograms
8244 * @hide
8245 */
8246 @Override
8247 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8249 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250
8251 final long identity = Binder.clearCallingIdentity();
8252 try {
8253 return RIL.getTelephonyRILTimingHistograms();
8254 } finally {
8255 Binder.restoreCallingIdentity(identity);
8256 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008257 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008258
8259 /**
8260 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008261 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8262 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008263 * Require system privileges. In the future we may add this to carrier APIs.
8264 *
Michele Berionne482f8202018-11-27 18:57:59 -08008265 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008266 */
8267 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008268 @TelephonyManager.SetCarrierRestrictionResult
8269 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008270 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008271 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008272
Michele Berionne482f8202018-11-27 18:57:59 -08008273 if (carrierRestrictionRules == null) {
8274 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008275 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 final long identity = Binder.clearCallingIdentity();
8278 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008279 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008280 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281 } finally {
8282 Binder.restoreCallingIdentity(identity);
8283 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008284 }
8285
8286 /**
8287 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008288 * Get the allowed carrier list and the excluded carrier list, including the priority between
8289 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008290 * Require system privileges. In the future we may add this to carrier APIs.
8291 *
Michele Berionne482f8202018-11-27 18:57:59 -08008292 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008293 */
8294 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008295 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008296 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008297 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298
8299 final long identity = Binder.clearCallingIdentity();
8300 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008301 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8302 if (response instanceof CarrierRestrictionRules) {
8303 return (CarrierRestrictionRules) response;
8304 }
8305 // Response is an Exception of some kind,
8306 // which is signalled to the user as a NULL retval
8307 return null;
8308 } catch (Exception e) {
8309 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8310 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311 } finally {
8312 Binder.restoreCallingIdentity(identity);
8313 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008314 }
8315
fionaxu59545b42016-05-25 15:53:37 -07008316 /**
fionaxu59545b42016-05-25 15:53:37 -07008317 * Action set from carrier signalling broadcast receivers to enable/disable radio
8318 * @param subId the subscription ID that this action applies to.
8319 * @param enabled control enable or disable radio.
8320 * {@hide}
8321 */
8322 @Override
8323 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8324 enforceModifyPermission();
8325 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008326
8327 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008328 if (phone == null) {
8329 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8330 return;
8331 }
8332 try {
8333 phone.carrierActionSetRadioEnabled(enabled);
8334 } catch (Exception e) {
8335 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 } finally {
8337 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008338 }
8339 }
8340
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008341 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008342 * Enable or disable Voice over NR (VoNR)
8343 * @param subId the subscription ID that this action applies to.
8344 * @param enabled enable or disable VoNR.
8345 * @return operation result.
8346 */
8347 @Override
8348 public int setVoNrEnabled(int subId, boolean enabled) {
8349 enforceModifyPermission();
8350 final Phone phone = getPhone(subId);
8351
8352 final long identity = Binder.clearCallingIdentity();
8353 if (phone == null) {
8354 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8355 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8356 }
8357
8358 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8359 try {
8360 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8361 workSource);
8362 if (DBG) log("setVoNrEnabled result: " + result);
8363 return result;
8364 } finally {
8365 Binder.restoreCallingIdentity(identity);
8366 }
8367 }
8368
8369 /**
8370 * Is voice over NR enabled
8371 * @return true if VoNR is enabled else false
8372 */
8373 @Override
8374 public boolean isVoNrEnabled(int subId) {
8375 enforceReadPrivilegedPermission("isVoNrEnabled");
8376 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8377 final long identity = Binder.clearCallingIdentity();
8378 try {
8379 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8380 null, subId, workSource);
8381 if (DBG) log("isVoNrEnabled: " + isEnabled);
8382 return isEnabled;
8383 } finally {
8384 Binder.restoreCallingIdentity(identity);
8385 }
8386 }
8387
8388 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008389 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8390 * network status based on which carrier apps could apply actions accordingly,
8391 * enable/disable default url handler for example.
8392 *
8393 * @param subId the subscription ID that this action applies to.
8394 * @param report control start/stop reporting the default network status.
8395 * {@hide}
8396 */
8397 @Override
8398 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8399 enforceModifyPermission();
8400 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008401
8402 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008403 if (phone == null) {
8404 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8405 return;
8406 }
8407 try {
8408 phone.carrierActionReportDefaultNetworkStatus(report);
8409 } catch (Exception e) {
8410 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008411 } finally {
8412 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008413 }
8414 }
8415
8416 /**
fionaxud9622282017-07-17 17:51:30 -07008417 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8418 * @param subId the subscription ID that this action applies to.
8419 * {@hide}
8420 */
8421 @Override
8422 public void carrierActionResetAll(int subId) {
8423 enforceModifyPermission();
8424 final Phone phone = getPhone(subId);
8425 if (phone == null) {
8426 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8427 return;
8428 }
8429 try {
8430 phone.carrierActionResetAll();
8431 } catch (Exception e) {
8432 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8433 }
8434 }
8435
8436 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008437 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8438 * bug report is being generated.
8439 */
8440 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008441 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008442 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8443 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008444 writer.println("Permission Denial: can't dump Phone from pid="
8445 + Binder.getCallingPid()
8446 + ", uid=" + Binder.getCallingUid()
8447 + "without permission "
8448 + android.Manifest.permission.DUMP);
8449 return;
8450 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008451 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008452 }
Jack Yueb89b242016-06-22 13:27:47 -07008453
Brad Ebingerdac2f002018-04-03 15:17:52 -07008454 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008455 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8456 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8457 @NonNull String[] args) {
8458 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8459 this, in.getFileDescriptor(), out.getFileDescriptor(),
8460 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008461 }
8462
Jack Yueb89b242016-06-22 13:27:47 -07008463 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008464 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008465 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008466 * @param reason the reason the data enable change is taking place
8467 * @param enabled True if enabling the data, otherwise disabling.
8468 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008469 */
8470 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008471 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008472 boolean enabled) {
8473 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8474 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8475 try {
8476 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008477 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008478 } catch (SecurityException se) {
8479 enforceModifyPermission();
8480 }
8481 } else {
8482 enforceModifyPermission();
8483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008484
8485 final long identity = Binder.clearCallingIdentity();
8486 try {
8487 Phone phone = getPhone(subId);
8488 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008489 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8490 phone.carrierActionSetMeteredApnsEnabled(enabled);
8491 } else {
8492 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8493 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008494 }
8495 } finally {
8496 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008497 }
8498 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008499
8500 /**
8501 * Get Client request stats
8502 * @return List of Client Request Stats
8503 * @hide
8504 */
8505 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008506 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8507 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008509 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008510 return null;
8511 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008512 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008513
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008514 final long identity = Binder.clearCallingIdentity();
8515 try {
8516 if (phone != null) {
8517 return phone.getClientRequestStats();
8518 }
8519
8520 return null;
8521 } finally {
8522 Binder.restoreCallingIdentity(identity);
8523 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008524 }
8525
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008526 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008527 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008528 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008529 }
Jack Yueb4124c2017-02-16 15:32:43 -08008530
8531 /**
Grace Chen70990072017-03-24 17:21:30 -07008532 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008533 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008534 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008535 * @param state State of SIM (power down, power up, pass through)
8536 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8537 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8538 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008539 *
8540 **/
8541 @Override
Grace Chen70990072017-03-24 17:21:30 -07008542 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008543 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008544 Phone phone = PhoneFactory.getPhone(slotIndex);
8545
vagdeviaf9a5b92018-08-15 16:01:53 -07008546 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008548 final long identity = Binder.clearCallingIdentity();
8549 try {
8550 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008551 phone.setSimPowerState(state, null, workSource);
8552 }
8553 } finally {
8554 Binder.restoreCallingIdentity(identity);
8555 }
8556 }
8557
8558 /**
8559 * Set SIM card power state.
8560 *
8561 * @param slotIndex SIM slot id.
8562 * @param state State of SIM (power down, power up, pass through)
8563 * @param callback callback to trigger after success or failure
8564 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8565 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8566 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8567 *
8568 **/
8569 @Override
8570 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8571 IIntegerConsumer callback) {
8572 enforceModifyPermission();
8573 Phone phone = PhoneFactory.getPhone(slotIndex);
8574
8575 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8576
8577 final long identity = Binder.clearCallingIdentity();
8578 try {
8579 if (phone != null) {
8580 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8581 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008582 }
8583 } finally {
8584 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008585 }
8586 }
Shuo Qiandd210312017-04-12 22:11:33 +00008587
Tyler Gunn65d45c22017-06-05 11:22:26 -07008588 private boolean isUssdApiAllowed(int subId) {
8589 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008590 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008591 if (configManager == null) {
8592 return false;
8593 }
8594 PersistableBundle pb = configManager.getConfigForSubId(subId);
8595 if (pb == null) {
8596 return false;
8597 }
8598 return pb.getBoolean(
8599 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8600 }
8601
Shuo Qiandd210312017-04-12 22:11:33 +00008602 /**
8603 * Check if phone is in emergency callback mode
8604 * @return true if phone is in emergency callback mode
8605 * @param subId sub id
8606 */
goneil9c5f4872017-12-05 14:07:56 -08008607 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008608 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008609 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008610 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008611
8612 final long identity = Binder.clearCallingIdentity();
8613 try {
8614 if (phone != null) {
8615 return phone.isInEcm();
8616 } else {
8617 return false;
8618 }
8619 } finally {
8620 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008621 }
8622 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008623
8624 /**
8625 * Get the current signal strength information for the given subscription.
8626 * Because this information is not updated when the device is in a low power state
8627 * it should not be relied-upon to be current.
8628 * @param subId Subscription index
8629 * @return the most recent cached signal strength info from the modem
8630 */
8631 @Override
8632 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008633 final long identity = Binder.clearCallingIdentity();
8634 try {
8635 Phone p = getPhone(subId);
8636 if (p == null) {
8637 return null;
8638 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008640 return p.getSignalStrength();
8641 } finally {
8642 Binder.restoreCallingIdentity(identity);
8643 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008644 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008645
Pengquan Meng77b7f132018-08-22 14:49:57 -07008646 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008647 * Get the current modem radio state for the given slot.
8648 * @param slotIndex slot index.
8649 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008650 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008651 * @return the current radio power state from the modem
8652 */
8653 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008654 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008655 Phone phone = PhoneFactory.getPhone(slotIndex);
8656 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8658 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008659 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8660 }
8661
8662 final long identity = Binder.clearCallingIdentity();
8663 try {
8664 return phone.getRadioPowerState();
8665 } finally {
8666 Binder.restoreCallingIdentity(identity);
8667 }
8668 }
8669 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8670 }
8671
8672 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008673 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8674 *
8675 * <p>Requires one of the following permissions:
8676 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008677 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008678 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8679 * privileges.
8680 *
8681 * @param subId subscription id
8682 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8683 * {@code false}.
8684 */
8685 @Override
8686 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008687 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008688 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008689 try {
8690 mApp.enforceCallingOrSelfPermission(
8691 android.Manifest.permission.ACCESS_NETWORK_STATE,
8692 functionName);
8693 } catch (Exception e) {
8694 mApp.enforceCallingOrSelfPermission(
8695 permission.READ_BASIC_PHONE_STATE, functionName);
8696 }
Shuo Qian093013d2020-08-13 15:42:55 -07008697 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008698 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008699 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008700 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008701
Pengquan Menga1bb6272018-09-06 09:59:22 -07008702 boolean isEnabled = false;
8703 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008704 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008705 Phone phone = getPhone(subId);
8706 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008707 } finally {
8708 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008709 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008710 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008711 }
8712
8713
8714 /**
8715 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8716 *
8717 * <p> Requires permission:
8718 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8719 * privileges.
8720 *
8721 * @param subId subscription id
8722 * @param isEnabled {@code true} means enable, {@code false} means disable.
8723 */
8724 @Override
8725 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8727 mApp, subId, "setDataRoamingEnabled");
8728
Pengquan Menga1bb6272018-09-06 09:59:22 -07008729 final long identity = Binder.clearCallingIdentity();
8730 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008731 Phone phone = getPhone(subId);
8732 if (phone != null) {
8733 phone.setDataRoamingEnabled(isEnabled);
8734 }
8735 } finally {
8736 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008737 }
8738 }
8739
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008740 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008741 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008742 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008743 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008744 mApp, subId, "isManualNetworkSelectionAllowed");
8745
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008746 boolean isAllowed = true;
8747 final long identity = Binder.clearCallingIdentity();
8748 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008749 Phone phone = getPhone(subId);
8750 if (phone != null) {
8751 isAllowed = phone.isCspPlmnEnabled();
8752 }
8753 } finally {
8754 Binder.restoreCallingIdentity(identity);
8755 }
8756 return isAllowed;
8757 }
8758
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008759 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8760 UiccProfile profile = port.getUiccProfile();
8761 if (profile == null ||
8762 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8763 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8764 return false;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008765 }
8766 return true;
8767 }
8768
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008769 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008770 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008771 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008772 mApp.getSystemService(AppOpsManager.class)
8773 .checkPackage(Binder.getCallingUid(), callingPackage);
8774
Jordan Liu1e142fc2019-04-22 15:10:43 -07008775 boolean hasReadPermission = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008776 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008777 try {
8778 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008779 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008780 } catch (SecurityException e) {
8781 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8782 // has carrier privileges on an active UICC
8783 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8784 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008785 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008786 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008787 }
sandeepjs0a502c42021-09-27 15:34:44 +00008788 // checking compatibility, if calling app's target SDK is T and beyond.
8789 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8790 Binder.getCallingUid())) {
8791 isIccIdAccessRestricted = true;
8792 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008793 final long identity = Binder.clearCallingIdentity();
8794 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008795 UiccController uiccController = UiccController.getInstance();
8796 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008797 if (hasReadPermission) {
8798 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008799 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008800
8801 // Remove private info if the caller doesn't have access
8802 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8803 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjs0a502c42021-09-27 15:34:44 +00008804 //setting the value after compatibility check
8805 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008806 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8807 // is available
sandeepjs0a502c42021-09-27 15:34:44 +00008808 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008809 if (card == null) {
8810 // assume no access if the card is unavailable
sandeepjs0a502c42021-09-27 15:34:44 +00008811 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008812 continue;
8813 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008814 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8815 if (portInfos.isEmpty()) {
sandeepjs0a502c42021-09-27 15:34:44 +00008816 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008817 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008818 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008819 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8820 for (UiccPortInfo portInfo : portInfos) {
8821 UiccPort port = uiccController.getUiccPortForSlot(
8822 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8823 if (port == null) {
8824 // assume no access if port is null
8825 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8826 continue;
8827 }
8828 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8829 uiccPortInfos.add(portInfo);
8830 } else {
8831 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8832 }
8833 }
8834 filteredInfos.add(new UiccCardInfo(
8835 cardInfo.isEuicc(),
8836 cardInfo.getCardId(),
8837 null,
8838 cardInfo.getPhysicalSlotIndex(),
8839 cardInfo.isRemovable(),
8840 cardInfo.isMultipleEnabledProfilesSupported(),
8841 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008842 }
8843 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008844 } finally {
8845 Binder.restoreCallingIdentity(identity);
8846 }
8847 }
8848
sandeepjs0a502c42021-09-27 15:34:44 +00008849 /**
8850 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8851 * generally private and require carrier privileges to view.
8852 *
8853 * @hide
8854 */
8855 @NonNull
8856 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8857 List<UiccPortInfo> portinfo = new ArrayList<>();
8858 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8859 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8860 }
8861 return new UiccCardInfo(
8862 cardInfo.isEuicc(),
8863 cardInfo.getCardId(),
8864 null,
8865 cardInfo.getPhysicalSlotIndex(),
8866 cardInfo.isRemovable(),
8867 cardInfo.isMultipleEnabledProfilesSupported(),
8868 portinfo
8869 );
8870 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008871
sandeepjs0a502c42021-09-27 15:34:44 +00008872 /**
8873 * @hide
8874 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8875 * These values are generally private and require carrier privileges to view.
8876 */
8877 @NonNull
8878 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8879 return new UiccPortInfo(
8880 UiccPortInfo.ICCID_REDACTED,
8881 portInfo.getPortIndex(),
8882 portInfo.getLogicalSlotIndex(),
8883 portInfo.isActive()
8884 );
8885 }
8886 @Override
8887 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjs29b7e8e2021-11-17 04:05:58 +00008888 // Verify that the callingPackage belongs to the calling UID
sandeepjs0a502c42021-09-27 15:34:44 +00008889 mApp.getSystemService(AppOpsManager.class)
8890 .checkPackage(Binder.getCallingUid(), callingPackage);
8891
8892 boolean hasReadPermission = false;
8893 boolean isLogicalSlotAccessRestricted = false;
sandeepjs0a502c42021-09-27 15:34:44 +00008894
8895 try {
8896 enforceReadPrivilegedPermission("getUiccSlotsInfo");
8897 hasReadPermission = true;
8898 } catch (SecurityException e) {
8899 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8900 // has carrier privileges on an active UICC
8901 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8902 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8903 hasReadPermission = true;
8904 }
8905 }
8906
8907 // checking compatibility, if calling app's target SDK is T and beyond.
8908 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8909 Binder.getCallingUid())) {
8910 isLogicalSlotAccessRestricted = true;
8911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008912 final long identity = Binder.clearCallingIdentity();
8913 try {
8914 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8915 if (slots == null) {
8916 Rlog.i(LOG_TAG, "slots is null.");
8917 return null;
8918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008919 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8920 for (int i = 0; i < slots.length; i++) {
8921 UiccSlot slot = slots[i];
8922 if (slot == null) {
8923 continue;
8924 }
8925
Jordan Liu7be7e652019-05-06 18:55:02 +00008926 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927 UiccCard card = slot.getUiccCard();
8928 if (card != null) {
8929 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008930 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008931 cardId = slot.getEid();
8932 if (TextUtils.isEmpty(cardId)) {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008933 // If cardId is null, use iccId of default port as cardId. Check if has
8934 // read permission otherwise set to null.(card is null which means no
8935 // carrier permission)
8936 cardId = hasReadPermission ? slot.getIccId(
8937 TelephonyManager.DEFAULT_PORT_INDEX) : null;
Jordan Liu01bd00d2019-09-12 16:19:43 -07008938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008939 }
8940
Jordan Liu857451f2019-05-09 16:35:35 -07008941 if (cardId != null) {
8942 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8943 // if cardId is an EID, it's all digits so this is fine
8944 cardId = IccUtils.stripTrailingFs(cardId);
8945 }
8946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008947 int cardState = 0;
8948 switch (slot.getCardState()) {
8949 case CARDSTATE_ABSENT:
8950 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8951 break;
8952 case CARDSTATE_PRESENT:
8953 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8954 break;
8955 case CARDSTATE_ERROR:
8956 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8957 break;
8958 case CARDSTATE_RESTRICTED:
8959 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8960 break;
8961 default:
8962 break;
8963
8964 }
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008965 List<UiccPortInfo> portInfos = new ArrayList<>();
8966 int[] portIndexes = slot.getPortList();
8967 for (int portIdx : portIndexes) {
8968 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
8969 callingPackage, hasReadPermission));
8970 if (slot.isPortActive(portIdx)) {
8971 UiccPort port = slot.getUiccCard().getUiccPort(portIdx);
8972 portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(),
8973 port.getPhoneId(), true));
8974 } else {
8975 portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false));
8976 }
8977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008978 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 slot.isEuicc(),
8980 cardId,
8981 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008982 slot.isExtendedApduSupported(),
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008983 slot.isRemovable(), portInfos);
sandeepjs0a502c42021-09-27 15:34:44 +00008984 //setting the value after compatibility check
8985 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008986 }
8987 return infos;
8988 } finally {
8989 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008990 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008991 }
8992
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00008993 /* Returns null if doesn't have read permission or carrier privilege access. */
8994 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8995 boolean hasReadPermission) {
8996 String iccId = slot.getIccId(portIndex);
8997 if (hasReadPermission) { // if has read permission
8998 return iccId;
8999 } else {
9000 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9001 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9002 // if no read permission, checking carrier privilege access
9003 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9004 return iccId;
9005 }
9006 }
9007 }
9008 // No read permission or carrier privilege access.
9009 return UiccPortInfo.ICCID_REDACTED;
9010 }
9011
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009012 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00009013 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009014 public boolean switchSlots(int[] physicalSlots) {
9015 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009016
9017 final long identity = Binder.clearCallingIdentity();
9018 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00009019 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9020 for (int i = 0; i < physicalSlots.length; i++) {
9021 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9022 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9023 physicalSlots[i], i));
9024 }
9025 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009026 } finally {
9027 Binder.restoreCallingIdentity(identity);
9028 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009029 }
Jack Yu4c988042018-02-27 15:30:01 -08009030
9031 @Override
sandeepjs0a502c42021-09-27 15:34:44 +00009032 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9033 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9034 enforceModifyPermission();
9035
9036 final long identity = Binder.clearCallingIdentity();
9037 try {
Muralidhar Reddy70bf65a2021-11-19 03:07:54 +00009038 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjs0a502c42021-09-27 15:34:44 +00009039 } finally {
9040 Binder.restoreCallingIdentity(identity);
9041 }
9042 }
9043
9044 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009045 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009046 final long identity = Binder.clearCallingIdentity();
9047 try {
9048 return UiccController.getInstance().getCardIdForDefaultEuicc();
9049 } finally {
9050 Binder.restoreCallingIdentity(identity);
9051 }
9052 }
9053
Pengquan Meng85728fb2018-03-12 16:31:21 -07009054 /**
goneil47ffb6e2018-04-06 15:40:58 -07009055 * A test API to reload the UICC profile.
9056 *
9057 * <p>Requires that the calling app has permission
9058 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9059 * @hide
9060 */
9061 @Override
9062 public void refreshUiccProfile(int subId) {
9063 enforceModifyPermission();
9064
9065 final long identity = Binder.clearCallingIdentity();
9066 try {
9067 Phone phone = getPhone(subId);
9068 if (phone == null) {
9069 return;
9070 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009071 UiccPort uiccPort = phone.getUiccPort();
9072 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009073 return;
9074 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009075 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009076 if (uiccProfile == null) {
9077 return;
9078 }
9079 uiccProfile.refresh();
9080 } finally {
9081 Binder.restoreCallingIdentity(identity);
9082 }
9083 }
9084
9085 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009086 * Returns false if the mobile data is disabled by default, otherwise return true.
9087 */
9088 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009089 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009090 }
9091
9092 /**
9093 * Returns true if the data roaming is enabled by default, i.e the system property
9094 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9095 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9096 */
9097 private boolean getDefaultDataRoamingEnabled(int subId) {
9098 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009099 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009100 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009101 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9102 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9103 return isDataRoamingEnabled;
9104 }
9105
9106 /**
9107 * Returns the default network type for the given {@code subId}, if the default network type is
9108 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9109 */
9110 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009111 List<Integer> list = TelephonyProperties.default_network();
9112 int phoneId = mSubscriptionController.getPhoneId(subId);
9113 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9114 return list.get(phoneId);
9115 }
9116 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009117 }
fionaxua13278b2018-03-21 00:08:13 -07009118
9119 @Override
9120 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009121 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009122 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009123
9124 final long identity = Binder.clearCallingIdentity();
9125 try {
9126 final Phone phone = getPhone(subId);
9127 if (phone == null) {
9128 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9129 return;
9130 }
chen xueaba88a2019-03-15 13:15:10 -07009131 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9132 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009133 if (carrierPrivilegeRules == null) {
9134 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9135 } else {
9136 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009138 } finally {
9139 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009140 }
fionaxua13278b2018-03-21 00:08:13 -07009141 }
9142
9143 @Override
9144 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009145 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009146
9147 final long identity = Binder.clearCallingIdentity();
9148 try {
9149 final Phone phone = getPhone(subId);
9150 if (phone == null) {
9151 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9152 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9153 }
9154 return phone.getCarrierIdListVersion();
9155 } finally {
9156 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009157 }
fionaxua13278b2018-03-21 00:08:13 -07009158 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009159
9160 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009161 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9162 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009163 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009164 mApp, subId, callingPackage, callingFeatureId,
9165 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009166 return -1;
9167 }
9168
9169 final long identity = Binder.clearCallingIdentity();
9170 try {
9171 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
9174 }
9175 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009176
9177 @Override
9178 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009179 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009180 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009181 mApp, subId, "getCdmaRoamingMode");
9182
9183 final long identity = Binder.clearCallingIdentity();
9184 try {
9185 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9186 } finally {
9187 Binder.restoreCallingIdentity(identity);
9188 }
9189 }
9190
9191 @Override
9192 public boolean setCdmaRoamingMode(int subId, int mode) {
9193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9194 mApp, subId, "setCdmaRoamingMode");
9195
9196 final long identity = Binder.clearCallingIdentity();
9197 try {
9198 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
9201 }
9202 }
9203
9204 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009205 public int getCdmaSubscriptionMode(int subId) {
9206 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009207 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009208 mApp, subId, "getCdmaSubscriptionMode");
9209
9210 final long identity = Binder.clearCallingIdentity();
9211 try {
9212 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9213 } finally {
9214 Binder.restoreCallingIdentity(identity);
9215 }
9216 }
9217
9218 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009219 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9221 mApp, subId, "setCdmaSubscriptionMode");
9222
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
9225 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9226 } finally {
9227 Binder.restoreCallingIdentity(identity);
9228 }
9229 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009230
sqianc5eccab2018-10-19 18:46:41 -07009231 @Override
sqian8c685422019-02-22 15:55:18 -08009232 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009233 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009235 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9236 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009237 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9238 }
9239 final long identity = Binder.clearCallingIdentity();
9240 try {
sqian854d44b2018-12-12 16:48:18 -08009241 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9242 for (Phone phone: PhoneFactory.getPhones()) {
9243 if (phone.getEmergencyNumberTracker() != null
9244 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9245 emergencyNumberListInternal.put(
9246 phone.getSubId(),
9247 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9248 }
sqian11b7a0e2018-12-05 18:48:28 -08009249 }
sqian854d44b2018-12-12 16:48:18 -08009250 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009251 } finally {
9252 Binder.restoreCallingIdentity(identity);
9253 }
sqianc5eccab2018-10-19 18:46:41 -07009254 }
9255
9256 @Override
sqian8c685422019-02-22 15:55:18 -08009257 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009258 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009259 if (!exactMatch) {
9260 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009261 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009262 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009263 }
9264 final long identity = Binder.clearCallingIdentity();
9265 try {
sqian854d44b2018-12-12 16:48:18 -08009266 for (Phone phone: PhoneFactory.getPhones()) {
9267 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009268 && phone.getEmergencyNumberTracker()
9269 .isEmergencyNumber(number, exactMatch)) {
9270 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009271 }
sqian11b7a0e2018-12-05 18:48:28 -08009272 }
9273 return false;
9274 } finally {
9275 Binder.restoreCallingIdentity(identity);
9276 }
9277 }
9278
sqianf4ca7ed2019-01-15 18:32:07 -08009279 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009280 * Start emergency callback mode for GsmCdmaPhone for testing.
9281 */
9282 @Override
9283 public void startEmergencyCallbackMode() {
9284 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9285 "startEmergencyCallbackMode");
9286 enforceModifyPermission();
9287 final long identity = Binder.clearCallingIdentity();
9288 try {
9289 for (Phone phone : PhoneFactory.getPhones()) {
9290 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9291 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9292 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9293 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9294 gsmCdmaPhone.obtainMessage(
9295 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9296 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9297 }
9298 }
9299 } finally {
9300 Binder.restoreCallingIdentity(identity);
9301 }
9302 }
9303
9304 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009305 * Update emergency number list for test mode.
9306 */
9307 @Override
9308 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9309 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9310 "updateEmergencyNumberListTestMode");
9311
9312 final long identity = Binder.clearCallingIdentity();
9313 try {
9314 for (Phone phone: PhoneFactory.getPhones()) {
9315 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9316 if (tracker != null) {
9317 tracker.executeEmergencyNumberTestModeCommand(action, num);
9318 }
9319 }
9320 } finally {
9321 Binder.restoreCallingIdentity(identity);
9322 }
9323 }
9324
9325 /**
9326 * Get the full emergency number list for test mode.
9327 */
9328 @Override
9329 public List<String> getEmergencyNumberListTestMode() {
9330 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9331 "getEmergencyNumberListTestMode");
9332
9333 final long identity = Binder.clearCallingIdentity();
9334 try {
9335 Set<String> emergencyNumbers = new HashSet<>();
9336 for (Phone phone: PhoneFactory.getPhones()) {
9337 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9338 if (tracker != null) {
9339 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9340 emergencyNumbers.add(num.getNumber());
9341 }
9342 }
9343 }
9344 return new ArrayList<>(emergencyNumbers);
9345 } finally {
9346 Binder.restoreCallingIdentity(identity);
9347 }
9348 }
9349
chen xud6b45bd2018-10-30 22:27:10 -07009350 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009351 public int getEmergencyNumberDbVersion(int subId) {
9352 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9353
9354 final long identity = Binder.clearCallingIdentity();
9355 try {
9356 final Phone phone = getPhone(subId);
9357 if (phone == null) {
9358 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9359 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9360 }
9361 return phone.getEmergencyNumberDbVersion();
9362 } finally {
9363 Binder.restoreCallingIdentity(identity);
9364 }
9365 }
9366
9367 @Override
9368 public void notifyOtaEmergencyNumberDbInstalled() {
9369 enforceModifyPermission();
9370
9371 final long identity = Binder.clearCallingIdentity();
9372 try {
9373 for (Phone phone: PhoneFactory.getPhones()) {
9374 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9375 if (tracker != null) {
9376 tracker.updateOtaEmergencyNumberDatabase();
9377 }
9378 }
9379 } finally {
9380 Binder.restoreCallingIdentity(identity);
9381 }
9382 }
9383
9384 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009385 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009386 enforceActiveEmergencySessionPermission();
9387
9388 final long identity = Binder.clearCallingIdentity();
9389 try {
9390 for (Phone phone: PhoneFactory.getPhones()) {
9391 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9392 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009393 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9394 }
9395 }
9396 } finally {
9397 Binder.restoreCallingIdentity(identity);
9398 }
9399 }
9400
9401 @Override
9402 public void resetOtaEmergencyNumberDbFilePath() {
9403 enforceActiveEmergencySessionPermission();
9404
9405 final long identity = Binder.clearCallingIdentity();
9406 try {
9407 for (Phone phone: PhoneFactory.getPhones()) {
9408 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9409 if (tracker != null) {
9410 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009411 }
9412 }
9413 } finally {
9414 Binder.restoreCallingIdentity(identity);
9415 }
9416 }
9417
9418 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009419 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9420 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9421 Phone phone = getPhone(subId);
9422 if (phone == null) {
9423 return null;
9424 }
9425 final long identity = Binder.clearCallingIdentity();
9426 try {
9427 UiccProfile profile = UiccController.getInstance()
9428 .getUiccProfileForPhone(phone.getPhoneId());
9429 if (profile != null) {
9430 return profile.getCertsFromCarrierPrivilegeAccessRules();
9431 }
9432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 return null;
9436 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009437
9438 /**
9439 * Enable or disable a modem stack.
9440 */
9441 @Override
9442 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9443 enforceModifyPermission();
9444
9445 final long identity = Binder.clearCallingIdentity();
9446 try {
9447 Phone phone = PhoneFactory.getPhone(slotIndex);
9448 if (phone == null) {
9449 return false;
9450 } else {
9451 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9452 }
9453 } finally {
9454 Binder.restoreCallingIdentity(identity);
9455 }
9456 }
Michelecea4cf22018-12-21 15:00:11 -08009457
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009458 /**
9459 * Whether a modem stack is enabled or not.
9460 */
9461 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009462 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9463 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009464 Phone phone = PhoneFactory.getPhone(slotIndex);
9465 if (phone == null) return false;
9466
9467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009468 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9469 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009470 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9471 }
9472
9473 final long identity = Binder.clearCallingIdentity();
9474 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009475 try {
9476 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9477 } catch (NoSuchElementException ex) {
9478 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9479 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009480 } finally {
9481 Binder.restoreCallingIdentity(identity);
9482 }
9483 }
9484
Michelecea4cf22018-12-21 15:00:11 -08009485 @Override
Michele0ea7d782019-03-19 14:58:42 -07009486 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009487 enforceModifyPermission();
9488
9489 final long identity = Binder.clearCallingIdentity();
9490 try {
9491 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009492 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009493 .commit();
9494 } finally {
9495 Binder.restoreCallingIdentity(identity);
9496 }
9497 }
9498
9499 @Override
Michele0ea7d782019-03-19 14:58:42 -07009500 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009501 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009503 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9504 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009505 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009506 }
Michelecea4cf22018-12-21 15:00:11 -08009507
9508 final long identity = Binder.clearCallingIdentity();
9509 try {
Michele0ea7d782019-03-19 14:58:42 -07009510 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009511 } finally {
9512 Binder.restoreCallingIdentity(identity);
9513 }
9514 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009515
Michele0ea7d782019-03-19 14:58:42 -07009516 @TelephonyManager.IsMultiSimSupportedResult
9517 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009518 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9519 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9520 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009521 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9522 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009523 }
9524 // Check if the hardware supports multisim functionality. If usage of multisim is not
9525 // supported by the modem, indicate that it is restricted.
9526 PhoneCapability staticCapability =
9527 mPhoneConfigurationManager.getStaticPhoneCapability();
9528 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009529 loge("isMultiSimSupportedInternal: no static configuration available");
9530 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009531 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009532 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009533 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9534 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009535 }
9536 // Check if support of multiple SIMs is restricted by carrier
9537 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009538 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009539 }
9540
Michele0ea7d782019-03-19 14:58:42 -07009541 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009542 }
9543
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009544 /**
9545 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009546 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9547 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9548 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009549 * @param numOfSims number of active sims we want to switch to
9550 */
9551 @Override
9552 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009553 if (numOfSims == 1) {
9554 enforceModifyPermission();
9555 } else {
9556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9557 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9558 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009559 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009560
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009561 try {
Michele30b57b22019-03-01 12:01:14 -08009562 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009563 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009564 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9565 return;
9566 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009567 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9568 } finally {
9569 Binder.restoreCallingIdentity(identity);
9570 }
9571 }
9572
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009573 @Override
9574 public boolean isApplicationOnUicc(int subId, int appType) {
9575 enforceReadPrivilegedPermission("isApplicationOnUicc");
9576 Phone phone = getPhone(subId);
9577 if (phone == null) {
9578 return false;
9579 }
9580 final long identity = Binder.clearCallingIdentity();
9581 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009582 UiccPort uiccPort = phone.getUiccPort();
9583 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009584 return false;
9585 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009586 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009587 if (uiccProfile == null) {
9588 return false;
9589 }
9590 if (TelephonyManager.APPTYPE_SIM <= appType
9591 && appType <= TelephonyManager.APPTYPE_ISIM) {
9592 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9593 }
9594 return false;
9595 } finally {
9596 Binder.restoreCallingIdentity(identity);
9597 }
9598 }
9599
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009600 /**
chen xub4baa772019-04-03 10:23:41 -07009601 * Get whether making changes to modem configurations will trigger reboot.
9602 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009603 */
9604 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009605 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9606 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009608 mApp, subId, callingPackage, callingFeatureId,
9609 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009610 return false;
9611 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009612 final long identity = Binder.clearCallingIdentity();
9613 try {
9614 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9615 } finally {
9616 Binder.restoreCallingIdentity(identity);
9617 }
9618 }
9619
Nathan Harold29f5f052019-02-15 13:41:57 -08009620 private void updateModemStateMetrics() {
9621 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9622 // TODO: check the state for each modem if the api is ready.
9623 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9624 }
9625
Pengquan Meng3889a572019-01-23 11:16:29 -08009626 @Override
sandeepjs29b7e8e2021-11-17 04:05:58 +00009627 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009628 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjs29b7e8e2021-11-17 04:05:58 +00009629 // Verify that the callingPackage belongs to the calling UID
9630 mApp.getSystemService(AppOpsManager.class)
9631 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009632 final long identity = Binder.clearCallingIdentity();
sandeepjs29b7e8e2021-11-17 04:05:58 +00009633 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009634 try {
sandeepjs29b7e8e2021-11-17 04:05:58 +00009635 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9636 if (slotInfos != null) {
9637 for (int i = 0; i < slotInfos.length; i++) {
9638 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9639 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9640 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9641 portInfo.getLogicalSlotIndex()));
9642 }
9643 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009644 }
9645 }
sandeepjs29b7e8e2021-11-17 04:05:58 +00009646 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
9650 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009651
9652 /**
9653 * Get the IRadio HAL Version
9654 */
9655 @Override
9656 public int getRadioHalVersion() {
9657 Phone phone = getDefaultPhone();
9658 if (phone == null) return -1;
9659 HalVersion hv = phone.getHalVersion();
9660 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9661 return hv.major * 100 + hv.minor;
9662 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009663
9664 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009665 * Get the current calling package name.
9666 * @return the current calling package name
9667 */
9668 @Override
9669 public String getCurrentPackageName() {
9670 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9671 }
9672
9673 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009674 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9675 * corresponding network requests on a subId.
9676 *
9677 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009678 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009679 * 2) APN is un-metered for this subscription, or
9680 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009681 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009682 *
9683 * @return whether data is allowed for a apn type.
9684 *
9685 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009686 */
9687 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009688 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009689 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9690 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009691
9692 // Now that all security checks passes, perform the operation as ourselves.
9693 final long identity = Binder.clearCallingIdentity();
9694 try {
9695 Phone phone = getPhone(subId);
9696 if (phone == null) return false;
9697
Jack Yu41407ee2019-05-13 16:54:09 -07009698 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009699 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9700 } finally {
9701 Binder.restoreCallingIdentity(identity);
9702 }
9703 }
9704
9705 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009706 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009707 enforceReadPrivilegedPermission("isApnMetered");
9708
9709 // Now that all security checks passes, perform the operation as ourselves.
9710 final long identity = Binder.clearCallingIdentity();
9711 try {
9712 Phone phone = getPhone(subId);
9713 if (phone == null) return true; // By default return true.
9714
Jack Yu41407ee2019-05-13 16:54:09 -07009715 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009716 } finally {
9717 Binder.restoreCallingIdentity(identity);
9718 }
9719 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009720
9721 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009722 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9723 int subscriptionId, IBooleanConsumer resultCallback) {
9724 enforceModifyPermission();
9725 long token = Binder.clearCallingIdentity();
9726 try {
9727 Phone phone = getPhone(subscriptionId);
9728 if (phone == null) {
9729 try {
9730 if (resultCallback != null) {
9731 resultCallback.accept(false);
9732 }
9733 } catch (RemoteException e) {
9734 // ignore
9735 }
9736 return;
9737 }
9738 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9739 Pair.create(specifiers, (x) -> {
9740 try {
9741 if (resultCallback != null) {
9742 resultCallback.accept(x);
9743 }
9744 } catch (RemoteException e) {
9745 // ignore
9746 }
9747 });
9748 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9749 } finally {
9750 Binder.restoreCallingIdentity(token);
9751 }
9752 }
9753
9754 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009755 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9756 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009757 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009758 mApp, subId, "getSystemSelectionChannels");
9759 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9760 final long identity = Binder.clearCallingIdentity();
9761 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009762 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9763 if (result instanceof IllegalStateException) {
9764 throw (IllegalStateException) result;
9765 }
9766 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009767 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9768 return specifiers;
9769 } finally {
9770 Binder.restoreCallingIdentity(identity);
9771 }
9772 }
9773
9774 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009775 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009776 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009777 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9778 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9779 if (iccRecords == null) {
9780 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9781 return false;
9782 }
9783 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9784 }
9785
9786 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009787 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9788 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009789 if (callingPackage == null) {
9790 callingPackage = getCurrentPackageName();
9791 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009792 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9793 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009794 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9795 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009796 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9797 }
9798 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9799 Intent intent = new Intent();
9800 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9801 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9802 // Bring up choose default SMS subscription dialog right now
9803 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9804 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9805 mApp.startActivity(intent);
9806 }
chen xud5ca2d52019-05-28 15:20:57 -07009807
9808 @Override
9809 public String getMmsUAProfUrl(int subId) {
9810 //TODO investigate if this API should require proper permission check in R b/133791609
9811 final long identity = Binder.clearCallingIdentity();
9812 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009813 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9814 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9815 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9816 return carrierUAProfUrl;
9817 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009818 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9819 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009820 } finally {
9821 Binder.restoreCallingIdentity(identity);
9822 }
9823 }
9824
9825 @Override
9826 public String getMmsUserAgent(int subId) {
9827 //TODO investigate if this API should require proper permission check in R b/133791609
9828 final long identity = Binder.clearCallingIdentity();
9829 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009830 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9831 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9832 if (!TextUtils.isEmpty(carrierUserAgent)) {
9833 return carrierUserAgent;
9834 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009835 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9836 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009837 } finally {
9838 Binder.restoreCallingIdentity(identity);
9839 }
9840 }
Jack Yub07d4972019-05-28 16:12:25 -07009841
9842 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009843 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9844 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009845
Jack Yub07d4972019-05-28 16:12:25 -07009846 final long identity = Binder.clearCallingIdentity();
9847 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009848 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009849 if (phone == null) return false;
9850
Hall Liua62f5da2020-09-25 10:42:19 -07009851 switch (policy) {
9852 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9853 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9854 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9855 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9856 default:
9857 throw new IllegalArgumentException(policy + " is not a valid policy");
9858 }
Jack Yub07d4972019-05-28 16:12:25 -07009859 } finally {
9860 Binder.restoreCallingIdentity(identity);
9861 }
9862 }
9863
9864 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009865 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009866 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009867 enforceModifyPermission();
9868
changbettyd5c246e2019-12-24 15:40:37 +08009869 final long identity = Binder.clearCallingIdentity();
9870 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009871 Phone phone = getPhone(subscriptionId);
9872 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009873
Hall Liua62f5da2020-09-25 10:42:19 -07009874 switch (policy) {
9875 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9876 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9877 break;
9878 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9879 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9880 break;
9881 default:
9882 throw new IllegalArgumentException(policy + " is not a valid policy");
9883 }
changbettyd5c246e2019-12-24 15:40:37 +08009884 } finally {
9885 Binder.restoreCallingIdentity(identity);
9886 }
9887 }
9888
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009889 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009890 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009891 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9892 * otherwise.
9893 */
9894 @Override
9895 public void setCepEnabled(boolean isCepEnabled) {
9896 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9897
9898 final long identity = Binder.clearCallingIdentity();
9899 try {
9900 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9901 for (Phone phone : PhoneFactory.getPhones()) {
9902 Phone defaultPhone = phone.getImsPhone();
9903 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9904 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9905 ImsPhoneCallTracker imsPhoneCallTracker =
9906 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9907 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9908 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9909 + imsPhone.getMsisdn());
9910 }
9911 }
9912 } finally {
9913 Binder.restoreCallingIdentity(identity);
9914 }
9915 }
allenwtsu46dcc572020-01-08 18:24:03 +08009916
9917 /**
9918 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9919 *
9920 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9921 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9922 * before being read.
9923 */
9924 @Override
9925 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9926 isCompressed) {
9927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9928 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009929 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9930 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9931 }
9932 if (!isImsAvailableOnDevice()) {
9933 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9934 "IMS not available on device.");
9935 }
9936
9937 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009938 try {
Hui Wang761a6682020-10-31 05:12:53 +00009939 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9940 } finally {
9941 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009942 }
9943 }
zoey chene02881a2019-12-30 16:11:23 +08009944
9945 @Override
9946 public boolean isIccLockEnabled(int subId) {
9947 enforceReadPrivilegedPermission("isIccLockEnabled");
9948
9949 // Now that all security checks passes, perform the operation as ourselves.
9950 final long identity = Binder.clearCallingIdentity();
9951 try {
9952 Phone phone = getPhone(subId);
9953 if (phone != null && phone.getIccCard() != null) {
9954 return phone.getIccCard().getIccLockEnabled();
9955 } else {
9956 return false;
9957 }
9958 } finally {
9959 Binder.restoreCallingIdentity(identity);
9960 }
9961 }
9962
9963 /**
9964 * Set the ICC pin lock enabled or disabled.
9965 *
9966 * @return an integer representing the status of IccLock enabled or disabled in the following
9967 * three cases:
9968 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9969 * successfully.
9970 * - Positive number and zero for remaining password attempts.
9971 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9972 *
9973 */
9974 @Override
9975 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9976 enforceModifyPermission();
9977
9978 Phone phone = getPhone(subId);
9979 if (phone == null) {
9980 return 0;
9981 }
9982 // Now that all security checks passes, perform the operation as ourselves.
9983 final long identity = Binder.clearCallingIdentity();
9984 try {
9985 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9986 new Pair<Boolean, String>(enabled, password), phone, null);
9987 return attemptsRemaining;
9988
9989 } catch (Exception e) {
9990 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9991 } finally {
9992 Binder.restoreCallingIdentity(identity);
9993 }
9994 return 0;
9995 }
9996
9997 /**
9998 * Change the ICC password used in ICC pin lock.
9999 *
10000 * @return an integer representing the status of IccLock changed in the following three cases:
10001 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10002 * - Positive number and zero for remaining password attempts.
10003 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10004 *
10005 */
10006 @Override
10007 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10008 enforceModifyPermission();
10009
10010 Phone phone = getPhone(subId);
10011 if (phone == null) {
10012 return 0;
10013 }
10014 // Now that all security checks passes, perform the operation as ourselves.
10015 final long identity = Binder.clearCallingIdentity();
10016 try {
10017 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10018 new Pair<String, String>(oldPassword, newPassword), phone, null);
10019 return attemptsRemaining;
10020
10021 } catch (Exception e) {
10022 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10023 } finally {
10024 Binder.restoreCallingIdentity(identity);
10025 }
10026 return 0;
10027 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010028
10029 /**
10030 * Request for receiving user activity notification
10031 */
10032 @Override
10033 public void requestUserActivityNotification() {
10034 if (!mNotifyUserActivity.get()
10035 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10036 mNotifyUserActivity.set(true);
10037 }
10038 }
10039
10040 /**
10041 * Called when userActivity is signalled in the power manager.
10042 * This is safe to call from any thread, with any window manager locks held or not.
10043 */
10044 @Override
10045 public void userActivity() {
10046 // ***************************************
10047 // * Inherited from PhoneWindowManager *
10048 // ***************************************
10049 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10050 // WITH ITS LOCKS HELD.
10051 //
10052 // This code must be VERY careful about the locks
10053 // it acquires.
10054 // In fact, the current code acquires way too many,
10055 // and probably has lurking deadlocks.
10056
10057 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10058 throw new SecurityException("Only the OS may call notifyUserActivity()");
10059 }
10060
10061 if (mNotifyUserActivity.getAndSet(false)) {
10062 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10063 USER_ACTIVITY_NOTIFICATION_DELAY);
10064 }
10065 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010066
10067 @Override
10068 public boolean canConnectTo5GInDsdsMode() {
10069 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10070 }
Jack Yud10cdd42020-09-28 20:28:01 -070010071
10072 @Override
10073 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10074 String callingFeatureId) {
10075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10076 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10077 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10078 }
10079
10080 Phone phone = getPhone(subId);
10081 if (phone == null) {
10082 throw new RuntimeException("phone is not available");
10083 }
10084 // Now that all security checks passes, perform the operation as ourselves.
10085 final long identity = Binder.clearCallingIdentity();
10086 try {
10087 return phone.getEquivalentHomePlmns();
10088 } finally {
10089 Binder.restoreCallingIdentity(identity);
10090 }
10091 }
Daniel Bright59e67312020-11-13 11:49:37 -080010092
10093 @Override
10094 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010095 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10096 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010097 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010098 if (radioInterfaceCapabilities == null) {
10099 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010100 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010101 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010102 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010103
Hui Wang641e81c2020-10-12 12:14:23 -070010104 @Override
10105 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10106 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010107 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10108 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10109 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10110 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10111 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010112 if (DBG) {
10113 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10114 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10115 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10116 }
10117
10118 if (!SubscriptionManager.isValidSubscriptionId(subId)
10119 || appType < TelephonyManager.APPTYPE_UNKNOWN
10120 || appType > TelephonyManager.APPTYPE_ISIM
10121 || nafUrl == null || securityProtocol == null || callback == null) {
10122 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10123 if (callback != null) {
10124 try {
10125 callback.onAuthenticationFailure(
10126 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10127 } catch (RemoteException exception) {
10128 log("Fail to notify onAuthenticationFailure due to " + exception);
10129 }
10130 return;
10131 }
10132 }
10133
10134 final long token = Binder.clearCallingIdentity();
10135 try {
10136 getGbaManager(subId).bootstrapAuthenticationRequest(
10137 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10138 forceBootStrapping, callback));
10139 } finally {
10140 Binder.restoreCallingIdentity(token);
10141 }
10142 }
10143
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010144 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010145 * Attempts to set the radio power state for all phones for thermal reason.
10146 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010147 * requested radio power state will actually be set. See {@link
10148 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10149 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010150 * @param enable {@code true} if trying to turn radio on.
10151 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10152 * false}.
10153 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010154 private boolean setRadioPowerForThermal(boolean enable) {
10155 boolean isPhoneAvailable = false;
10156 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10157 Phone phone = PhoneFactory.getPhone(i);
10158 if (phone != null) {
10159 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10160 isPhoneAvailable = true;
10161 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010162 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010163
10164 // return true if successfully informed the phone object about the thermal radio power
10165 // request.
10166 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010167 }
10168
10169 private int handleDataThrottlingRequest(int subId,
10170 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010171 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10172 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10173 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10174 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10175 throw new IllegalArgumentException("modem does not support data throttling");
10176 }
10177
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010178 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10179 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010180 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010181 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10182 }
10183
10184 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
10185
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010186 if (isDataThrottlingSupported) {
10187 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010188 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010189 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10190 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10191 } else if (thermalMitigationResult
10192 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010193 log("Modem likely does not support data throttling on secondary carrier. Data " +
10194 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10195 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010196 }
10197 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010198 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010199
10200 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010201 }
10202
Jack Nudelman644b91a2021-03-12 14:09:48 -080010203 private static List<String> getThermalMitigationAllowlist(Context context) {
10204 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10205 for (String pckg : context.getResources()
10206 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10207 sThermalMitigationAllowlistedPackages.add(pckg);
10208 }
10209 }
10210
10211 return sThermalMitigationAllowlistedPackages;
10212 }
10213
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010214 private boolean isAnyPhoneInEmergencyState() {
10215 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10216 if (tm.isInEmergencyCall()) {
10217 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10218 return true;
10219 }
10220 for (Phone phone : PhoneFactory.getPhones()) {
10221 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10222 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10223 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10224 + phone.isInEcm());
10225 return true;
10226 }
10227 }
10228
10229 return false;
10230 }
10231
Jack Nudelman644b91a2021-03-12 14:09:48 -080010232 /**
10233 * Used by shell commands to add an authorized package name for thermal mitigation.
10234 * @param packageName name of package to be allowlisted
10235 * @param context
10236 */
10237 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10238 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10239 sThermalMitigationAllowlistedPackages.add(packageName);
10240 }
10241
10242 /**
10243 * Used by shell commands to remove an authorized package name for thermal mitigation.
10244 * @param packageName name of package to remove from allowlist
10245 * @param context
10246 */
10247 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10248 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10249 sThermalMitigationAllowlistedPackages.remove(packageName);
10250 }
10251
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010252 /**
10253 * Thermal mitigation request to control functionalities at modem.
10254 *
10255 * @param subId the id of the subscription.
10256 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010257 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010258 *
10259 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10260 */
10261 @Override
10262 @ThermalMitigationResult
10263 public int sendThermalMitigationRequest(
10264 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010265 ThermalMitigationRequest thermalMitigationRequest,
10266 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010267 enforceModifyPermission();
10268
Jack Nudelman644b91a2021-03-12 14:09:48 -080010269 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10270 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10271 .contains(callingPackage)) {
10272 throw new SecurityException("Calling package must be configured in the device config. "
10273 + "calling package: " + callingPackage);
10274 }
10275
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010276 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10277 final long identity = Binder.clearCallingIdentity();
10278
10279 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10280 try {
10281 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10282 switch (thermalMitigationAction) {
10283 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10284 thermalMitigationResult =
10285 handleDataThrottlingRequest(subId,
10286 thermalMitigationRequest.getDataThrottlingRequest());
10287 break;
10288 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10289 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10290 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10291 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10292 }
10293
10294 // Ensure that radio is on. If not able to power on due to phone being
10295 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010296 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010297 thermalMitigationResult =
10298 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10299 break;
10300 }
10301
10302 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10303 false);
10304 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10305 break;
10306 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10307 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10308 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10309 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10310 }
10311
10312 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10313 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010314 Phone phone = getPhone(subId);
10315 if (phone == null) {
10316 thermalMitigationResult =
10317 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10318 break;
10319 }
10320
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010321 TelephonyConnectionService service =
10322 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010323 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010324 Log.e(LOG_TAG, "An emergency call is pending");
10325 thermalMitigationResult =
10326 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10327 break;
10328 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010329 thermalMitigationResult =
10330 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10331 break;
10332 }
10333 } else {
10334 thermalMitigationResult =
10335 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10336 break;
10337 }
10338
10339 // Turn radio off. If not able to power off due to phone being unavailable,
10340 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010341 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010342 thermalMitigationResult =
10343 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10344 break;
10345 }
10346 thermalMitigationResult =
10347 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10348 break;
10349 default:
10350 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10351 + "not exist. Requested action: " + thermalMitigationAction);
10352 }
10353 } catch (IllegalArgumentException e) {
10354 throw e;
10355 } catch (Exception e) {
10356 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10357 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10358 } finally {
10359 Binder.restoreCallingIdentity(identity);
10360 }
10361
10362 if (DBG) {
10363 log("thermalMitigationRequest returning with thermalMitigationResult: "
10364 + thermalMitigationResult);
10365 }
10366
10367 return thermalMitigationResult;
10368 }
Hui Wang641e81c2020-10-12 12:14:23 -070010369
10370 /**
10371 * Set the GbaService Package Name that Telephony will bind to.
10372 *
10373 * @param subId The sim that the GbaService is associated with.
10374 * @param packageName The name of the package to be replaced with.
10375 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10376 */
10377 @Override
10378 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10379 enforceModifyPermission();
10380
10381 final long identity = Binder.clearCallingIdentity();
10382 try {
10383 return getGbaManager(subId).overrideServicePackage(packageName);
10384 } finally {
10385 Binder.restoreCallingIdentity(identity);
10386 }
10387 }
10388
10389 /**
10390 * Return the package name of the currently bound GbaService.
10391 *
10392 * @param subId The sim that the GbaService is associated with.
10393 * @return the package name of the GbaService configuration, null if GBA is not supported.
10394 */
10395 @Override
10396 public String getBoundGbaService(int subId) {
10397 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10398
10399 final long identity = Binder.clearCallingIdentity();
10400 try {
10401 return getGbaManager(subId).getServicePackage();
10402 } finally {
10403 Binder.restoreCallingIdentity(identity);
10404 }
10405 }
10406
10407 /**
10408 * Set the release time for telephony to unbind GbaService.
10409 *
10410 * @param subId The sim that the GbaService is associated with.
10411 * @param interval The release time to unbind GbaService by millisecond.
10412 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10413 */
10414 @Override
10415 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10416 enforceModifyPermission();
10417
10418 final long identity = Binder.clearCallingIdentity();
10419 try {
10420 return getGbaManager(subId).overrideReleaseTime(interval);
10421 } finally {
10422 Binder.restoreCallingIdentity(identity);
10423 }
10424 }
10425
10426 /**
10427 * Return the release time for telephony to unbind GbaService.
10428 *
10429 * @param subId The sim that the GbaService is associated with.
10430 * @return The release time to unbind GbaService by millisecond.
10431 */
10432 @Override
10433 public int getGbaReleaseTime(int subId) {
10434 enforceReadPrivilegedPermission("getGbaReleaseTime");
10435
10436 final long identity = Binder.clearCallingIdentity();
10437 try {
10438 return getGbaManager(subId).getReleaseTime();
10439 } finally {
10440 Binder.restoreCallingIdentity(identity);
10441 }
10442 }
10443
10444 private GbaManager getGbaManager(int subId) {
10445 GbaManager instance = GbaManager.getInstance(subId);
10446 if (instance == null) {
10447 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10448 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10449 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10450 }
10451 return instance;
10452 }
Hui Wang761a6682020-10-31 05:12:53 +000010453
10454 /**
10455 * indicate whether the device and the carrier can support
10456 * RCS VoLTE single registration.
10457 */
10458 @Override
10459 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010460 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10461 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10462 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10463 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010464
10465 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10466 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10467 }
10468
10469 final long identity = Binder.clearCallingIdentity();
10470 try {
10471 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10472 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010473 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10474 if (isCapable != null) {
10475 return isCapable;
10476 }
Hui Wang761a6682020-10-31 05:12:53 +000010477 }
Hui Wang67af90e2021-06-04 16:57:15 -070010478 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10479 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
10484
10485 /**
10486 * Register RCS provisioning callback.
10487 */
10488 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010489 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010490 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010491 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010492 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010493 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10494 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010495
10496 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10497 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10498 }
10499 if (!isImsAvailableOnDevice()) {
10500 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10501 "IMS not available on device.");
10502 }
10503
10504 final long identity = Binder.clearCallingIdentity();
10505 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010506 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010507 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010508 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10509 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010510 }
Hui Wang761a6682020-10-31 05:12:53 +000010511 } finally {
10512 Binder.restoreCallingIdentity(identity);
10513 }
10514 }
10515
10516 /**
10517 * Unregister RCS provisioning callback.
10518 */
10519 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010520 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010521 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010522 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010523 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010524 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10525 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010526
10527 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10528 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10529 }
10530 if (!isImsAvailableOnDevice()) {
10531 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10532 "IMS not available on device.");
10533 }
10534
10535 final long identity = Binder.clearCallingIdentity();
10536 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010537 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010538 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010539 } finally {
10540 Binder.restoreCallingIdentity(identity);
10541 }
10542 }
10543
10544 /**
10545 * trigger RCS reconfiguration.
10546 */
10547 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010548 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10549 "triggerRcsReconfiguration",
10550 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010551
10552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10553 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10554 }
10555 if (!isImsAvailableOnDevice()) {
10556 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10557 "IMS not available on device.");
10558 }
10559
10560 final long identity = Binder.clearCallingIdentity();
10561 try {
10562 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10563 } finally {
10564 Binder.restoreCallingIdentity(identity);
10565 }
10566 }
10567
10568 /**
10569 * Provide the client configuration parameters of the RCS application.
10570 */
10571 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010572 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10573 "setRcsClientConfiguration",
10574 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010575
10576 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10577 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10578 }
10579 if (!isImsAvailableOnDevice()) {
10580 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10581 "IMS not available on device.");
10582 }
10583
10584 final long identity = Binder.clearCallingIdentity();
10585
10586 try {
10587 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10588 if (configBinder == null) {
10589 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010590 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10591 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010592 } else {
10593 configBinder.setRcsClientConfiguration(rcc);
10594 }
10595 } catch (RemoteException e) {
10596 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010597 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10598 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010599 } finally {
10600 Binder.restoreCallingIdentity(identity);
10601 }
10602 }
10603
10604 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010605 * Enables or disables the test mode for RCS VoLTE single registration.
10606 */
10607 @Override
10608 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10609 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10610 "setRcsSingleRegistrationTestModeEnabled");
10611
10612 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10613 }
10614
10615 /**
10616 * Gets the test mode for RCS VoLTE single registration.
10617 */
10618 @Override
10619 public boolean getRcsSingleRegistrationTestModeEnabled() {
10620 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10621 "getRcsSingleRegistrationTestModeEnabled");
10622
10623 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10624 }
10625
10626 /**
Hui Wang761a6682020-10-31 05:12:53 +000010627 * Overrides the config of RCS VoLTE single registration enabled for the device.
10628 */
10629 @Override
10630 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10631 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10632 "setDeviceSingleRegistrationEnabledOverride");
10633 enforceModifyPermission();
10634
10635 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10636 : Boolean.parseBoolean(enabledStr);
10637 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010638 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010639 }
10640
10641 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010642 * Sends a device to device communication message. Only usable via shell.
10643 * @param message message to send.
10644 * @param value message value.
10645 */
10646 @Override
10647 public void sendDeviceToDeviceMessage(int message, int value) {
10648 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010649 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010650 enforceModifyPermission();
10651
10652 final long identity = Binder.clearCallingIdentity();
10653 try {
10654 TelephonyConnectionService service =
10655 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10656 if (service == null) {
10657 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10658 return;
10659 }
10660 service.sendTestDeviceToDeviceMessage(message, value);
10661 } finally {
10662 Binder.restoreCallingIdentity(identity);
10663 }
10664 }
10665
Tyler Gunnbabbda02021-02-10 11:05:02 -080010666 /**
10667 * Sets the specified device to device transport active.
10668 * @param transport The transport to set active.
10669 */
10670 @Override
10671 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10672 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10673 "setActiveDeviceToDeviceTransport");
10674 enforceModifyPermission();
10675
10676 final long identity = Binder.clearCallingIdentity();
10677 try {
10678 TelephonyConnectionService service =
10679 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10680 if (service == null) {
10681 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10682 return;
10683 }
10684 service.setActiveDeviceToDeviceTransport(transport);
10685 } finally {
10686 Binder.restoreCallingIdentity(identity);
10687 }
10688 }
Tyler Gunn92479152021-01-20 16:30:10 -080010689
Tyler Gunnd4575212021-05-03 14:46:49 -070010690 @Override
10691 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10692 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10693 "setDeviceToDeviceForceEnabled");
10694
10695 final long identity = Binder.clearCallingIdentity();
10696 try {
10697 Arrays.stream(PhoneFactory.getPhones()).forEach(
10698 p -> {
10699 Phone thePhone = p.getImsPhone();
10700 if (thePhone != null && thePhone instanceof ImsPhone) {
10701 ImsPhone imsPhone = (ImsPhone) thePhone;
10702 CallTracker tracker = imsPhone.getCallTracker();
10703 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10704 ImsPhoneCallTracker imsPhoneCallTracker =
10705 (ImsPhoneCallTracker) tracker;
10706 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10707 }
10708 }
10709 }
10710 );
10711 } finally {
10712 Binder.restoreCallingIdentity(identity);
10713 }
10714 }
10715
Tyler Gunn92479152021-01-20 16:30:10 -080010716 /**
Hui Wang761a6682020-10-31 05:12:53 +000010717 * Gets the config of RCS VoLTE single registration enabled for the device.
10718 */
10719 @Override
10720 public boolean getDeviceSingleRegistrationEnabled() {
10721 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10722 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10723 }
10724
10725 /**
10726 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10727 */
10728 @Override
10729 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10730 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10731 "setCarrierSingleRegistrationEnabledOverride");
10732 enforceModifyPermission();
10733
10734 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10735 : Boolean.parseBoolean(enabledStr);
10736 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10737 subId, enabled);
10738 }
10739
10740 /**
10741 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10742 */
10743 @Override
10744 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10745 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10746 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10747 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010748
10749 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010750 * Overrides the ims feature validation result
10751 */
10752 @Override
10753 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10754 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10755 "setImsFeatureValidationOverride");
10756
10757 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10758 : Boolean.parseBoolean(enabledStr);
10759 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10760 subId, enabled);
10761 }
10762
10763 /**
10764 * Gets the ims feature validation override value
10765 */
10766 @Override
10767 public boolean getImsFeatureValidationOverride(int subId) {
10768 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10769 "getImsFeatureValidationOverride");
10770 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10771 }
10772
10773 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010774 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10775 * their mobile plan.
10776 */
10777 @Override
10778 public String getMobileProvisioningUrl() {
10779 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10780 final long identity = Binder.clearCallingIdentity();
10781 try {
10782 return getDefaultPhone().getMobileProvisioningUrl();
10783 } finally {
10784 Binder.restoreCallingIdentity(identity);
10785 }
10786 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010787
James.cf Linbcdf8b32021-01-14 16:44:13 +080010788 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010789 * Get the EAB contact from the EAB database.
10790 */
10791 @Override
10792 public String getContactFromEab(String contact) {
10793 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10794 enforceModifyPermission();
10795 final long identity = Binder.clearCallingIdentity();
10796 try {
10797 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10798 } finally {
10799 Binder.restoreCallingIdentity(identity);
10800 }
10801 }
10802
10803 /**
Calvin Pana1434322021-07-01 19:27:01 +080010804 * Get the EAB capability from the EAB database.
10805 */
10806 @Override
10807 public String getCapabilityFromEab(String contact) {
10808 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10809 enforceModifyPermission();
10810 final long identity = Binder.clearCallingIdentity();
10811 try {
10812 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10813 } finally {
10814 Binder.restoreCallingIdentity(identity);
10815 }
10816 }
10817
10818 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010819 * Remove the EAB contacts from the EAB database.
10820 */
10821 @Override
10822 public int removeContactFromEab(int subId, String contacts) {
10823 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10824 enforceModifyPermission();
10825 final long identity = Binder.clearCallingIdentity();
10826 try {
10827 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
10832
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010833 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010834 public boolean getDeviceUceEnabled() {
10835 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10836 final long identity = Binder.clearCallingIdentity();
10837 try {
10838 return mApp.getDeviceUceEnabled();
10839 } finally {
10840 Binder.restoreCallingIdentity(identity);
10841 }
10842 }
10843
10844 @Override
10845 public void setDeviceUceEnabled(boolean isEnabled) {
10846 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10847 final long identity = Binder.clearCallingIdentity();
10848 try {
10849 mApp.setDeviceUceEnabled(isEnabled);
10850 } finally {
10851 Binder.restoreCallingIdentity(identity);
10852 }
10853 }
10854
Brad Ebinger14d467f2021-02-12 06:18:28 +000010855 /**
10856 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10857 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10858 */
10859 // Used for SHELL command only right now.
10860 @Override
10861 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10862 List<String> featureTags) {
10863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10864 "addUceRegistrationOverrideShell");
10865 final long identity = Binder.clearCallingIdentity();
10866 try {
10867 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10868 new ArraySet<>(featureTags));
10869 } catch (ImsException e) {
10870 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10871 } finally {
10872 Binder.restoreCallingIdentity(identity);
10873 }
10874 }
10875
10876 /**
10877 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10878 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10879 */
10880 // Used for SHELL command only right now.
10881 @Override
10882 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10883 List<String> featureTags) {
10884 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10885 "removeUceRegistrationOverrideShell");
10886 final long identity = Binder.clearCallingIdentity();
10887 try {
10888 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10889 new ArraySet<>(featureTags));
10890 } catch (ImsException e) {
10891 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10892 } finally {
10893 Binder.restoreCallingIdentity(identity);
10894 }
10895 }
10896
10897 /**
10898 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10899 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10900 */
10901 // Used for SHELL command only right now.
10902 @Override
10903 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10905 "clearUceRegistrationOverrideShell");
10906 final long identity = Binder.clearCallingIdentity();
10907 try {
10908 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10909 } catch (ImsException e) {
10910 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10911 } finally {
10912 Binder.restoreCallingIdentity(identity);
10913 }
10914 }
10915
10916 /**
10917 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10918 */
10919 // Used for SHELL command only right now.
10920 @Override
10921 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10922 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10923 "getLatestRcsContactUceCapabilityShell");
10924 final long identity = Binder.clearCallingIdentity();
10925 try {
10926 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10927 } catch (ImsException e) {
10928 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10929 } finally {
10930 Binder.restoreCallingIdentity(identity);
10931 }
10932 }
10933
10934 /**
10935 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10936 * device does not have an active PUBLISH.
10937 */
10938 // Used for SHELL command only right now.
10939 @Override
10940 public String getLastUcePidfXmlShell(int subId) {
10941 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10942 final long identity = Binder.clearCallingIdentity();
10943 try {
10944 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10945 } catch (ImsException e) {
10946 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10947 } finally {
10948 Binder.restoreCallingIdentity(identity);
10949 }
10950 }
10951
James.cf Line8713a42021-04-29 16:04:26 +080010952 /**
10953 * Remove UCE requests cannot be sent to the network status.
10954 */
10955 // Used for SHELL command only right now.
10956 @Override
10957 public boolean removeUceRequestDisallowedStatus(int subId) {
10958 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10959 final long identity = Binder.clearCallingIdentity();
10960 try {
10961 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10962 } catch (ImsException e) {
10963 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10964 } finally {
10965 Binder.restoreCallingIdentity(identity);
10966 }
10967 }
10968
James.cf Lin0fc71b02021-05-25 01:37:38 +080010969 /**
10970 * Remove UCE requests cannot be sent to the network status.
10971 */
10972 // Used for SHELL command only.
10973 @Override
10974 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10975 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10976 final long identity = Binder.clearCallingIdentity();
10977 try {
10978 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10979 } catch (ImsException e) {
10980 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10981 } finally {
10982 Binder.restoreCallingIdentity(identity);
10983 }
10984 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010985
James.cf Lin4b784aa2021-01-31 03:25:15 +080010986 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010987 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10988 String callingPackage) {
10989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10990 mApp, subId, "setSignalStrengthUpdateRequest");
10991
10992 final int callingUid = Binder.getCallingUid();
10993 // Verify that tha callingPackage belongs to the calling UID
10994 mApp.getSystemService(AppOpsManager.class)
10995 .checkPackage(callingUid, callingPackage);
10996
Rambo Wang3607f502021-02-01 21:51:40 -080010997 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010998
10999 final long identity = Binder.clearCallingIdentity();
11000 try {
11001 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11002 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11003
11004 if (result instanceof IllegalStateException) {
11005 throw (IllegalStateException) result;
11006 }
11007 } finally {
11008 Binder.restoreCallingIdentity(identity);
11009 }
11010 }
11011
11012 @Override
11013 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11014 String callingPackage) {
11015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11016 mApp, subId, "clearSignalStrengthUpdateRequest");
11017
11018 final int callingUid = Binder.getCallingUid();
11019 // Verify that tha callingPackage belongs to the calling UID
11020 mApp.getSystemService(AppOpsManager.class)
11021 .checkPackage(callingUid, callingPackage);
11022
11023 final long identity = Binder.clearCallingIdentity();
11024 try {
11025 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11026 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11027
11028 if (result instanceof IllegalStateException) {
11029 throw (IllegalStateException) result;
11030 }
11031 } finally {
11032 Binder.restoreCallingIdentity(identity);
11033 }
11034 }
11035
Rambo Wang3607f502021-02-01 21:51:40 -080011036 private static void validateSignalStrengthUpdateRequest(Context context,
11037 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011038 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11039 // phone/system process do not have further restriction on request
11040 return;
11041 }
11042
11043 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011044 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011045 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011046 context.enforceCallingOrSelfPermission(
11047 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11048 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011049 }
11050
11051 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11052 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11053 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11054 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11055 || info.isEnabled()) {
11056 throw new IllegalArgumentException(
11057 "Only system can set hide fields in SignalThresholdInfo");
11058 }
11059
11060 // Thresholds length for each RAN need in range. This has been validated in
11061 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11062 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11063 final int[] thresholds = info.getThresholds();
11064 Objects.requireNonNull(thresholds);
11065 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11066 || thresholds.length
11067 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11068 throw new IllegalArgumentException(
11069 "thresholds length is out of range: " + thresholds.length);
11070 }
11071 }
11072 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011073
11074 /**
11075 * Gets the current phone capability.
11076 *
11077 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11078 * @return the PhoneCapability which describes the data connection capability of modem.
11079 * It's used to evaluate possible phone config change, for example from single
11080 * SIM device to multi-SIM device.
11081 */
11082 @Override
11083 public PhoneCapability getPhoneCapability() {
11084 enforceReadPrivilegedPermission("getPhoneCapability");
11085 final long identity = Binder.clearCallingIdentity();
11086 try {
11087 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11088 } finally {
11089 Binder.restoreCallingIdentity(identity);
11090 }
11091 }
Michele Berionne5e411512020-11-13 02:36:59 +000011092
11093 /**
11094 * Prepare TelephonyManager for an unattended reboot. The reboot is
11095 * required to be done shortly after the API is invoked.
11096 */
11097 @Override
11098 @TelephonyManager.PrepareUnattendedRebootResult
11099 public int prepareForUnattendedReboot() {
11100 enforceRebootPermission();
11101
11102 final long identity = Binder.clearCallingIdentity();
11103 try {
11104 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
11105 } finally {
11106 Binder.restoreCallingIdentity(identity);
11107 }
11108 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011109
11110 /**
11111 * Request to get the current slicing configuration including URSP rules and
11112 * NSSAIs (configured, allowed and rejected).
11113 *
11114 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11115 */
11116 @Override
11117 public void getSlicingConfig(ResultReceiver callback) {
11118 enforceReadPrivilegedPermission("getSlicingConfig");
11119
11120 final long identity = Binder.clearCallingIdentity();
11121 try {
11122 Phone phone = getDefaultPhone();
11123 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000011128
11129 /**
11130 * Register an IMS connection state callback
11131 */
11132 @Override
11133 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11134 String callingPackage) {
11135 if (feature == ImsFeature.FEATURE_MMTEL) {
11136 // ImsMmTelManager
11137 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11138 TelephonyPermissions
11139 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11140 mApp, subId, "registerImsStateCallback");
11141 } else if (feature == ImsFeature.FEATURE_RCS) {
11142 // ImsRcsManager or SipDelegateManager
11143 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11144 Binder.getCallingUid(), "registerImsStateCallback",
11145 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11146 Manifest.permission.READ_PRECISE_PHONE_STATE,
11147 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11148 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11149 }
11150
11151 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11152 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11153 "IMS not available on device.");
11154 }
11155
11156 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11157 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11158 }
11159
11160 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11161 if (controller == null) {
11162 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11163 "IMS not available on device.");
11164 }
11165
11166 if (callingPackage == null) {
11167 callingPackage = getCurrentPackageName();
11168 }
11169
11170 final long token = Binder.clearCallingIdentity();
11171 try {
11172 int slotId = getSlotIndexOrException(subId);
11173 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
11174 } catch (ImsException e) {
11175 throw new ServiceSpecificException(e.getCode());
11176 } finally {
11177 Binder.restoreCallingIdentity(token);
11178 }
11179 }
11180
11181 /**
11182 * Unregister an IMS connection state callback
11183 */
11184 @Override
11185 public void unregisterImsStateCallback(IImsStateCallback cb) {
11186 final long token = Binder.clearCallingIdentity();
11187 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11188 if (controller == null) {
11189 return;
11190 }
11191 try {
11192 controller.unregisterImsStateCallback(cb);
11193 } finally {
11194 Binder.restoreCallingIdentity(token);
11195 }
11196 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011197
11198 /**
11199 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11200 *
11201 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11202 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11203 * SecurityException.
11204 * If there is current registered network this value will be same as the registered cell
11205 * identity. If the device goes out of service the previous cell identity is cached and
11206 * will be returned. If the cache age of the Cell identity is more than 24 hours
11207 * it will be cleared and null will be returned.
11208 *
11209 */
11210 @Override
11211 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11212 String callingFeatureId) {
11213 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11214 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11215 LocationAccessPolicy.checkLocationPermission(mApp,
11216 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11217 .setCallingPackage(callingPackage)
11218 .setCallingFeatureId(callingFeatureId)
11219 .setCallingPid(Binder.getCallingPid())
11220 .setCallingUid(Binder.getCallingUid())
11221 .setMethod("getLastKnownCellIdentity")
11222 .setLogAsInfo(true)
11223 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11224 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11225 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11226 .build());
11227
11228 boolean hasFinePermission =
11229 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11230 if (!hasFinePermission
11231 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11232 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
11233 + "and BIND_CONNECTION_SERVICE permission.");
11234 }
11235
11236 final long identity = Binder.clearCallingIdentity();
11237 try {
11238 Phone phone = getPhone(subId);
11239 if (phone == null) return null;
11240 ServiceStateTracker sst = phone.getServiceStateTracker();
11241 if (sst == null) return null;
11242 return sst.getLastKnownCellIdentity();
11243 } finally {
11244 Binder.restoreCallingIdentity(identity);
11245 }
11246 }
jimsun38340bf2021-10-26 15:01:23 +080011247
11248 /**
11249 * Sets the modem service class Name that Telephony will bind to.
11250 *
11251 * @param serviceName The class name of the modem service.
11252 * @return true if the operation is succeed, otherwise false.
11253 */
11254 public boolean setModemService(String serviceName) {
11255 Log.d(LOG_TAG, "setModemService - " + serviceName);
11256 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11258 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11259 "setModemService");
11260 return mPhoneConfigurationManager.setModemService(serviceName);
11261 }
11262
11263 /**
11264 * Return the class name of the currently bounded modem service.
11265 *
11266 * @return the class name of the modem service.
11267 */
11268 public String getModemService() {
11269 String result;
11270 Log.d(LOG_TAG, "getModemService");
11271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11272 TelephonyPermissions
11273 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11274 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11275 "getModemService");
11276 result = mPhoneConfigurationManager.getModemService();
11277 Log.d(LOG_TAG, "result = " + result);
11278 return result;
11279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011280}