blob: 218a79a9b3feb11ee60923d8c84ea10e8f2a73c8 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Hall Liu82694d52020-12-11 18:22:04 -080032import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070033import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070034import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.content.Context;
36import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070037import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070038import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080039import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070040import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.net.Uri;
42import android.os.AsyncResult;
43import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080044import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Bundle;
46import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.Looper;
49import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070050import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080051import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070052import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070053import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080054import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080055import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070056import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070057import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080058import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070060import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070061import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070062import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070063import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080064import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070065import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090066import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080067import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080068import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070069import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070070import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080071import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080072import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070073import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
111import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700112import android.telephony.gba.GbaAuthRequest;
113import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700114import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000116import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700117import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700118import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800119import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700120import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700122import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000123import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700124import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800126import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800128import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700131import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800133import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800134
Andrew Lee312e8172014-10-23 17:01:36 -0700135import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800136import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800137import com.android.ims.rcs.uce.eab.EabUtil;
Shuo Qian4a594052020-01-23 11:59:30 -0800138import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700140import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700141import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800142import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700143import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700144import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800145import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700147import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800148import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800149import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800150import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700151import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800153import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800155import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700156import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700157import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700158import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700160import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800161import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700162import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700163import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700164import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700165import com.android.internal.telephony.RIL;
Jack Yu5f7092c2018-04-13 14:05:37 -0700166import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700167import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700168import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800169import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800170import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700172import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800173import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700174import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800175import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700176import com.android.internal.telephony.imsphone.ImsPhone;
177import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800178import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700179import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700180import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800181import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800183import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700184import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800185import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700186import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800187import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000188import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800189import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700190import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700191import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800192import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800193import com.android.phone.callcomposer.CallComposerPictureManager;
194import com.android.phone.callcomposer.CallComposerPictureTransfer;
195import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700196import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700197import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800198import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700199import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700200import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800201import com.android.services.telephony.TelecomAccountRegistry;
202import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800203import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800204
Hall Liu82694d52020-12-11 18:22:04 -0800205import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700206import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800207import java.io.IOException;
208import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700209import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700210import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800211import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800212import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800213import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800214import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100215import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800216import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700217import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800218import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800219import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800220import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800221import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800222import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223
224/**
225 * Implementation of the ITelephony interface.
226 */
Santos Cordon117fee72014-05-16 17:56:12 -0700227public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228 private static final String LOG_TAG = "PhoneInterfaceManager";
229 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
230 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800231 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232
233 // Message codes used with mMainThreadHandler
234 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700235 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
236 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700237 private static final int CMD_OPEN_CHANNEL = 9;
238 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
239 private static final int CMD_CLOSE_CHANNEL = 11;
240 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800241 private static final int CMD_NV_READ_ITEM = 13;
242 private static final int EVENT_NV_READ_ITEM_DONE = 14;
243 private static final int CMD_NV_WRITE_ITEM = 15;
244 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
245 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
246 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700247 private static final int CMD_RESET_MODEM_CONFIG = 19;
248 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800249 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
250 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800251 private static final int CMD_SEND_ENVELOPE = 25;
252 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000253 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
254 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700255 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
256 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
257 private static final int CMD_EXCHANGE_SIM_IO = 31;
258 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800259 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
260 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700261 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
262 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700263 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
264 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700265 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
266 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
267 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
268 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700269 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
270 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
271 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
272 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700273 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800274 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
275 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000276 private static final int CMD_SWITCH_SLOTS = 50;
277 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700278 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
279 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
280 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
281 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
282 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
283 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
284 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
285 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700286 private static final int CMD_GET_ALL_CELL_INFO = 60;
287 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
288 private static final int CMD_GET_CELL_LOCATION = 62;
289 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700290 private static final int CMD_MODEM_REBOOT = 64;
291 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700292 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
293 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800294 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
295 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700296 private static final int CMD_GET_MODEM_STATUS = 70;
297 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700298 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
299 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700300 private static final int CMD_ERASE_MODEM_CONFIG = 74;
301 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800302 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
303 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
304 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
305 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800306 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
307 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800308 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800309 private static final int CMD_GET_CALL_FORWARDING = 83;
310 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
311 private static final int CMD_SET_CALL_FORWARDING = 85;
312 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
313 private static final int CMD_GET_CALL_WAITING = 87;
314 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
315 private static final int CMD_SET_CALL_WAITING = 89;
316 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700317 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
318 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
319 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
320 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700321 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
322 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800323 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
324 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800325 private static final int CMD_SET_DATA_THROTTLING = 99;
326 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800327 private static final int CMD_SET_SIM_POWER = 101;
328 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800329 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
330 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
331 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
332 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800333 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
334 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000335 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800337 // Parameters of select command.
338 private static final int SELECT_COMMAND = 0xA4;
339 private static final int SELECT_P1 = 0x04;
340 private static final int SELECT_P2 = 0;
341 private static final int SELECT_P3 = 0x10;
342
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 /** The singleton instance. */
344 private static PhoneInterfaceManager sInstance;
345
Wink Saville3ab207e2014-11-20 13:07:20 -0800346 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800347 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800348 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700349 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800350 private AppOpsManager mAppOps;
351 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800352 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800353 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700354 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355
Peter Wangdafb9ac2020-01-15 14:13:38 -0800356 /** User Activity */
357 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800358 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
359
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700360 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
361
Derek Tan97ebb422014-09-05 16:55:38 -0700362 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
363 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800364 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800365 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700366
Michelecea4cf22018-12-21 15:00:11 -0800367 // String to store multi SIM allowed
368 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
369
Derek Tan740e1672017-06-27 14:56:27 -0700370 // The AID of ISD-R.
371 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
372
yinxub1bed742017-04-17 11:45:04 -0700373 private NetworkScanRequestTracker mNetworkScanRequestTracker;
374
David Kelly5e06a7f2018-03-12 14:10:59 +0000375 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
376 private static final int MANUFACTURER_CODE_LENGTH = 8;
377
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800378 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
379
Derek Tan89e89d42014-07-08 17:00:10 -0700380 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700381 * Experiment flag to enable erase modem config on reset network, default value is false
382 */
383 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
384 "reset_network_erase_modem_config_enabled";
385
Rambo Wang0f050d82021-02-12 11:43:36 -0800386 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
387
Naina Nallurid63128d2019-09-17 14:10:30 -0700388 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700389 * A request object to use for transmitting data to an ICC.
390 */
391 private static final class IccAPDUArgument {
392 public int channel, cla, command, p1, p2, p3;
393 public String data;
394
395 public IccAPDUArgument(int channel, int cla, int command,
396 int p1, int p2, int p3, String data) {
397 this.channel = channel;
398 this.cla = cla;
399 this.command = command;
400 this.p1 = p1;
401 this.p2 = p2;
402 this.p3 = p3;
403 this.data = data;
404 }
405 }
406
407 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700408 * A request object to use for transmitting data to an ICC.
409 */
410 private static final class ManualNetworkSelectionArgument {
411 public OperatorInfo operatorInfo;
412 public boolean persistSelection;
413
414 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
415 this.operatorInfo = operatorInfo;
416 this.persistSelection = persistSelection;
417 }
418 }
419
420 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
422 * request after sending. The main thread will notify the request when it is complete.
423 */
424 private static final class MainThreadRequest {
425 /** The argument to use for the request */
426 public Object argument;
427 /** The result of the request that is run on the main thread */
428 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800429 // The subscriber id that this request applies to. Defaults to
430 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
431 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432
Nathan Harold92bed182018-10-12 18:16:49 -0700433 // In cases where subId is unavailable, the caller needs to specify the phone.
434 public Phone phone;
435
vagdeviaf9a5b92018-08-15 16:01:53 -0700436 public WorkSource workSource;
437
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 public MainThreadRequest(Object argument) {
439 this.argument = argument;
440 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800441
Nathan Harold92bed182018-10-12 18:16:49 -0700442 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
443 this.argument = argument;
444 if (phone != null) {
445 this.phone = phone;
446 }
447 this.workSource = workSource;
448 }
449
vagdeviaf9a5b92018-08-15 16:01:53 -0700450 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800451 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800452 if (subId != null) {
453 this.subId = subId;
454 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700455 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 }
458
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800459 private static final class IncomingThirdPartyCallArgs {
460 public final ComponentName component;
461 public final String callId;
462 public final String callerDisplayName;
463
464 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
465 String callerDisplayName) {
466 this.component = component;
467 this.callId = callId;
468 this.callerDisplayName = callerDisplayName;
469 }
470 }
471
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 /**
473 * A handler that processes messages on the main thread in the phone process. Since many
474 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
475 * inbound binder threads to the main thread in the phone process. The Binder thread
476 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
477 * on, which will be notified when the operation completes and will contain the result of the
478 * request.
479 *
480 * <p>If a MainThreadRequest object is provided in the msg.obj field,
481 * note that request.result must be set to something non-null for the calling thread to
482 * unblock.
483 */
484 private final class MainThreadHandler extends Handler {
485 @Override
486 public void handleMessage(Message msg) {
487 MainThreadRequest request;
488 Message onCompleted;
489 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800492 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700493
494 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 case CMD_HANDLE_USSD_REQUEST: {
496 request = (MainThreadRequest) msg.obj;
497 final Phone phone = getPhoneFromRequest(request);
498 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
499 String ussdRequest = ussdObject.first;
500 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700501
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 if (!isUssdApiAllowed(request.subId)) {
503 // Carrier does not support use of this API, return failure.
504 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
505 UssdResponse response = new UssdResponse(ussdRequest, null);
506 Bundle returnData = new Bundle();
507 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
508 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700509
Pengquan Menga1bb6272018-09-06 09:59:22 -0700510 request.result = true;
511 notifyRequester(request);
512 return;
513 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700514
Pengquan Menga1bb6272018-09-06 09:59:22 -0700515 try {
516 request.result = phone != null
517 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
518 } catch (CallStateException cse) {
519 request.result = false;
520 }
521 // Wake up the requesting thread
522 notifyRequester(request);
523 break;
pkanwar32d516d2016-10-14 19:37:38 -0700524 }
525
Yorke Lee716f67e2015-06-17 15:39:16 -0700526 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700528 final Phone phone = getPhoneFromRequest(request);
529 request.result = phone != null ?
530 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
531 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700538 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800540 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 if (uiccCard == null) {
542 loge("iccTransmitApduLogicalChannel: No UICC");
543 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
547 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700548 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 iccArgument.channel, iccArgument.cla, iccArgument.command,
550 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 break;
554
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 ar = (AsyncResult) msg.obj;
557 request = (MainThreadRequest) ar.userObj;
558 if (ar.exception == null && ar.result != null) {
559 request.result = ar.result;
560 } else {
561 request.result = new IccIoResult(0x6F, 0, (byte[])null);
562 if (ar.result == null) {
563 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800564 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800566 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 } else {
568 loge("iccTransmitApduLogicalChannel: Unknown exception");
569 }
570 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700571 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 break;
573
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
575 request = (MainThreadRequest) msg.obj;
576 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800577 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700578 if (uiccCard == null) {
579 loge("iccTransmitApduBasicChannel: No UICC");
580 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 } else {
583 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
584 request);
585 uiccCard.iccTransmitApduBasicChannel(
586 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
587 iccArgument.p3, iccArgument.data, onCompleted);
588 }
589 break;
590
591 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
592 ar = (AsyncResult) msg.obj;
593 request = (MainThreadRequest) ar.userObj;
594 if (ar.exception == null && ar.result != null) {
595 request.result = ar.result;
596 } else {
597 request.result = new IccIoResult(0x6F, 0, (byte[])null);
598 if (ar.result == null) {
599 loge("iccTransmitApduBasicChannel: Empty response");
600 } else if (ar.exception instanceof CommandException) {
601 loge("iccTransmitApduBasicChannel: CommandException: " +
602 ar.exception);
603 } else {
604 loge("iccTransmitApduBasicChannel: Unknown exception");
605 }
606 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700607 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 break;
609
610 case CMD_EXCHANGE_SIM_IO:
611 request = (MainThreadRequest) msg.obj;
612 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800613 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 if (uiccCard == null) {
615 loge("iccExchangeSimIO: No UICC");
616 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 } else {
619 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
620 request);
621 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
622 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
623 iccArgument.data, onCompleted);
624 }
625 break;
626
627 case EVENT_EXCHANGE_SIM_IO_DONE:
628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
630 if (ar.exception == null && ar.result != null) {
631 request.result = ar.result;
632 } else {
633 request.result = new IccIoResult(0x6f, 0, (byte[])null);
634 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 break;
637
Derek Tan4d5e5c12014-02-04 11:54:58 -0800638 case CMD_SEND_ENVELOPE:
639 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800640 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700641 if (uiccCard == null) {
642 loge("sendEnvelopeWithStatus: No UICC");
643 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700645 } else {
646 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
647 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
648 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800649 break;
650
651 case EVENT_SEND_ENVELOPE_DONE:
652 ar = (AsyncResult) msg.obj;
653 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700654 if (ar.exception == null && ar.result != null) {
655 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800656 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700657 request.result = new IccIoResult(0x6F, 0, (byte[])null);
658 if (ar.result == null) {
659 loge("sendEnvelopeWithStatus: Empty response");
660 } else if (ar.exception instanceof CommandException) {
661 loge("sendEnvelopeWithStatus: CommandException: " +
662 ar.exception);
663 } else {
664 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
665 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800666 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800668 break;
669
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 case CMD_OPEN_CHANNEL:
671 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800672 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800673 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 if (uiccCard == null) {
675 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800676 request.result = new IccOpenLogicalChannelResponse(-1,
677 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 } else {
680 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800681 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
682 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 break;
685
686 case EVENT_OPEN_CHANNEL_DONE:
687 ar = (AsyncResult) msg.obj;
688 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700689 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 int[] result = (int[]) ar.result;
692 int channelId = result[0];
693 byte[] selectResponse = null;
694 if (result.length > 1) {
695 selectResponse = new byte[result.length - 1];
696 for (int i = 1; i < result.length; ++i) {
697 selectResponse[i - 1] = (byte) result[i];
698 }
699 }
700 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700701 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 if (ar.result == null) {
704 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 if (ar.exception != null) {
707 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
708 }
709
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700710 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700711 if (ar.exception instanceof CommandException) {
712 CommandException.Error error =
713 ((CommandException) (ar.exception)).getCommandError();
714 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700715 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700716 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700717 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 }
719 }
720 openChannelResp = new IccOpenLogicalChannelResponse(
721 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700723 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700724 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700725 break;
726
727 case CMD_CLOSE_CHANNEL:
728 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800729 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700730 if (uiccCard == null) {
731 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900732 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700734 } else {
735 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
736 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
737 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 break;
739
740 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800741 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
742 break;
743
744 case CMD_NV_READ_ITEM:
745 request = (MainThreadRequest) msg.obj;
746 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800747 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
748 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800749 break;
750
751 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700752 ar = (AsyncResult) msg.obj;
753 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800754 if (ar.exception == null && ar.result != null) {
755 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800757 request.result = "";
758 if (ar.result == null) {
759 loge("nvReadItem: Empty response");
760 } else if (ar.exception instanceof CommandException) {
761 loge("nvReadItem: CommandException: " +
762 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800764 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 }
766 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700767 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 break;
769
Jake Hambye994d462014-02-03 13:10:13 -0800770 case CMD_NV_WRITE_ITEM:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
773 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800774 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700775 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800776 break;
777
778 case EVENT_NV_WRITE_ITEM_DONE:
779 handleNullReturnEvent(msg, "nvWriteItem");
780 break;
781
782 case CMD_NV_WRITE_CDMA_PRL:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800785 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800786 break;
787
788 case EVENT_NV_WRITE_CDMA_PRL_DONE:
789 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
790 break;
791
chen xu6dac5ab2018-10-26 17:39:23 -0700792 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800793 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700794 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800795 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800796 break;
797
chen xu6dac5ab2018-10-26 17:39:23 -0700798 case EVENT_RESET_MODEM_CONFIG_DONE:
799 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800800 break;
801
Sooraj Sasindran37444802020-08-11 10:40:43 -0700802 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
803 request = (MainThreadRequest) msg.obj;
804 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
805 request);
806 Phone phone = getPhoneFromRequest(request);
807 if (phone != null) {
808 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
809 } else {
810 loge("isNRDualConnectivityEnabled: No phone object");
811 request.result = false;
812 notifyRequester(request);
813 }
814 break;
815 }
816
817 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
818 ar = (AsyncResult) msg.obj;
819 request = (MainThreadRequest) ar.userObj;
820 if (ar.exception == null && ar.result != null) {
821 request.result = ar.result;
822 } else {
823 // request.result must be set to something non-null
824 // for the calling thread to unblock
825 if (request.result != null) {
826 request.result = ar.result;
827 } else {
828 request.result = false;
829 }
830 if (ar.result == null) {
831 loge("isNRDualConnectivityEnabled: Empty response");
832 } else if (ar.exception instanceof CommandException) {
833 loge("isNRDualConnectivityEnabled: CommandException: "
834 + ar.exception);
835 } else {
836 loge("isNRDualConnectivityEnabled: Unknown exception");
837 }
838 }
839 notifyRequester(request);
840 break;
841
842 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
845 Phone phone = getPhoneFromRequest(request);
846 if (phone != null) {
847 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
848 request.workSource);
849 } else {
850 loge("enableNrDualConnectivity: No phone object");
851 request.result =
852 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
853 notifyRequester(request);
854 }
855 break;
856 }
857
858 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
859 ar = (AsyncResult) msg.obj;
860 request = (MainThreadRequest) ar.userObj;
861 if (ar.exception == null) {
862 request.result =
863 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
864 } else {
865 request.result =
866 TelephonyManager
867 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
868 if (ar.exception instanceof CommandException) {
869 CommandException.Error error =
870 ((CommandException) (ar.exception)).getCommandError();
871 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
872 request.result =
873 TelephonyManager
874 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
875 }
876 loge("enableNrDualConnectivity" + ": CommandException: "
877 + ar.exception);
878 } else {
879 loge("enableNrDualConnectivity" + ": Unknown exception");
880 }
881 }
882 notifyRequester(request);
883 break;
884 }
885
SongFerngWang3ef3e072020-12-21 16:41:52 +0800886 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800887 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800888 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
889 request);
890 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800891 break;
892
SongFerngWang3ef3e072020-12-21 16:41:52 +0800893 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result; // Integer
898 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530899 // request.result must be set to something non-null
900 // for the calling thread to unblock
901 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800903 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800905 loge("getAllowedNetworkTypesBitmask: CommandException: "
906 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800908 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800909 }
910 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700911 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800912 break;
913
SongFerngWang3ef3e072020-12-21 16:41:52 +0800914 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800915 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800916 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
917 request);
918 Pair<Integer, Long> reasonWithNetworkTypes =
919 (Pair<Integer, Long>) request.argument;
920 getPhoneFromRequest(request).setAllowedNetworkTypes(
921 reasonWithNetworkTypes.first,
922 reasonWithNetworkTypes.second,
923 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800924 break;
925
SongFerngWang3ef3e072020-12-21 16:41:52 +0800926 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
927 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800928 break;
929
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000930 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
931 request = (MainThreadRequest)msg.obj;
932 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800933 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000934 break;
935
936 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
937 ar = (AsyncResult)msg.obj;
938 request = (MainThreadRequest)ar.userObj;
939 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700940 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000941 break;
942
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800943 case CMD_SET_VOICEMAIL_NUMBER:
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
946 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800947 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
948 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800949 break;
950
951 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
952 handleNullReturnEvent(msg, "setVoicemailNumber");
953 break;
954
Stuart Scott54788802015-03-30 13:18:01 -0700955 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
958 request);
959 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
960 break;
961
962 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
963 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
964 break;
965
Shishir Agrawal302c8692015-06-19 13:49:39 -0700966 case CMD_PERFORM_NETWORK_SCAN:
967 request = (MainThreadRequest) msg.obj;
968 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
969 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
970 break;
971
Hall Liu27d24262020-09-18 19:04:59 -0700972 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800973 request = (MainThreadRequest) msg.obj;
974 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700975 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
976 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
977 request.argument;
978 int callForwardingReason = args.first;
979 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800980 break;
Hall Liu27d24262020-09-18 19:04:59 -0700981 }
982 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700985 TelephonyManager.CallForwardingInfoCallback callback =
986 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
987 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800988 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700989 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800990 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
991 for (CallForwardInfo callForwardInfo : callForwardInfos) {
992 // Service Class is a bit mask per 3gpp 27.007. Search for
993 // any service for voice call.
994 if ((callForwardInfo.serviceClass
995 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700996 callForwardingInfo = new CallForwardingInfo(true,
997 callForwardInfo.reason,
998 callForwardInfo.number,
999 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001000 break;
1001 }
1002 }
1003 // Didn't find a call forward info for voice call.
1004 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001005 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1006 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001007 }
Hall Liu27d24262020-09-18 19:04:59 -07001008 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001009 } else {
1010 if (ar.result == null) {
1011 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1012 }
1013 if (ar.exception != null) {
1014 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1015 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001016 int errorCode = TelephonyManager
1017 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001018 if (ar.exception instanceof CommandException) {
1019 CommandException.Error error =
1020 ((CommandException) (ar.exception)).getCommandError();
1021 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001022 errorCode = TelephonyManager
1023 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001024 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001025 errorCode = TelephonyManager
1026 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001027 }
1028 }
Hall Liu27d24262020-09-18 19:04:59 -07001029 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001030 }
Shuo Qian4a594052020-01-23 11:59:30 -08001031 break;
Hall Liu27d24262020-09-18 19:04:59 -07001032 }
Shuo Qian4a594052020-01-23 11:59:30 -08001033
Hall Liu27d24262020-09-18 19:04:59 -07001034 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001037 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001038 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001039 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1040 request.argument).first;
1041 request.phone.setCallForwardingOption(
1042 callForwardingInfoToSet.isEnabled()
1043 ? CommandsInterface.CF_ACTION_ENABLE
1044 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001045 callForwardingInfoToSet.getReason(),
1046 callForwardingInfoToSet.getNumber(),
1047 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1048 break;
Hall Liu27d24262020-09-18 19:04:59 -07001049 }
Shuo Qian4a594052020-01-23 11:59:30 -08001050
Hall Liu27d24262020-09-18 19:04:59 -07001051 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001052 ar = (AsyncResult) msg.obj;
1053 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001054 Consumer<Integer> callback =
1055 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1056 request.argument).second;
1057 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001058 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001059 int errorCode = TelephonyManager.CallForwardingInfoCallback
1060 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001061 if (ar.exception instanceof CommandException) {
1062 CommandException.Error error =
1063 ((CommandException) (ar.exception)).getCommandError();
1064 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001065 errorCode = TelephonyManager.CallForwardingInfoCallback
1066 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001067 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001068 errorCode = TelephonyManager.CallForwardingInfoCallback
1069 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001070 }
1071 }
1072 callback.accept(errorCode);
1073 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001074 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001075 }
Shuo Qian4a594052020-01-23 11:59:30 -08001076 break;
Hall Liu27d24262020-09-18 19:04:59 -07001077 }
Shuo Qian4a594052020-01-23 11:59:30 -08001078
Hall Liu27d24262020-09-18 19:04:59 -07001079 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001080 request = (MainThreadRequest) msg.obj;
1081 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1082 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1083 break;
Hall Liu27d24262020-09-18 19:04:59 -07001084 }
Shuo Qian4a594052020-01-23 11:59:30 -08001085
Hall Liu27d24262020-09-18 19:04:59 -07001086 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001087 ar = (AsyncResult) msg.obj;
1088 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001089 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001090 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1091 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001092 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 // Service Class is a bit mask per 3gpp 27.007.
1094 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001095 if (callForwardResults.length > 1
1096 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001097 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001098 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001099 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1100 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001101 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001102 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001103 }
1104 } else {
1105 if (ar.result == null) {
1106 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1107 }
1108 if (ar.exception != null) {
1109 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1110 }
1111 if (ar.exception instanceof CommandException) {
1112 CommandException.Error error =
1113 ((CommandException) (ar.exception)).getCommandError();
1114 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1115 callForwardingStatus =
1116 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1117 }
1118 }
1119 }
Hall Liu27d24262020-09-18 19:04:59 -07001120 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001121 break;
Hall Liu27d24262020-09-18 19:04:59 -07001122 }
Shuo Qian4a594052020-01-23 11:59:30 -08001123
Hall Liu27d24262020-09-18 19:04:59 -07001124 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001125 request = (MainThreadRequest) msg.obj;
1126 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001127 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1128 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001129 break;
Hall Liu27d24262020-09-18 19:04:59 -07001130 }
Shuo Qian4a594052020-01-23 11:59:30 -08001131
Hall Liu27d24262020-09-18 19:04:59 -07001132 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001133 ar = (AsyncResult) msg.obj;
1134 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001135 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1136 Consumer<Integer> callback =
1137 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1138 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001139 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001140 if (ar.exception instanceof CommandException) {
1141 CommandException.Error error =
1142 ((CommandException) (ar.exception)).getCommandError();
1143 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1144 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1145 } else {
1146 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1147 }
1148 } else {
1149 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1150 }
1151 } else {
1152 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1153 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
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
Shishir Agrawal302c8692015-06-19 13:49:39 -07001158 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1159 ar = (AsyncResult) msg.obj;
1160 request = (MainThreadRequest) ar.userObj;
1161 CellNetworkScanResult cellScanResult;
1162 if (ar.exception == null && ar.result != null) {
1163 cellScanResult = new CellNetworkScanResult(
1164 CellNetworkScanResult.STATUS_SUCCESS,
1165 (List<OperatorInfo>) ar.result);
1166 } else {
1167 if (ar.result == null) {
1168 loge("getCellNetworkScanResults: Empty response");
1169 }
1170 if (ar.exception != null) {
1171 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1172 }
1173 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1174 if (ar.exception instanceof CommandException) {
1175 CommandException.Error error =
1176 ((CommandException) (ar.exception)).getCommandError();
1177 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1178 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1179 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1180 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1181 }
1182 }
1183 cellScanResult = new CellNetworkScanResult(errorCode, null);
1184 }
1185 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001186 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001187 break;
1188
1189 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1190 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001191 ManualNetworkSelectionArgument selArg =
1192 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001193 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1194 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001195 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1196 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001197 break;
1198
1199 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001200 ar = (AsyncResult) msg.obj;
1201 request = (MainThreadRequest) ar.userObj;
1202 if (ar.exception == null) {
1203 request.result = true;
1204 } else {
1205 request.result = false;
1206 loge("setNetworkSelectionModeManual " + ar.exception);
1207 }
1208 notifyRequester(request);
1209 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001210 break;
1211
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001212 case CMD_GET_MODEM_ACTIVITY_INFO:
1213 request = (MainThreadRequest) msg.obj;
1214 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001215 if (defaultPhone != null) {
1216 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001217 } else {
1218 ResultReceiver result = (ResultReceiver) request.argument;
1219 Bundle bundle = new Bundle();
1220 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001221 new ModemActivityInfo(0, 0, 0,
1222 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001223 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001224 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001225 break;
1226
Hall Liud0f208c2020-10-14 16:54:44 -07001227 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001228 ar = (AsyncResult) msg.obj;
1229 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001230 ResultReceiver result = (ResultReceiver) request.argument;
1231
Hall Liud0f208c2020-10-14 16:54:44 -07001232 ModemActivityInfo ret = null;
1233 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001234 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001235 // Update the last modem activity info and the result of the request.
1236 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1237 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001238 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001239 int[] txTimeMs = info.getTransmitTimeMillis();
1240 int[] lastModemTxTimeMs = mLastModemActivityInfo
1241 .getTransmitTimeMillis();
1242 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1243 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1244 }
Hall Liu49656c02020-10-09 19:00:11 -07001245 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001246 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1247 + mLastModemActivityInfo.getSleepTimeMillis());
1248 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1249 + mLastModemActivityInfo.getIdleTimeMillis());
1250 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1251 mLastModemActivityInfo.setReceiveTimeMillis(
1252 info.getReceiveTimeMillis()
1253 + mLastModemActivityInfo.getReceiveTimeMillis());
1254 }
Hall Liu49656c02020-10-09 19:00:11 -07001255 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001256 mLastModemActivityInfo.getSleepTimeMillis(),
1257 mLastModemActivityInfo.getIdleTimeMillis(),
1258 mLastModemActivityInfo.getTransmitTimeMillis(),
1259 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001260 } else {
1261 if (ar.result == null) {
1262 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001263 error = TelephonyManager.ModemActivityInfoException
1264 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001265 } else if (ar.exception instanceof CommandException) {
1266 loge("queryModemActivityInfo: CommandException: " +
1267 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001268 error = TelephonyManager.ModemActivityInfoException
1269 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001270 } else {
1271 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001272 error = TelephonyManager.ModemActivityInfoException
1273 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001274 }
1275 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001276 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001277 if (ret != null) {
1278 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1279 } else {
1280 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1281 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001282 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001283 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001284 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001285 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001286
Meng Wang1a7c35a2016-05-05 20:56:15 -07001287 case CMD_SET_ALLOWED_CARRIERS:
1288 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001289 CarrierRestrictionRules argument =
1290 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001291 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001292 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001293 break;
1294
1295 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1296 ar = (AsyncResult) msg.obj;
1297 request = (MainThreadRequest) ar.userObj;
1298 if (ar.exception == null && ar.result != null) {
1299 request.result = ar.result;
1300 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001301 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1302 if (ar.exception instanceof CommandException) {
1303 loge("setAllowedCarriers: CommandException: " + ar.exception);
1304 CommandException.Error error =
1305 ((CommandException) (ar.exception)).getCommandError();
1306 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1307 request.result =
1308 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1309 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001310 } else {
1311 loge("setAllowedCarriers: Unknown exception");
1312 }
1313 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001314 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001315 break;
1316
1317 case CMD_GET_ALLOWED_CARRIERS:
1318 request = (MainThreadRequest) msg.obj;
1319 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001320 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001321 break;
1322
1323 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1324 ar = (AsyncResult) msg.obj;
1325 request = (MainThreadRequest) ar.userObj;
1326 if (ar.exception == null && ar.result != null) {
1327 request.result = ar.result;
1328 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001329 request.result = new IllegalStateException(
1330 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001331 if (ar.result == null) {
1332 loge("getAllowedCarriers: Empty response");
1333 } else if (ar.exception instanceof CommandException) {
1334 loge("getAllowedCarriers: CommandException: " +
1335 ar.exception);
1336 } else {
1337 loge("getAllowedCarriers: Unknown exception");
1338 }
1339 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001340 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001341 break;
1342
Nathan Haroldb3014052017-01-25 15:57:32 -08001343 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1344 ar = (AsyncResult) msg.obj;
1345 request = (MainThreadRequest) ar.userObj;
1346 if (ar.exception == null && ar.result != null) {
1347 request.result = ar.result;
1348 } else {
1349 request.result = new IllegalArgumentException(
1350 "Failed to retrieve Forbidden Plmns");
1351 if (ar.result == null) {
1352 loge("getForbiddenPlmns: Empty response");
1353 } else {
1354 loge("getForbiddenPlmns: Unknown exception");
1355 }
1356 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001357 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001358 break;
1359
1360 case CMD_GET_FORBIDDEN_PLMNS:
1361 request = (MainThreadRequest) msg.obj;
1362 uiccCard = getUiccCardFromRequest(request);
1363 if (uiccCard == null) {
1364 loge("getForbiddenPlmns() UiccCard is null");
1365 request.result = new IllegalArgumentException(
1366 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001367 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001368 break;
1369 }
1370 Integer appType = (Integer) request.argument;
1371 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1372 if (uiccApp == null) {
1373 loge("getForbiddenPlmns() no app with specified type -- "
1374 + appType);
1375 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001376 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001377 break;
1378 } else {
1379 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1380 + " specified type -- " + appType);
1381 }
1382 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1383 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1384 onCompleted);
1385 break;
1386
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001387 case CMD_SWITCH_SLOTS:
1388 request = (MainThreadRequest) msg.obj;
1389 int[] physicalSlots = (int[]) request.argument;
1390 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1391 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1392 break;
1393
1394 case EVENT_SWITCH_SLOTS_DONE:
1395 ar = (AsyncResult) msg.obj;
1396 request = (MainThreadRequest) ar.userObj;
1397 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001398 notifyRequester(request);
1399 break;
1400 case CMD_GET_NETWORK_SELECTION_MODE:
1401 request = (MainThreadRequest) msg.obj;
1402 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1403 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1404 break;
1405
1406 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 if (ar.exception != null) {
1410 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1411 } else {
1412 int mode = ((int[]) ar.result)[0];
1413 if (mode == 0) {
1414 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1415 } else {
1416 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1417 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001418 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001419 notifyRequester(request);
1420 break;
1421 case CMD_GET_CDMA_ROAMING_MODE:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1424 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1425 break;
1426 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1427 ar = (AsyncResult) msg.obj;
1428 request = (MainThreadRequest) ar.userObj;
1429 if (ar.exception != null) {
1430 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1431 } else {
1432 request.result = ((int[]) ar.result)[0];
1433 }
1434 notifyRequester(request);
1435 break;
1436 case CMD_SET_CDMA_ROAMING_MODE:
1437 request = (MainThreadRequest) msg.obj;
1438 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1439 int mode = (int) request.argument;
1440 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1441 break;
1442 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1443 ar = (AsyncResult) msg.obj;
1444 request = (MainThreadRequest) ar.userObj;
1445 request.result = ar.exception == null;
1446 notifyRequester(request);
1447 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001448 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1449 request = (MainThreadRequest) msg.obj;
1450 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1451 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1452 break;
1453 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
1456 if (ar.exception != null) {
1457 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1458 } else {
1459 request.result = ((int[]) ar.result)[0];
1460 }
1461 notifyRequester(request);
1462 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001463 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1464 request = (MainThreadRequest) msg.obj;
1465 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1466 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001467 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1468 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001469 break;
1470 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
1473 request.result = ar.exception == null;
1474 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001475 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001476 case CMD_GET_ALL_CELL_INFO:
1477 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001478 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001479 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001480 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001481 case EVENT_GET_ALL_CELL_INFO_DONE:
1482 ar = (AsyncResult) msg.obj;
1483 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001484 // If a timeout occurs, the response will be null
1485 request.result = (ar.exception == null && ar.result != null)
1486 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001487 synchronized (request) {
1488 request.notifyAll();
1489 }
1490 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001491 case CMD_REQUEST_CELL_INFO_UPDATE:
1492 request = (MainThreadRequest) msg.obj;
1493 request.phone.requestCellInfoUpdate(request.workSource,
1494 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1495 break;
1496 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
1499 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1500 try {
1501 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001502 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001503 cb.onError(
1504 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1505 ar.exception.getClass().getName(),
1506 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001507 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001508 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001509 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001510 } else {
1511 // use the result as returned
1512 cb.onCellInfo((List<CellInfo>) ar.result);
1513 }
1514 } catch (RemoteException re) {
1515 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1516 }
1517 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001518 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001519 request = (MainThreadRequest) msg.obj;
1520 WorkSource ws = (WorkSource) request.argument;
1521 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001522 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001523 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001524 }
1525 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001526 ar = (AsyncResult) msg.obj;
1527 request = (MainThreadRequest) ar.userObj;
1528 if (ar.exception == null) {
1529 request.result = ar.result;
1530 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001531 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001532 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001533 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001534 }
1535
1536 synchronized (request) {
1537 request.notifyAll();
1538 }
1539 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001540 }
chen xu6dac5ab2018-10-26 17:39:23 -07001541 case CMD_MODEM_REBOOT:
1542 request = (MainThreadRequest) msg.obj;
1543 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001544 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001545 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001546 case EVENT_CMD_MODEM_REBOOT_DONE:
1547 handleNullReturnEvent(msg, "rebootModem");
1548 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001549 case CMD_REQUEST_ENABLE_MODEM:
1550 request = (MainThreadRequest) msg.obj;
1551 boolean enable = (boolean) request.argument;
1552 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001553 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001554 PhoneConfigurationManager.getInstance()
1555 .enablePhone(request.phone, enable, onCompleted);
1556 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001557 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
1560 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001561 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001562 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001563 if ((boolean) request.result) {
1564 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1565 updateModemStateMetrics();
1566 } else {
1567 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1568 + ar.exception);
1569 }
1570 notifyRequester(request);
1571 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001572 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001573 case CMD_GET_MODEM_STATUS:
1574 request = (MainThreadRequest) msg.obj;
1575 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1576 PhoneConfigurationManager.getInstance()
1577 .getPhoneStatusFromModem(request.phone, onCompleted);
1578 break;
1579 case EVENT_GET_MODEM_STATUS_DONE:
1580 ar = (AsyncResult) msg.obj;
1581 request = (MainThreadRequest) ar.userObj;
1582 int id = request.phone.getPhoneId();
1583 if (ar.exception == null && ar.result != null) {
1584 request.result = ar.result;
1585 //update the cache as modem status has changed
1586 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1587 (boolean) request.result);
1588 } else {
1589 // Return true if modem status cannot be retrieved. For most cases,
1590 // modem status is on. And for older version modems, GET_MODEM_STATUS
1591 // and disable modem are not supported. Modem is always on.
1592 // TODO: this should be fixed in R to support a third
1593 // status UNKNOWN b/131631629
1594 request.result = true;
1595 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1596 + ar.exception);
1597 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001598 notifyRequester(request);
1599 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001600 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1601 request = (MainThreadRequest) msg.obj;
1602 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1603 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1604 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1605 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1606 break;
1607 }
1608 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1609 ar = (AsyncResult) msg.obj;
1610 request = (MainThreadRequest) ar.userObj;
1611 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1612 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1613 args.second.accept(ar.exception == null);
1614 notifyRequester(request);
1615 break;
1616 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001617 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1618 request = (MainThreadRequest) msg.obj;
1619 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1620 Phone phone = getPhoneFromRequest(request);
1621 if (phone != null) {
1622 phone.getSystemSelectionChannels(onCompleted);
1623 } else {
1624 loge("getSystemSelectionChannels: No phone object");
1625 request.result = new ArrayList<RadioAccessSpecifier>();
1626 notifyRequester(request);
1627 }
1628 break;
1629 }
1630 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception == null && ar.result != null) {
1634 request.result = ar.result;
1635 } else {
1636 request.result = new IllegalArgumentException(
1637 "Failed to retrieve system selection channels");
1638 if (ar.result == null) {
1639 loge("getSystemSelectionChannels: Empty response");
1640 } else {
1641 loge("getSystemSelectionChannels: Unknown exception");
1642 }
1643 }
1644 notifyRequester(request);
1645 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001646 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1647 ar = (AsyncResult) msg.obj;
1648 request = (MainThreadRequest) ar.userObj;
1649 if (ar.exception == null && ar.result != null) {
1650 request.result = ar.result;
1651 } else {
1652 request.result = -1;
1653 loge("Failed to set Forbidden Plmns");
1654 if (ar.result == null) {
1655 loge("setForbidenPlmns: Empty response");
1656 } else if (ar.exception != null) {
1657 loge("setForbiddenPlmns: Exception: " + ar.exception);
1658 request.result = -1;
1659 } else {
1660 loge("setForbiddenPlmns: Unknown exception");
1661 }
1662 }
1663 notifyRequester(request);
1664 break;
1665 case CMD_SET_FORBIDDEN_PLMNS:
1666 request = (MainThreadRequest) msg.obj;
1667 uiccCard = getUiccCardFromRequest(request);
1668 if (uiccCard == null) {
1669 loge("setForbiddenPlmns: UiccCard is null");
1670 request.result = -1;
1671 notifyRequester(request);
1672 break;
1673 }
1674 Pair<Integer, List<String>> setFplmnsArgs =
1675 (Pair<Integer, List<String>>) request.argument;
1676 appType = setFplmnsArgs.first;
1677 List<String> fplmns = setFplmnsArgs.second;
1678 uiccApp = uiccCard.getApplicationByType(appType);
1679 if (uiccApp == null) {
1680 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1681 request.result = -1;
1682 loge("Failed to get UICC App");
1683 notifyRequester(request);
1684 } else {
1685 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1686 ((SIMRecords) uiccApp.getIccRecords())
1687 .setForbiddenPlmns(onCompleted, fplmns);
1688 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001689 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001690 case CMD_ERASE_MODEM_CONFIG:
1691 request = (MainThreadRequest) msg.obj;
1692 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1693 defaultPhone.eraseModemConfig(onCompleted);
1694 break;
1695 case EVENT_ERASE_MODEM_CONFIG_DONE:
1696 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001697 break;
zoey chene02881a2019-12-30 16:11:23 +08001698
1699 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1700 request = (MainThreadRequest) msg.obj;
1701 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1702 Pair<String, String> changed = (Pair<String, String>) request.argument;
1703 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1704 changed.first, changed.second, onCompleted);
1705 break;
1706 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1707 ar = (AsyncResult) msg.obj;
1708 request = (MainThreadRequest) ar.userObj;
1709 if (ar.exception == null) {
1710 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001711 // If the operation is successful, update the PIN storage
1712 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1713 int phoneId = getPhoneFromRequest(request).getPhoneId();
1714 UiccController.getInstance().getPinStorage()
1715 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001716 } else {
1717 request.result = msg.arg1;
1718 }
1719 notifyRequester(request);
1720 break;
1721
Michele Berionne5e411512020-11-13 02:36:59 +00001722 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1725 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1726 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1727 enabled.first, enabled.second, onCompleted);
1728 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001729 }
zoey chene02881a2019-12-30 16:11:23 +08001730 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1731 ar = (AsyncResult) msg.obj;
1732 request = (MainThreadRequest) ar.userObj;
1733 if (ar.exception == null) {
1734 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001735 // If the operation is successful, update the PIN storage
1736 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1737 int phoneId = getPhoneFromRequest(request).getPhoneId();
1738 if (enabled.first) {
1739 UiccController.getInstance().getPinStorage()
1740 .storePin(enabled.second, phoneId);
1741 } else {
1742 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1743 }
zoey chene02881a2019-12-30 16:11:23 +08001744 } else {
1745 request.result = msg.arg1;
1746 }
Michele Berionne5e411512020-11-13 02:36:59 +00001747
1748
zoey chene02881a2019-12-30 16:11:23 +08001749 notifyRequester(request);
1750 break;
1751
Peter Wangdafb9ac2020-01-15 14:13:38 -08001752 case MSG_NOTIFY_USER_ACTIVITY:
1753 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001754 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001755 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1756 getDefaultPhone().getContext().sendBroadcastAsUser(
1757 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1758 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001759
1760 case CMD_SET_DATA_THROTTLING: {
1761 request = (MainThreadRequest) msg.obj;
1762 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1763 DataThrottlingRequest dataThrottlingRequest =
1764 (DataThrottlingRequest) request.argument;
1765 Phone phone = getPhoneFromRequest(request);
1766 if (phone != null) {
1767 phone.setDataThrottling(onCompleted,
1768 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1769 dataThrottlingRequest.getCompletionDurationMillis());
1770 } else {
1771 loge("setDataThrottling: No phone object");
1772 request.result =
1773 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1774 notifyRequester(request);
1775 }
1776
1777 break;
1778 }
1779 case EVENT_SET_DATA_THROTTLING_DONE:
1780 ar = (AsyncResult) msg.obj;
1781 request = (MainThreadRequest) ar.userObj;
1782
1783 if (ar.exception == null) {
1784 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1785 } else if (ar.exception instanceof CommandException) {
1786 loge("setDataThrottling: CommandException: " + ar.exception);
1787 CommandException.Error error =
1788 ((CommandException) (ar.exception)).getCommandError();
1789
1790 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1791 request.result = TelephonyManager
1792 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1793 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1794 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1795 } else {
1796 request.result =
1797 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1798 }
1799 } else {
1800 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1801 }
1802 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1803 notifyRequester(request);
1804 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001805
1806 case CMD_SET_SIM_POWER: {
1807 request = (MainThreadRequest) msg.obj;
1808 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1809 request = (MainThreadRequest) msg.obj;
1810 int stateToSet =
1811 ((Pair<Integer, IIntegerConsumer>)
1812 request.argument).first;
1813 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1814 break;
1815 }
1816 case EVENT_SET_SIM_POWER_DONE: {
1817 ar = (AsyncResult) msg.obj;
1818 request = (MainThreadRequest) ar.userObj;
1819 IIntegerConsumer callback =
1820 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1821 if (ar.exception != null) {
1822 loge("setSimPower exception: " + ar.exception);
1823 int errorCode = TelephonyManager.CallForwardingInfoCallback
1824 .RESULT_ERROR_UNKNOWN;
1825 if (ar.exception instanceof CommandException) {
1826 CommandException.Error error =
1827 ((CommandException) (ar.exception)).getCommandError();
1828 if (error == CommandException.Error.SIM_ERR) {
1829 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1830 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1831 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1832 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1833 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1834 } else {
1835 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1836 }
1837 }
1838 try {
1839 callback.accept(errorCode);
1840 } catch (RemoteException e) {
1841 // Ignore if the remote process is no longer available to call back.
1842 Log.w(LOG_TAG, "setSimPower: callback not available.");
1843 }
1844 } else {
1845 try {
1846 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1847 } catch (RemoteException e) {
1848 // Ignore if the remote process is no longer available to call back.
1849 Log.w(LOG_TAG, "setSimPower: callback not available.");
1850 }
1851 }
1852 break;
1853 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001854 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1855 request = (MainThreadRequest) msg.obj;
1856
1857 final Phone phone = getPhoneFromRequest(request);
1858 if (phone == null || phone.getServiceStateTracker() == null) {
1859 request.result = new IllegalStateException("Phone or SST is null");
1860 notifyRequester(request);
1861 break;
1862 }
1863
1864 Pair<Integer, SignalStrengthUpdateRequest> pair =
1865 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1866 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1867 request);
1868 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1869 request.subId, pair.first /*callingUid*/,
1870 pair.second /*request*/, onCompleted);
1871 break;
1872 }
1873 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1874 ar = (AsyncResult) msg.obj;
1875 request = (MainThreadRequest) ar.userObj;
1876 // request.result will be the exception of ar if present, true otherwise.
1877 // Be cautious not to leave result null which will wait() forever
1878 request.result = ar.exception != null ? ar.exception : true;
1879 notifyRequester(request);
1880 break;
1881 }
1882 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1883 request = (MainThreadRequest) msg.obj;
1884
1885 Phone phone = getPhoneFromRequest(request);
1886 if (phone == null || phone.getServiceStateTracker() == null) {
1887 request.result = new IllegalStateException("Phone or SST is null");
1888 notifyRequester(request);
1889 break;
1890 }
1891
1892 Pair<Integer, SignalStrengthUpdateRequest> pair =
1893 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1894 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1895 request);
1896 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1897 request.subId, pair.first /*callingUid*/,
1898 pair.second /*request*/, onCompleted);
1899 break;
1900 }
1901 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1902 ar = (AsyncResult) msg.obj;
1903 request = (MainThreadRequest) ar.userObj;
1904 request.result = ar.exception != null ? ar.exception : true;
1905 notifyRequester(request);
1906 break;
1907 }
Jordan Liu109698e2020-11-24 14:50:34 -08001908
Michele Berionne5e411512020-11-13 02:36:59 +00001909 case CMD_PREPARE_UNATTENDED_REBOOT:
1910 request = (MainThreadRequest) msg.obj;
1911 request.result =
1912 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1913 notifyRequester(request);
1914 break;
1915
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 default:
1917 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1918 break;
1919 }
1920 }
Jake Hambye994d462014-02-03 13:10:13 -08001921
Pengquan Menga1bb6272018-09-06 09:59:22 -07001922 private void notifyRequester(MainThreadRequest request) {
1923 synchronized (request) {
1924 request.notifyAll();
1925 }
1926 }
1927
Jake Hambye994d462014-02-03 13:10:13 -08001928 private void handleNullReturnEvent(Message msg, String command) {
1929 AsyncResult ar = (AsyncResult) msg.obj;
1930 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1931 if (ar.exception == null) {
1932 request.result = true;
1933 } else {
1934 request.result = false;
1935 if (ar.exception instanceof CommandException) {
1936 loge(command + ": CommandException: " + ar.exception);
1937 } else {
1938 loge(command + ": Unknown exception");
1939 }
1940 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001941 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
1945 /**
1946 * Posts the specified command to be executed on the main thread,
1947 * waits for the request to complete, and returns the result.
1948 * @see #sendRequestAsync
1949 */
1950 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001951 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1952 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001953 }
1954
1955 /**
1956 * Posts the specified command to be executed on the main thread,
1957 * waits for the request to complete, and returns the result.
1958 * @see #sendRequestAsync
1959 */
1960 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1961 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001962 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001963 }
1964
1965 /**
1966 * Posts the specified command to be executed on the main thread,
1967 * waits for the request to complete, and returns the result.
1968 * @see #sendRequestAsync
1969 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001970 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001971 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1972 }
1973
1974 /**
1975 * Posts the specified command to be executed on the main thread,
1976 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1977 * if not timeout or null otherwise.
1978 * @see #sendRequestAsync
1979 */
1980 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1981 long timeoutInMs) {
1982 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001983 }
1984
1985 /**
1986 * Posts the specified command to be executed on the main thread,
1987 * waits for the request to complete, and returns the result.
1988 * @see #sendRequestAsync
1989 */
Nathan Harold92bed182018-10-12 18:16:49 -07001990 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001991 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001992 }
1993
1994 /**
1995 * Posts the specified command to be executed on the main thread,
1996 * waits for the request to complete, and returns the result.
1997 * @see #sendRequestAsync
1998 */
1999 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002000 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2001 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002002 }
2003
2004 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002005 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2006 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2007 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002008 * @see #sendRequestAsync
2009 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002010 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2011 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2013 throw new RuntimeException("This method will deadlock if called from the main thread.");
2014 }
2015
Nathan Harold92bed182018-10-12 18:16:49 -07002016 MainThreadRequest request = null;
2017 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2018 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2019 } else if (phone != null) {
2020 request = new MainThreadRequest(argument, phone, workSource);
2021 } else {
2022 request = new MainThreadRequest(argument, subId, workSource);
2023 }
2024
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002025 Message msg = mMainThreadHandler.obtainMessage(command, request);
2026 msg.sendToTarget();
2027
Rambo Wang0f050d82021-02-12 11:43:36 -08002028
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002030 if (timeoutInMs >= 0) {
2031 // Wait for at least timeoutInMs before returning null request result
2032 long now = SystemClock.elapsedRealtime();
2033 long deadline = now + timeoutInMs;
2034 while (request == null && now < deadline) {
2035 try {
2036 request.wait(deadline - now);
2037 } catch (InterruptedException e) {
2038 // Do nothing, go back and check if request is completed or timeout
2039 } finally {
2040 now = SystemClock.elapsedRealtime();
2041 }
2042 }
2043 } else {
2044 // Wait for the request to complete
2045 while (request.result == null) {
2046 try {
2047 request.wait();
2048 } catch (InterruptedException e) {
2049 // Do nothing, go back and wait until the request is complete
2050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 }
2052 }
2053 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002054 if (request.result == null) {
2055 Log.wtf(LOG_TAG,
2056 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 return request.result;
2059 }
2060
2061 /**
2062 * Asynchronous ("fire and forget") version of sendRequest():
2063 * Posts the specified command to be executed on the main thread, and
2064 * returns immediately.
2065 * @see #sendRequest
2066 */
2067 private void sendRequestAsync(int command) {
2068 mMainThreadHandler.sendEmptyMessage(command);
2069 }
2070
2071 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002072 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002073 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002074 */
2075 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002076 sendRequestAsync(command, argument, null, null);
2077 }
2078
2079 /**
2080 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2081 * @see {@link #sendRequest(int,Object)}
2082 */
2083 private void sendRequestAsync(
2084 int command, Object argument, Phone phone, WorkSource workSource) {
2085 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002086 Message msg = mMainThreadHandler.obtainMessage(command, request);
2087 msg.sendToTarget();
2088 }
2089
2090 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 * Initialize the singleton PhoneInterfaceManager instance.
2092 * This is only done once, at startup, from PhoneApp.onCreate().
2093 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002094 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 synchronized (PhoneInterfaceManager.class) {
2096 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002097 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 } else {
2099 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2100 }
2101 return sInstance;
2102 }
2103 }
2104
2105 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002106 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002109 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002110 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2112 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002113 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002114 mTelephonySharedPreferences =
2115 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002116 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002117 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002118 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002119
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 publish();
2121 }
2122
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002123 private Phone getDefaultPhone() {
2124 Phone thePhone = getPhone(getDefaultSubscription());
2125 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2126 }
2127
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 private void publish() {
2129 if (DBG) log("publish: " + this);
2130
Peter Wangc035ce42020-01-08 21:00:22 -08002131 TelephonyFrameworkInitializer
2132 .getTelephonyServiceManager()
2133 .getTelephonyServiceRegisterer()
2134 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 }
2136
Stuart Scott584921c2015-01-15 17:10:34 -08002137 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002138 if (request.phone != null) {
2139 return request.phone;
2140 } else {
2141 return getPhoneFromSubId(request.subId);
2142 }
2143 }
2144
2145 private Phone getPhoneFromSubId(int subId) {
2146 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2147 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002148 }
2149
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002150 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2151 Phone phone = getPhoneFromRequest(request);
2152 return phone == null ? null :
2153 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2154 }
2155
Wink Saville36469e72014-06-11 15:17:00 -07002156 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002157 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002158 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160
Naina Nallurid63128d2019-09-17 14:10:30 -07002161 private void sendEraseModemConfig(Phone phone) {
2162 if (phone != null) {
2163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2164 mApp, phone.getSubId(), "eraseModemConfig");
2165 final long identity = Binder.clearCallingIdentity();
2166 try {
2167 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2168 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2169 } finally {
2170 Binder.restoreCallingIdentity(identity);
2171 }
2172 }
2173 }
2174
Peter Wang44b186e2020-01-13 23:33:09 -08002175 private boolean isImsAvailableOnDevice() {
2176 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2177 if (pm == null) {
2178 // For some reason package manger is not available.. This will fail internally anyway,
2179 // so do not throw error and allow.
2180 return true;
2181 }
2182 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2183 }
2184
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002186 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002187 }
2188
Wink Savilleb564aae2014-10-23 10:18:09 -07002189 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 if (DBG) log("dial: " + number);
2191 // No permission check needed here: This is just a wrapper around the
2192 // ACTION_DIAL intent, which is available to any app since it puts up
2193 // the UI before it does anything.
2194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002195 final long identity = Binder.clearCallingIdentity();
2196 try {
2197 String url = createTelUrl(number);
2198 if (url == null) {
2199 return;
2200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002202 // PENDING: should we just silently fail if phone is offhook or ringing?
2203 PhoneConstants.State state = mCM.getState(subId);
2204 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2205 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2206 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2207 mApp.startActivity(intent);
2208 }
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 }
2212 }
2213
2214 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002215 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002216 }
2217
Wink Savilleb564aae2014-10-23 10:18:09 -07002218 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 if (DBG) log("call: " + number);
2220
2221 // This is just a wrapper around the ACTION_CALL intent, but we still
2222 // need to do a permission check since we're calling startActivity()
2223 // from the context of the phone app.
2224 enforceCallPermission();
2225
Jordan Liu1617b712019-07-10 15:06:26 -07002226 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 != AppOpsManager.MODE_ALLOWED) {
2228 return;
2229 }
2230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231 final long identity = Binder.clearCallingIdentity();
2232 try {
2233 String url = createTelUrl(number);
2234 if (url == null) {
2235 return;
2236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238 boolean isValid = false;
2239 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2240 if (slist != null) {
2241 for (SubscriptionInfo subInfoRecord : slist) {
2242 if (subInfoRecord.getSubscriptionId() == subId) {
2243 isValid = true;
2244 break;
2245 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002246 }
Wink Saville08874612014-08-31 19:19:58 -07002247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002248 if (!isValid) {
2249 return;
2250 }
Wink Saville08874612014-08-31 19:19:58 -07002251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002252 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2253 intent.putExtra(SUBSCRIPTION_KEY, subId);
2254 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2255 mApp.startActivity(intent);
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
2258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
Wink Savilleb564aae2014-10-23 10:18:09 -07002261 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002262 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002263 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2264 }
2265
Wink Savilleb564aae2014-10-23 10:18:09 -07002266 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002267 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002268 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2269 }
2270
Wink Savilleb564aae2014-10-23 10:18:09 -07002271 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002273
2274 final long identity = Binder.clearCallingIdentity();
2275 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002276 Phone phone = getPhone(subId);
2277 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002278 checkSimPin.start();
2279 return checkSimPin.unlockSim(null, pin);
2280 } finally {
2281 Binder.restoreCallingIdentity(identity);
2282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 }
2284
Wink Savilleb564aae2014-10-23 10:18:09 -07002285 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002287
2288 final long identity = Binder.clearCallingIdentity();
2289 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002290 Phone phone = getPhone(subId);
2291 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292 checkSimPuk.start();
2293 return checkSimPuk.unlockSim(puk, pin);
2294 } finally {
2295 Binder.restoreCallingIdentity(identity);
2296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298
2299 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002300 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 * a synchronous one.
2302 */
2303 private static class UnlockSim extends Thread {
2304
2305 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002306 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307
2308 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002309 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2310 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311
2312 // For replies from SimCard interface
2313 private Handler mHandler;
2314
2315 // For async handler to identify request type
2316 private static final int SUPPLY_PIN_COMPLETE = 100;
2317
Michele Berionne5e411512020-11-13 02:36:59 +00002318 UnlockSim(int phoneId, IccCard simCard) {
2319 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 mSimCard = simCard;
2321 }
2322
2323 @Override
2324 public void run() {
2325 Looper.prepare();
2326 synchronized (UnlockSim.this) {
2327 mHandler = new Handler() {
2328 @Override
2329 public void handleMessage(Message msg) {
2330 AsyncResult ar = (AsyncResult) msg.obj;
2331 switch (msg.what) {
2332 case SUPPLY_PIN_COMPLETE:
2333 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2334 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002335 mRetryCount = msg.arg1;
2336 if (ar.exception != null) {
2337 if (ar.exception instanceof CommandException &&
2338 ((CommandException)(ar.exception)).getCommandError()
2339 == CommandException.Error.PASSWORD_INCORRECT) {
2340 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002341 } //When UiccCardApp dispose,handle message and return exception
2342 else if (ar.exception instanceof CommandException &&
2343 ((CommandException) (ar.exception)).getCommandError()
2344 == CommandException.Error.ABORTED) {
2345 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002346 } else {
2347 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2348 }
2349 } else {
2350 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 mDone = true;
2353 UnlockSim.this.notifyAll();
2354 }
2355 break;
2356 }
2357 }
2358 };
2359 UnlockSim.this.notifyAll();
2360 }
2361 Looper.loop();
2362 }
2363
2364 /*
2365 * Use PIN or PUK to unlock SIM card
2366 *
2367 * If PUK is null, unlock SIM card with PIN
2368 *
2369 * If PUK is not null, unlock SIM card with PUK and set PIN code
2370 */
Wink Saville9de0f752013-10-22 19:04:03 -07002371 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372
2373 while (mHandler == null) {
2374 try {
2375 wait();
2376 } catch (InterruptedException e) {
2377 Thread.currentThread().interrupt();
2378 }
2379 }
2380 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2381
2382 if (puk == null) {
2383 mSimCard.supplyPin(pin, callback);
2384 } else {
2385 mSimCard.supplyPuk(puk, pin, callback);
2386 }
2387
2388 while (!mDone) {
2389 try {
2390 Log.d(LOG_TAG, "wait for done");
2391 wait();
2392 } catch (InterruptedException e) {
2393 // Restore the interrupted status
2394 Thread.currentThread().interrupt();
2395 }
2396 }
2397 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002398 int[] resultArray = new int[2];
2399 resultArray[0] = mResult;
2400 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002401
2402 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2403 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2404 }
2405
Wink Saville9de0f752013-10-22 19:04:03 -07002406 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 }
2408 }
2409
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002410 /**
2411 * This method has been removed due to privacy and stability concerns.
2412 */
2413 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002415 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2416 return;
Wink Saville36469e72014-06-11 15:17:00 -07002417 }
2418
Nathan Harold1f889d82020-06-04 17:05:26 -07002419 @Override
2420 public void updateServiceLocationWithPackageName(String callingPackage) {
2421 mApp.getSystemService(AppOpsManager.class)
2422 .checkPackage(Binder.getCallingUid(), callingPackage);
2423
Nathan Haroldf096d982020-11-18 17:18:06 -08002424 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002425 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2426 // Callers targeting S have no business invoking this method.
2427 return;
2428 }
2429
2430 LocationAccessPolicy.LocationPermissionResult locationResult =
2431 LocationAccessPolicy.checkLocationPermission(mApp,
2432 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2433 .setCallingPackage(callingPackage)
2434 .setCallingFeatureId(null)
2435 .setCallingPid(Binder.getCallingPid())
2436 .setCallingUid(Binder.getCallingUid())
2437 .setMethod("updateServiceLocation")
2438 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2439 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2440 .build());
2441 // Apps that lack location permission have no business calling this method;
2442 // however, because no permission was declared in the public API, denials must
2443 // all be "soft".
2444 switch (locationResult) {
2445 case DENIED_HARD: /* fall through */
2446 case DENIED_SOFT:
2447 return;
2448 }
2449
2450 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002451 final long identity = Binder.clearCallingIdentity();
2452 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002453 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002455 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456 }
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 }
2461
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002462 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002463 @Override
2464 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002465 return isRadioOnWithFeature(callingPackage, null);
2466 }
2467
2468
2469 @Override
2470 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2471 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2472 callingFeatureId);
2473 }
2474
2475 @Deprecated
2476 @Override
2477 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2478 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002479 }
2480
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002481 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002482 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2483 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002484 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002485 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002486 return false;
2487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002488
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 return isRadioOnForSubscriber(subId);
2492 } finally {
2493 Binder.restoreCallingIdentity(identity);
2494 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002495 }
2496
2497 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 final Phone phone = getPhone(subId);
2501 if (phone != null) {
2502 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2503 } else {
2504 return false;
2505 }
2506 } finally {
2507 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 }
2510
2511 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002512 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 }
Wink Saville36469e72014-06-11 15:17:00 -07002514
Wink Savilleb564aae2014-10-23 10:18:09 -07002515 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517
2518 final long identity = Binder.clearCallingIdentity();
2519 try {
2520 final Phone phone = getPhone(subId);
2521 if (phone != null) {
2522 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2523 }
2524 } finally {
2525 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002526 }
Wink Saville36469e72014-06-11 15:17:00 -07002527 }
2528
2529 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002530 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002531 }
2532
Wink Savilleb564aae2014-10-23 10:18:09 -07002533 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002534 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535
2536 final long identity = Binder.clearCallingIdentity();
2537 try {
2538 final Phone phone = getPhone(subId);
2539 if (phone == null) {
2540 return false;
2541 }
2542 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2543 toggleRadioOnOffForSubscriber(subId);
2544 }
2545 return true;
2546 } finally {
2547 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002549 }
Wink Saville36469e72014-06-11 15:17:00 -07002550
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002551 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002552 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002553 /*
2554 * If any of the Radios are available, it will need to be
2555 * shutdown. So return true if any Radio is available.
2556 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2560 Phone phone = PhoneFactory.getPhone(i);
2561 if (phone != null && phone.isRadioAvailable()) return true;
2562 }
2563 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2564 return false;
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002567 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002568 }
2569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002571 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572 enforceModifyPermission();
2573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2577 logv("Shutting down Phone " + i);
2578 shutdownRadioUsingPhoneId(i);
2579 }
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002582 }
2583 }
2584
2585 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002586 Phone phone = PhoneFactory.getPhone(phoneId);
2587 if (phone != null && phone.isRadioAvailable()) {
2588 phone.shutdownRadio();
2589 }
2590 }
2591
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002593 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2598 if (defaultPhone != null) {
2599 defaultPhone.setRadioPower(turnOn);
2600 return true;
2601 } else {
2602 loge("There's no default phone.");
2603 return false;
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002607 }
Wink Saville36469e72014-06-11 15:17:00 -07002608 }
2609
Wink Savilleb564aae2014-10-23 10:18:09 -07002610 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612
2613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 final Phone phone = getPhone(subId);
2616 if (phone != null) {
2617 phone.setRadioPower(turnOn);
2618 return true;
2619 } else {
2620 return false;
2621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626
Wink Saville36469e72014-06-11 15:17:00 -07002627 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002628 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002629 public boolean enableDataConnectivity() {
2630 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631
2632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 int subId = mSubscriptionController.getDefaultDataSubId();
2635 final Phone phone = getPhone(subId);
2636 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002637 phone.getDataEnabledSettings().setDataEnabled(
2638 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 return true;
2640 } else {
2641 return false;
2642 }
2643 } finally {
2644 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002645 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 }
2647
Wink Saville36469e72014-06-11 15:17:00 -07002648 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002649 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 public boolean disableDataConnectivity() {
2651 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652
2653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 int subId = mSubscriptionController.getDefaultDataSubId();
2656 final Phone phone = getPhone(subId);
2657 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002658 phone.getDataEnabledSettings().setDataEnabled(
2659 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 return true;
2661 } else {
2662 return false;
2663 }
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 }
2668
Sanket Padawe356d7632015-06-22 14:03:32 -07002669 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002670 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 final long identity = Binder.clearCallingIdentity();
2672 try {
2673 final Phone phone = getPhone(subId);
2674 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002675 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676 } else {
2677 return false;
2678 }
2679 } finally {
2680 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002681 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 }
2683
2684 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002685 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002686 }
2687
pkanwarae03a6b2016-11-06 20:37:09 -08002688 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 enforceCallPermission();
2690
2691 final long identity = Binder.clearCallingIdentity();
2692 try {
2693 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2694 return;
2695 }
2696 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2697 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
2700 }
pkanwar32d516d2016-10-14 19:37:38 -07002701 };
2702
Wink Savilleb564aae2014-10-23 10:18:09 -07002703 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705
2706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2709 return false;
2710 }
2711 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 }
2716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002718 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002719 }
2720
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002721 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 Phone phone = PhoneFactory.getPhone(slotIndex);
2725 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2726 PhoneConstantConversions.convertCallState(phone.getState());
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
2729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 }
2731
Sanket Padawe356d7632015-06-22 14:03:32 -07002732 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002733 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002734 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2735 }
2736
2737 @Override
2738 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 final long identity = Binder.clearCallingIdentity();
2740 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002741 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 if (phone != null) {
2743 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2744 } else {
2745 return PhoneConstantConversions.convertDataState(
2746 PhoneConstants.DataState.DISCONNECTED);
2747 }
2748 } finally {
2749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 }
2752
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002754 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002755 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2756 }
2757
2758 @Override
2759 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760 final long identity = Binder.clearCallingIdentity();
2761 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002762 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763 if (phone != null) {
2764 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2765 } else {
2766 return TelephonyManager.DATA_ACTIVITY_NONE;
2767 }
2768 } finally {
2769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
2773 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002774 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002775 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002776 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002777
2778 LocationAccessPolicy.LocationPermissionResult locationResult =
2779 LocationAccessPolicy.checkLocationPermission(mApp,
2780 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2781 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002782 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002783 .setCallingPid(Binder.getCallingPid())
2784 .setCallingUid(Binder.getCallingUid())
2785 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002786 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002787 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2788 .build());
2789 switch (locationResult) {
2790 case DENIED_HARD:
2791 throw new SecurityException("Not allowed to access cell location");
2792 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002793 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2794 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 }
2796
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002797 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002801 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002802 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803 } finally {
2804 Binder.restoreCallingIdentity(identity);
2805 }
Svetoslav64fad262015-04-14 14:35:21 -07002806 }
2807
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002808 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002809 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002810 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2811 // registered cell info, so return a NULL country instead.
2812 final long identity = Binder.clearCallingIdentity();
2813 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002814 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2815 // Get default phone in this case.
2816 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2817 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002818 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002820 if (phone == null) return "";
2821 ServiceStateTracker sst = phone.getServiceStateTracker();
2822 if (sst == null) return "";
2823 LocaleTracker lt = sst.getLocaleTracker();
2824 if (lt == null) return "";
2825 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2826 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2827 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002828 } finally {
2829 Binder.restoreCallingIdentity(identity);
2830 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002831 }
2832
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002833 /**
2834 * This method was removed due to potential issues caused by performing partial
2835 * updates of service state, and lack of a credible use case.
2836 *
2837 * This has the ability to break the telephony implementation by disabling notification of
2838 * changes in device connectivity. DO NOT USE THIS!
2839 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002840 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 public void enableLocationUpdates() {
2842 mApp.enforceCallingOrSelfPermission(
2843 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 }
2845
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002846 /**
2847 * This method was removed due to potential issues caused by performing partial
2848 * updates of service state, and lack of a credible use case.
2849 *
2850 * This has the ability to break the telephony implementation by disabling notification of
2851 * changes in device connectivity. DO NOT USE THIS!
2852 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002853 @Override
2854 public void disableLocationUpdates() {
2855 mApp.enforceCallingOrSelfPermission(
2856 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 }
2858
2859 @Override
2860 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002861 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2862 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002863 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002864 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2865 throw new SecurityException(
2866 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2867 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002868
Jordan Liu1617b712019-07-10 15:06:26 -07002869 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2871 return null;
2872 }
Svetoslav64fad262015-04-14 14:35:21 -07002873
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002874 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002876 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002877 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878
Nathan Haroldf180aac2018-06-01 18:43:55 -07002879 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2880 for (CellInfo ci : info) {
2881 if (ci instanceof CellInfoGsm) {
2882 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2883 } else if (ci instanceof CellInfoWcdma) {
2884 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002886 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002887 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 }
2889
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002890 private List<CellInfo> getCachedCellInfo() {
2891 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2892 for (Phone phone : PhoneFactory.getPhones()) {
2893 List<CellInfo> info = phone.getAllCellInfo();
2894 if (info != null) cellInfos.addAll(info);
2895 }
2896 return cellInfos;
2897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898
2899 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002900 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002901 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002902 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002903
2904 LocationAccessPolicy.LocationPermissionResult locationResult =
2905 LocationAccessPolicy.checkLocationPermission(mApp,
2906 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2907 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002908 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002909 .setCallingPid(Binder.getCallingPid())
2910 .setCallingUid(Binder.getCallingUid())
2911 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002912 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002913 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2914 .build());
2915 switch (locationResult) {
2916 case DENIED_HARD:
2917 throw new SecurityException("Not allowed to access cell info");
2918 case DENIED_SOFT:
2919 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921
Nathan Haroldf096d982020-11-18 17:18:06 -08002922 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002923 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2924 return getCachedCellInfo();
2925 }
2926
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002927 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002928 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2932 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002933 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002934 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935 if (info != null) cellInfos.addAll(info);
2936 }
2937 return cellInfos;
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 }
2941 }
2942
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002943 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002944 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2945 String callingFeatureId) {
2946 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2947 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002948 }
2949
2950 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002951 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2952 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002953 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002954 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002955 }
2956
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002957 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2958 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002959 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002960 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002961
2962 LocationAccessPolicy.LocationPermissionResult locationResult =
2963 LocationAccessPolicy.checkLocationPermission(mApp,
2964 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2965 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002966 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002967 .setCallingPid(Binder.getCallingPid())
2968 .setCallingUid(Binder.getCallingUid())
2969 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002970 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2971 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002972 .build());
2973 switch (locationResult) {
2974 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002975 if (TelephonyPermissions
2976 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002977 // Safetynet logging for b/154934934
2978 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2979 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002980 throw new SecurityException("Not allowed to access cell info");
2981 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002982 if (TelephonyPermissions
2983 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002984 // Safetynet logging for b/154934934
2985 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2986 }
Nathan Harold5320c422019-05-09 10:26:08 -07002987 try {
2988 cb.onCellInfo(new ArrayList<CellInfo>());
2989 } catch (RemoteException re) {
2990 // Drop without consequences
2991 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002992 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002993 }
2994
Nathan Harolda939a962019-05-09 10:13:47 -07002995
2996 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002997 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2998
2999 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3000 }
3001
3002 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003003 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003004 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003005 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006
3007 final long identity = Binder.clearCallingIdentity();
3008 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003009 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010 } finally {
3011 Binder.restoreCallingIdentity(identity);
3012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003013 }
3014
Shishir Agrawala9f32182016-04-12 12:00:16 -07003015 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003016 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003017 Phone phone = PhoneFactory.getPhone(slotIndex);
3018 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003019 return null;
3020 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003021 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003022 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003023 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003024 return null;
3025 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 return phone.getImei();
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003033 }
3034
3035 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003036 public String getTypeAllocationCodeForSlot(int slotIndex) {
3037 Phone phone = PhoneFactory.getPhone(slotIndex);
3038 String tac = null;
3039 if (phone != null) {
3040 String imei = phone.getImei();
3041 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3042 }
3043 return tac;
3044 }
3045
3046 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003047 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003048 Phone phone = PhoneFactory.getPhone(slotIndex);
3049 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003050 return null;
3051 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003052
Jeff Davidson913390f2018-02-23 17:11:49 -08003053 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003054 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003055 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003056 return null;
3057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003058
3059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 return phone.getMeid();
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
Jack Yu2af8d712017-03-15 17:14:14 -07003065 }
3066
3067 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003068 public String getManufacturerCodeForSlot(int slotIndex) {
3069 Phone phone = PhoneFactory.getPhone(slotIndex);
3070 String manufacturerCode = null;
3071 if (phone != null) {
3072 String meid = phone.getMeid();
3073 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3074 }
3075 return manufacturerCode;
3076 }
3077
3078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003079 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3080 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003081 Phone phone = PhoneFactory.getPhone(slotIndex);
3082 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003083 return null;
3084 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003085 int subId = phone.getSubId();
3086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003087 mApp, subId, callingPackage, callingFeatureId,
3088 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003089 return null;
3090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003091
3092 final long identity = Binder.clearCallingIdentity();
3093 try {
3094 return phone.getDeviceSvn();
3095 } finally {
3096 Binder.restoreCallingIdentity(identity);
3097 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003098 }
3099
fionaxu43304da2017-11-27 22:51:16 -08003100 @Override
3101 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 final Phone phone = getPhone(subId);
3105 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
fionaxu43304da2017-11-27 22:51:16 -08003109 }
3110
3111 @Override
3112 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 final Phone phone = getPhone(subId);
3116 return phone == null ? null : phone.getCarrierName();
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
fionaxu43304da2017-11-27 22:51:16 -08003120 }
3121
calvinpanffe225e2018-11-01 19:43:06 +08003122 @Override
chen xu0026ca62019-03-06 15:28:50 -08003123 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 final Phone phone = getPhone(subId);
3127 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003128 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
3132 }
3133
3134 @Override
chen xu0026ca62019-03-06 15:28:50 -08003135 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003139 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
3143 }
3144
chen xu651eec72018-11-11 19:03:44 -08003145 @Override
chen xu864e11c2018-12-06 22:10:03 -08003146 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3147 if (!isSubscriptionMccMnc) {
3148 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3149 }
chen xu651eec72018-11-11 19:03:44 -08003150 final Phone phone = PhoneFactory.getPhone(slotIndex);
3151 if (phone == null) {
3152 return TelephonyManager.UNKNOWN_CARRIER_ID;
3153 }
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
3160 }
3161
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162 //
3163 // Internal helper methods.
3164 //
3165
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003166 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3168 *
3169 * @throws SecurityException if the caller does not have the required permission
3170 */
3171 private void enforceModifyPermission() {
3172 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3173 }
3174
Shuo Qiancd19c462020-01-16 20:51:11 -08003175 /**
3176 * Make sure the caller is system.
3177 *
3178 * @throws SecurityException if the caller is not system.
3179 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003180 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003181 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3182 throw new SecurityException("Caller must be system");
3183 }
3184 }
3185
Shuo Qian3b6ee772019-11-13 17:43:31 -08003186 private void enforceActiveEmergencySessionPermission() {
3187 mApp.enforceCallingOrSelfPermission(
3188 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3189 }
3190
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 /**
3192 * Make sure the caller has the CALL_PHONE permission.
3193 *
3194 * @throws SecurityException if the caller does not have the required permission
3195 */
3196 private void enforceCallPermission() {
3197 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3198 }
3199
paulhu5a773602019-08-23 19:17:33 +08003200 private void enforceSettingsPermission() {
3201 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003202 }
3203
Michele Berionne5e411512020-11-13 02:36:59 +00003204 private void enforceRebootPermission() {
3205 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3206 }
3207
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 private String createTelUrl(String number) {
3209 if (TextUtils.isEmpty(number)) {
3210 return null;
3211 }
3212
Jake Hambye994d462014-02-03 13:10:13 -08003213 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 }
3215
Ihab Awadf9e92732013-12-05 18:02:52 -08003216 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003217 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3218 }
3219
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003220 private static void logv(String msg) {
3221 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3222 }
3223
Ihab Awadf9e92732013-12-05 18:02:52 -08003224 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003225 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3226 }
3227
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003228 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003229 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003230 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003231 }
3232
Sanket Padawe356d7632015-06-22 14:03:32 -07003233 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003234 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 final Phone phone = PhoneFactory.getPhone(slotIndex);
3238 if (phone == null) {
3239 return PhoneConstants.PHONE_TYPE_NONE;
3240 } else {
3241 return phone.getPhoneType();
3242 }
3243 } finally {
3244 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003245 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003246 }
3247
3248 /**
3249 * Returns the CDMA ERI icon index to display
3250 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003251 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003252 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3253 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3254 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003255 }
3256
Sanket Padawe356d7632015-06-22 14:03:32 -07003257 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003258 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3259 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003261 mApp, subId, callingPackage, callingFeatureId,
3262 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003263 return -1;
3264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265
3266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 final Phone phone = getPhone(subId);
3269 if (phone != null) {
3270 return phone.getCdmaEriIconIndex();
3271 } else {
3272 return -1;
3273 }
3274 } finally {
3275 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 }
3278
3279 /**
3280 * Returns the CDMA ERI icon mode,
3281 * 0 - ON
3282 * 1 - FLASHING
3283 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003285 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3286 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3287 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003288 }
3289
Sanket Padawe356d7632015-06-22 14:03:32 -07003290 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003291 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3292 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003294 mApp, subId, callingPackage, callingFeatureId,
3295 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003296 return -1;
3297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003298
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 final Phone phone = getPhone(subId);
3302 if (phone != null) {
3303 return phone.getCdmaEriIconMode();
3304 } else {
3305 return -1;
3306 }
3307 } finally {
3308 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003310 }
3311
3312 /**
3313 * Returns the CDMA ERI text,
3314 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003315 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003316 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3317 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3318 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003319 }
3320
Sanket Padawe356d7632015-06-22 14:03:32 -07003321 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003322 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3323 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003325 mApp, subId, callingPackage, callingFeatureId,
3326 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003327 return null;
3328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329
3330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 final Phone phone = getPhone(subId);
3333 if (phone != null) {
3334 return phone.getCdmaEriText();
3335 } else {
3336 return null;
3337 }
3338 } finally {
3339 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003341 }
3342
3343 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003344 * Returns the CDMA MDN.
3345 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003346 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003347 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3349 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350
3351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003354 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 return phone.getLine1Number();
3356 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003357 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 return null;
3359 }
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003362 }
3363 }
3364
3365 /**
3366 * Returns the CDMA MIN.
3367 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003368 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003369 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3371 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003372
3373 final long identity = Binder.clearCallingIdentity();
3374 try {
3375 final Phone phone = getPhone(subId);
3376 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3377 return phone.getCdmaMin();
3378 } else {
3379 return null;
3380 }
3381 } finally {
3382 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003383 }
3384 }
3385
Hall Liud892bec2018-11-30 14:51:45 -08003386 @Override
3387 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3388 INumberVerificationCallback callback, String callingPackage) {
3389 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3390 != PERMISSION_GRANTED) {
3391 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3392 }
3393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3394
3395 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3396 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003397 throw new SecurityException("Calling package must be configured in the device config: "
3398 + "calling package: " + callingPackage
3399 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003400 }
3401
3402 if (range == null) {
3403 throw new NullPointerException("Range must be non-null");
3404 }
3405
3406 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003407 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003408
3409 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3410 }
3411
Junda Liuca05d5d2014-08-14 22:36:34 -07003412 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 * Returns true if CDMA provisioning needs to run.
3414 */
3415 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003416 final long identity = Binder.clearCallingIdentity();
3417 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003418 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003422 }
3423
3424 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003425 * Sets the voice mail number of a given subId.
3426 */
3427 @Override
3428 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003429 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3430 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003431
3432 final long identity = Binder.clearCallingIdentity();
3433 try {
3434 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3435 new Pair<String, String>(alphaTag, number), new Integer(subId));
3436 return success;
3437 } finally {
3438 Binder.restoreCallingIdentity(identity);
3439 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003440 }
3441
Ta-wei Yen87c49842016-05-13 21:19:52 -07003442 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003443 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3444 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003445 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3446 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003447 if (!TextUtils.equals(callingPackage, systemDialer)) {
3448 throw new SecurityException("caller must be system dialer");
3449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450
3451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3454 if (phoneAccountHandle == null) {
3455 return null;
3456 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003457 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003458 } finally {
3459 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003460 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003461 }
3462
3463 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003464 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3465 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003466 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003468 mApp, subId, callingPackage, callingFeatureId,
3469 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003470 return null;
3471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003472
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003473 final long identity = Binder.clearCallingIdentity();
3474 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003475 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003476 } finally {
3477 Binder.restoreCallingIdentity(identity);
3478 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003479 }
3480
3481 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003482 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3483 VisualVoicemailSmsFilterSettings settings) {
3484 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003485
3486 final long identity = Binder.clearCallingIdentity();
3487 try {
3488 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003489 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003490 } finally {
3491 Binder.restoreCallingIdentity(identity);
3492 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003493 }
3494
3495 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003496 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3497 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498
3499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003502 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003503 } finally {
3504 Binder.restoreCallingIdentity(identity);
3505 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003506 }
3507
3508 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003509 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3510 String callingPackage, int subId) {
3511 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003512
3513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003516 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003517 } finally {
3518 Binder.restoreCallingIdentity(identity);
3519 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003520 }
3521
3522 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003523 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003524 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003525
3526 final long identity = Binder.clearCallingIdentity();
3527 try {
3528 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003529 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530 } finally {
3531 Binder.restoreCallingIdentity(identity);
3532 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003533 }
3534
3535 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003536 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3537 String callingAttributionTag, int subId, String number, int port, String text,
3538 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003539 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003540 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003541 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003542 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003543 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3544 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003545 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003546
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003547 /**
fionaxu0152e512016-11-14 13:36:14 -08003548 * Sets the voice activation state of a given subId.
3549 */
3550 @Override
3551 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3553 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554
3555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 final Phone phone = getPhone(subId);
3558 if (phone != null) {
3559 phone.setVoiceActivationState(activationState);
3560 } else {
3561 loge("setVoiceActivationState fails with invalid subId: " + subId);
3562 }
3563 } finally {
3564 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003565 }
3566 }
3567
3568 /**
3569 * Sets the data activation state of a given subId.
3570 */
3571 @Override
3572 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3574 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575
3576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 final Phone phone = getPhone(subId);
3579 if (phone != null) {
3580 phone.setDataActivationState(activationState);
3581 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003582 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583 }
3584 } finally {
3585 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003586 }
3587 }
3588
3589 /**
3590 * Returns the voice activation state of a given subId.
3591 */
3592 @Override
3593 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003594 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
fionaxu0152e512016-11-14 13:36:14 -08003596 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 if (phone != null) {
3600 return phone.getVoiceActivationState();
3601 } else {
3602 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3603 }
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003606 }
3607 }
3608
3609 /**
3610 * Returns the data activation state of a given subId.
3611 */
3612 @Override
3613 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003615
fionaxu0152e512016-11-14 13:36:14 -08003616 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003617 final long identity = Binder.clearCallingIdentity();
3618 try {
3619 if (phone != null) {
3620 return phone.getDataActivationState();
3621 } else {
3622 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3623 }
3624 } finally {
3625 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003626 }
3627 }
3628
3629 /**
Wink Saville36469e72014-06-11 15:17:00 -07003630 * Returns the unread count of voicemails for a subId
3631 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003632 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003633 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3634 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003636 mApp, subId, callingPackage, callingFeatureId,
3637 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003638 return 0;
3639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640 final long identity = Binder.clearCallingIdentity();
3641 try {
3642 final Phone phone = getPhone(subId);
3643 if (phone != null) {
3644 return phone.getVoiceMessageCount();
3645 } else {
3646 return 0;
3647 }
3648 } finally {
3649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003651 }
3652
3653 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003654 * returns true, if the device is in a state where both voice and data
3655 * are supported simultaneously. This can change based on location or network condition.
3656 */
3657 @Override
3658 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 final Phone phone = getPhone(subId);
3662 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003666 }
3667
3668 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003669 * Send the dialer code if called from the current default dialer or the caller has
3670 * carrier privilege.
3671 * @param inputCode The dialer code to send
3672 */
3673 @Override
3674 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003675 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003677 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3678 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003679 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003680 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003681 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003683
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003686 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
fionaxu235cc5e2017-03-06 22:25:57 -08003690 }
3691
Pengquan Menga1bb6272018-09-06 09:59:22 -07003692 @Override
3693 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003694 TelephonyPermissions
3695 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3696 mApp, subId, "getNetworkSelectionMode");
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 if (!isActiveSubscription(subId)) {
3700 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3701 }
3702 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3703 } finally {
3704 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003706 }
3707
Brad Ebinger35c841c2018-10-01 10:40:55 -07003708 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003709 public boolean isInEmergencySmsMode() {
3710 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 for (Phone phone : PhoneFactory.getPhones()) {
3714 if (phone.isInEmergencySmsMode()) {
3715 return true;
3716 }
3717 }
3718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
3721 return false;
3722 }
3723
shilu366312e2019-12-17 09:28:10 -08003724 /**
3725 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3726 * @param subId The subscription to use to check the configuration.
3727 * @param c The callback that will be used to send the result.
3728 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003729 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003730 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3731 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003732 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3733 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003734
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003735 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3736 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3737 "IMS not available on device.");
3738 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003739 final long token = Binder.clearCallingIdentity();
3740 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003743 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003744 } catch (ImsException e) {
3745 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 } finally {
3747 Binder.restoreCallingIdentity(token);
3748 }
3749 }
3750
shilu366312e2019-12-17 09:28:10 -08003751 /**
3752 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3753 * @param subId The subscription to use to check the configuration.
3754 * @param c The callback that will be used to send the result.
3755 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003757 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003758 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3759 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003760 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3761 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3762 }
Meng Wangafbc5852019-09-19 17:37:13 -07003763 final long token = Binder.clearCallingIdentity();
3764 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003765 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003766 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3767 .removeRegistrationCallbackForSubscription(c, subId);
3768 } catch (ImsException e) {
3769 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3770 + "is inactive, ignoring unregister.");
3771 // If the subscription is no longer active, just return, since the callback
3772 // will already have been removed internally.
3773 } finally {
3774 Binder.restoreCallingIdentity(token);
3775 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003776 }
3777
Brad Ebingera34a6c22019-10-22 17:36:18 -07003778 /**
3779 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3780 */
3781 @Override
3782 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3783 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3784 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3785 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3786 "IMS not available on device.");
3787 }
3788 final long token = Binder.clearCallingIdentity();
3789 try {
3790 Phone phone = getPhone(subId);
3791 if (phone == null) {
3792 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3793 + subId + "'");
3794 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3795 }
3796 phone.getImsRegistrationState(regState -> {
3797 try {
3798 consumer.accept((regState == null)
3799 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3800 } catch (RemoteException e) {
3801 // Ignore if the remote process is no longer available to call back.
3802 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3803 }
3804 });
3805 } finally {
3806 Binder.restoreCallingIdentity(token);
3807 }
3808 }
3809
3810 /**
3811 * Get the transport type for the IMS service registration state.
3812 */
3813 @Override
3814 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003815 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3816 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003817 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3818 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3819 "IMS not available on device.");
3820 }
3821 final long token = Binder.clearCallingIdentity();
3822 try {
3823 Phone phone = getPhone(subId);
3824 if (phone == null) {
3825 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3826 + subId + "'");
3827 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3828 }
3829 phone.getImsRegistrationTech(regTech -> {
3830 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3831 int regTechConverted = (regTech == null)
3832 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3833 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3834 regTechConverted);
3835 try {
3836 consumer.accept(regTechConverted);
3837 } catch (RemoteException e) {
3838 // Ignore if the remote process is no longer available to call back.
3839 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3840 }
3841 });
3842 } finally {
3843 Binder.restoreCallingIdentity(token);
3844 }
3845 }
3846
shilu366312e2019-12-17 09:28:10 -08003847 /**
3848 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3849 * @param subId The subscription to use to check the configuration.
3850 * @param c The callback that will be used to send the result.
3851 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003853 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3854 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003855 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3856 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003857 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3858 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3859 "IMS not available on device.");
3860 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003861 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3862 final long token = Binder.clearCallingIdentity();
3863 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003864 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003865 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003866 } catch (ImsException e) {
3867 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 } finally {
3869 Binder.restoreCallingIdentity(token);
3870 }
3871 }
3872
shilu366312e2019-12-17 09:28:10 -08003873 /**
3874 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3875 * @param subId The subscription to use to check the configuration.
3876 * @param c The callback that will be used to send the result.
3877 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003878 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003879 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003880 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3881 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003882 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3883 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3884 }
Meng Wangafbc5852019-09-19 17:37:13 -07003885
3886 final long token = Binder.clearCallingIdentity();
3887 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003888 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003889 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003890 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003891 } catch (ImsException e) {
3892 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3893 + "is inactive, ignoring unregister.");
3894 // If the subscription is no longer active, just return, since the callback
3895 // will already have been removed internally.
3896 } finally {
3897 Binder.restoreCallingIdentity(token);
3898 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 }
3900
3901 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003902 public boolean isCapable(int subId, int capability, int regTech) {
3903 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003904 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3905 final long token = Binder.clearCallingIdentity();
3906 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003907 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003908 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003909 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3911 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003912 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003913 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3914 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 } finally {
3916 Binder.restoreCallingIdentity(token);
3917 }
3918 }
3919
3920 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003921 public boolean isAvailable(int subId, int capability, int regTech) {
3922 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003923 final long token = Binder.clearCallingIdentity();
3924 try {
3925 Phone phone = getPhone(subId);
3926 if (phone == null) return false;
3927 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003928 } catch (com.android.ims.ImsException e) {
3929 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3930 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003931 } finally {
3932 Binder.restoreCallingIdentity(token);
3933 }
3934 }
3935
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003936 /**
3937 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3938 * subscription.
3939 * @param subId The subscription to use to check the configuration.
3940 * @param callback The callback that will be used to send the result.
3941 * @param capability The MmTelFeature capability that will be used to send the result.
3942 * @param transportType The transport type of the MmTelFeature capability.
3943 */
3944 @Override
3945 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3946 int transportType) {
3947 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3948 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3949 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3950 "IMS not available on device.");
3951 }
3952 final long token = Binder.clearCallingIdentity();
3953 try {
3954 int slotId = getSlotIndex(subId);
3955 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3956 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3957 + subId + "'");
3958 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3959 }
3960 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3961 transportType, aBoolean -> {
3962 try {
3963 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3964 } catch (RemoteException e) {
3965 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3966 + "running. Ignore");
3967 }
3968 });
3969 } finally {
3970 Binder.restoreCallingIdentity(token);
3971 }
3972 }
3973
shilu366312e2019-12-17 09:28:10 -08003974 /**
3975 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3976 * @param subId The subscription to use to check the configuration.
3977 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003978 @Override
3979 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003980 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3981 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003982
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3984 final long token = Binder.clearCallingIdentity();
3985 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003986 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003988 } catch (ImsException e) {
3989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 } finally {
3991 Binder.restoreCallingIdentity(token);
3992 }
3993 }
3994
3995 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003996 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003998 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003999 final long identity = Binder.clearCallingIdentity();
4000 try {
4001 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004002 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004003 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004004 } catch (ImsException e) {
4005 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 } finally {
4007 Binder.restoreCallingIdentity(identity);
4008 }
4009 }
4010
shilu366312e2019-12-17 09:28:10 -08004011 /**
4012 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4013 * @param subId The subscription to use to check the configuration.
4014 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004016 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004017 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4018 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004019 final long identity = Binder.clearCallingIdentity();
4020 try {
4021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004022 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4023 } catch (ImsException e) {
4024 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
4028 }
4029
4030 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004031 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004033 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004037 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004038 } catch (ImsException e) {
4039 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
4043 }
4044
shilu366312e2019-12-17 09:28:10 -08004045 /**
4046 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4047 * @param subId The subscription to use to check the configuration.
4048 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 @Override
4050 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004051 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4052 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004056 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004058 } catch (ImsException e) {
4059 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 } finally {
4061 Binder.restoreCallingIdentity(identity);
4062 }
4063 }
4064
4065 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004066 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004068 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004069 final long identity = Binder.clearCallingIdentity();
4070 try {
4071 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004072 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004073 } catch (ImsException e) {
4074 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
4078 }
4079
shilu366312e2019-12-17 09:28:10 -08004080 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004081 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4082 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4083 * @param subId The subscription to use to check the configuration.
4084 */
4085 @Override
4086 public boolean isCrossSimCallingEnabledByUser(int subId) {
4087 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4088 mApp, subId, "isCrossSimCallingEnabledByUser");
4089 final long identity = Binder.clearCallingIdentity();
4090 try {
4091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4092 return ImsManager.getInstance(mApp,
4093 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4094 } catch (ImsException e) {
4095 throw new ServiceSpecificException(e.getCode());
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
4098 }
4099 }
4100
4101 /**
4102 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4103 * Requires MODIFY_PHONE_STATE permission.
4104 * @param subId The subscription to use to check the configuration.
4105 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4106 * false otherwise
4107 */
4108 @Override
4109 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4111 "setCrossSimCallingEnabled");
4112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4115 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4116 .setCrossSimCallingEnabled(isEnabled);
4117 } catch (ImsException e) {
4118 throw new ServiceSpecificException(e.getCode());
4119 } finally {
4120 Binder.restoreCallingIdentity(identity);
4121 }
4122 }
4123
4124 /**
shilu366312e2019-12-17 09:28:10 -08004125 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4126 * @param subId The subscription to use to check the configuration.
4127 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 @Override
4129 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004130 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4131 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004132 final long identity = Binder.clearCallingIdentity();
4133 try {
4134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004135 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004137 } catch (ImsException e) {
4138 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 } finally {
4140 Binder.restoreCallingIdentity(identity);
4141 }
4142 }
4143
4144 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004145 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004147 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004151 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004153 } catch (ImsException e) {
4154 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 } finally {
4156 Binder.restoreCallingIdentity(identity);
4157 }
4158 }
4159
4160 @Override
4161 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4163 "setVoWiFiNonPersistent");
4164 final long identity = Binder.clearCallingIdentity();
4165 try {
4166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004167 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004168 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004169 } catch (ImsException e) {
4170 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 } finally {
4172 Binder.restoreCallingIdentity(identity);
4173 }
4174 }
4175
shilu366312e2019-12-17 09:28:10 -08004176 /**
4177 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4178 * @param subId The subscription to use to check the configuration.
4179 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 @Override
4181 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004182 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4183 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 final long identity = Binder.clearCallingIdentity();
4185 try {
4186 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004187 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004189 } catch (ImsException e) {
4190 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 } finally {
4192 Binder.restoreCallingIdentity(identity);
4193 }
4194 }
4195
4196 @Override
4197 public void setVoWiFiModeSetting(int subId, int mode) {
4198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4199 "setVoWiFiModeSetting");
4200 final long identity = Binder.clearCallingIdentity();
4201 try {
4202 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004203 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004205 } catch (ImsException e) {
4206 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
4210 }
4211
4212 @Override
4213 public int getVoWiFiRoamingModeSetting(int subId) {
4214 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004218 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
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(identity);
4224 }
4225 }
4226
4227 @Override
4228 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4230 "setVoWiFiRoamingModeSetting");
4231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004234 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004236 } catch (ImsException e) {
4237 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004238 } finally {
4239 Binder.restoreCallingIdentity(identity);
4240 }
4241 }
4242
4243 @Override
4244 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4246 "setRttCapabilityEnabled");
4247 final long identity = Binder.clearCallingIdentity();
4248 try {
4249 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004250 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4251 } catch (ImsException e) {
4252 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
4256 }
4257
shilu366312e2019-12-17 09:28:10 -08004258 /**
4259 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4260 * @param subId The subscription to use to check the configuration.
4261 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004262 @Override
4263 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004264 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4265 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004266 final long identity = Binder.clearCallingIdentity();
4267 try {
4268 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004269 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004270 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004271 } catch (ImsException e) {
4272 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 } finally {
4274 Binder.restoreCallingIdentity(identity);
4275 }
4276 }
4277
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004278 @Override
4279 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4280 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004283 if (!isImsAvailableOnDevice()) {
4284 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4285 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004286 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004287 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004288 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004289 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004290 } catch (ImsException e) {
4291 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004292 } finally {
4293 Binder.restoreCallingIdentity(identity);
4294 }
4295 }
4296
4297 @Override
4298 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4299 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4300 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004301 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4302 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4303 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004304 try {
4305 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004306 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004307 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004308 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004309 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4310 + "is inactive, ignoring unregister.");
4311 // If the subscription is no longer active, just return, since the callback will already
4312 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
4316 }
4317
allenwtsu99c623b2020-01-03 18:24:23 +08004318
4319 private void checkModifyPhoneStatePermission(int subId, String message) {
4320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4321 message);
4322 }
4323
4324 private boolean isImsProvisioningRequired(int subId, int capability,
4325 boolean isMmtelCapability) {
4326 Phone phone = getPhone(subId);
4327 if (phone == null) {
4328 loge("phone instance null for subid " + subId);
4329 return false;
4330 }
4331 if (isMmtelCapability) {
4332 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4333 return false;
4334 }
4335 } else {
4336 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4337 return false;
4338 }
4339 }
4340 return true;
4341 }
4342
4343 @Override
4344 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4345 boolean isProvisioned) {
4346 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4347
4348 final long identity = Binder.clearCallingIdentity();
4349 try {
4350 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4351 if (!isImsProvisioningRequired(subId, capability, false)) {
4352 return;
4353 }
4354
4355 // this capability requires provisioning, route to the correct API.
4356 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4357 switch (capability) {
4358 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4359 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4360 ims.setEabProvisioned(isProvisioned);
4361 break;
4362 default: {
4363 throw new IllegalArgumentException("Tried to set provisioning for "
4364 + "rcs capability '" + capability + "', which does not require "
4365 + "provisioning.");
4366 }
4367 }
4368 } finally {
4369 Binder.restoreCallingIdentity(identity);
4370 }
4371
4372 }
4373
4374
4375 @Override
4376 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4377 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4378 final long identity = Binder.clearCallingIdentity();
4379 try {
4380 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4381 if (!isImsProvisioningRequired(subId, capability, false)) {
4382 return true;
4383 }
4384
4385 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4386 switch (capability) {
4387 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4388 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4389 return ims.isEabProvisionedOnDevice();
4390
4391 default: {
4392 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4393 + "capability '" + capability + "', which does not require "
4394 + "provisioning.");
4395 }
4396 }
4397
4398 } finally {
4399 Binder.restoreCallingIdentity(identity);
4400 }
4401 }
4402
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004403 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004404 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4405 boolean isProvisioned) {
4406 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4407 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4408 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4409 }
allenwtsu99c623b2020-01-03 18:24:23 +08004410 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004411 final long identity = Binder.clearCallingIdentity();
4412 try {
4413 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004414 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004415 return;
4416 }
4417
4418 // this capability requires provisioning, route to the correct API.
4419 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4420 switch (capability) {
4421 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4422 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4423 ims.setVolteProvisioned(isProvisioned);
4424 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4425 ims.setWfcProvisioned(isProvisioned);
4426 }
4427 break;
4428 }
4429 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4430 // There is currently no difference in VT provisioning type.
4431 ims.setVtProvisioned(isProvisioned);
4432 break;
4433 }
4434 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4435 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4436 // change the capability of the feature instead if needed.
4437 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4438 == isProvisioned) {
4439 // No change in provisioning.
4440 return;
4441 }
4442 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4443 try {
4444 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004445 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004446 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4447 + ", Exception" + e.getMessage());
4448 }
4449 break;
4450 }
4451 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004452 throw new IllegalArgumentException("Tried to set provisioning for "
4453 + "MmTel capability '" + capability + "', which does not require "
4454 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004455 }
4456 }
4457
4458 } finally {
4459 Binder.restoreCallingIdentity(identity);
4460 }
4461 }
4462
4463 @Override
4464 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4465 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4466 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4467 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4468 }
4469 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004473 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004474 return true;
4475 }
4476
4477 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4478 switch (capability) {
4479 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4480 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4481 return ims.isVolteProvisionedOnDevice();
4482 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4483 return ims.isWfcProvisionedOnDevice();
4484 }
4485 // This should never happen, since we are checking tech above to make sure it
4486 // is either LTE or IWLAN.
4487 throw new IllegalArgumentException("Invalid radio technology for voice "
4488 + "capability.");
4489 }
4490 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4491 // There is currently no difference in VT provisioning type.
4492 return ims.isVtProvisionedOnDevice();
4493 }
4494 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4495 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4496 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4497 }
4498 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004499 throw new IllegalArgumentException(
4500 "Tried to get provisioning for MmTel capability '" + capability
4501 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004502 }
4503 }
4504
4505 } finally {
4506 Binder.restoreCallingIdentity(identity);
4507 }
4508 }
4509
4510 @Override
4511 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4512 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4513 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4514 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4515 }
4516 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4517 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4518 return (provisionedBits & capability) > 0;
4519 }
4520
4521 @Override
4522 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4523 boolean isProvisioned) {
4524 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4525 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4526 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4527 }
4528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4529 "setProvisioningStatusForCapability");
4530 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4531 // If the current provisioning status for capability already matches isProvisioned,
4532 // do nothing.
4533 if (((provisionedBits & capability) > 0) == isProvisioned) {
4534 return;
4535 }
4536 if (isProvisioned) {
4537 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4538 } else {
4539 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4540 }
4541 }
4542
4543 /**
4544 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4545 * technology. The bitfield should mirror the bitfield defined by
4546 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4547 */
4548 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4549 String key = getMmTelProvisioningKey(subId, tech);
4550 // Default is no capabilities are provisioned.
4551 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4552 }
4553
4554 /**
4555 * Sets the MmTel capability provisioning bitfield (defined by
4556 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4557 * technology specified.
4558 *
4559 * Note: This is a synchronous command and should not be called on UI thread.
4560 */
4561 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4562 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4563 String key = getMmTelProvisioningKey(subId, tech);
4564 editor.putInt(key, newField);
4565 editor.commit();
4566 }
4567
4568 private static String getMmTelProvisioningKey(int subId, int tech) {
4569 // resulting key is provision_ims_mmtel_{subId}_{tech}
4570 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4571 }
4572
4573 /**
4574 * Query CarrierConfig to see if the specified capability requires provisioning for the
4575 * carrier associated with the subscription id.
4576 */
4577 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4578 int capability) {
4579 CarrierConfigManager configManager = new CarrierConfigManager(context);
4580 PersistableBundle c = configManager.getConfigForSubId(subId);
4581 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004582 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004583 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4584 false);
4585 boolean requireVoiceVtProvisioning = c.getBoolean(
4586 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4587
4588 // First check to make sure that the capability requires provisioning.
4589 switch (capability) {
4590 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4591 // intentional fallthrough
4592 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4593 if (requireVoiceVtProvisioning) {
4594 // Voice and Video requires provisioning
4595 return true;
4596 }
4597 break;
4598 }
4599 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4600 if (requireUtProvisioning) {
4601 // UT requires provisioning
4602 return true;
4603 }
4604 break;
4605 }
4606 }
4607 return false;
4608 }
4609
allenwtsu99c623b2020-01-03 18:24:23 +08004610 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4611 int capability) {
4612 CarrierConfigManager configManager = new CarrierConfigManager(context);
4613 PersistableBundle c = configManager.getConfigForSubId(subId);
4614
4615 boolean requireRcsProvisioning = c.getBoolean(
4616 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4617
4618 // First check to make sure that the capability requires provisioning.
4619 switch (capability) {
4620 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4621 // intentional fallthrough
4622 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4623 if (requireRcsProvisioning) {
4624 // OPTION or PRESENCE requires provisioning
4625 return true;
4626 }
4627 break;
4628 }
4629 }
4630 return false;
4631 }
4632
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004633 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004634 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004635 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4636 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4637 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004638 enforceReadPrivilegedPermission("getImsProvisioningInt");
4639 final long identity = Binder.clearCallingIdentity();
4640 try {
4641 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004642 int slotId = getSlotIndex(subId);
4643 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4644 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4645 + subId + "' for key:" + key);
4646 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4647 }
4648 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004649 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004650 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4651 + subId + "' for key:" + key);
4652 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
4656 }
4657
4658 @Override
4659 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004660 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4661 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4662 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004663 enforceReadPrivilegedPermission("getImsProvisioningString");
4664 final long identity = Binder.clearCallingIdentity();
4665 try {
4666 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004667 int slotId = getSlotIndex(subId);
4668 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4669 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4670 + subId + "' for key:" + key);
4671 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4672 }
4673 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004674 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004675 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4676 + subId + "' for key:" + key);
4677 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004678 } finally {
4679 Binder.restoreCallingIdentity(identity);
4680 }
4681 }
4682
4683 @Override
4684 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004685 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4686 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4687 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4689 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004693 int slotId = getSlotIndex(subId);
4694 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4695 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4696 + subId + "' for key:" + key);
4697 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4698 }
4699 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004700 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004701 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4702 + "' for key:" + key);
4703 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004704 } finally {
4705 Binder.restoreCallingIdentity(identity);
4706 }
4707 }
4708
4709 @Override
4710 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004711 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4712 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4713 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4715 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004716 final long identity = Binder.clearCallingIdentity();
4717 try {
4718 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004719 int slotId = getSlotIndex(subId);
4720 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4721 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4722 + subId + "' for key:" + key);
4723 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4724 }
4725 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004726 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004727 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4728 + "' for key:" + key);
4729 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004730 } finally {
4731 Binder.restoreCallingIdentity(identity);
4732 }
4733 }
4734
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004735 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004736 int slotId = SubscriptionManager.getSlotIndex(subId);
4737 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004738 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4739 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004740 }
4741 return slotId;
4742 }
4743
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004744 private int getSlotIndex(int subId) {
4745 int slotId = SubscriptionManager.getSlotIndex(subId);
4746 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4747 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4748 }
4749 return slotId;
4750 }
4751
Wink Saville36469e72014-06-11 15:17:00 -07004752 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004753 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004754 */
4755 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004756 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4757 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004758 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004759 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004760 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004761 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004762 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004763 mApp, subId, callingPackage, callingFeatureId,
4764 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004765 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4766 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004768 final long identity = Binder.clearCallingIdentity();
4769 try {
4770 final Phone phone = getPhone(subId);
4771 if (phone != null) {
4772 return phone.getServiceState().getDataNetworkType();
4773 } else {
4774 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4775 }
4776 } finally {
4777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004779 }
4780
4781 /**
4782 * Returns the data network type
4783 */
4784 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004785 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4786 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4787 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004788 }
4789
4790 /**
4791 * Returns the data network type for a subId
4792 */
4793 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004794 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4795 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004796 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004797 mApp, subId, callingPackage, callingFeatureId,
4798 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004799 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4800 }
4801
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802 final long identity = Binder.clearCallingIdentity();
4803 try {
4804 final Phone phone = getPhone(subId);
4805 if (phone != null) {
4806 return phone.getServiceState().getDataNetworkType();
4807 } else {
4808 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4809 }
4810 } finally {
4811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004813 }
4814
4815 /**
Wink Saville36469e72014-06-11 15:17:00 -07004816 * Returns the Voice network type for a subId
4817 */
4818 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004819 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4820 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004821 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004822 mApp, subId, callingPackage, callingFeatureId,
4823 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004824 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4825 }
4826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827 final long identity = Binder.clearCallingIdentity();
4828 try {
4829 final Phone phone = getPhone(subId);
4830 if (phone != null) {
4831 return phone.getServiceState().getVoiceNetworkType();
4832 } else {
4833 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4834 }
4835 } finally {
4836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004838 }
4839
4840 /**
4841 * @return true if a ICC card is present
4842 */
4843 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004844 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004845 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4846 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004847 }
4848
4849 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004850 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004851 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004852 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004853 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 final Phone phone = PhoneFactory.getPhone(slotIndex);
4857 if (phone != null) {
4858 return phone.getIccCard().hasIccCard();
4859 } else {
4860 return false;
4861 }
4862 } finally {
4863 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004865 }
4866
4867 /**
4868 * Return if the current radio is LTE on CDMA. This
4869 * is a tri-state return value as for a period of time
4870 * the mode may be unknown.
4871 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004872 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004873 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004874 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004875 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004876 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004877 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4878 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4879 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004880 }
4881
Sanket Padawe356d7632015-06-22 14:03:32 -07004882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004883 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4884 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004885 try {
4886 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4887 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004888 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4889 }
4890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 final Phone phone = getPhone(subId);
4894 if (phone == null) {
4895 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4896 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004897 return TelephonyProperties.lte_on_cdma_device()
4898 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899 }
4900 } finally {
4901 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004902 }
Wink Saville36469e72014-06-11 15:17:00 -07004903 }
4904
Wink Saville36469e72014-06-11 15:17:00 -07004905 /**
4906 * {@hide}
4907 * Returns Default subId, 0 in the case of single standby.
4908 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004909 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004910 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004911 }
4912
Shishir Agrawala9f32182016-04-12 12:00:16 -07004913 private int getSlotForDefaultSubscription() {
4914 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4915 }
4916
Wink Savilleb564aae2014-10-23 10:18:09 -07004917 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004918 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004919 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004920
Pengquan Menge92a50d2018-09-21 15:54:48 -07004921 private boolean isActiveSubscription(int subId) {
4922 return mSubscriptionController.isActiveSubId(subId);
4923 }
4924
Ihab Awadf2177b72013-11-25 13:33:23 -08004925 /**
4926 * @see android.telephony.TelephonyManager.WifiCallingChoices
4927 */
4928 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929 final long identity = Binder.clearCallingIdentity();
4930 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004931 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4933 getWhenToMakeWifiCallsDefaultPreference());
4934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004937 }
4938
4939 /**
4940 * @see android.telephony.TelephonyManager.WifiCallingChoices
4941 */
4942 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 final long identity = Binder.clearCallingIdentity();
4944 try {
4945 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004946 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004951 }
4952
Sailesh Nepald1e68152013-12-12 19:08:02 -08004953 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004954 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004955 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004956 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004957
Jordan Liu4c733742019-02-28 12:03:40 -08004958 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4959 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4960 if (phoneId == -1) {
4961 throw new IllegalArgumentException("Given slot index: " + slotIndex
4962 + " does not correspond to an active phone");
4963 }
4964 return PhoneFactory.getPhone(phoneId);
4965 }
4966
Shishir Agrawal566b7612013-10-28 14:41:00 -07004967 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004968 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4969 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4971 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004973 if (DBG) {
4974 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4975 }
4976 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4977 p2);
4978 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004979
Jordan Liu4c733742019-02-28 12:03:40 -08004980
4981 @Override
4982 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4983 int slotIndex, String callingPackage, String aid, int p2) {
4984 enforceModifyPermission();
4985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4986 if (DBG) {
4987 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4988 }
4989 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4990 callingPackage, aid, p2);
4991 }
4992
4993 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4994 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 final long identity = Binder.clearCallingIdentity();
4996 try {
4997 if (TextUtils.equals(ISDR_AID, aid)) {
4998 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004999 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5000 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 if (bestComponent == null
5002 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5003 loge("The calling package is not allowed to access ISD-R.");
5004 throw new SecurityException(
5005 "The calling package is not allowed to access ISD-R.");
5006 }
Derek Tan740e1672017-06-27 14:56:27 -07005007 }
Derek Tan740e1672017-06-27 14:56:27 -07005008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005010 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5011 null /* workSource */);
5012 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 return response;
5014 } finally {
5015 Binder.restoreCallingIdentity(identity);
5016 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005017 }
5018
5019 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005020 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5022 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005023 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5024 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5025 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005026
Jordan Liu4c733742019-02-28 12:03:40 -08005027 @Override
5028 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5029 enforceModifyPermission();
5030 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5031 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5032 channel);
5033 }
5034
5035 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 final long identity = Binder.clearCallingIdentity();
5037 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 if (channel < 0) {
5039 return false;
5040 }
Jordan Liu4c733742019-02-28 12:03:40 -08005041 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5042 null /* workSource */);
5043 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 return success;
5045 } finally {
5046 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005047 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005048 }
5049
5050 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005051 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005052 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5054 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005055 if (DBG) {
5056 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5057 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5058 + p3 + " data=" + data);
5059 }
5060 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5061 command, p1, p2, p3, data);
5062 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005063
Jordan Liu4c733742019-02-28 12:03:40 -08005064 @Override
5065 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5066 int command, int p1, int p2, int p3, String data) {
5067 enforceModifyPermission();
5068 if (DBG) {
5069 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5070 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5071 + p3 + " data=" + data);
5072 }
5073 return iccTransmitApduLogicalChannelWithPermission(
5074 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5075 data);
5076 }
5077
5078 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5079 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 final long identity = Binder.clearCallingIdentity();
5081 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005082 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 return "";
5084 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005087 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5088 null /* workSource */);
5089 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 // Append the returned status code to the end of the response payload.
5092 String s = Integer.toHexString(
5093 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5094 if (response.payload != null) {
5095 s = IccUtils.bytesToHexString(response.payload) + s;
5096 }
5097 return s;
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005100 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005101 }
Jake Hambye994d462014-02-03 13:10:13 -08005102
Evan Charltonc66da362014-05-16 14:06:40 -07005103 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005104 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5105 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5107 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005109 if (DBG) {
5110 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5111 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5112 }
5113 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5114 cla, command, p1, p2, p3, data);
5115 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005116
Jordan Liu4c733742019-02-28 12:03:40 -08005117 @Override
5118 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5119 int command, int p1, int p2, int p3, String data) {
5120 enforceModifyPermission();
5121 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5122 if (DBG) {
5123 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5124 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5125 + " data=" + data);
5126 }
5127
5128 return iccTransmitApduBasicChannelWithPermission(
5129 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5130 p2, p3, data);
5131 }
5132
5133 // open APDU basic channel assuming the caller has sufficient permissions
5134 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5135 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136 final long identity = Binder.clearCallingIdentity();
5137 try {
5138 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5139 && TextUtils.equals(ISDR_AID, data)) {
5140 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005141 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5142 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 if (bestComponent == null
5144 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5145 loge("The calling package is not allowed to select ISD-R.");
5146 throw new SecurityException(
5147 "The calling package is not allowed to select ISD-R.");
5148 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005149 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005150
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005152 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5153 null /* workSource */);
5154 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 // Append the returned status code to the end of the response payload.
5157 String s = Integer.toHexString(
5158 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5159 if (response.payload != null) {
5160 s = IccUtils.bytesToHexString(response.payload) + s;
5161 }
5162 return s;
5163 } finally {
5164 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005165 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005166 }
5167
5168 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005169 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005170 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5172 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005173
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 final long identity = Binder.clearCallingIdentity();
5175 try {
5176 if (DBG) {
5177 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5178 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5179 }
5180
5181 IccIoResult response =
5182 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5183 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5184 subId);
5185
5186 if (DBG) {
5187 log("Exchange SIM_IO [R]" + response);
5188 }
5189
5190 byte[] result = null;
5191 int length = 2;
5192 if (response.payload != null) {
5193 length = 2 + response.payload.length;
5194 result = new byte[length];
5195 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5196 } else {
5197 result = new byte[length];
5198 }
5199
5200 result[length - 1] = (byte) response.sw2;
5201 result[length - 2] = (byte) response.sw1;
5202 return result;
5203 } finally {
5204 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005205 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005206 }
5207
Nathan Haroldb3014052017-01-25 15:57:32 -08005208 /**
5209 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5210 * on a particular subscription
5211 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005212 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5213 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005215 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005216 return null;
5217 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218
5219 final long identity = Binder.clearCallingIdentity();
5220 try {
5221 if (appType != TelephonyManager.APPTYPE_USIM
5222 && appType != TelephonyManager.APPTYPE_SIM) {
5223 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5224 return null;
5225 }
5226 Object response = sendRequest(
5227 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5228 if (response instanceof String[]) {
5229 return (String[]) response;
5230 }
yincheng zhao2737e882019-09-06 17:06:54 -07005231 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005233 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 } finally {
5235 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005236 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005237 }
5238
yincheng zhao2737e882019-09-06 17:06:54 -07005239 /**
5240 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5241 * subscription.
5242 *
5243 * @param subId the id of the subscription.
5244 * @param appType the uicc app type, must be USIM or SIM.
5245 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5246 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005247 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005248 * @return number of fplmns that is successfully written to the SIM.
5249 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005250 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5251 String callingFeatureId) {
5252 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5253 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005254 if (DBG) logv("no permissions for setForbiddenplmns");
5255 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5256 }
5257 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5258 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5259 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5260 }
5261 if (fplmns == null) {
5262 throw new IllegalArgumentException("Fplmn List provided is null");
5263 }
5264 for (String fplmn : fplmns) {
5265 if (!CellIdentity.isValidPlmn(fplmn)) {
5266 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5267 }
5268 }
5269 final long identity = Binder.clearCallingIdentity();
5270 try {
5271 Object response = sendRequest(
5272 CMD_SET_FORBIDDEN_PLMNS,
5273 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5274 subId);
5275 return (int) response;
5276 } finally {
5277 Binder.restoreCallingIdentity(identity);
5278 }
5279 }
5280
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005281 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005282 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5284 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 final long identity = Binder.clearCallingIdentity();
5287 try {
5288 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5289 if (response.payload == null) {
5290 return "";
5291 }
Evan Charltonc66da362014-05-16 14:06:40 -07005292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 // Append the returned status code to the end of the response payload.
5294 String s = Integer.toHexString(
5295 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5296 s = IccUtils.bytesToHexString(response.payload) + s;
5297 return s;
5298 } finally {
5299 Binder.restoreCallingIdentity(identity);
5300 }
Evan Charltonc66da362014-05-16 14:06:40 -07005301 }
5302
Jake Hambye994d462014-02-03 13:10:13 -08005303 /**
5304 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5305 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5306 *
5307 * @param itemID the ID of the item to read
5308 * @return the NV item as a String, or null on error.
5309 */
5310 @Override
5311 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005312 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5314 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315
5316 final long identity = Binder.clearCallingIdentity();
5317 try {
5318 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005319 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5321 return value;
5322 } finally {
5323 Binder.restoreCallingIdentity(identity);
5324 }
Jake Hambye994d462014-02-03 13:10:13 -08005325 }
5326
5327 /**
5328 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5329 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5330 *
5331 * @param itemID the ID of the item to read
5332 * @param itemValue the value to write, as a String
5333 * @return true on success; false on any failure
5334 */
5335 @Override
5336 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005337 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5339 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340
5341 final long identity = Binder.clearCallingIdentity();
5342 try {
5343 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5344 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005345 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5347 return success;
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
5350 }
Jake Hambye994d462014-02-03 13:10:13 -08005351 }
5352
5353 /**
5354 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5355 * Used for device configuration by some CDMA operators.
5356 *
5357 * @param preferredRoamingList byte array containing the new PRL
5358 * @return true on success; false on any failure
5359 */
5360 @Override
5361 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5363 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364
5365 final long identity = Binder.clearCallingIdentity();
5366 try {
5367 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5368 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5369 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5370 return success;
5371 } finally {
5372 Binder.restoreCallingIdentity(identity);
5373 }
Jake Hambye994d462014-02-03 13:10:13 -08005374 }
5375
5376 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005377 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005378 * Used for device configuration by some CDMA operators.
5379 *
chen xu6dac5ab2018-10-26 17:39:23 -07005380 * @param slotIndex - device slot.
5381 *
Jake Hambye994d462014-02-03 13:10:13 -08005382 * @return true on success; false on any failure
5383 */
5384 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005385 public boolean resetModemConfig(int slotIndex) {
5386 Phone phone = PhoneFactory.getPhone(slotIndex);
5387 if (phone != null) {
5388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5389 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390
chen xu6dac5ab2018-10-26 17:39:23 -07005391 final long identity = Binder.clearCallingIdentity();
5392 try {
5393 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5394 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5395 return success;
5396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 }
chen xu6dac5ab2018-10-26 17:39:23 -07005400 return false;
5401 }
5402
5403 /**
5404 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5405 *
5406 * @param slotIndex - device slot.
5407 *
5408 * @return true on success; false on any failure
5409 */
5410 @Override
5411 public boolean rebootModem(int slotIndex) {
5412 Phone phone = PhoneFactory.getPhone(slotIndex);
5413 if (phone != null) {
5414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5415 mApp, phone.getSubId(), "rebootModem");
5416
5417 final long identity = Binder.clearCallingIdentity();
5418 try {
5419 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5420 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5421 return success;
5422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
5425 }
5426 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005427 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005428
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005429 public String[] getPcscfAddress(String apnType, String callingPackage,
5430 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005431 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5433 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005434 return new String[0];
5435 }
5436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 final long identity = Binder.clearCallingIdentity();
5438 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005439 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 } finally {
5441 Binder.restoreCallingIdentity(identity);
5442 }
Wink Saville36469e72014-06-11 15:17:00 -07005443 }
5444
Brad Ebinger51f743a2017-01-23 13:50:20 -08005445 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005446 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5447 * {@link #disableIms(int)}.
5448 * @param slotIndex device slot.
5449 */
5450 public void resetIms(int slotIndex) {
5451 enforceModifyPermission();
5452
5453 final long identity = Binder.clearCallingIdentity();
5454 try {
5455 if (mImsResolver == null) {
5456 // may happen if the does not support IMS.
5457 return;
5458 }
5459 mImsResolver.disableIms(slotIndex);
5460 mImsResolver.enableIms(slotIndex);
5461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
5464 }
5465
5466 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005467 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5468 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005469 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005470 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005471 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472
5473 final long identity = Binder.clearCallingIdentity();
5474 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005475 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005476 // may happen if the device does not support IMS.
5477 return;
5478 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005479 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 } finally {
5481 Binder.restoreCallingIdentity(identity);
5482 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005483 }
5484
5485 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005486 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5487 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005488 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005489 public void disableIms(int slotId) {
5490 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491
5492 final long identity = Binder.clearCallingIdentity();
5493 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005494 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005495 // may happen if the device does not support IMS.
5496 return;
5497 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005498 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005502 }
5503
5504 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005505 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5506 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005507 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005508 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005509 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511
5512 final long identity = Binder.clearCallingIdentity();
5513 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005514 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005515 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5516 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005517 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005518 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519 } finally {
5520 Binder.restoreCallingIdentity(identity);
5521 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005522 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005523 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005524 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5525 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005526 @Override
5527 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005528 enforceModifyPermission();
5529
5530 final long identity = Binder.clearCallingIdentity();
5531 try {
5532 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005533 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
5537 }
5538
5539 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005540 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005541 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005542 */
5543 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545
5546 final long identity = Binder.clearCallingIdentity();
5547 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005548 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005549 // may happen if the device does not support IMS.
5550 return null;
5551 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005552 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005556 }
5557
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005558 /**
5559 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005560 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005561 */
5562 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005567 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005568 // may happen if the device does not support IMS.
5569 return null;
5570 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005571 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005575 }
5576
Brad Ebinger884c07b2018-02-15 16:17:40 -08005577 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005578 * Sets the ImsService Package Name that Telephony will bind to.
5579 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005580 * @param slotIndex the slot ID that the ImsService should bind for.
5581 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005582 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005583 * @param featureTypes An integer array of feature types associated with a packageName.
5584 * @param packageName The name of the package that the current configuration will be replaced
5585 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005586 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005587 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005588 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5589 int[] featureTypes, String packageName) {
5590 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5591 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5593 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005594 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 final long identity = Binder.clearCallingIdentity();
5597 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005598 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005599 // may happen if the device does not support IMS.
5600 return false;
5601 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005602 Map<Integer, String> featureConfig = new HashMap<>();
5603 for (int featureType : featureTypes) {
5604 featureConfig.put(featureType, packageName);
5605 }
5606 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5607 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005611 }
5612
5613 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005614 * Clears any carrier ImsService overrides for the slot index specified that were previously
5615 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5616 *
5617 * This should only be used for testing.
5618 *
5619 * @param slotIndex the slot ID that the ImsService should bind for.
5620 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5621 */
5622 @Override
5623 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5624 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5625 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5626 "clearCarrierImsServiceOverride");
5627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5628 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5629 "clearCarrierImsServiceOverride");
5630
5631 final long identity = Binder.clearCallingIdentity();
5632 try {
5633 if (mImsResolver == null) {
5634 // may happen if the device does not support IMS.
5635 return false;
5636 }
5637 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
5641 }
5642
5643 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005644 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005645 *
5646 * @param slotId The slot that the ImsService is associated with.
5647 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5648 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005649 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005650 * @return the package name of the ImsService configuration.
5651 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005652 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5653 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005654 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005655 TelephonyPermissions
5656 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5657 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5658 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660 final long identity = Binder.clearCallingIdentity();
5661 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005662 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005663 // may happen if the device does not support IMS.
5664 return "";
5665 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005666 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005667 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5668 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005672 }
5673
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005674 /**
5675 * Get the MmTelFeature state associated with the requested subscription id.
5676 * @param subId The subscription that the MmTelFeature is associated with.
5677 * @param callback A callback with an integer containing the
5678 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5679 */
5680 @Override
5681 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5682 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5683 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5684 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5685 "IMS not available on device.");
5686 }
5687 final long token = Binder.clearCallingIdentity();
5688 try {
5689 int slotId = getSlotIndex(subId);
5690 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5691 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5692 + subId + "'");
5693 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5694 }
5695 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5696 try {
5697 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5698 } catch (RemoteException e) {
5699 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5700 + "Ignore");
5701 }
5702 });
5703 } finally {
5704 Binder.restoreCallingIdentity(token);
5705 }
5706 }
5707
Daniel Brightbb5840b2021-01-12 15:48:18 -08005708 /**
5709 * Sets the ims registration state on all valid {@link Phone}s.
5710 */
5711 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713
5714 final long identity = Binder.clearCallingIdentity();
5715 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005716 // NOTE: Before S, this method only set the default phone.
5717 for (final Phone phone : PhoneFactory.getPhones()) {
5718 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5719 phone.setImsRegistrationState(registered);
5720 }
5721 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
Wink Saville36469e72014-06-11 15:17:00 -07005725 }
5726
5727 /**
Stuart Scott54788802015-03-30 13:18:01 -07005728 * Set the network selection mode to automatic.
5729 *
5730 */
5731 @Override
5732 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5734 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
shilufc958392020-01-20 11:36:01 -08005738 if (!isActiveSubscription(subId)) {
5739 return;
5740 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005742 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5743 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744 } finally {
5745 Binder.restoreCallingIdentity(identity);
5746 }
Stuart Scott54788802015-03-30 13:18:01 -07005747 }
5748
Jack Yud10cdd42020-09-28 20:28:01 -07005749 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005750 * Ask the radio to connect to the input network and change selection mode to manual.
5751 *
5752 * @param subId the id of the subscription.
5753 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5754 * the operator to attach to.
5755 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5756 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5757 * normal network selection next time.
5758 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005759 */
5760 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005761 public boolean setNetworkSelectionModeManual(
5762 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5764 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005765
5766 if (!isActiveSubscription(subId)) {
5767 return false;
5768 }
5769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 final long identity = Binder.clearCallingIdentity();
5771 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005772 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005774 if (DBG) {
5775 log("setNetworkSelectionModeManual: subId: " + subId
5776 + " operator: " + operatorInfo);
5777 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
5781 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005782 }
shilu84f6e8b2019-12-19 13:58:01 -08005783 /**
5784 * Get the manual network selection
5785 *
5786 * @param subId the id of the subscription.
5787 *
5788 * @return the previously saved user selected PLMN
5789 */
5790 @Override
5791 public String getManualNetworkSelectionPlmn(int subId) {
5792 TelephonyPermissions
5793 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5794 mApp, subId, "getManualNetworkSelectionPlmn");
5795
5796 final long identity = Binder.clearCallingIdentity();
5797 try {
5798 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005799 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005800 }
5801
5802 final Phone phone = getPhone(subId);
5803 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005804 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005805 }
5806 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5807 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5808 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5809 } finally {
5810 Binder.restoreCallingIdentity(identity);
5811 }
5812 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005813
5814 /**
5815 * Scans for available networks.
5816 */
5817 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005818 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5819 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5821 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005822 LocationAccessPolicy.LocationPermissionResult locationResult =
5823 LocationAccessPolicy.checkLocationPermission(mApp,
5824 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5825 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005826 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005827 .setCallingPid(Binder.getCallingPid())
5828 .setCallingUid(Binder.getCallingUid())
5829 .setMethod("getCellNetworkScanResults")
5830 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005831 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5832 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005833 .build());
5834 switch (locationResult) {
5835 case DENIED_HARD:
5836 throw new SecurityException("Not allowed to access scan results -- location");
5837 case DENIED_SOFT:
5838 return null;
5839 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840
Pengquan Menga1bb6272018-09-06 09:59:22 -07005841 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 try {
5843 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005844 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005845 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005849 }
5850
5851 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005852 * Get the call forwarding info, given the call forwarding reason.
5853 */
5854 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005855 public void getCallForwarding(int subId, int callForwardingReason,
5856 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005857 enforceReadPrivilegedPermission("getCallForwarding");
5858 long identity = Binder.clearCallingIdentity();
5859 try {
5860 if (DBG) {
5861 log("getCallForwarding: subId " + subId
5862 + " callForwardingReason" + callForwardingReason);
5863 }
Hall Liu27d24262020-09-18 19:04:59 -07005864
5865 Phone phone = getPhone(subId);
5866 if (phone == null) {
5867 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005868 callback.onError(
5869 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005870 } catch (RemoteException e) {
5871 // ignore
5872 }
5873 return;
5874 }
5875
5876 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5877 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5878 @Override
5879 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5880 try {
5881 callback.onCallForwardingInfoAvailable(info);
5882 } catch (RemoteException e) {
5883 // ignore
5884 }
5885 }
5886
5887 @Override
5888 public void onError(int error) {
5889 try {
5890 callback.onError(error);
5891 } catch (RemoteException e) {
5892 // ignore
5893 }
5894 }
5895 });
5896 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005897 } finally {
5898 Binder.restoreCallingIdentity(identity);
5899 }
5900 }
5901
5902 /**
5903 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5904 * reason, the number to forward, and the timeout before the forwarding is attempted.
5905 */
5906 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005907 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5908 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005909 enforceModifyPermission();
5910 long identity = Binder.clearCallingIdentity();
5911 try {
5912 if (DBG) {
5913 log("setCallForwarding: subId " + subId
5914 + " callForwardingInfo" + callForwardingInfo);
5915 }
Hall Liu27d24262020-09-18 19:04:59 -07005916
5917 Phone phone = getPhone(subId);
5918 if (phone == null) {
5919 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005920 callback.accept(
5921 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005922 } catch (RemoteException e) {
5923 // ignore
5924 }
5925 return;
5926 }
5927
5928 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5929 FunctionalUtils.ignoreRemoteException(callback::accept));
5930
5931 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
5935 }
5936
5937 /**
Hall Liu27d24262020-09-18 19:04:59 -07005938 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005939 */
5940 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005941 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005942 enforceReadPrivilegedPermission("getCallForwarding");
5943 long identity = Binder.clearCallingIdentity();
5944 try {
Hall Liu27d24262020-09-18 19:04:59 -07005945
5946 Phone phone = getPhone(subId);
5947 if (phone == null) {
5948 try {
5949 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5950 } catch (RemoteException e) {
5951 // ignore
5952 }
5953 return;
5954 }
5955
5956 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5957
Shuo Qian4a594052020-01-23 11:59:30 -08005958 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005959 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
5963 }
5964
5965 /**
Hall Liu27d24262020-09-18 19:04:59 -07005966 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005967 */
5968 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005969 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005970 enforceModifyPermission();
5971 long identity = Binder.clearCallingIdentity();
5972 try {
Hall Liu27d24262020-09-18 19:04:59 -07005973 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5974
5975 Phone phone = getPhone(subId);
5976 if (phone == null) {
5977 try {
5978 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5979 } catch (RemoteException e) {
5980 // ignore
5981 }
5982 return;
5983 }
5984
5985 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5986 FunctionalUtils.ignoreRemoteException(callback::accept));
5987
5988 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005989 } finally {
5990 Binder.restoreCallingIdentity(identity);
5991 }
5992 }
5993
5994 /**
yinxub1bed742017-04-17 11:45:04 -07005995 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005996 *
yinxub1bed742017-04-17 11:45:04 -07005997 * @param subId id of the subscription
5998 * @param request contains the radio access networks with bands/channels to scan
5999 * @param messenger callback messenger for scan results or errors
6000 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006001 * @return the id of the requested scan which can be used to stop the scan.
6002 */
6003 @Override
6004 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006005 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6007 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006008 LocationAccessPolicy.LocationPermissionResult locationResult =
6009 LocationAccessPolicy.checkLocationPermission(mApp,
6010 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6011 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006012 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006013 .setCallingPid(Binder.getCallingPid())
6014 .setCallingUid(Binder.getCallingUid())
6015 .setMethod("requestNetworkScan")
6016 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006017 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6018 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006019 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006020 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006021 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6022 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006023 if (e != null) {
6024 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6025 throw e;
6026 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006027 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006028 return TelephonyScanManager.INVALID_SCAN_ID;
6029 }
6030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 }
Hall Liu912dfd32019-04-25 14:02:26 -07006032 int callingUid = Binder.getCallingUid();
6033 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006034 final long identity = Binder.clearCallingIdentity();
6035 try {
6036 return mNetworkScanRequestTracker.startNetworkScan(
6037 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006038 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
yinxu504e1392017-04-12 16:03:22 -07006042 }
6043
Hall Liub2ac8ef2019-02-28 15:56:23 -08006044 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006045 NetworkScanRequest request, int subId, String callingPackage) {
6046 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006047 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6048 boolean hasNetworkScanPermission =
6049 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6050 == PERMISSION_GRANTED;
6051
6052 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6053 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6054 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006055 }
6056
6057 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6058 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006059 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6060 return new SecurityException("Specific channels must not be"
6061 + " scanned without location access.");
6062 }
6063 }
6064 }
6065
Hall Liub2ac8ef2019-02-28 15:56:23 -08006066 return null;
6067 }
6068
yinxu504e1392017-04-12 16:03:22 -07006069 /**
6070 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006071 *
6072 * @param subId id of the subscription
6073 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006074 */
6075 @Override
6076 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6078 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079
Hall Liu912dfd32019-04-25 14:02:26 -07006080 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 final long identity = Binder.clearCallingIdentity();
6082 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006083 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 } finally {
6085 Binder.restoreCallingIdentity(identity);
6086 }
yinxu504e1392017-04-12 16:03:22 -07006087 }
6088
6089 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006090 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006091 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006092 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006093 */
6094 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006095 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006096 TelephonyPermissions
6097 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006098 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099
6100 final long identity = Binder.clearCallingIdentity();
6101 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006102 if (DBG) log("getAllowedNetworkTypesBitmask");
6103 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6104 int networkTypesBitmask = (result != null ? result[0] : -1);
6105 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6106 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 } finally {
6108 Binder.restoreCallingIdentity(identity);
6109 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006110 }
6111
6112 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006113 * Get the allowed network types for certain reason.
6114 *
6115 * @param subId the id of the subscription.
6116 * @param reason the reason the allowed network type change is taking place
6117 * @return the allowed network types.
6118 */
6119 @Override
6120 public long getAllowedNetworkTypesForReason(int subId,
6121 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6122 TelephonyPermissions
6123 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6124 mApp, subId, "getAllowedNetworkTypesForReason");
6125 final long identity = Binder.clearCallingIdentity();
6126 try {
6127 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6128 } finally {
6129 Binder.restoreCallingIdentity(identity);
6130 }
6131 }
6132
6133 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006134 * Enable/Disable E-UTRA-NR Dual Connectivity
6135 * @param subId subscription id of the sim card
6136 * @param nrDualConnectivityState expected NR dual connectivity state
6137 * This can be passed following states
6138 * <ol>
6139 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6140 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6141 * <li>Disable NR dual connectivity and force secondary cell to be released
6142 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6143 * </ol>
6144 * @return operation result.
6145 */
6146 @Override
6147 public int setNrDualConnectivityState(int subId,
6148 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6150 mApp, subId, "enableNRDualConnectivity");
6151 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6152 final long identity = Binder.clearCallingIdentity();
6153 try {
6154 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6155 nrDualConnectivityState, subId,
6156 workSource);
6157 if (DBG) log("enableNRDualConnectivity result: " + result);
6158 return result;
6159 } finally {
6160 Binder.restoreCallingIdentity(identity);
6161 }
6162 }
6163
6164 /**
6165 * Is E-UTRA-NR Dual Connectivity enabled
6166 * @return true if dual connectivity is enabled else false
6167 */
6168 @Override
6169 public boolean isNrDualConnectivityEnabled(int subId) {
6170 TelephonyPermissions
6171 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6172 mApp, subId, "isNRDualConnectivityEnabled");
6173 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6174 final long identity = Binder.clearCallingIdentity();
6175 try {
6176 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6177 null, subId, workSource);
6178 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6179 return isEnabled;
6180 } finally {
6181 Binder.restoreCallingIdentity(identity);
6182 }
6183 }
6184
6185 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006186 * get carrier bandwidth per primary and secondary carrier
6187 * @param subId subscription id of the sim card
6188 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6189 */
6190 @Override
6191 public CarrierBandwidth getCarrierBandwidth(int subId) {
6192 TelephonyPermissions
6193 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6194 mApp, subId, "isNRDualConnectivityEnabled");
6195 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6196 final long identity = Binder.clearCallingIdentity();
6197 try {
6198 CarrierBandwidth carrierBandwidth =
6199 getPhoneFromSubId(subId).getCarrierBandwidth();
6200 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6201 return carrierBandwidth;
6202 } finally {
6203 Binder.restoreCallingIdentity(identity);
6204 }
6205 }
6206
6207 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006208 * Set the allowed network types of the device and
6209 * provide the reason triggering the allowed network change.
6210 *
6211 * @param subId the id of the subscription.
6212 * @param reason the reason the allowed network type change is taking place
6213 * @param allowedNetworkTypes the allowed network types.
6214 * @return true on success; false on any failure.
6215 */
6216 @Override
6217 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006218 @TelephonyManager.AllowedNetworkTypesReason int reason,
6219 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6221 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006222 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6223 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6224 return false;
6225 }
6226
6227 if (DBG) {
6228 log("setAllowedNetworkTypesForReason: " + reason
6229 + " value: " + allowedNetworkTypes);
6230 }
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006231 final long identity = Binder.clearCallingIdentity();
6232 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006233 Boolean success = (Boolean) sendRequest(
6234 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6235 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6236
6237 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6238 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006239 } finally {
6240 Binder.restoreCallingIdentity(identity);
6241 }
6242 }
6243
6244 /**
Miaoa84611c2019-03-15 09:21:10 +08006245 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006246 *
Miaoa84611c2019-03-15 09:21:10 +08006247 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006248 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006249 * @hide
6250 */
6251 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006252 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006253 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006255 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 try {
Miaoa84611c2019-03-15 09:21:10 +08006257 if (phone != null) {
6258 return phone.hasMatchedTetherApnSetting();
6259 } else {
6260 return false;
6261 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 } finally {
6263 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006264 }
Junda Liu475951f2014-11-07 16:45:03 -08006265 }
6266
6267 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006268 * Enable or disable always reporting signal strength changes from radio.
6269 *
6270 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6271 */
6272 @Override
6273 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6274 enforceModifyPermission();
6275 enforceSystemCaller();
6276
6277 final long identity = Binder.clearCallingIdentity();
6278 final Phone phone = getPhone(subId);
6279 try {
6280 if (phone != null) {
6281 if (DBG) {
6282 log("setAlwaysReportSignalStrength: subId=" + subId
6283 + " isEnable=" + isEnable);
6284 }
6285 phone.setAlwaysReportSignalStrength(isEnable);
6286 } else {
6287 loge("setAlwaysReportSignalStrength: no phone found for subId="
6288 + subId);
6289 }
6290 } finally {
6291 Binder.restoreCallingIdentity(identity);
6292 }
6293 }
6294
6295 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006296 * Get the user enabled state of Mobile Data.
6297 *
6298 * TODO: remove and use isUserDataEnabled.
6299 * This can't be removed now because some vendor codes
6300 * calls through ITelephony directly while they should
6301 * use TelephonyManager.
6302 *
6303 * @return true on enabled
6304 */
6305 @Override
6306 public boolean getDataEnabled(int subId) {
6307 return isUserDataEnabled(subId);
6308 }
6309
6310 /**
6311 * Get whether mobile data is enabled per user setting.
6312 *
6313 * There are other factors deciding whether mobile data is actually enabled, but they are
6314 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006315 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006316 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006317 *
6318 * @return {@code true} if data is enabled else {@code false}
6319 */
6320 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006321 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006322 try {
6323 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6324 null);
6325 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6327 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329
6330 final long identity = Binder.clearCallingIdentity();
6331 try {
6332 int phoneId = mSubscriptionController.getPhoneId(subId);
6333 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6334 Phone phone = PhoneFactory.getPhone(phoneId);
6335 if (phone != null) {
6336 boolean retVal = phone.isUserDataEnabled();
6337 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6338 return retVal;
6339 } else {
6340 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6341 return false;
6342 }
6343 } finally {
6344 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006345 }
6346 }
6347
6348 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006349 * Checks if the device is capable of mobile data by considering whether whether the
6350 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6351 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006352 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006353 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006354 */
6355 @Override
6356 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006357 try {
6358 try {
6359 mApp.enforceCallingOrSelfPermission(
6360 android.Manifest.permission.ACCESS_NETWORK_STATE,
6361 null);
6362 } catch (Exception e) {
6363 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6364 "isDataEnabled");
6365 }
6366 } catch (Exception e) {
6367 enforceReadPrivilegedPermission("isDataEnabled");
6368 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369
6370 final long identity = Binder.clearCallingIdentity();
6371 try {
6372 int phoneId = mSubscriptionController.getPhoneId(subId);
6373 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6374 Phone phone = PhoneFactory.getPhone(phoneId);
6375 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006376 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6378 return retVal;
6379 } else {
6380 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6381 return false;
6382 }
6383 } finally {
6384 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006385 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006386 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006387
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006388 /**
6389 * Check if data is enabled for a specific reason
6390 * @param subId Subscription index
6391 * @param reason the reason the data enable change is taking place
6392 * @return {@code true} if the overall data is enabled; {@code false} if not.
6393 */
6394 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006395 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006396 @TelephonyManager.DataEnabledReason int reason) {
6397 try {
6398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6399 null);
6400 } catch (Exception e) {
6401 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006402 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006403 }
6404
6405
6406 final long identity = Binder.clearCallingIdentity();
6407 try {
6408 int phoneId = mSubscriptionController.getPhoneId(subId);
6409 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006410 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006411 + " reason=" + reason);
6412 }
6413 Phone phone = PhoneFactory.getPhone(phoneId);
6414 if (phone != null) {
6415 boolean retVal;
6416 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6417 retVal = phone.isUserDataEnabled();
6418 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006419 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006420 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006421 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006422 return retVal;
6423 } else {
6424 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006425 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006426 + subId + " retVal=false");
6427 }
6428 return false;
6429 }
6430 } finally {
6431 Binder.restoreCallingIdentity(identity);
6432 }
6433 }
6434
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006435 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006436 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006437 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6438 // Skip the check if it's one of these special uids
6439 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6440 }
6441
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006442 //load access rules from carrier configs, and check those as well: b/139133814
6443 SubscriptionController subController = SubscriptionController.getInstance();
6444 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6445 || subController == null) return privilegeFromSim;
6446
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006447 PackageManager pkgMgr = phone.getContext().getPackageManager();
6448 String[] packages = pkgMgr.getPackagesForUid(uid);
6449
6450 final long identity = Binder.clearCallingIdentity();
6451 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006452 int subId = phone.getSubId();
6453 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6454 // A test override is in place for the privileges for this subId, so don't try to
6455 // read the subscription privileges.
6456 return privilegeFromSim;
6457 }
6458 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006459 SubscriptionManager subManager = (SubscriptionManager)
6460 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6461 for (String pkg : packages) {
6462 if (subManager.canManageSubscription(subInfo, pkg)) {
6463 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6464 }
6465 }
6466 return privilegeFromSim;
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
6469 }
6470 }
6471
6472 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6473 String pkgName) {
6474 //load access rules from carrier configs, and check those as well: b/139133814
6475 SubscriptionController subController = SubscriptionController.getInstance();
6476 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6477 || subController == null) return privilegeFromSim;
6478
6479 final long identity = Binder.clearCallingIdentity();
6480 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006481 int subId = phone.getSubId();
6482 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6483 // A test override is in place for the privileges for this subId, so don't try to
6484 // read the subscription privileges.
6485 return privilegeFromSim;
6486 }
6487 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006488 SubscriptionManager subManager = (SubscriptionManager)
6489 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6490 return subManager.canManageSubscription(subInfo, pkgName)
6491 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6492 } finally {
6493 Binder.restoreCallingIdentity(identity);
6494 }
6495 }
6496
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006497 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006498 public int getCarrierPrivilegeStatus(int subId) {
6499 final Phone phone = getPhone(subId);
6500 if (phone == null) {
6501 loge("getCarrierPrivilegeStatus: Invalid subId");
6502 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6503 }
6504 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006505 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006506 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006507 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6508 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006509
6510 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6511 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006512 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006513 }
Junda Liu29340342014-07-10 15:23:27 -07006514
6515 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006516 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006517 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006518 final Phone phone = getPhone(subId);
6519 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006520 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006521 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6522 }
6523 UiccProfile profile =
6524 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6525 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006526 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006527 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6528 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006529 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006530 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006531 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006532 }
6533
6534 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006535 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6536 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006537 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006538 }
6539
6540 int phoneId = SubscriptionManager.getPhoneId(subId);
6541 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006542 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006543 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006544 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6545 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006546 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6547 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6548 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006549 }
6550
6551 @Override
6552 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006553 if (TextUtils.isEmpty(pkgName))
6554 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006555 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6556 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6557 UiccCard card = UiccController.getInstance().getUiccCard(i);
6558 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006559 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006560 continue;
6561 }
6562
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006563 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6564 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6565 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006566 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6567 break;
6568 }
6569 }
6570
6571 return result;
Junda Liu29340342014-07-10 15:23:27 -07006572 }
Derek Tan89e89d42014-07-08 17:00:10 -07006573
6574 @Override
Junda Liue64de782015-04-16 17:19:16 -07006575 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6576 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6577 loge("phoneId " + phoneId + " is not valid.");
6578 return null;
6579 }
6580 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006581 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006582 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006583 return null ;
6584 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006585 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006586 }
6587
Amith Yamasani6e118872016-02-19 12:53:51 -08006588 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006589 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006590 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006591 List<String> privilegedPackages = new ArrayList<>();
6592 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006593 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6594 // has UICC in that slot.
6595 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006596 if (card.hasCarrierPrivilegeRules()) {
6597 if (packages == null) {
6598 // Only check packages in user 0 for now
6599 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006600 PackageManager.MATCH_DISABLED_COMPONENTS
6601 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006602 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006603 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006604 }
6605 for (int p = packages.size() - 1; p >= 0; p--) {
6606 PackageInfo pkgInfo = packages.get(p);
6607 if (pkgInfo != null && pkgInfo.packageName != null
6608 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006609 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006610 privilegedPackages.add(pkgInfo.packageName);
6611 }
6612 }
6613 }
6614 }
6615 return privilegedPackages;
6616 }
6617
chen xuf7e9fe82019-05-09 19:31:02 -07006618 @Override
6619 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006620 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6621
6622 final long identity = Binder.clearCallingIdentity();
6623
chen xuf7e9fe82019-05-09 19:31:02 -07006624 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006625 try {
6626 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6627 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6628 }
6629 } finally {
6630 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006631 }
6632 return privilegedPackages;
6633 }
6634
Wink Savilleb564aae2014-10-23 10:18:09 -07006635 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006636 final Phone phone = getPhone(subId);
6637 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006638 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006639 return null;
6640 }
6641 String iccId = card.getIccId();
6642 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006643 return null;
6644 }
6645 return iccId;
6646 }
6647
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006648 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006649 public void setCallComposerStatus(int subId, int status) {
6650 enforceModifyPermission();
6651
6652 final long identity = Binder.clearCallingIdentity();
6653 try {
6654 Phone phone = getPhone(subId);
6655 if (phone != null) {
6656 Phone defaultPhone = phone.getImsPhone();
6657 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6658 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6659 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006660 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6661 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006662 }
6663 }
Shuo Qian284ae752020-12-22 19:10:14 -08006664 } catch (ImsException e) {
6665 throw new ServiceSpecificException(e.getCode());
6666 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006667 Binder.restoreCallingIdentity(identity);
6668 }
6669 }
6670
6671 @Override
6672 public int getCallComposerStatus(int subId) {
6673 enforceReadPrivilegedPermission("getCallComposerStatus");
6674
6675 final long identity = Binder.clearCallingIdentity();
6676 try {
6677 Phone phone = getPhone(subId);
6678 if (phone != null) {
6679 Phone defaultPhone = phone.getImsPhone();
6680 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6681 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6682 return imsPhone.getCallComposerStatus();
6683 }
6684 }
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
6688 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6689 }
6690
6691 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006692 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6693 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006694 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006695 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 final long identity = Binder.clearCallingIdentity();
6698 try {
6699 final String iccId = getIccId(subId);
6700 final Phone phone = getPhone(subId);
6701 if (phone == null) {
6702 return false;
6703 }
6704 final String subscriberId = phone.getSubscriberId();
6705
6706 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006707 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 + subscriberId + " to " + number);
6709 }
6710
6711 if (TextUtils.isEmpty(iccId)) {
6712 return false;
6713 }
6714
6715 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6716
6717 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6718 if (alphaTag == null) {
6719 editor.remove(alphaTagPrefKey);
6720 } else {
6721 editor.putString(alphaTagPrefKey, alphaTag);
6722 }
6723
6724 // Record both the line number and IMSI for this ICCID, since we need to
6725 // track all merged IMSIs based on line number
6726 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6727 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6728 if (number == null) {
6729 editor.remove(numberPrefKey);
6730 editor.remove(subscriberPrefKey);
6731 } else {
6732 editor.putString(numberPrefKey, number);
6733 editor.putString(subscriberPrefKey, subscriberId);
6734 }
6735
6736 editor.commit();
6737 return true;
6738 } finally {
6739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006740 }
Derek Tan7226c842014-07-02 17:42:23 -07006741 }
6742
6743 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006744 public String getLine1NumberForDisplay(int subId, String callingPackage,
6745 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006746 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006748 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006749 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006750 return null;
6751 }
Derek Tan97ebb422014-09-05 16:55:38 -07006752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753 final long identity = Binder.clearCallingIdentity();
6754 try {
6755 String iccId = getIccId(subId);
6756 if (iccId != null) {
6757 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6758 if (DBG_MERGE) {
6759 log("getLine1NumberForDisplay returning "
6760 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6761 }
6762 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006764 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6765 return null;
6766 } finally {
6767 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006768 }
Derek Tan7226c842014-07-02 17:42:23 -07006769 }
6770
6771 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006772 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6773 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006775 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006776 return null;
6777 }
Derek Tan97ebb422014-09-05 16:55:38 -07006778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 final long identity = Binder.clearCallingIdentity();
6780 try {
6781 String iccId = getIccId(subId);
6782 if (iccId != null) {
6783 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6784 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6785 }
6786 return null;
6787 } finally {
6788 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006789 }
Derek Tan7226c842014-07-02 17:42:23 -07006790 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006791
6792 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006793 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6794 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006795 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6796 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006797 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006798 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006799 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006800 return null;
6801 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006802
Jordan Liub49b04b2019-05-06 14:45:15 -07006803 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6804 // the process, where TelephonyManager was instantiated.
6805 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006806 final long identity = Binder.clearCallingIdentity();
6807 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006808 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 final TelephonyManager tele = TelephonyManager.from(context);
6810 final SubscriptionManager sub = SubscriptionManager.from(context);
6811
6812 // Figure out what subscribers are currently active
6813 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814
Jordan Liub49b04b2019-05-06 14:45:15 -07006815 // Only consider subs which match the current subId
6816 // This logic can be simplified. See b/131189269 for progress.
6817 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006818 activeSubscriberIds.add(tele.getSubscriberId(subId));
6819 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820
6821 // First pass, find a number override for an active subscriber
6822 String mergeNumber = null;
6823 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6824 for (String key : prefs.keySet()) {
6825 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6826 final String subscriberId = (String) prefs.get(key);
6827 if (activeSubscriberIds.contains(subscriberId)) {
6828 final String iccId = key.substring(
6829 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6830 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6831 mergeNumber = (String) prefs.get(numberKey);
6832 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006833 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006834 + " for active subscriber " + subscriberId);
6835 }
6836 if (!TextUtils.isEmpty(mergeNumber)) {
6837 break;
6838 }
6839 }
6840 }
6841 }
6842
6843 // Shortcut when no active merged subscribers
6844 if (TextUtils.isEmpty(mergeNumber)) {
6845 return null;
6846 }
6847
6848 // Second pass, find all subscribers under that line override
6849 final ArraySet<String> result = new ArraySet<>();
6850 for (String key : prefs.keySet()) {
6851 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6852 final String number = (String) prefs.get(key);
6853 if (mergeNumber.equals(number)) {
6854 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6855 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6856 final String subscriberId = (String) prefs.get(subscriberKey);
6857 if (!TextUtils.isEmpty(subscriberId)) {
6858 result.add(subscriberId);
6859 }
6860 }
6861 }
6862 }
6863
6864 final String[] resultArray = result.toArray(new String[result.size()]);
6865 Arrays.sort(resultArray);
6866 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006867 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6869 }
6870 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006871 } finally {
6872 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006873 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006874 }
6875
6876 @Override
zoey chen38003472019-12-13 17:16:31 +08006877 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6878 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006879
6880 final long identity = Binder.clearCallingIdentity();
6881 try {
6882 final TelephonyManager telephonyManager = mApp.getSystemService(
6883 TelephonyManager.class);
6884 String subscriberId = telephonyManager.getSubscriberId(subId);
6885 if (subscriberId == null) {
6886 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006887 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006888 + subId);
6889 }
6890 return null;
6891 }
6892
6893 final SubscriptionInfo info = SubscriptionController.getInstance()
6894 .getSubscriptionInfo(subId);
6895 final ParcelUuid groupUuid = info.getGroupUuid();
6896 // If it doesn't belong to any group, return just subscriberId of itself.
6897 if (groupUuid == null) {
6898 return new String[]{subscriberId};
6899 }
6900
6901 // Get all subscriberIds from the group.
6902 final List<String> mergedSubscriberIds = new ArrayList<>();
6903 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006904 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006905 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006906 for (SubscriptionInfo subInfo : groupInfos) {
6907 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6908 if (subscriberId != null) {
6909 mergedSubscriberIds.add(subscriberId);
6910 }
6911 }
6912
6913 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6914 } finally {
6915 Binder.restoreCallingIdentity(identity);
6916
6917 }
6918 }
6919
6920 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006921 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006922 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006923 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006924
6925 final long identity = Binder.clearCallingIdentity();
6926 try {
6927 final Phone phone = getPhone(subId);
6928 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6929 } finally {
6930 Binder.restoreCallingIdentity(identity);
6931 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006932 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006933
6934 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006935 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006936 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6937 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006938 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6939 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006940
6941 final long identity = Binder.clearCallingIdentity();
6942 try {
6943 final Phone phone = getPhone(subId);
6944 if (phone == null) {
6945 return false;
6946 }
6947 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6948 cdmaNonRoamingList);
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006951 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006952 }
6953
6954 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006955 @Deprecated
6956 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6957 enforceModifyPermission();
6958
6959 int returnValue = 0;
6960 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006961 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006962 if(result.exception == null) {
6963 if (result.result != null) {
6964 byte[] responseData = (byte[])(result.result);
6965 if(responseData.length > oemResp.length) {
6966 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6967 responseData.length + "bytes. Buffer Size is " +
6968 oemResp.length + "bytes.");
6969 }
6970 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6971 returnValue = responseData.length;
6972 }
6973 } else {
6974 CommandException ex = (CommandException) result.exception;
6975 returnValue = ex.getCommandError().ordinal();
6976 if(returnValue > 0) returnValue *= -1;
6977 }
6978 } catch (RuntimeException e) {
6979 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6980 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6981 if(returnValue > 0) returnValue *= -1;
6982 }
6983
6984 return returnValue;
6985 }
6986
6987 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006988 public void setRadioCapability(RadioAccessFamily[] rafs) {
6989 try {
6990 ProxyController.getInstance().setRadioCapability(rafs);
6991 } catch (RuntimeException e) {
6992 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6993 }
6994 }
6995
6996 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006997 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006998 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006999 try {
7000 TelephonyPermissions
7001 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7002 mApp, phone.getSubId(), "getRadioAccessFamily");
7003 } catch (SecurityException e) {
7004 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7005 throw e;
7006 }
chen xub97461a2018-10-26 14:17:57 -07007007 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007008 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007009 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007011 final long identity = Binder.clearCallingIdentity();
7012 try {
chen xub97461a2018-10-26 14:17:57 -07007013 TelephonyPermissions
7014 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7015 mApp, phone.getSubId(), "getRadioAccessFamily");
7016 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017 } finally {
7018 Binder.restoreCallingIdentity(identity);
7019 }
chen xub97461a2018-10-26 14:17:57 -07007020 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007021 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007022
7023 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007024 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007025 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007026 try {
7027 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7028 Binder.getCallingUid())) {
7029 throw new SecurityException("Package uid and package name do not match: "
7030 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7031 }
7032 } catch (PackageManager.NameNotFoundException e) {
7033 throw new SecurityException("Package name invalid:" + callingPackage);
7034 }
7035 RoleManager rm = mApp.getSystemService(RoleManager.class);
7036 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7037 if (!dialerRoleHolders.contains(callingPackage)) {
7038 throw new SecurityException("App must be the dialer role holder to"
7039 + " upload a call composer pic");
7040 }
7041
7042 Executors.newSingleThreadExecutor().execute(() -> {
7043 ByteArrayOutputStream output = new ByteArrayOutputStream(
7044 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7045 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7046 boolean readUntilEnd = false;
7047 int totalBytesRead = 0;
7048 byte[] buffer = new byte[16 * 1024];
7049 while (true) {
7050 int numRead;
7051 try {
7052 numRead = input.read(buffer);
7053 } catch (IOException e) {
7054 try {
7055 fd.checkError();
7056 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7057 null);
7058 } catch (IOException e1) {
7059 // This means that the other side closed explicitly with an error. If this
7060 // happens, log and ignore.
7061 loge("Remote end of call composer picture pipe closed: " + e1);
7062 }
7063 break;
7064 }
7065 if (numRead == -1) {
7066 readUntilEnd = true;
7067 break;
7068 }
7069 totalBytesRead += numRead;
7070 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7071 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7072 try {
7073 input.close();
7074 } catch (IOException e) {
7075 // ignore
7076 }
7077 break;
7078 }
7079 output.write(buffer, 0, numRead);
7080 }
7081 // Generally, the remote end will close the file descriptors. The only case where we
7082 // close is above, where the picture size is too big.
7083
7084 try {
7085 fd.checkError();
7086 } catch (IOException e) {
7087 loge("Remote end for call composer closed with an error: " + e);
7088 return;
7089 }
7090
Hall Liuaa4211e2021-01-20 15:43:39 -08007091 if (!readUntilEnd) {
7092 loge("Did not finish reading entire image; aborting");
7093 return;
7094 }
Hall Liu82694d52020-12-11 18:22:04 -08007095
Hall Liuaa4211e2021-01-20 15:43:39 -08007096 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7097 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7098 new CallComposerPictureTransfer.Factory() {},
7099 imageData,
7100 (result) -> {
7101 if (result.first != null) {
7102 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7103 Bundle outputResult = new Bundle();
7104 outputResult.putParcelable(
7105 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7106 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7107 outputResult);
7108 } else {
7109 callback.send(result.second, null);
7110 }
7111 }
7112 );
Hall Liu82694d52020-12-11 18:22:04 -08007113 });
7114 }
7115
7116 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007117 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007118 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007119 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120
7121 final long identity = Binder.clearCallingIdentity();
7122 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007123 ImsManager.getInstance(defaultPhone.getContext(),
7124 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125 } finally {
7126 Binder.restoreCallingIdentity(identity);
7127 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007128 }
7129
7130 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007131 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007132 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7134 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007135 return false;
7136 }
Svet Ganovb320e182015-04-16 12:30:10 -07007137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 final long identity = Binder.clearCallingIdentity();
7139 try {
7140 // Check the user preference and the system-level IMS setting. Even if the user has
7141 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7142 // In the long run, we may instead need to check if there exists a connection service
7143 // which can support video calling.
7144 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007145 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146 return imsManager.isVtEnabledByPlatform()
7147 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7148 && imsManager.isVtEnabledByUser();
7149 } finally {
7150 Binder.restoreCallingIdentity(identity);
7151 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007152 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007153
Andrew Leea1239f22015-03-02 17:44:07 -08007154 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007155 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7156 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007158 mApp, subId, callingPackage, callingFeatureId,
7159 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 return false;
7161 }
7162
7163 final long identity = Binder.clearCallingIdentity();
7164 try {
7165 CarrierConfigManager configManager =
7166 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007167 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7169 } finally {
7170 Binder.restoreCallingIdentity(identity);
7171 }
Andrew Leea1239f22015-03-02 17:44:07 -08007172 }
7173
7174 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007175 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007177 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178 return false;
7179 }
7180
7181 final long identity = Binder.clearCallingIdentity();
7182 try {
7183 CarrierConfigManager configManager =
7184 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007185 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007186 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7187 } finally {
7188 Binder.restoreCallingIdentity(identity);
7189 }
Andrew Leea1239f22015-03-02 17:44:07 -08007190 }
7191
Andrew Lee9431b832015-03-09 18:46:45 -07007192 @Override
7193 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007194 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007195 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007196 }
7197
7198 @Override
7199 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 final long identity = Binder.clearCallingIdentity();
7201 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007202 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 } finally {
7204 Binder.restoreCallingIdentity(identity);
7205 }
Andrew Lee9431b832015-03-09 18:46:45 -07007206 }
7207
Hall Liuf6668912018-10-31 17:05:23 -07007208 /**
7209 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7210 * support for the feature and device firmware support.
7211 *
7212 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7213 */
7214 @Override
7215 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007217 final Phone phone = getPhone(subscriptionId);
7218 if (phone == null) {
7219 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7220 return false;
7221 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007223 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7225 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007226 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 return isCarrierSupported && isDeviceSupported;
7228 } finally {
7229 Binder.restoreCallingIdentity(identity);
7230 }
Hall Liu98187582018-01-22 19:15:32 -08007231 }
7232
Hall Liuf6668912018-10-31 17:05:23 -07007233 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007234 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7235 * RTT setting, will return true if the device and carrier both support RTT.
7236 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007237 */
7238 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 final long identity = Binder.clearCallingIdentity();
7240 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007241 boolean isRttSupported = isRttSupported(subscriptionId);
7242 boolean isUserRttSettingOn = Settings.Secure.getInt(
7243 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7244 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7245 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7246 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247 } finally {
7248 Binder.restoreCallingIdentity(identity);
7249 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007250 }
7251
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007252 @Deprecated
7253 @Override
7254 public String getDeviceId(String callingPackage) {
7255 return getDeviceIdWithFeature(callingPackage, null);
7256 }
7257
Sanket Padawe7310cc72015-01-14 09:53:20 -08007258 /**
7259 * Returns the unique device ID of phone, for example, the IMEI for
7260 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7261 *
7262 * <p>Requires Permission:
7263 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7264 */
7265 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007266 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007267 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007268 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007269 return null;
7270 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007271 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007272 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007273 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007274 return null;
7275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007276
7277 final long identity = Binder.clearCallingIdentity();
7278 try {
7279 return phone.getDeviceId();
7280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007283 }
7284
Ping Sunc67b7c22016-03-02 19:16:45 +08007285 /**
7286 * {@hide}
7287 * Returns the IMS Registration Status on a particular subid
7288 *
7289 * @param subId
7290 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007291 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007292 Phone phone = getPhone(subId);
7293 if (phone != null) {
7294 return phone.isImsRegistered();
7295 } else {
7296 return false;
7297 }
7298 }
7299
Santos Cordon7a1885b2015-02-03 11:15:19 -08007300 @Override
7301 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 final long identity = Binder.clearCallingIdentity();
7303 try {
7304 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7305 } finally {
7306 Binder.restoreCallingIdentity(identity);
7307 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007308 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007309
Tyler Gunnf70ed162019-04-03 15:28:53 -07007310 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007311 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007312 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007314 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007315 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7316 }
7317 final long identity = Binder.clearCallingIdentity();
7318 try {
7319 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7320 } finally {
7321 Binder.restoreCallingIdentity(identity);
7322 }
7323 }
7324
7325 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007326 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007327 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7328 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007329 final long identity = Binder.clearCallingIdentity();
7330 try {
7331 Phone phone = getPhone(subscriptionId);
7332 if (phone == null) {
7333 return null;
7334 }
7335 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
7339 }
7340
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007341 /**
7342 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007343 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007344 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 Phone phone = getPhone(subId);
7348 if (phone != null) {
7349 return phone.isWifiCallingEnabled();
7350 } else {
7351 return false;
7352 }
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007355 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007356 }
7357
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007358 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007359 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007360 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007361 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007362 final long identity = Binder.clearCallingIdentity();
7363 try {
7364 Phone phone = getPhone(subId);
7365 if (phone != null) {
7366 return phone.isVideoEnabled();
7367 } else {
7368 return false;
7369 }
7370 } finally {
7371 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007372 }
7373 }
7374
7375 /**
7376 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7377 * defined in {@link ImsRegistrationImplBase}.
7378 */
7379 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 final long identity = Binder.clearCallingIdentity();
7381 try {
7382 Phone phone = getPhone(subId);
7383 if (phone != null) {
7384 return phone.getImsRegistrationTech();
7385 } else {
7386 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7387 }
7388 } finally {
7389 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007390 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007391 }
7392
Stuart Scott8eef64f2015-04-08 15:13:54 -07007393 @Override
7394 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007395 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007396 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7397 return;
7398 }
7399
Svet Ganovcc087f82015-05-12 20:35:54 -07007400 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007401
Svet Ganovcc087f82015-05-12 20:35:54 -07007402 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007403 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7404 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007405 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007406 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007407 setNetworkSelectionModeAutomatic(subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007408 setAllowedNetworkTypesForReason(subId,
7409 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7410 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7411 setAllowedNetworkTypesForReason(subId,
7412 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7413 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7414 setAllowedNetworkTypesForReason(subId,
7415 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7416 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Yomna Nasser3f777b62021-02-17 03:38:52 +00007417 setAllowedNetworkTypesForReason(subId,
7418 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G,
7419 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007420 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7421 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007422 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007423 // There has been issues when Sms raw table somehow stores orphan
7424 // fragments. They lead to garbled message when new fragments come
7425 // in and combined with those stale ones. In case this happens again,
7426 // user can reset all network settings which will clean up this table.
7427 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007428 // Clean up IMS settings as well here.
7429 int slotId = getSlotIndex(subId);
7430 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7431 ImsManager.getInstance(mApp, slotId).factoryReset();
7432 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007433
7434 // Erase modem config if erase modem on network setting is enabled.
7435 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7436 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7437 if (configValue != null && Boolean.parseBoolean(configValue)) {
7438 sendEraseModemConfig(getDefaultPhone());
7439 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007440 } finally {
7441 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007442 }
7443 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007444
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007445 private void cleanUpSmsRawTable(Context context) {
7446 ContentResolver resolver = context.getContentResolver();
7447 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7448 resolver.delete(uri, null, null);
7449 }
7450
Narayan Kamath1c496c22015-04-16 14:40:19 +01007451 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007452 public String getSimLocaleForSubscriber(int subId) {
7453 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7454 final Phone phone = getPhone(subId);
7455 if (phone == null) {
7456 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007457 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007458 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 final long identity = Binder.clearCallingIdentity();
7460 try {
chen xu5d3637b2019-01-21 23:31:38 -08007461 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007462 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007463 if (info == null) {
7464 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7465 return null;
7466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 // Try and fetch the locale from the carrier properties or from the SIM language
7468 // preferences (EF-PL and EF-LI)...
7469 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007471 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7472 if (localeFromDefaultSim != null) {
7473 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7474 if (DBG) log("Using locale from subId: " + subId + " locale: "
7475 + localeFromDefaultSim);
7476 return localeFromDefaultSim.toLanguageTag();
7477 } else {
7478 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 }
7480 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 // The SIM language preferences only store a language (e.g. fr = French), not an
7483 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7484 // the SIM and carrier preferences does not include a country we add the country
7485 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007486 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007488 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 return mccLocale.toLanguageTag();
7490 }
7491
7492 if (DBG) log("No locale found - returning null");
7493 return null;
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007497 }
7498
7499 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007500 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007501 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007502 }
7503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 /**
7505 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7506 */
7507 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007508 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007509 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007510 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007511
Chenjie Yu1ba97252018-01-11 18:16:20 -08007512 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007513 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007514
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007515 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007516 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7517 * representing the state of the modem.
7518 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007519 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7520 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007521 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007522 */
7523 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007524 public void requestModemActivityInfo(ResultReceiver result) {
7525 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007526 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007530 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 } finally {
7532 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007533 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007534 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007535
Siddharth Rayb8114062018-06-17 15:02:38 -07007536 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7537 // less than total activity duration.
7538 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7539 if (info == null) {
7540 return false;
7541 }
7542 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007543 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7544 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7545
Siddharth Rayb8114062018-06-17 15:02:38 -07007546 return (info.isValid()
7547 && (info.getSleepTimeMillis() <= activityDurationMs)
7548 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007549 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007550 && (totalTxTimeMs <= activityDurationMs));
7551 }
7552
Jack Yu85bd38a2015-11-09 11:34:32 -08007553 /**
7554 * {@hide}
7555 * Returns the service state information on specified subscription.
7556 */
7557 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007558 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7559 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007561 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007562 return null;
7563 }
7564
Hall Liuf19c44f2018-11-27 14:38:17 -08007565 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7566 LocationAccessPolicy.checkLocationPermission(mApp,
7567 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7568 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007569 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007570 .setCallingPid(Binder.getCallingPid())
7571 .setCallingUid(Binder.getCallingUid())
7572 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007573 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007574 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007575 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7576 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007577 .build());
7578
7579 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7580 LocationAccessPolicy.checkLocationPermission(mApp,
7581 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7582 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007583 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007584 .setCallingPid(Binder.getCallingPid())
7585 .setCallingUid(Binder.getCallingUid())
7586 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007587 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007588 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007589 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7590 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007591 .build());
7592 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7593 boolean hasFinePermission =
7594 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7595 boolean hasCoarsePermission =
7596 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7597
Jack Yu479f40e2020-10-27 21:29:25 -07007598 final Phone phone = getPhone(subId);
7599 if (phone == null) {
7600 return null;
7601 }
7602
Jordan Liu0f2bc442020-11-18 16:47:37 -08007603 final long identity = Binder.clearCallingIdentity();
7604
Jack Yu479f40e2020-10-27 21:29:25 -07007605 boolean isCallingPackageDataService = phone.getDataServicePackages()
7606 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007607 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007608 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7609 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7610 Rlog.d(LOG_TAG,
7611 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7612 return null;
7613 }
7614
Hall Liuf19c44f2018-11-27 14:38:17 -08007615 ServiceState ss = phone.getServiceState();
7616
7617 // Scrub out the location info in ServiceState depending on what level of access
7618 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007619 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007620 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7621 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 } finally {
7623 Binder.restoreCallingIdentity(identity);
7624 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007625 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007626
7627 /**
7628 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7629 *
7630 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7631 * voicemail ringtone.
7632 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7633 * PhoneAccount.
7634 */
7635 @Override
7636 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007637 final long identity = Binder.clearCallingIdentity();
7638 try {
7639 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7640 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007641 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007642 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7645 } finally {
7646 Binder.restoreCallingIdentity(identity);
7647 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007648 }
7649
7650 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007651 * Sets the per-account voicemail ringtone.
7652 *
7653 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7654 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7655 *
7656 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7657 * voicemail ringtone.
7658 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7659 * PhoneAccount.
7660 */
7661 @Override
7662 public void setVoicemailRingtoneUri(String callingPackage,
7663 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007664 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007666 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7667 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7669 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7670 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672
7673 final long identity = Binder.clearCallingIdentity();
7674 try {
7675 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7676 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007677 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 }
7679 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7680 } finally {
7681 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007682 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007683 }
7684
7685 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007686 * Returns whether vibration is set for voicemail notification in Phone settings.
7687 *
7688 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7689 * voicemail vibration setting.
7690 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7691 */
7692 @Override
7693 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 final long identity = Binder.clearCallingIdentity();
7695 try {
7696 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7697 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007698 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007705 }
7706
Youhan Wange64578a2016-05-02 15:32:42 -07007707 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007708 * Sets the per-account voicemail vibration.
7709 *
7710 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7711 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7712 *
7713 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7714 * voicemail vibration setting.
7715 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7716 * specific PhoneAccount.
7717 */
7718 @Override
7719 public void setVoicemailVibrationEnabled(String callingPackage,
7720 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007721 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007723 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7724 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7726 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7727 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007728 }
7729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730 final long identity = Binder.clearCallingIdentity();
7731 try {
7732 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7733 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007734 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 }
7736 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7737 } finally {
7738 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007739 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007740 }
7741
7742 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007743 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7744 *
7745 * @throws SecurityException if the caller does not have the required permission
7746 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007747 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007748 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007749 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007750 }
7751
7752 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007753 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7754 * permission.
7755 *
7756 * @throws SecurityException if the caller does not have the required permission
7757 */
7758 private void enforceSendSmsPermission() {
7759 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7760 }
7761
7762 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007763 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007764 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007765 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007766 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007767 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007768 final long identity = Binder.clearCallingIdentity();
7769 try {
7770 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007771 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007772 if (componentName == null) {
7773 throw new SecurityException(
7774 "Caller not current active visual voicemail package[null]");
7775 }
7776 String vvmPackage = componentName.getPackageName();
7777 if (!callingPackage.equals(vvmPackage)) {
7778 throw new SecurityException("Caller not current active visual voicemail package["
7779 + vvmPackage + "]");
7780 }
7781 } finally {
7782 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007783 }
7784 }
7785
7786 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007787 * Return the application ID for the app type.
7788 *
7789 * @param subId the subscription ID that this request applies to.
7790 * @param appType the uicc app type.
7791 * @return Application ID for specificied app type, or null if no uicc.
7792 */
7793 @Override
7794 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007795 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007796 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797
7798 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007799 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 if (phone == null) {
7801 return null;
7802 }
7803 String aid = null;
7804 try {
7805 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7806 .getApplicationByType(appType).getAid();
7807 } catch (Exception e) {
7808 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7809 }
7810 return aid;
7811 } finally {
7812 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007813 }
Youhan Wange64578a2016-05-02 15:32:42 -07007814 }
7815
Youhan Wang4001d252016-05-11 10:29:41 -07007816 /**
7817 * Return the Electronic Serial Number.
7818 *
7819 * @param subId the subscription ID that this request applies to.
7820 * @return ESN or null if error.
7821 */
7822 @Override
7823 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007824 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007825 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826
7827 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007828 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829 if (phone == null) {
7830 return null;
7831 }
7832 String esn = null;
7833 try {
7834 esn = phone.getEsn();
7835 } catch (Exception e) {
7836 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7837 }
7838 return esn;
7839 } finally {
7840 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007841 }
Youhan Wang4001d252016-05-11 10:29:41 -07007842 }
7843
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007844 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007845 * Return the Preferred Roaming List Version.
7846 *
7847 * @param subId the subscription ID that this request applies to.
7848 * @return PRLVersion or null if error.
7849 */
7850 @Override
7851 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007852 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007853 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007854
7855 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007856 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 if (phone == null) {
7858 return null;
7859 }
7860 String cdmaPrlVersion = null;
7861 try {
7862 cdmaPrlVersion = phone.getCdmaPrlVersion();
7863 } catch (Exception e) {
7864 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7865 }
7866 return cdmaPrlVersion;
7867 } finally {
7868 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007869 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007870 }
7871
7872 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007873 * Get snapshot of Telephony histograms
7874 * @return List of Telephony histograms
7875 * @hide
7876 */
7877 @Override
7878 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7880 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007881
7882 final long identity = Binder.clearCallingIdentity();
7883 try {
7884 return RIL.getTelephonyRILTimingHistograms();
7885 } finally {
7886 Binder.restoreCallingIdentity(identity);
7887 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007888 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007889
7890 /**
7891 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007892 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7893 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007894 * Require system privileges. In the future we may add this to carrier APIs.
7895 *
Michele Berionne482f8202018-11-27 18:57:59 -08007896 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007897 */
7898 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007899 @TelephonyManager.SetCarrierRestrictionResult
7900 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007901 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007902 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007903
Michele Berionne482f8202018-11-27 18:57:59 -08007904 if (carrierRestrictionRules == null) {
7905 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007906 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007908 final long identity = Binder.clearCallingIdentity();
7909 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007910 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007911 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 } finally {
7913 Binder.restoreCallingIdentity(identity);
7914 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007915 }
7916
7917 /**
7918 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007919 * Get the allowed carrier list and the excluded carrier list, including the priority between
7920 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007921 * Require system privileges. In the future we may add this to carrier APIs.
7922 *
Michele Berionne482f8202018-11-27 18:57:59 -08007923 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007924 */
7925 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007926 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007927 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007928 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007929
7930 final long identity = Binder.clearCallingIdentity();
7931 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007932 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7933 if (response instanceof CarrierRestrictionRules) {
7934 return (CarrierRestrictionRules) response;
7935 }
7936 // Response is an Exception of some kind,
7937 // which is signalled to the user as a NULL retval
7938 return null;
7939 } catch (Exception e) {
7940 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7941 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942 } finally {
7943 Binder.restoreCallingIdentity(identity);
7944 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007945 }
7946
fionaxu59545b42016-05-25 15:53:37 -07007947 /**
fionaxu59545b42016-05-25 15:53:37 -07007948 * Action set from carrier signalling broadcast receivers to enable/disable radio
7949 * @param subId the subscription ID that this action applies to.
7950 * @param enabled control enable or disable radio.
7951 * {@hide}
7952 */
7953 @Override
7954 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7955 enforceModifyPermission();
7956 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957
7958 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007959 if (phone == null) {
7960 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7961 return;
7962 }
7963 try {
7964 phone.carrierActionSetRadioEnabled(enabled);
7965 } catch (Exception e) {
7966 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967 } finally {
7968 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007969 }
7970 }
7971
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007972 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007973 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7974 * network status based on which carrier apps could apply actions accordingly,
7975 * enable/disable default url handler for example.
7976 *
7977 * @param subId the subscription ID that this action applies to.
7978 * @param report control start/stop reporting the default network status.
7979 * {@hide}
7980 */
7981 @Override
7982 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7983 enforceModifyPermission();
7984 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985
7986 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007987 if (phone == null) {
7988 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7989 return;
7990 }
7991 try {
7992 phone.carrierActionReportDefaultNetworkStatus(report);
7993 } catch (Exception e) {
7994 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995 } finally {
7996 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007997 }
7998 }
7999
8000 /**
fionaxud9622282017-07-17 17:51:30 -07008001 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8002 * @param subId the subscription ID that this action applies to.
8003 * {@hide}
8004 */
8005 @Override
8006 public void carrierActionResetAll(int subId) {
8007 enforceModifyPermission();
8008 final Phone phone = getPhone(subId);
8009 if (phone == null) {
8010 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8011 return;
8012 }
8013 try {
8014 phone.carrierActionResetAll();
8015 } catch (Exception e) {
8016 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8017 }
8018 }
8019
8020 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008021 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8022 * bug report is being generated.
8023 */
8024 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008025 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008026 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8027 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008028 writer.println("Permission Denial: can't dump Phone from pid="
8029 + Binder.getCallingPid()
8030 + ", uid=" + Binder.getCallingUid()
8031 + "without permission "
8032 + android.Manifest.permission.DUMP);
8033 return;
8034 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008035 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008036 }
Jack Yueb89b242016-06-22 13:27:47 -07008037
Brad Ebingerdac2f002018-04-03 15:17:52 -07008038 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008039 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8040 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8041 @NonNull String[] args) {
8042 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8043 this, in.getFileDescriptor(), out.getFileDescriptor(),
8044 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008045 }
8046
Jack Yueb89b242016-06-22 13:27:47 -07008047 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008048 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008049 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008050 * @param reason the reason the data enable change is taking place
8051 * @param enabled True if enabling the data, otherwise disabling.
8052 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008053 */
8054 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008055 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008056 boolean enabled) {
8057 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8058 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8059 try {
8060 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008061 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008062 } catch (SecurityException se) {
8063 enforceModifyPermission();
8064 }
8065 } else {
8066 enforceModifyPermission();
8067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008068
8069 final long identity = Binder.clearCallingIdentity();
8070 try {
8071 Phone phone = getPhone(subId);
8072 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008073 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8074 phone.carrierActionSetMeteredApnsEnabled(enabled);
8075 } else {
8076 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8077 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078 }
8079 } finally {
8080 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008081 }
8082 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008083
8084 /**
8085 * Get Client request stats
8086 * @return List of Client Request Stats
8087 * @hide
8088 */
8089 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008090 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8091 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008093 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008094 return null;
8095 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008096 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098 final long identity = Binder.clearCallingIdentity();
8099 try {
8100 if (phone != null) {
8101 return phone.getClientRequestStats();
8102 }
8103
8104 return null;
8105 } finally {
8106 Binder.restoreCallingIdentity(identity);
8107 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008108 }
8109
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008110 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008111 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008112 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008113 }
Jack Yueb4124c2017-02-16 15:32:43 -08008114
8115 /**
Grace Chen70990072017-03-24 17:21:30 -07008116 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008117 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008118 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008119 * @param state State of SIM (power down, power up, pass through)
8120 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8121 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8122 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008123 *
8124 **/
8125 @Override
Grace Chen70990072017-03-24 17:21:30 -07008126 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008127 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008128 Phone phone = PhoneFactory.getPhone(slotIndex);
8129
vagdeviaf9a5b92018-08-15 16:01:53 -07008130 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132 final long identity = Binder.clearCallingIdentity();
8133 try {
8134 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008135 phone.setSimPowerState(state, null, workSource);
8136 }
8137 } finally {
8138 Binder.restoreCallingIdentity(identity);
8139 }
8140 }
8141
8142 /**
8143 * Set SIM card power state.
8144 *
8145 * @param slotIndex SIM slot id.
8146 * @param state State of SIM (power down, power up, pass through)
8147 * @param callback callback to trigger after success or failure
8148 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8149 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8150 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8151 *
8152 **/
8153 @Override
8154 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8155 IIntegerConsumer callback) {
8156 enforceModifyPermission();
8157 Phone phone = PhoneFactory.getPhone(slotIndex);
8158
8159 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8160
8161 final long identity = Binder.clearCallingIdentity();
8162 try {
8163 if (phone != null) {
8164 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8165 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008166 }
8167 } finally {
8168 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008169 }
8170 }
Shuo Qiandd210312017-04-12 22:11:33 +00008171
Tyler Gunn65d45c22017-06-05 11:22:26 -07008172 private boolean isUssdApiAllowed(int subId) {
8173 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008174 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008175 if (configManager == null) {
8176 return false;
8177 }
8178 PersistableBundle pb = configManager.getConfigForSubId(subId);
8179 if (pb == null) {
8180 return false;
8181 }
8182 return pb.getBoolean(
8183 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8184 }
8185
Shuo Qiandd210312017-04-12 22:11:33 +00008186 /**
8187 * Check if phone is in emergency callback mode
8188 * @return true if phone is in emergency callback mode
8189 * @param subId sub id
8190 */
goneil9c5f4872017-12-05 14:07:56 -08008191 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008192 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008193 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008194 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008195
8196 final long identity = Binder.clearCallingIdentity();
8197 try {
8198 if (phone != null) {
8199 return phone.isInEcm();
8200 } else {
8201 return false;
8202 }
8203 } finally {
8204 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008205 }
8206 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008207
8208 /**
8209 * Get the current signal strength information for the given subscription.
8210 * Because this information is not updated when the device is in a low power state
8211 * it should not be relied-upon to be current.
8212 * @param subId Subscription index
8213 * @return the most recent cached signal strength info from the modem
8214 */
8215 @Override
8216 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217 final long identity = Binder.clearCallingIdentity();
8218 try {
8219 Phone p = getPhone(subId);
8220 if (p == null) {
8221 return null;
8222 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 return p.getSignalStrength();
8225 } finally {
8226 Binder.restoreCallingIdentity(identity);
8227 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008228 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008229
Pengquan Meng77b7f132018-08-22 14:49:57 -07008230 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008231 * Get the current modem radio state for the given slot.
8232 * @param slotIndex slot index.
8233 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008234 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008235 * @return the current radio power state from the modem
8236 */
8237 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008238 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008239 Phone phone = PhoneFactory.getPhone(slotIndex);
8240 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8242 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008243 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8244 }
8245
8246 final long identity = Binder.clearCallingIdentity();
8247 try {
8248 return phone.getRadioPowerState();
8249 } finally {
8250 Binder.restoreCallingIdentity(identity);
8251 }
8252 }
8253 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8254 }
8255
8256 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008257 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8258 *
8259 * <p>Requires one of the following permissions:
8260 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8261 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8262 * privileges.
8263 *
8264 * @param subId subscription id
8265 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8266 * {@code false}.
8267 */
8268 @Override
8269 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008270 try {
8271 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8272 null);
8273 } catch (Exception e) {
8274 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8275 mApp, subId, "isDataRoamingEnabled");
8276 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008277
Pengquan Menga1bb6272018-09-06 09:59:22 -07008278 boolean isEnabled = false;
8279 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008280 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008281 Phone phone = getPhone(subId);
8282 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008283 } finally {
8284 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008285 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008286 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008287 }
8288
8289
8290 /**
8291 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8292 *
8293 * <p> Requires permission:
8294 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8295 * privileges.
8296 *
8297 * @param subId subscription id
8298 * @param isEnabled {@code true} means enable, {@code false} means disable.
8299 */
8300 @Override
8301 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8303 mApp, subId, "setDataRoamingEnabled");
8304
Pengquan Menga1bb6272018-09-06 09:59:22 -07008305 final long identity = Binder.clearCallingIdentity();
8306 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008307 Phone phone = getPhone(subId);
8308 if (phone != null) {
8309 phone.setDataRoamingEnabled(isEnabled);
8310 }
8311 } finally {
8312 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008313 }
8314 }
8315
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008316 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008317 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008318 TelephonyPermissions
8319 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008320 mApp, subId, "isManualNetworkSelectionAllowed");
8321
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008322 boolean isAllowed = true;
8323 final long identity = Binder.clearCallingIdentity();
8324 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008325 Phone phone = getPhone(subId);
8326 if (phone != null) {
8327 isAllowed = phone.isCspPlmnEnabled();
8328 }
8329 } finally {
8330 Binder.restoreCallingIdentity(identity);
8331 }
8332 return isAllowed;
8333 }
8334
8335 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008336 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008337 // Verify that tha callingPackage belongs to the calling UID
8338 mApp.getSystemService(AppOpsManager.class)
8339 .checkPackage(Binder.getCallingUid(), callingPackage);
8340
Jordan Liu1e142fc2019-04-22 15:10:43 -07008341 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008342 try {
8343 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008344 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008345 } catch (SecurityException e) {
8346 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8347 // has carrier privileges on an active UICC
8348 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8349 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008350 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008351 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008352 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008353
8354 final long identity = Binder.clearCallingIdentity();
8355 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008356 UiccController uiccController = UiccController.getInstance();
8357 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008358 if (hasReadPermission) {
8359 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008360 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008361
8362 // Remove private info if the caller doesn't have access
8363 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8364 for (UiccCardInfo cardInfo : cardInfos) {
8365 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8366 // is available
8367 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8368 if (card == null || card.getUiccProfile() == null) {
8369 // assume no access if the card or profile is unavailable
8370 filteredInfos.add(cardInfo.getUnprivileged());
8371 continue;
8372 }
8373 UiccProfile profile = card.getUiccProfile();
8374 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8375 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8376 filteredInfos.add(cardInfo);
8377 } else {
8378 filteredInfos.add(cardInfo.getUnprivileged());
8379 }
8380 }
8381 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
8385 }
8386
8387 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008388 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008389 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8394 if (slots == null) {
8395 Rlog.i(LOG_TAG, "slots is null.");
8396 return null;
8397 }
8398
8399 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8400 for (int i = 0; i < slots.length; i++) {
8401 UiccSlot slot = slots[i];
8402 if (slot == null) {
8403 continue;
8404 }
8405
Jordan Liu7be7e652019-05-06 18:55:02 +00008406 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 UiccCard card = slot.getUiccCard();
8408 if (card != null) {
8409 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008410 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008411 cardId = slot.getEid();
8412 if (TextUtils.isEmpty(cardId)) {
8413 cardId = slot.getIccId();
8414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008415 }
8416
Jordan Liu857451f2019-05-09 16:35:35 -07008417 if (cardId != null) {
8418 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8419 // if cardId is an EID, it's all digits so this is fine
8420 cardId = IccUtils.stripTrailingFs(cardId);
8421 }
8422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008423 int cardState = 0;
8424 switch (slot.getCardState()) {
8425 case CARDSTATE_ABSENT:
8426 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8427 break;
8428 case CARDSTATE_PRESENT:
8429 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8430 break;
8431 case CARDSTATE_ERROR:
8432 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8433 break;
8434 case CARDSTATE_RESTRICTED:
8435 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8436 break;
8437 default:
8438 break;
8439
8440 }
8441
8442 infos[i] = new UiccSlotInfo(
8443 slot.isActive(),
8444 slot.isEuicc(),
8445 cardId,
8446 cardState,
8447 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008448 slot.isExtendedApduSupported(),
8449 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450 }
8451 return infos;
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008454 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008455 }
8456
8457 @Override
8458 public boolean switchSlots(int[] physicalSlots) {
8459 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008460
8461 final long identity = Binder.clearCallingIdentity();
8462 try {
8463 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8464 } finally {
8465 Binder.restoreCallingIdentity(identity);
8466 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008467 }
Jack Yu4c988042018-02-27 15:30:01 -08008468
8469 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008470 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008471 final long identity = Binder.clearCallingIdentity();
8472 try {
8473 return UiccController.getInstance().getCardIdForDefaultEuicc();
8474 } finally {
8475 Binder.restoreCallingIdentity(identity);
8476 }
8477 }
8478
Pengquan Meng85728fb2018-03-12 16:31:21 -07008479 /**
goneil47ffb6e2018-04-06 15:40:58 -07008480 * A test API to reload the UICC profile.
8481 *
8482 * <p>Requires that the calling app has permission
8483 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8484 * @hide
8485 */
8486 @Override
8487 public void refreshUiccProfile(int subId) {
8488 enforceModifyPermission();
8489
8490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 Phone phone = getPhone(subId);
8493 if (phone == null) {
8494 return;
8495 }
8496 UiccCard uiccCard = phone.getUiccCard();
8497 if (uiccCard == null) {
8498 return;
8499 }
8500 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8501 if (uiccProfile == null) {
8502 return;
8503 }
8504 uiccProfile.refresh();
8505 } finally {
8506 Binder.restoreCallingIdentity(identity);
8507 }
8508 }
8509
8510 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008511 * Returns false if the mobile data is disabled by default, otherwise return true.
8512 */
8513 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008514 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008515 }
8516
8517 /**
8518 * Returns true if the data roaming is enabled by default, i.e the system property
8519 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8520 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8521 */
8522 private boolean getDefaultDataRoamingEnabled(int subId) {
8523 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008524 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008525 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008526 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8527 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8528 return isDataRoamingEnabled;
8529 }
8530
8531 /**
8532 * Returns the default network type for the given {@code subId}, if the default network type is
8533 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8534 */
8535 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008536 List<Integer> list = TelephonyProperties.default_network();
8537 int phoneId = mSubscriptionController.getPhoneId(subId);
8538 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8539 return list.get(phoneId);
8540 }
8541 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008542 }
fionaxua13278b2018-03-21 00:08:13 -07008543
8544 @Override
8545 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008546 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008547 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008548
8549 final long identity = Binder.clearCallingIdentity();
8550 try {
8551 final Phone phone = getPhone(subId);
8552 if (phone == null) {
8553 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8554 return;
8555 }
chen xueaba88a2019-03-15 13:15:10 -07008556 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8557 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008558 if (carrierPrivilegeRules == null) {
8559 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8560 } else {
8561 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008563 } finally {
8564 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008565 }
fionaxua13278b2018-03-21 00:08:13 -07008566 }
8567
8568 @Override
8569 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008570 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571
8572 final long identity = Binder.clearCallingIdentity();
8573 try {
8574 final Phone phone = getPhone(subId);
8575 if (phone == null) {
8576 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8577 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8578 }
8579 return phone.getCarrierIdListVersion();
8580 } finally {
8581 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008582 }
fionaxua13278b2018-03-21 00:08:13 -07008583 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008584
8585 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008586 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8587 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008589 mApp, subId, callingPackage, callingFeatureId,
8590 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008591 return -1;
8592 }
8593
8594 final long identity = Binder.clearCallingIdentity();
8595 try {
8596 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8597 } finally {
8598 Binder.restoreCallingIdentity(identity);
8599 }
8600 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008601
8602 @Override
8603 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008604 TelephonyPermissions
8605 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008606 mApp, subId, "getCdmaRoamingMode");
8607
8608 final long identity = Binder.clearCallingIdentity();
8609 try {
8610 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8611 } finally {
8612 Binder.restoreCallingIdentity(identity);
8613 }
8614 }
8615
8616 @Override
8617 public boolean setCdmaRoamingMode(int subId, int mode) {
8618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8619 mApp, subId, "setCdmaRoamingMode");
8620
8621 final long identity = Binder.clearCallingIdentity();
8622 try {
8623 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8624 } finally {
8625 Binder.restoreCallingIdentity(identity);
8626 }
8627 }
8628
8629 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008630 public int getCdmaSubscriptionMode(int subId) {
8631 TelephonyPermissions
8632 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8633 mApp, subId, "getCdmaSubscriptionMode");
8634
8635 final long identity = Binder.clearCallingIdentity();
8636 try {
8637 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8638 } finally {
8639 Binder.restoreCallingIdentity(identity);
8640 }
8641 }
8642
8643 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008644 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8646 mApp, subId, "setCdmaSubscriptionMode");
8647
8648 final long identity = Binder.clearCallingIdentity();
8649 try {
8650 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8651 } finally {
8652 Binder.restoreCallingIdentity(identity);
8653 }
8654 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008655
sqianc5eccab2018-10-19 18:46:41 -07008656 @Override
sqian8c685422019-02-22 15:55:18 -08008657 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008658 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008660 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8661 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008662 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8663 }
8664 final long identity = Binder.clearCallingIdentity();
8665 try {
sqian854d44b2018-12-12 16:48:18 -08008666 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8667 for (Phone phone: PhoneFactory.getPhones()) {
8668 if (phone.getEmergencyNumberTracker() != null
8669 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8670 emergencyNumberListInternal.put(
8671 phone.getSubId(),
8672 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8673 }
sqian11b7a0e2018-12-05 18:48:28 -08008674 }
sqian854d44b2018-12-12 16:48:18 -08008675 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008676 } finally {
8677 Binder.restoreCallingIdentity(identity);
8678 }
sqianc5eccab2018-10-19 18:46:41 -07008679 }
8680
8681 @Override
sqian8c685422019-02-22 15:55:18 -08008682 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008683 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008684 if (!exactMatch) {
8685 TelephonyPermissions
8686 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008687 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008688 }
8689 final long identity = Binder.clearCallingIdentity();
8690 try {
sqian854d44b2018-12-12 16:48:18 -08008691 for (Phone phone: PhoneFactory.getPhones()) {
8692 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008693 && phone.getEmergencyNumberTracker()
8694 .isEmergencyNumber(number, exactMatch)) {
8695 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008696 }
sqian11b7a0e2018-12-05 18:48:28 -08008697 }
8698 return false;
8699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
8702 }
8703
sqianf4ca7ed2019-01-15 18:32:07 -08008704 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008705 * Start emergency callback mode for GsmCdmaPhone for testing.
8706 */
8707 @Override
8708 public void startEmergencyCallbackMode() {
8709 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8710 "startEmergencyCallbackMode");
8711 enforceModifyPermission();
8712 final long identity = Binder.clearCallingIdentity();
8713 try {
8714 for (Phone phone : PhoneFactory.getPhones()) {
8715 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8716 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8717 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8718 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8719 gsmCdmaPhone.obtainMessage(
8720 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8721 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8722 }
8723 }
8724 } finally {
8725 Binder.restoreCallingIdentity(identity);
8726 }
8727 }
8728
8729 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008730 * Update emergency number list for test mode.
8731 */
8732 @Override
8733 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8734 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8735 "updateEmergencyNumberListTestMode");
8736
8737 final long identity = Binder.clearCallingIdentity();
8738 try {
8739 for (Phone phone: PhoneFactory.getPhones()) {
8740 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8741 if (tracker != null) {
8742 tracker.executeEmergencyNumberTestModeCommand(action, num);
8743 }
8744 }
8745 } finally {
8746 Binder.restoreCallingIdentity(identity);
8747 }
8748 }
8749
8750 /**
8751 * Get the full emergency number list for test mode.
8752 */
8753 @Override
8754 public List<String> getEmergencyNumberListTestMode() {
8755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8756 "getEmergencyNumberListTestMode");
8757
8758 final long identity = Binder.clearCallingIdentity();
8759 try {
8760 Set<String> emergencyNumbers = new HashSet<>();
8761 for (Phone phone: PhoneFactory.getPhones()) {
8762 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8763 if (tracker != null) {
8764 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8765 emergencyNumbers.add(num.getNumber());
8766 }
8767 }
8768 }
8769 return new ArrayList<>(emergencyNumbers);
8770 } finally {
8771 Binder.restoreCallingIdentity(identity);
8772 }
8773 }
8774
chen xud6b45bd2018-10-30 22:27:10 -07008775 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008776 public int getEmergencyNumberDbVersion(int subId) {
8777 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8778
8779 final long identity = Binder.clearCallingIdentity();
8780 try {
8781 final Phone phone = getPhone(subId);
8782 if (phone == null) {
8783 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8784 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8785 }
8786 return phone.getEmergencyNumberDbVersion();
8787 } finally {
8788 Binder.restoreCallingIdentity(identity);
8789 }
8790 }
8791
8792 @Override
8793 public void notifyOtaEmergencyNumberDbInstalled() {
8794 enforceModifyPermission();
8795
8796 final long identity = Binder.clearCallingIdentity();
8797 try {
8798 for (Phone phone: PhoneFactory.getPhones()) {
8799 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8800 if (tracker != null) {
8801 tracker.updateOtaEmergencyNumberDatabase();
8802 }
8803 }
8804 } finally {
8805 Binder.restoreCallingIdentity(identity);
8806 }
8807 }
8808
8809 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008810 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008811 enforceActiveEmergencySessionPermission();
8812
8813 final long identity = Binder.clearCallingIdentity();
8814 try {
8815 for (Phone phone: PhoneFactory.getPhones()) {
8816 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8817 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008818 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8819 }
8820 }
8821 } finally {
8822 Binder.restoreCallingIdentity(identity);
8823 }
8824 }
8825
8826 @Override
8827 public void resetOtaEmergencyNumberDbFilePath() {
8828 enforceActiveEmergencySessionPermission();
8829
8830 final long identity = Binder.clearCallingIdentity();
8831 try {
8832 for (Phone phone: PhoneFactory.getPhones()) {
8833 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8834 if (tracker != null) {
8835 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008836 }
8837 }
8838 } finally {
8839 Binder.restoreCallingIdentity(identity);
8840 }
8841 }
8842
8843 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008844 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8845 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8846 Phone phone = getPhone(subId);
8847 if (phone == null) {
8848 return null;
8849 }
8850 final long identity = Binder.clearCallingIdentity();
8851 try {
8852 UiccProfile profile = UiccController.getInstance()
8853 .getUiccProfileForPhone(phone.getPhoneId());
8854 if (profile != null) {
8855 return profile.getCertsFromCarrierPrivilegeAccessRules();
8856 }
8857 } finally {
8858 Binder.restoreCallingIdentity(identity);
8859 }
8860 return null;
8861 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008862
8863 /**
8864 * Enable or disable a modem stack.
8865 */
8866 @Override
8867 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8868 enforceModifyPermission();
8869
8870 final long identity = Binder.clearCallingIdentity();
8871 try {
8872 Phone phone = PhoneFactory.getPhone(slotIndex);
8873 if (phone == null) {
8874 return false;
8875 } else {
8876 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8877 }
8878 } finally {
8879 Binder.restoreCallingIdentity(identity);
8880 }
8881 }
Michelecea4cf22018-12-21 15:00:11 -08008882
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008883 /**
8884 * Whether a modem stack is enabled or not.
8885 */
8886 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008887 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8888 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008889 Phone phone = PhoneFactory.getPhone(slotIndex);
8890 if (phone == null) return false;
8891
8892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008893 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8894 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008895 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8896 }
8897
8898 final long identity = Binder.clearCallingIdentity();
8899 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008900 try {
8901 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8902 } catch (NoSuchElementException ex) {
8903 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8904 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008905 } finally {
8906 Binder.restoreCallingIdentity(identity);
8907 }
8908 }
8909
Michelecea4cf22018-12-21 15:00:11 -08008910 @Override
Michele0ea7d782019-03-19 14:58:42 -07008911 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008912 enforceModifyPermission();
8913
8914 final long identity = Binder.clearCallingIdentity();
8915 try {
8916 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008917 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008918 .commit();
8919 } finally {
8920 Binder.restoreCallingIdentity(identity);
8921 }
8922 }
8923
8924 @Override
Michele0ea7d782019-03-19 14:58:42 -07008925 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008926 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008927 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008928 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8929 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008930 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008931 }
Michelecea4cf22018-12-21 15:00:11 -08008932
8933 final long identity = Binder.clearCallingIdentity();
8934 try {
Michele0ea7d782019-03-19 14:58:42 -07008935 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008936 } finally {
8937 Binder.restoreCallingIdentity(identity);
8938 }
8939 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008940
Michele0ea7d782019-03-19 14:58:42 -07008941 @TelephonyManager.IsMultiSimSupportedResult
8942 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008943 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8944 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8945 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008946 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8947 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008948 }
8949 // Check if the hardware supports multisim functionality. If usage of multisim is not
8950 // supported by the modem, indicate that it is restricted.
8951 PhoneCapability staticCapability =
8952 mPhoneConfigurationManager.getStaticPhoneCapability();
8953 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008954 loge("isMultiSimSupportedInternal: no static configuration available");
8955 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008956 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008957 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008958 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8959 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008960 }
8961 // Check if support of multiple SIMs is restricted by carrier
8962 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008963 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008964 }
8965
Michele0ea7d782019-03-19 14:58:42 -07008966 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008967 }
8968
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008969 /**
8970 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008971 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8972 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8973 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008974 * @param numOfSims number of active sims we want to switch to
8975 */
8976 @Override
8977 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008978 if (numOfSims == 1) {
8979 enforceModifyPermission();
8980 } else {
8981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8982 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8983 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008984 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008985
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008986 try {
Michele30b57b22019-03-01 12:01:14 -08008987 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008988 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008989 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8990 return;
8991 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008992 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8993 } finally {
8994 Binder.restoreCallingIdentity(identity);
8995 }
8996 }
8997
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008998 @Override
8999 public boolean isApplicationOnUicc(int subId, int appType) {
9000 enforceReadPrivilegedPermission("isApplicationOnUicc");
9001 Phone phone = getPhone(subId);
9002 if (phone == null) {
9003 return false;
9004 }
9005 final long identity = Binder.clearCallingIdentity();
9006 try {
9007 UiccCard uiccCard = phone.getUiccCard();
9008 if (uiccCard == null) {
9009 return false;
9010 }
9011 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9012 if (uiccProfile == null) {
9013 return false;
9014 }
9015 if (TelephonyManager.APPTYPE_SIM <= appType
9016 && appType <= TelephonyManager.APPTYPE_ISIM) {
9017 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9018 }
9019 return false;
9020 } finally {
9021 Binder.restoreCallingIdentity(identity);
9022 }
9023 }
9024
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009025 /**
chen xub4baa772019-04-03 10:23:41 -07009026 * Get whether making changes to modem configurations will trigger reboot.
9027 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009028 */
9029 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009030 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9031 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009033 mApp, subId, callingPackage, callingFeatureId,
9034 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009035 return false;
9036 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009037 final long identity = Binder.clearCallingIdentity();
9038 try {
9039 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9040 } finally {
9041 Binder.restoreCallingIdentity(identity);
9042 }
9043 }
9044
Nathan Harold29f5f052019-02-15 13:41:57 -08009045 private void updateModemStateMetrics() {
9046 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9047 // TODO: check the state for each modem if the api is ready.
9048 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9049 }
9050
Pengquan Meng3889a572019-01-23 11:16:29 -08009051 @Override
9052 public int[] getSlotsMapping() {
9053 enforceReadPrivilegedPermission("getSlotsMapping");
9054
9055 final long identity = Binder.clearCallingIdentity();
9056 try {
9057 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9058 // All logical slots should have a mapping to a physical slot.
9059 int[] logicalSlotsMapping = new int[phoneCount];
9060 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9061 for (int i = 0; i < slotInfos.length; i++) {
9062 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9063 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9064 }
9065 }
9066 return logicalSlotsMapping;
9067 } finally {
9068 Binder.restoreCallingIdentity(identity);
9069 }
9070 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009071
9072 /**
9073 * Get the IRadio HAL Version
9074 */
9075 @Override
9076 public int getRadioHalVersion() {
9077 Phone phone = getDefaultPhone();
9078 if (phone == null) return -1;
9079 HalVersion hv = phone.getHalVersion();
9080 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9081 return hv.major * 100 + hv.minor;
9082 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009083
9084 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009085 * Get the current calling package name.
9086 * @return the current calling package name
9087 */
9088 @Override
9089 public String getCurrentPackageName() {
9090 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9091 }
9092
9093 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009094 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9095 * corresponding network requests on a subId.
9096 *
9097 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009098 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009099 * 2) APN is un-metered for this subscription, or
9100 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009101 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009102 *
9103 * @return whether data is allowed for a apn type.
9104 *
9105 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009106 */
9107 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009108 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009109 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9110 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009111
9112 // Now that all security checks passes, perform the operation as ourselves.
9113 final long identity = Binder.clearCallingIdentity();
9114 try {
9115 Phone phone = getPhone(subId);
9116 if (phone == null) return false;
9117
Jack Yu41407ee2019-05-13 16:54:09 -07009118 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009119 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9120 } finally {
9121 Binder.restoreCallingIdentity(identity);
9122 }
9123 }
9124
9125 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009126 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009127 enforceReadPrivilegedPermission("isApnMetered");
9128
9129 // Now that all security checks passes, perform the operation as ourselves.
9130 final long identity = Binder.clearCallingIdentity();
9131 try {
9132 Phone phone = getPhone(subId);
9133 if (phone == null) return true; // By default return true.
9134
Jack Yu41407ee2019-05-13 16:54:09 -07009135 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009136 } finally {
9137 Binder.restoreCallingIdentity(identity);
9138 }
9139 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009140
9141 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009142 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9143 int subscriptionId, IBooleanConsumer resultCallback) {
9144 enforceModifyPermission();
9145 long token = Binder.clearCallingIdentity();
9146 try {
9147 Phone phone = getPhone(subscriptionId);
9148 if (phone == null) {
9149 try {
9150 if (resultCallback != null) {
9151 resultCallback.accept(false);
9152 }
9153 } catch (RemoteException e) {
9154 // ignore
9155 }
9156 return;
9157 }
9158 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9159 Pair.create(specifiers, (x) -> {
9160 try {
9161 if (resultCallback != null) {
9162 resultCallback.accept(x);
9163 }
9164 } catch (RemoteException e) {
9165 // ignore
9166 }
9167 });
9168 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9169 } finally {
9170 Binder.restoreCallingIdentity(token);
9171 }
9172 }
9173
9174 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009175 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9176 TelephonyPermissions
9177 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9178 mApp, subId, "getSystemSelectionChannels");
9179 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9180 final long identity = Binder.clearCallingIdentity();
9181 try {
9182 List<RadioAccessSpecifier> specifiers =
9183 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9184 null, subId, workSource);
9185 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9186 return specifiers;
9187 } finally {
9188 Binder.restoreCallingIdentity(identity);
9189 }
9190 }
9191
9192 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009193 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009194 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009195 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9196 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9197 if (iccRecords == null) {
9198 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9199 return false;
9200 }
9201 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9202 }
9203
9204 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009205 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9206 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009207 if (callingPackage == null) {
9208 callingPackage = getCurrentPackageName();
9209 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009210 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9211 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009212 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9213 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009214 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9215 }
9216 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9217 Intent intent = new Intent();
9218 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9219 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9220 // Bring up choose default SMS subscription dialog right now
9221 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9222 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9223 mApp.startActivity(intent);
9224 }
chen xud5ca2d52019-05-28 15:20:57 -07009225
9226 @Override
9227 public String getMmsUAProfUrl(int subId) {
9228 //TODO investigate if this API should require proper permission check in R b/133791609
9229 final long identity = Binder.clearCallingIdentity();
9230 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009231 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9232 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9233 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9234 return carrierUAProfUrl;
9235 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009236 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9237 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009238 } finally {
9239 Binder.restoreCallingIdentity(identity);
9240 }
9241 }
9242
9243 @Override
9244 public String getMmsUserAgent(int subId) {
9245 //TODO investigate if this API should require proper permission check in R b/133791609
9246 final long identity = Binder.clearCallingIdentity();
9247 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009248 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9249 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9250 if (!TextUtils.isEmpty(carrierUserAgent)) {
9251 return carrierUserAgent;
9252 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009253 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9254 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009255 } finally {
9256 Binder.restoreCallingIdentity(identity);
9257 }
9258 }
Jack Yub07d4972019-05-28 16:12:25 -07009259
9260 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009261 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9262 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009263
Jack Yub07d4972019-05-28 16:12:25 -07009264 final long identity = Binder.clearCallingIdentity();
9265 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009266 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009267 if (phone == null) return false;
9268
Hall Liua62f5da2020-09-25 10:42:19 -07009269 switch (policy) {
9270 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9271 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9272 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9273 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9274 default:
9275 throw new IllegalArgumentException(policy + " is not a valid policy");
9276 }
Jack Yub07d4972019-05-28 16:12:25 -07009277 } finally {
9278 Binder.restoreCallingIdentity(identity);
9279 }
9280 }
9281
9282 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009283 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009284 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009285 enforceModifyPermission();
9286
changbettyd5c246e2019-12-24 15:40:37 +08009287 final long identity = Binder.clearCallingIdentity();
9288 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009289 Phone phone = getPhone(subscriptionId);
9290 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009291
Hall Liua62f5da2020-09-25 10:42:19 -07009292 switch (policy) {
9293 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9294 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9295 break;
9296 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9297 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9298 break;
9299 default:
9300 throw new IllegalArgumentException(policy + " is not a valid policy");
9301 }
changbettyd5c246e2019-12-24 15:40:37 +08009302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 }
9306
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009307 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009308 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009309 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9310 * otherwise.
9311 */
9312 @Override
9313 public void setCepEnabled(boolean isCepEnabled) {
9314 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9315
9316 final long identity = Binder.clearCallingIdentity();
9317 try {
9318 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9319 for (Phone phone : PhoneFactory.getPhones()) {
9320 Phone defaultPhone = phone.getImsPhone();
9321 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9322 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9323 ImsPhoneCallTracker imsPhoneCallTracker =
9324 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9325 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9326 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9327 + imsPhone.getMsisdn());
9328 }
9329 }
9330 } finally {
9331 Binder.restoreCallingIdentity(identity);
9332 }
9333 }
allenwtsu46dcc572020-01-08 18:24:03 +08009334
9335 /**
9336 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9337 *
9338 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9339 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9340 * before being read.
9341 */
9342 @Override
9343 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9344 isCompressed) {
9345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9346 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009347 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9348 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9349 }
9350 if (!isImsAvailableOnDevice()) {
9351 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9352 "IMS not available on device.");
9353 }
9354
9355 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009356 try {
Hui Wang761a6682020-10-31 05:12:53 +00009357 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9358 } finally {
9359 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009360 }
9361 }
zoey chene02881a2019-12-30 16:11:23 +08009362
9363 @Override
9364 public boolean isIccLockEnabled(int subId) {
9365 enforceReadPrivilegedPermission("isIccLockEnabled");
9366
9367 // Now that all security checks passes, perform the operation as ourselves.
9368 final long identity = Binder.clearCallingIdentity();
9369 try {
9370 Phone phone = getPhone(subId);
9371 if (phone != null && phone.getIccCard() != null) {
9372 return phone.getIccCard().getIccLockEnabled();
9373 } else {
9374 return false;
9375 }
9376 } finally {
9377 Binder.restoreCallingIdentity(identity);
9378 }
9379 }
9380
9381 /**
9382 * Set the ICC pin lock enabled or disabled.
9383 *
9384 * @return an integer representing the status of IccLock enabled or disabled in the following
9385 * three cases:
9386 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9387 * successfully.
9388 * - Positive number and zero for remaining password attempts.
9389 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9390 *
9391 */
9392 @Override
9393 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9394 enforceModifyPermission();
9395
9396 Phone phone = getPhone(subId);
9397 if (phone == null) {
9398 return 0;
9399 }
9400 // Now that all security checks passes, perform the operation as ourselves.
9401 final long identity = Binder.clearCallingIdentity();
9402 try {
9403 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9404 new Pair<Boolean, String>(enabled, password), phone, null);
9405 return attemptsRemaining;
9406
9407 } catch (Exception e) {
9408 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9409 } finally {
9410 Binder.restoreCallingIdentity(identity);
9411 }
9412 return 0;
9413 }
9414
9415 /**
9416 * Change the ICC password used in ICC pin lock.
9417 *
9418 * @return an integer representing the status of IccLock changed in the following three cases:
9419 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9420 * - Positive number and zero for remaining password attempts.
9421 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9422 *
9423 */
9424 @Override
9425 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9426 enforceModifyPermission();
9427
9428 Phone phone = getPhone(subId);
9429 if (phone == null) {
9430 return 0;
9431 }
9432 // Now that all security checks passes, perform the operation as ourselves.
9433 final long identity = Binder.clearCallingIdentity();
9434 try {
9435 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9436 new Pair<String, String>(oldPassword, newPassword), phone, null);
9437 return attemptsRemaining;
9438
9439 } catch (Exception e) {
9440 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9441 } finally {
9442 Binder.restoreCallingIdentity(identity);
9443 }
9444 return 0;
9445 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009446
9447 /**
9448 * Request for receiving user activity notification
9449 */
9450 @Override
9451 public void requestUserActivityNotification() {
9452 if (!mNotifyUserActivity.get()
9453 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9454 mNotifyUserActivity.set(true);
9455 }
9456 }
9457
9458 /**
9459 * Called when userActivity is signalled in the power manager.
9460 * This is safe to call from any thread, with any window manager locks held or not.
9461 */
9462 @Override
9463 public void userActivity() {
9464 // ***************************************
9465 // * Inherited from PhoneWindowManager *
9466 // ***************************************
9467 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9468 // WITH ITS LOCKS HELD.
9469 //
9470 // This code must be VERY careful about the locks
9471 // it acquires.
9472 // In fact, the current code acquires way too many,
9473 // and probably has lurking deadlocks.
9474
9475 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9476 throw new SecurityException("Only the OS may call notifyUserActivity()");
9477 }
9478
9479 if (mNotifyUserActivity.getAndSet(false)) {
9480 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9481 USER_ACTIVITY_NOTIFICATION_DELAY);
9482 }
9483 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009484
9485 @Override
9486 public boolean canConnectTo5GInDsdsMode() {
9487 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9488 }
Jack Yud10cdd42020-09-28 20:28:01 -07009489
9490 @Override
9491 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9492 String callingFeatureId) {
9493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9494 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9495 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9496 }
9497
9498 Phone phone = getPhone(subId);
9499 if (phone == null) {
9500 throw new RuntimeException("phone is not available");
9501 }
9502 // Now that all security checks passes, perform the operation as ourselves.
9503 final long identity = Binder.clearCallingIdentity();
9504 try {
9505 return phone.getEquivalentHomePlmns();
9506 } finally {
9507 Binder.restoreCallingIdentity(identity);
9508 }
9509 }
Daniel Bright59e67312020-11-13 11:49:37 -08009510
9511 @Override
9512 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009513 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9514 Set<String> radioInterfaceCapabilities =
Daniel Bright59e67312020-11-13 11:49:37 -08009515 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9516 if (radioInterfaceCapabilities == null) {
9517 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009518 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009519 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009520 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009521
Hui Wang641e81c2020-10-12 12:14:23 -07009522 @Override
9523 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9524 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009525 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9526 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9527 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9528 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9529 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009530 if (DBG) {
9531 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9532 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9533 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9534 }
9535
9536 if (!SubscriptionManager.isValidSubscriptionId(subId)
9537 || appType < TelephonyManager.APPTYPE_UNKNOWN
9538 || appType > TelephonyManager.APPTYPE_ISIM
9539 || nafUrl == null || securityProtocol == null || callback == null) {
9540 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9541 if (callback != null) {
9542 try {
9543 callback.onAuthenticationFailure(
9544 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9545 } catch (RemoteException exception) {
9546 log("Fail to notify onAuthenticationFailure due to " + exception);
9547 }
9548 return;
9549 }
9550 }
9551
9552 final long token = Binder.clearCallingIdentity();
9553 try {
9554 getGbaManager(subId).bootstrapAuthenticationRequest(
9555 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9556 forceBootStrapping, callback));
9557 } finally {
9558 Binder.restoreCallingIdentity(token);
9559 }
9560 }
9561
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009562 /**
9563 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9564 * requested radio power state will actually be set. See {@link
9565 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9566 *
9567 * @param subId the subscription ID of the phone requesting to set the radio power state.
9568 * @param enable {@code true} if trying to turn radio on.
9569 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9570 * false}.
9571 */
9572 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9573 Phone phone = getPhone(subId);
9574 if (phone != null) {
9575 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9576 return true;
9577 }
9578 return false;
9579 }
9580
9581 private int handleDataThrottlingRequest(int subId,
9582 DataThrottlingRequest dataThrottlingRequest) {
9583 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9584 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9585 if (!setRadioPowerForThermal(subId, true)) {
9586 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9587 }
9588
9589 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9590
9591 int thermalMitigationResult =
9592 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9593 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9594 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9595 }
9596 return thermalMitigationResult;
9597 }
9598
9599 /**
9600 * Thermal mitigation request to control functionalities at modem.
9601 *
9602 * @param subId the id of the subscription.
9603 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9604 *
9605 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9606 */
9607 @Override
9608 @ThermalMitigationResult
9609 public int sendThermalMitigationRequest(
9610 int subId,
9611 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9612 enforceModifyPermission();
9613
9614 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9615 final long identity = Binder.clearCallingIdentity();
9616
9617 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9618 try {
9619 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9620 switch (thermalMitigationAction) {
9621 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9622 thermalMitigationResult =
9623 handleDataThrottlingRequest(subId,
9624 thermalMitigationRequest.getDataThrottlingRequest());
9625 break;
9626 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9627 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9628 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9629 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9630 }
9631
9632 // Ensure that radio is on. If not able to power on due to phone being
9633 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9634 if (!setRadioPowerForThermal(subId, true)) {
9635 thermalMitigationResult =
9636 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9637 break;
9638 }
9639
9640 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9641 false);
9642 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9643 break;
9644 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9645 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9646 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9647 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9648 }
9649
9650 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9651 if (registry != null) {
9652 TelephonyConnectionService service =
9653 registry.getTelephonyConnectionService();
9654 Phone phone = getPhone(subId);
9655 if (phone == null) {
9656 thermalMitigationResult =
9657 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9658 break;
9659 }
9660
9661 if (PhoneConstantConversions.convertCallState(phone.getState())
9662 != TelephonyManager.CALL_STATE_IDLE
9663 || phone.isInEmergencySmsMode() || phone.isInEcm()
9664 || (service != null && service.isEmergencyCallPending())) {
9665 String errorMessage = "Phone state is not valid. call state = "
9666 + PhoneConstantConversions.convertCallState(phone.getState())
9667 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9668 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9669 errorMessage += service == null
9670 ? " TelephonyConnectionService is null"
9671 : " isEmergencyCallPending = "
9672 + service.isEmergencyCallPending();
9673 Log.e(LOG_TAG, errorMessage);
9674 thermalMitigationResult =
9675 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9676 break;
9677 }
9678 } else {
9679 thermalMitigationResult =
9680 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9681 break;
9682 }
9683
9684 // Turn radio off. If not able to power off due to phone being unavailable,
9685 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9686 if (!setRadioPowerForThermal(subId, false)) {
9687 thermalMitigationResult =
9688 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9689 break;
9690 }
9691 thermalMitigationResult =
9692 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9693 break;
9694 default:
9695 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9696 + "not exist. Requested action: " + thermalMitigationAction);
9697 }
9698 } catch (IllegalArgumentException e) {
9699 throw e;
9700 } catch (Exception e) {
9701 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9702 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9703 } finally {
9704 Binder.restoreCallingIdentity(identity);
9705 }
9706
9707 if (DBG) {
9708 log("thermalMitigationRequest returning with thermalMitigationResult: "
9709 + thermalMitigationResult);
9710 }
9711
9712 return thermalMitigationResult;
9713 }
Hui Wang641e81c2020-10-12 12:14:23 -07009714
9715 /**
9716 * Set the GbaService Package Name that Telephony will bind to.
9717 *
9718 * @param subId The sim that the GbaService is associated with.
9719 * @param packageName The name of the package to be replaced with.
9720 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9721 */
9722 @Override
9723 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9724 enforceModifyPermission();
9725
9726 final long identity = Binder.clearCallingIdentity();
9727 try {
9728 return getGbaManager(subId).overrideServicePackage(packageName);
9729 } finally {
9730 Binder.restoreCallingIdentity(identity);
9731 }
9732 }
9733
9734 /**
9735 * Return the package name of the currently bound GbaService.
9736 *
9737 * @param subId The sim that the GbaService is associated with.
9738 * @return the package name of the GbaService configuration, null if GBA is not supported.
9739 */
9740 @Override
9741 public String getBoundGbaService(int subId) {
9742 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9743
9744 final long identity = Binder.clearCallingIdentity();
9745 try {
9746 return getGbaManager(subId).getServicePackage();
9747 } finally {
9748 Binder.restoreCallingIdentity(identity);
9749 }
9750 }
9751
9752 /**
9753 * Set the release time for telephony to unbind GbaService.
9754 *
9755 * @param subId The sim that the GbaService is associated with.
9756 * @param interval The release time to unbind GbaService by millisecond.
9757 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9758 */
9759 @Override
9760 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9761 enforceModifyPermission();
9762
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
9765 return getGbaManager(subId).overrideReleaseTime(interval);
9766 } finally {
9767 Binder.restoreCallingIdentity(identity);
9768 }
9769 }
9770
9771 /**
9772 * Return the release time for telephony to unbind GbaService.
9773 *
9774 * @param subId The sim that the GbaService is associated with.
9775 * @return The release time to unbind GbaService by millisecond.
9776 */
9777 @Override
9778 public int getGbaReleaseTime(int subId) {
9779 enforceReadPrivilegedPermission("getGbaReleaseTime");
9780
9781 final long identity = Binder.clearCallingIdentity();
9782 try {
9783 return getGbaManager(subId).getReleaseTime();
9784 } finally {
9785 Binder.restoreCallingIdentity(identity);
9786 }
9787 }
9788
9789 private GbaManager getGbaManager(int subId) {
9790 GbaManager instance = GbaManager.getInstance(subId);
9791 if (instance == null) {
9792 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9793 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9794 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9795 }
9796 return instance;
9797 }
Hui Wang761a6682020-10-31 05:12:53 +00009798
9799 /**
9800 * indicate whether the device and the carrier can support
9801 * RCS VoLTE single registration.
9802 */
9803 @Override
9804 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009805 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9806 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9807 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9808 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009809
9810 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9811 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9812 }
9813
9814 final long identity = Binder.clearCallingIdentity();
9815 try {
9816 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9817 if (rpm != null) {
9818 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9819 }
9820 return false;
9821 } finally {
9822 Binder.restoreCallingIdentity(identity);
9823 }
9824 }
9825
9826 /**
9827 * Register RCS provisioning callback.
9828 */
9829 @Override
9830 public void registerRcsProvisioningChangedCallback(int subId,
9831 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009832 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9833 Binder.getCallingUid(), "registerRcsProvisioningChangedCallback",
9834 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9835 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009836
9837 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9838 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9839 }
9840 if (!isImsAvailableOnDevice()) {
9841 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9842 "IMS not available on device.");
9843 }
9844
9845 final long identity = Binder.clearCallingIdentity();
9846 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009847 if (!RcsProvisioningMonitor.getInstance()
9848 .registerRcsProvisioningChangedCallback(subId, callback)) {
9849 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9850 "Service not available for the subscription.");
9851 }
Hui Wang761a6682020-10-31 05:12:53 +00009852 } finally {
9853 Binder.restoreCallingIdentity(identity);
9854 }
9855 }
9856
9857 /**
9858 * Unregister RCS provisioning callback.
9859 */
9860 @Override
9861 public void unregisterRcsProvisioningChangedCallback(int subId,
9862 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009863 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9864 Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback",
9865 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9866 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009867
9868 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9869 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9870 }
9871 if (!isImsAvailableOnDevice()) {
9872 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9873 "IMS not available on device.");
9874 }
9875
9876 final long identity = Binder.clearCallingIdentity();
9877 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009878 RcsProvisioningMonitor.getInstance()
9879 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
9883 }
9884
9885 /**
9886 * trigger RCS reconfiguration.
9887 */
9888 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009889 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9890 "triggerRcsReconfiguration",
9891 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009892
9893 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9894 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9895 }
9896 if (!isImsAvailableOnDevice()) {
9897 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9898 "IMS not available on device.");
9899 }
9900
9901 final long identity = Binder.clearCallingIdentity();
9902 try {
9903 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9904 } finally {
9905 Binder.restoreCallingIdentity(identity);
9906 }
9907 }
9908
9909 /**
9910 * Provide the client configuration parameters of the RCS application.
9911 */
9912 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009913 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9914 "setRcsClientConfiguration",
9915 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009916
9917 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9918 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9919 }
9920 if (!isImsAvailableOnDevice()) {
9921 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9922 "IMS not available on device.");
9923 }
9924
9925 final long identity = Binder.clearCallingIdentity();
9926
9927 try {
9928 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9929 if (configBinder == null) {
9930 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9931 } else {
9932 configBinder.setRcsClientConfiguration(rcc);
9933 }
9934 } catch (RemoteException e) {
9935 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9936 } finally {
9937 Binder.restoreCallingIdentity(identity);
9938 }
9939 }
9940
9941 /**
9942 * Overrides the config of RCS VoLTE single registration enabled for the device.
9943 */
9944 @Override
9945 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9946 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9947 "setDeviceSingleRegistrationEnabledOverride");
9948 enforceModifyPermission();
9949
9950 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9951 : Boolean.parseBoolean(enabledStr);
9952 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009953 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +00009954 }
9955
9956 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009957 * Sends a device to device communication message. Only usable via shell.
9958 * @param message message to send.
9959 * @param value message value.
9960 */
9961 @Override
9962 public void sendDeviceToDeviceMessage(int message, int value) {
9963 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -08009964 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -08009965 enforceModifyPermission();
9966
9967 final long identity = Binder.clearCallingIdentity();
9968 try {
9969 TelephonyConnectionService service =
9970 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9971 if (service == null) {
9972 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9973 return;
9974 }
9975 service.sendTestDeviceToDeviceMessage(message, value);
9976 } finally {
9977 Binder.restoreCallingIdentity(identity);
9978 }
9979 }
9980
Tyler Gunnbabbda02021-02-10 11:05:02 -08009981 /**
9982 * Sets the specified device to device transport active.
9983 * @param transport The transport to set active.
9984 */
9985 @Override
9986 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
9987 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9988 "setActiveDeviceToDeviceTransport");
9989 enforceModifyPermission();
9990
9991 final long identity = Binder.clearCallingIdentity();
9992 try {
9993 TelephonyConnectionService service =
9994 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9995 if (service == null) {
9996 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
9997 return;
9998 }
9999 service.setActiveDeviceToDeviceTransport(transport);
10000 } finally {
10001 Binder.restoreCallingIdentity(identity);
10002 }
10003 }
Tyler Gunn92479152021-01-20 16:30:10 -080010004
10005 /**
Hui Wang761a6682020-10-31 05:12:53 +000010006 * Gets the config of RCS VoLTE single registration enabled for the device.
10007 */
10008 @Override
10009 public boolean getDeviceSingleRegistrationEnabled() {
10010 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10011 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10012 }
10013
10014 /**
10015 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10016 */
10017 @Override
10018 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10019 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10020 "setCarrierSingleRegistrationEnabledOverride");
10021 enforceModifyPermission();
10022
10023 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10024 : Boolean.parseBoolean(enabledStr);
10025 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10026 subId, enabled);
10027 }
10028
10029 /**
10030 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10031 */
10032 @Override
10033 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10034 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10035 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10036 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010037
10038 /**
10039 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10040 * their mobile plan.
10041 */
10042 @Override
10043 public String getMobileProvisioningUrl() {
10044 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10045 final long identity = Binder.clearCallingIdentity();
10046 try {
10047 return getDefaultPhone().getMobileProvisioningUrl();
10048 } finally {
10049 Binder.restoreCallingIdentity(identity);
10050 }
10051 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010052
James.cf Linbcdf8b32021-01-14 16:44:13 +080010053 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010054 * Get the EAB contact from the EAB database.
10055 */
10056 @Override
10057 public String getContactFromEab(String contact) {
10058 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10059 enforceModifyPermission();
10060 final long identity = Binder.clearCallingIdentity();
10061 try {
10062 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10063 } finally {
10064 Binder.restoreCallingIdentity(identity);
10065 }
10066 }
10067
10068 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010069 * Remove the EAB contacts from the EAB database.
10070 */
10071 @Override
10072 public int removeContactFromEab(int subId, String contacts) {
10073 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10074 enforceModifyPermission();
10075 final long identity = Binder.clearCallingIdentity();
10076 try {
10077 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10078 } finally {
10079 Binder.restoreCallingIdentity(identity);
10080 }
10081 }
10082
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010083 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010084 public boolean getDeviceUceEnabled() {
10085 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10086 final long identity = Binder.clearCallingIdentity();
10087 try {
10088 return mApp.getDeviceUceEnabled();
10089 } finally {
10090 Binder.restoreCallingIdentity(identity);
10091 }
10092 }
10093
10094 @Override
10095 public void setDeviceUceEnabled(boolean isEnabled) {
10096 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10097 final long identity = Binder.clearCallingIdentity();
10098 try {
10099 mApp.setDeviceUceEnabled(isEnabled);
10100 } finally {
10101 Binder.restoreCallingIdentity(identity);
10102 }
10103 }
10104
10105 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010106 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10107 String callingPackage) {
10108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10109 mApp, subId, "setSignalStrengthUpdateRequest");
10110
10111 final int callingUid = Binder.getCallingUid();
10112 // Verify that tha callingPackage belongs to the calling UID
10113 mApp.getSystemService(AppOpsManager.class)
10114 .checkPackage(callingUid, callingPackage);
10115
10116 validateSignalStrengthUpdateRequest(request, callingUid);
10117
10118 final long identity = Binder.clearCallingIdentity();
10119 try {
10120 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10121 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10122
10123 if (result instanceof IllegalStateException) {
10124 throw (IllegalStateException) result;
10125 }
10126 } finally {
10127 Binder.restoreCallingIdentity(identity);
10128 }
10129 }
10130
10131 @Override
10132 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10133 String callingPackage) {
10134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10135 mApp, subId, "clearSignalStrengthUpdateRequest");
10136
10137 final int callingUid = Binder.getCallingUid();
10138 // Verify that tha callingPackage belongs to the calling UID
10139 mApp.getSystemService(AppOpsManager.class)
10140 .checkPackage(callingUid, callingPackage);
10141
10142 final long identity = Binder.clearCallingIdentity();
10143 try {
10144 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10145 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10146
10147 if (result instanceof IllegalStateException) {
10148 throw (IllegalStateException) result;
10149 }
10150 } finally {
10151 Binder.restoreCallingIdentity(identity);
10152 }
10153 }
10154
10155 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10156 int callingUid) {
10157 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10158 // phone/system process do not have further restriction on request
10159 return;
10160 }
10161
10162 // Applications has restrictions on how to use the request:
10163 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10164 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10165 // This is not system caller which has been checked above
10166 throw new IllegalArgumentException(
10167 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10168 }
10169
10170 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10171 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10172 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10173 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10174 || info.isEnabled()) {
10175 throw new IllegalArgumentException(
10176 "Only system can set hide fields in SignalThresholdInfo");
10177 }
10178
10179 // Thresholds length for each RAN need in range. This has been validated in
10180 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10181 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10182 final int[] thresholds = info.getThresholds();
10183 Objects.requireNonNull(thresholds);
10184 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10185 || thresholds.length
10186 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10187 throw new IllegalArgumentException(
10188 "thresholds length is out of range: " + thresholds.length);
10189 }
10190 }
10191 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010192
10193 /**
10194 * Gets the current phone capability.
10195 *
10196 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10197 * @return the PhoneCapability which describes the data connection capability of modem.
10198 * It's used to evaluate possible phone config change, for example from single
10199 * SIM device to multi-SIM device.
10200 */
10201 @Override
10202 public PhoneCapability getPhoneCapability() {
10203 enforceReadPrivilegedPermission("getPhoneCapability");
10204 final long identity = Binder.clearCallingIdentity();
10205 try {
10206 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10207 } finally {
10208 Binder.restoreCallingIdentity(identity);
10209 }
10210 }
Michele Berionne5e411512020-11-13 02:36:59 +000010211
10212 /**
10213 * Prepare TelephonyManager for an unattended reboot. The reboot is
10214 * required to be done shortly after the API is invoked.
10215 */
10216 @Override
10217 @TelephonyManager.PrepareUnattendedRebootResult
10218 public int prepareForUnattendedReboot() {
10219 enforceRebootPermission();
10220
10221 final long identity = Binder.clearCallingIdentity();
10222 try {
10223 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10224 } finally {
10225 Binder.restoreCallingIdentity(identity);
10226 }
10227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010228}