blob: ab1219adfc406cb97fa5d3e69478644aed6164ae [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Hall Liu82694d52020-12-11 18:22:04 -080032import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070033import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070034import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.content.Context;
36import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070037import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070038import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080039import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070040import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.net.Uri;
42import android.os.AsyncResult;
43import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080044import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Bundle;
46import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.Looper;
49import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070050import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080051import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070052import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070053import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080054import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080055import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070056import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070057import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080058import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070060import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070061import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070062import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070063import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080064import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070065import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090066import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080067import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080068import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070069import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070070import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080071import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080072import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070073import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
111import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700112import android.telephony.gba.GbaAuthRequest;
113import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700114import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000116import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700117import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700118import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800119import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700120import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700122import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000123import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700124import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800126import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800128import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700131import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800133import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800134
Andrew Lee312e8172014-10-23 17:01:36 -0700135import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800136import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800137import com.android.ims.rcs.uce.eab.EabUtil;
Shuo Qian4a594052020-01-23 11:59:30 -0800138import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700140import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700141import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800142import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700143import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700144import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800145import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700147import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800148import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800149import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800150import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700151import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800153import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800155import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700156import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700157import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700158import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700160import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800161import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700162import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700163import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700164import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700165import com.android.internal.telephony.RIL;
Daniel Bright94f43662021-03-01 14:43:40 -0800166import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700167import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700168import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800170import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800171import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800172import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700173import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800174import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700175import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800176import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700177import com.android.internal.telephony.imsphone.ImsPhone;
178import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800179import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700180import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700181import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800182import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800184import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700185import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800186import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800188import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000189import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800190import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700191import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700192import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800193import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800194import com.android.phone.callcomposer.CallComposerPictureManager;
195import com.android.phone.callcomposer.CallComposerPictureTransfer;
196import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700197import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700198import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800199import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700200import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700201import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800202import com.android.services.telephony.TelecomAccountRegistry;
203import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800204import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800205
Hall Liu82694d52020-12-11 18:22:04 -0800206import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700207import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800208import java.io.IOException;
209import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700210import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800212import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800213import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800214import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800215import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100216import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800217import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700218import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800219import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800220import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800222import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800223import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224
225/**
226 * Implementation of the ITelephony interface.
227 */
Santos Cordon117fee72014-05-16 17:56:12 -0700228public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229 private static final String LOG_TAG = "PhoneInterfaceManager";
230 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
231 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233
234 // Message codes used with mMainThreadHandler
235 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700236 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
237 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700238 private static final int CMD_OPEN_CHANNEL = 9;
239 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
240 private static final int CMD_CLOSE_CHANNEL = 11;
241 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800242 private static final int CMD_NV_READ_ITEM = 13;
243 private static final int EVENT_NV_READ_ITEM_DONE = 14;
244 private static final int CMD_NV_WRITE_ITEM = 15;
245 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
246 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
247 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700248 private static final int CMD_RESET_MODEM_CONFIG = 19;
249 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800250 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
251 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800252 private static final int CMD_SEND_ENVELOPE = 25;
253 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000254 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
255 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700256 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
257 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
258 private static final int CMD_EXCHANGE_SIM_IO = 31;
259 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800260 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
261 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700262 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
263 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700264 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
265 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700266 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
267 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
268 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
269 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700270 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
271 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
272 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
273 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700274 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800275 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
276 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000277 private static final int CMD_SWITCH_SLOTS = 50;
278 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700279 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
280 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
281 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
282 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
283 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
284 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
285 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
286 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700287 private static final int CMD_GET_ALL_CELL_INFO = 60;
288 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
289 private static final int CMD_GET_CELL_LOCATION = 62;
290 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700291 private static final int CMD_MODEM_REBOOT = 64;
292 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700293 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
294 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800295 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
296 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700297 private static final int CMD_GET_MODEM_STATUS = 70;
298 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700299 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
300 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700301 private static final int CMD_ERASE_MODEM_CONFIG = 74;
302 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800303 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
304 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
305 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
306 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800307 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
308 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800309 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800310 private static final int CMD_GET_CALL_FORWARDING = 83;
311 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
312 private static final int CMD_SET_CALL_FORWARDING = 85;
313 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
314 private static final int CMD_GET_CALL_WAITING = 87;
315 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
316 private static final int CMD_SET_CALL_WAITING = 89;
317 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700318 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
319 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
320 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
321 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700322 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
323 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800324 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
325 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800326 private static final int CMD_SET_DATA_THROTTLING = 99;
327 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800328 private static final int CMD_SET_SIM_POWER = 101;
329 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800330 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
331 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
332 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
333 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800334 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
335 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000336 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800338 // Parameters of select command.
339 private static final int SELECT_COMMAND = 0xA4;
340 private static final int SELECT_P1 = 0x04;
341 private static final int SELECT_P2 = 0;
342 private static final int SELECT_P3 = 0x10;
343
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 /** The singleton instance. */
345 private static PhoneInterfaceManager sInstance;
346
Wink Saville3ab207e2014-11-20 13:07:20 -0800347 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800348 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800349 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700350 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800351 private AppOpsManager mAppOps;
352 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800353 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800354 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700355 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800356 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Peter Wangdafb9ac2020-01-15 14:13:38 -0800358 /** User Activity */
359 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800360 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
361
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700362 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
363
Derek Tan97ebb422014-09-05 16:55:38 -0700364 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
365 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800366 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800367 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700368
Michelecea4cf22018-12-21 15:00:11 -0800369 // String to store multi SIM allowed
370 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
371
Derek Tan740e1672017-06-27 14:56:27 -0700372 // The AID of ISD-R.
373 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
374
yinxub1bed742017-04-17 11:45:04 -0700375 private NetworkScanRequestTracker mNetworkScanRequestTracker;
376
David Kelly5e06a7f2018-03-12 14:10:59 +0000377 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
378 private static final int MANUFACTURER_CODE_LENGTH = 8;
379
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800380 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
381
Derek Tan89e89d42014-07-08 17:00:10 -0700382 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700383 * Experiment flag to enable erase modem config on reset network, default value is false
384 */
385 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
386 "reset_network_erase_modem_config_enabled";
387
Rambo Wang0f050d82021-02-12 11:43:36 -0800388 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
389
Naina Nallurid63128d2019-09-17 14:10:30 -0700390 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700391 * A request object to use for transmitting data to an ICC.
392 */
393 private static final class IccAPDUArgument {
394 public int channel, cla, command, p1, p2, p3;
395 public String data;
396
397 public IccAPDUArgument(int channel, int cla, int command,
398 int p1, int p2, int p3, String data) {
399 this.channel = channel;
400 this.cla = cla;
401 this.command = command;
402 this.p1 = p1;
403 this.p2 = p2;
404 this.p3 = p3;
405 this.data = data;
406 }
407 }
408
409 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700410 * A request object to use for transmitting data to an ICC.
411 */
412 private static final class ManualNetworkSelectionArgument {
413 public OperatorInfo operatorInfo;
414 public boolean persistSelection;
415
416 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
417 this.operatorInfo = operatorInfo;
418 this.persistSelection = persistSelection;
419 }
420 }
421
422 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
424 * request after sending. The main thread will notify the request when it is complete.
425 */
426 private static final class MainThreadRequest {
427 /** The argument to use for the request */
428 public Object argument;
429 /** The result of the request that is run on the main thread */
430 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800431 // The subscriber id that this request applies to. Defaults to
432 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
433 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434
Nathan Harold92bed182018-10-12 18:16:49 -0700435 // In cases where subId is unavailable, the caller needs to specify the phone.
436 public Phone phone;
437
vagdeviaf9a5b92018-08-15 16:01:53 -0700438 public WorkSource workSource;
439
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 public MainThreadRequest(Object argument) {
441 this.argument = argument;
442 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800443
Nathan Harold92bed182018-10-12 18:16:49 -0700444 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
445 this.argument = argument;
446 if (phone != null) {
447 this.phone = phone;
448 }
449 this.workSource = workSource;
450 }
451
vagdeviaf9a5b92018-08-15 16:01:53 -0700452 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800453 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800454 if (subId != null) {
455 this.subId = subId;
456 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700457 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 }
460
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800461 private static final class IncomingThirdPartyCallArgs {
462 public final ComponentName component;
463 public final String callId;
464 public final String callerDisplayName;
465
466 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
467 String callerDisplayName) {
468 this.component = component;
469 this.callId = callId;
470 this.callerDisplayName = callerDisplayName;
471 }
472 }
473
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 /**
475 * A handler that processes messages on the main thread in the phone process. Since many
476 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
477 * inbound binder threads to the main thread in the phone process. The Binder thread
478 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
479 * on, which will be notified when the operation completes and will contain the result of the
480 * request.
481 *
482 * <p>If a MainThreadRequest object is provided in the msg.obj field,
483 * note that request.result must be set to something non-null for the calling thread to
484 * unblock.
485 */
486 private final class MainThreadHandler extends Handler {
487 @Override
488 public void handleMessage(Message msg) {
489 MainThreadRequest request;
490 Message onCompleted;
491 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800494 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700495
496 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 case CMD_HANDLE_USSD_REQUEST: {
498 request = (MainThreadRequest) msg.obj;
499 final Phone phone = getPhoneFromRequest(request);
500 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
501 String ussdRequest = ussdObject.first;
502 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700503
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 if (!isUssdApiAllowed(request.subId)) {
505 // Carrier does not support use of this API, return failure.
506 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
507 UssdResponse response = new UssdResponse(ussdRequest, null);
508 Bundle returnData = new Bundle();
509 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
510 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700511
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 request.result = true;
513 notifyRequester(request);
514 return;
515 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700516
Pengquan Menga1bb6272018-09-06 09:59:22 -0700517 try {
518 request.result = phone != null
519 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
520 } catch (CallStateException cse) {
521 request.result = false;
522 }
523 // Wake up the requesting thread
524 notifyRequester(request);
525 break;
pkanwar32d516d2016-10-14 19:37:38 -0700526 }
527
Yorke Lee716f67e2015-06-17 15:39:16 -0700528 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700530 final Phone phone = getPhoneFromRequest(request);
531 request.result = phone != null ?
532 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
533 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800542 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 if (uiccCard == null) {
544 loge("iccTransmitApduLogicalChannel: No UICC");
545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
549 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 iccArgument.channel, iccArgument.cla, iccArgument.command,
552 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 break;
556
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 ar = (AsyncResult) msg.obj;
559 request = (MainThreadRequest) ar.userObj;
560 if (ar.exception == null && ar.result != null) {
561 request.result = ar.result;
562 } else {
563 request.result = new IccIoResult(0x6F, 0, (byte[])null);
564 if (ar.result == null) {
565 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800566 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800568 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 } else {
570 loge("iccTransmitApduLogicalChannel: Unknown exception");
571 }
572 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 break;
575
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
577 request = (MainThreadRequest) msg.obj;
578 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800579 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 if (uiccCard == null) {
581 loge("iccTransmitApduBasicChannel: No UICC");
582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 } else {
585 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
586 request);
587 uiccCard.iccTransmitApduBasicChannel(
588 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
589 iccArgument.p3, iccArgument.data, onCompleted);
590 }
591 break;
592
593 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
594 ar = (AsyncResult) msg.obj;
595 request = (MainThreadRequest) ar.userObj;
596 if (ar.exception == null && ar.result != null) {
597 request.result = ar.result;
598 } else {
599 request.result = new IccIoResult(0x6F, 0, (byte[])null);
600 if (ar.result == null) {
601 loge("iccTransmitApduBasicChannel: Empty response");
602 } else if (ar.exception instanceof CommandException) {
603 loge("iccTransmitApduBasicChannel: CommandException: " +
604 ar.exception);
605 } else {
606 loge("iccTransmitApduBasicChannel: Unknown exception");
607 }
608 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 break;
611
612 case CMD_EXCHANGE_SIM_IO:
613 request = (MainThreadRequest) msg.obj;
614 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800615 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 if (uiccCard == null) {
617 loge("iccExchangeSimIO: No UICC");
618 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 } else {
621 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
622 request);
623 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
624 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
625 iccArgument.data, onCompleted);
626 }
627 break;
628
629 case EVENT_EXCHANGE_SIM_IO_DONE:
630 ar = (AsyncResult) msg.obj;
631 request = (MainThreadRequest) ar.userObj;
632 if (ar.exception == null && ar.result != null) {
633 request.result = ar.result;
634 } else {
635 request.result = new IccIoResult(0x6f, 0, (byte[])null);
636 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 break;
639
Derek Tan4d5e5c12014-02-04 11:54:58 -0800640 case CMD_SEND_ENVELOPE:
641 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800642 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 if (uiccCard == null) {
644 loge("sendEnvelopeWithStatus: No UICC");
645 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 } else {
648 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
649 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
650 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800651 break;
652
653 case EVENT_SEND_ENVELOPE_DONE:
654 ar = (AsyncResult) msg.obj;
655 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700656 if (ar.exception == null && ar.result != null) {
657 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800658 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700659 request.result = new IccIoResult(0x6F, 0, (byte[])null);
660 if (ar.result == null) {
661 loge("sendEnvelopeWithStatus: Empty response");
662 } else if (ar.exception instanceof CommandException) {
663 loge("sendEnvelopeWithStatus: CommandException: " +
664 ar.exception);
665 } else {
666 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
667 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800670 break;
671
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 case CMD_OPEN_CHANNEL:
673 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800674 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800675 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 if (uiccCard == null) {
677 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800678 request.result = new IccOpenLogicalChannelResponse(-1,
679 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 } else {
682 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800683 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
684 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 break;
687
688 case EVENT_OPEN_CHANNEL_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 int[] result = (int[]) ar.result;
694 int channelId = result[0];
695 byte[] selectResponse = null;
696 if (result.length > 1) {
697 selectResponse = new byte[result.length - 1];
698 for (int i = 1; i < result.length; ++i) {
699 selectResponse[i - 1] = (byte) result[i];
700 }
701 }
702 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700703 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 if (ar.result == null) {
706 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 if (ar.exception != null) {
709 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
710 }
711
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700712 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700713 if (ar.exception instanceof CommandException) {
714 CommandException.Error error =
715 ((CommandException) (ar.exception)).getCommandError();
716 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700717 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700718 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700719 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700720 }
721 }
722 openChannelResp = new IccOpenLogicalChannelResponse(
723 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700725 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 break;
728
729 case CMD_CLOSE_CHANNEL:
730 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800731 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700732 if (uiccCard == null) {
733 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900734 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700736 } else {
737 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
738 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
739 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 break;
741
742 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800743 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
744 break;
745
746 case CMD_NV_READ_ITEM:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800749 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
750 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800751 break;
752
753 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 ar = (AsyncResult) msg.obj;
755 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800756 if (ar.exception == null && ar.result != null) {
757 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800759 request.result = "";
760 if (ar.result == null) {
761 loge("nvReadItem: Empty response");
762 } else if (ar.exception instanceof CommandException) {
763 loge("nvReadItem: CommandException: " +
764 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800766 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 }
768 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 break;
771
Jake Hambye994d462014-02-03 13:10:13 -0800772 case CMD_NV_WRITE_ITEM:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
775 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800776 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700777 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800778 break;
779
780 case EVENT_NV_WRITE_ITEM_DONE:
781 handleNullReturnEvent(msg, "nvWriteItem");
782 break;
783
784 case CMD_NV_WRITE_CDMA_PRL:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800787 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
790 case EVENT_NV_WRITE_CDMA_PRL_DONE:
791 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
792 break;
793
chen xu6dac5ab2018-10-26 17:39:23 -0700794 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800795 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700796 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800797 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800798 break;
799
chen xu6dac5ab2018-10-26 17:39:23 -0700800 case EVENT_RESET_MODEM_CONFIG_DONE:
801 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800802 break;
803
Sooraj Sasindran37444802020-08-11 10:40:43 -0700804 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
805 request = (MainThreadRequest) msg.obj;
806 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
807 request);
808 Phone phone = getPhoneFromRequest(request);
809 if (phone != null) {
810 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
811 } else {
812 loge("isNRDualConnectivityEnabled: No phone object");
813 request.result = false;
814 notifyRequester(request);
815 }
816 break;
817 }
818
819 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null && ar.result != null) {
823 request.result = ar.result;
824 } else {
825 // request.result must be set to something non-null
826 // for the calling thread to unblock
827 if (request.result != null) {
828 request.result = ar.result;
829 } else {
830 request.result = false;
831 }
832 if (ar.result == null) {
833 loge("isNRDualConnectivityEnabled: Empty response");
834 } else if (ar.exception instanceof CommandException) {
835 loge("isNRDualConnectivityEnabled: CommandException: "
836 + ar.exception);
837 } else {
838 loge("isNRDualConnectivityEnabled: Unknown exception");
839 }
840 }
841 notifyRequester(request);
842 break;
843
844 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
847 Phone phone = getPhoneFromRequest(request);
848 if (phone != null) {
849 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
850 request.workSource);
851 } else {
852 loge("enableNrDualConnectivity: No phone object");
853 request.result =
854 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
855 notifyRequester(request);
856 }
857 break;
858 }
859
860 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
861 ar = (AsyncResult) msg.obj;
862 request = (MainThreadRequest) ar.userObj;
863 if (ar.exception == null) {
864 request.result =
865 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
866 } else {
867 request.result =
868 TelephonyManager
869 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
870 if (ar.exception instanceof CommandException) {
871 CommandException.Error error =
872 ((CommandException) (ar.exception)).getCommandError();
873 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
874 request.result =
875 TelephonyManager
876 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
877 }
878 loge("enableNrDualConnectivity" + ": CommandException: "
879 + ar.exception);
880 } else {
881 loge("enableNrDualConnectivity" + ": Unknown exception");
882 }
883 }
884 notifyRequester(request);
885 break;
886 }
887
SongFerngWang3ef3e072020-12-21 16:41:52 +0800888 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800889 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800890 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
891 request);
892 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800893 break;
894
SongFerngWang3ef3e072020-12-21 16:41:52 +0800895 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800896 ar = (AsyncResult) msg.obj;
897 request = (MainThreadRequest) ar.userObj;
898 if (ar.exception == null && ar.result != null) {
899 request.result = ar.result; // Integer
900 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530901 // request.result must be set to something non-null
902 // for the calling thread to unblock
903 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800905 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800906 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800907 loge("getAllowedNetworkTypesBitmask: CommandException: "
908 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800909 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800910 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800911 }
912 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700913 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800914 break;
915
SongFerngWang3ef3e072020-12-21 16:41:52 +0800916 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800918 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
919 request);
920 Pair<Integer, Long> reasonWithNetworkTypes =
921 (Pair<Integer, Long>) request.argument;
922 getPhoneFromRequest(request).setAllowedNetworkTypes(
923 reasonWithNetworkTypes.first,
924 reasonWithNetworkTypes.second,
925 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800926 break;
927
SongFerngWang3ef3e072020-12-21 16:41:52 +0800928 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
929 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800930 break;
931
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000932 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
933 request = (MainThreadRequest)msg.obj;
934 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800935 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000936 break;
937
938 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
939 ar = (AsyncResult)msg.obj;
940 request = (MainThreadRequest)ar.userObj;
941 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000943 break;
944
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800945 case CMD_SET_VOICEMAIL_NUMBER:
946 request = (MainThreadRequest) msg.obj;
947 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
948 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800949 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
950 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800951 break;
952
953 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
954 handleNullReturnEvent(msg, "setVoicemailNumber");
955 break;
956
Stuart Scott54788802015-03-30 13:18:01 -0700957 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
958 request = (MainThreadRequest) msg.obj;
959 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
960 request);
961 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
962 break;
963
964 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
965 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
966 break;
967
Shishir Agrawal302c8692015-06-19 13:49:39 -0700968 case CMD_PERFORM_NETWORK_SCAN:
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
971 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
972 break;
973
Hall Liu27d24262020-09-18 19:04:59 -0700974 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800975 request = (MainThreadRequest) msg.obj;
976 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700977 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
978 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
979 request.argument;
980 int callForwardingReason = args.first;
981 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800982 break;
Hall Liu27d24262020-09-18 19:04:59 -0700983 }
984 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700987 TelephonyManager.CallForwardingInfoCallback callback =
988 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
989 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800990 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700991 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800992 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
993 for (CallForwardInfo callForwardInfo : callForwardInfos) {
994 // Service Class is a bit mask per 3gpp 27.007. Search for
995 // any service for voice call.
996 if ((callForwardInfo.serviceClass
997 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700998 callForwardingInfo = new CallForwardingInfo(true,
999 callForwardInfo.reason,
1000 callForwardInfo.number,
1001 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001002 break;
1003 }
1004 }
1005 // Didn't find a call forward info for voice call.
1006 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001007 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1008 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001009 }
Hall Liu27d24262020-09-18 19:04:59 -07001010 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001011 } else {
1012 if (ar.result == null) {
1013 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1014 }
1015 if (ar.exception != null) {
1016 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1017 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001018 int errorCode = TelephonyManager
1019 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001020 if (ar.exception instanceof CommandException) {
1021 CommandException.Error error =
1022 ((CommandException) (ar.exception)).getCommandError();
1023 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001024 errorCode = TelephonyManager
1025 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001026 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001027 errorCode = TelephonyManager
1028 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001029 }
1030 }
Hall Liu27d24262020-09-18 19:04:59 -07001031 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001032 }
Shuo Qian4a594052020-01-23 11:59:30 -08001033 break;
Hall Liu27d24262020-09-18 19:04:59 -07001034 }
Shuo Qian4a594052020-01-23 11:59:30 -08001035
Hall Liu27d24262020-09-18 19:04:59 -07001036 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001037 request = (MainThreadRequest) msg.obj;
1038 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001039 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001040 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001041 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1042 request.argument).first;
1043 request.phone.setCallForwardingOption(
1044 callForwardingInfoToSet.isEnabled()
1045 ? CommandsInterface.CF_ACTION_ENABLE
1046 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001047 callForwardingInfoToSet.getReason(),
1048 callForwardingInfoToSet.getNumber(),
1049 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1050 break;
Hall Liu27d24262020-09-18 19:04:59 -07001051 }
Shuo Qian4a594052020-01-23 11:59:30 -08001052
Hall Liu27d24262020-09-18 19:04:59 -07001053 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001056 Consumer<Integer> callback =
1057 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1058 request.argument).second;
1059 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001060 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001061 int errorCode = TelephonyManager.CallForwardingInfoCallback
1062 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001063 if (ar.exception instanceof CommandException) {
1064 CommandException.Error error =
1065 ((CommandException) (ar.exception)).getCommandError();
1066 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001067 errorCode = TelephonyManager.CallForwardingInfoCallback
1068 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001069 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001070 errorCode = TelephonyManager.CallForwardingInfoCallback
1071 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001072 }
1073 }
1074 callback.accept(errorCode);
1075 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001076 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001077 }
Shuo Qian4a594052020-01-23 11:59:30 -08001078 break;
Hall Liu27d24262020-09-18 19:04:59 -07001079 }
Shuo Qian4a594052020-01-23 11:59:30 -08001080
Hall Liu27d24262020-09-18 19:04:59 -07001081 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001082 request = (MainThreadRequest) msg.obj;
1083 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1084 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1085 break;
Hall Liu27d24262020-09-18 19:04:59 -07001086 }
Shuo Qian4a594052020-01-23 11:59:30 -08001087
Hall Liu27d24262020-09-18 19:04:59 -07001088 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001089 ar = (AsyncResult) msg.obj;
1090 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001091 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001092 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1093 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001094 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001095 // Service Class is a bit mask per 3gpp 27.007.
1096 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001097 if (callForwardResults.length > 1
1098 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001099 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001100 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001101 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1102 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001103 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001104 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001105 }
1106 } else {
1107 if (ar.result == null) {
1108 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1109 }
1110 if (ar.exception != null) {
1111 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1112 }
1113 if (ar.exception instanceof CommandException) {
1114 CommandException.Error error =
1115 ((CommandException) (ar.exception)).getCommandError();
1116 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1117 callForwardingStatus =
1118 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1119 }
1120 }
1121 }
Hall Liu27d24262020-09-18 19:04:59 -07001122 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001123 break;
Hall Liu27d24262020-09-18 19:04:59 -07001124 }
Shuo Qian4a594052020-01-23 11:59:30 -08001125
Hall Liu27d24262020-09-18 19:04:59 -07001126 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001127 request = (MainThreadRequest) msg.obj;
1128 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001129 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1130 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001131 break;
Hall Liu27d24262020-09-18 19:04:59 -07001132 }
Shuo Qian4a594052020-01-23 11:59:30 -08001133
Hall Liu27d24262020-09-18 19:04:59 -07001134 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001135 ar = (AsyncResult) msg.obj;
1136 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001137 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1138 Consumer<Integer> callback =
1139 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1140 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001141 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001142 if (ar.exception instanceof CommandException) {
1143 CommandException.Error error =
1144 ((CommandException) (ar.exception)).getCommandError();
1145 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1146 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1147 } else {
1148 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1149 }
1150 } else {
1151 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1152 }
1153 } else {
1154 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1155 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001156 }
Shuo Qian4a594052020-01-23 11:59:30 -08001157 break;
Hall Liu27d24262020-09-18 19:04:59 -07001158 }
Shuo Qian4a594052020-01-23 11:59:30 -08001159
Shishir Agrawal302c8692015-06-19 13:49:39 -07001160 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
1163 CellNetworkScanResult cellScanResult;
1164 if (ar.exception == null && ar.result != null) {
1165 cellScanResult = new CellNetworkScanResult(
1166 CellNetworkScanResult.STATUS_SUCCESS,
1167 (List<OperatorInfo>) ar.result);
1168 } else {
1169 if (ar.result == null) {
1170 loge("getCellNetworkScanResults: Empty response");
1171 }
1172 if (ar.exception != null) {
1173 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1174 }
1175 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1176 if (ar.exception instanceof CommandException) {
1177 CommandException.Error error =
1178 ((CommandException) (ar.exception)).getCommandError();
1179 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1180 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1181 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1182 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1183 }
1184 }
1185 cellScanResult = new CellNetworkScanResult(errorCode, null);
1186 }
1187 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001188 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001189 break;
1190
1191 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1192 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001193 ManualNetworkSelectionArgument selArg =
1194 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001195 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1196 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001197 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1198 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001199 break;
1200
1201 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001202 ar = (AsyncResult) msg.obj;
1203 request = (MainThreadRequest) ar.userObj;
1204 if (ar.exception == null) {
1205 request.result = true;
1206 } else {
1207 request.result = false;
1208 loge("setNetworkSelectionModeManual " + ar.exception);
1209 }
1210 notifyRequester(request);
1211 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001212 break;
1213
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001214 case CMD_GET_MODEM_ACTIVITY_INFO:
1215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001217 if (defaultPhone != null) {
1218 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001219 } else {
1220 ResultReceiver result = (ResultReceiver) request.argument;
1221 Bundle bundle = new Bundle();
1222 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001223 new ModemActivityInfo(0, 0, 0,
1224 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001225 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001226 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001227 break;
1228
Hall Liud0f208c2020-10-14 16:54:44 -07001229 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001230 ar = (AsyncResult) msg.obj;
1231 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001232 ResultReceiver result = (ResultReceiver) request.argument;
1233
Hall Liud0f208c2020-10-14 16:54:44 -07001234 ModemActivityInfo ret = null;
1235 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001236 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001237 // Update the last modem activity info and the result of the request.
1238 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1239 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001240 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001241 int[] txTimeMs = info.getTransmitTimeMillis();
1242 int[] lastModemTxTimeMs = mLastModemActivityInfo
1243 .getTransmitTimeMillis();
1244 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1245 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1246 }
Hall Liu49656c02020-10-09 19:00:11 -07001247 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001248 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1249 + mLastModemActivityInfo.getSleepTimeMillis());
1250 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1251 + mLastModemActivityInfo.getIdleTimeMillis());
1252 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1253 mLastModemActivityInfo.setReceiveTimeMillis(
1254 info.getReceiveTimeMillis()
1255 + mLastModemActivityInfo.getReceiveTimeMillis());
1256 }
Hall Liu49656c02020-10-09 19:00:11 -07001257 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001258 mLastModemActivityInfo.getSleepTimeMillis(),
1259 mLastModemActivityInfo.getIdleTimeMillis(),
1260 mLastModemActivityInfo.getTransmitTimeMillis(),
1261 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001262 } else {
1263 if (ar.result == null) {
1264 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001265 error = TelephonyManager.ModemActivityInfoException
1266 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001267 } else if (ar.exception instanceof CommandException) {
1268 loge("queryModemActivityInfo: CommandException: " +
1269 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001270 error = TelephonyManager.ModemActivityInfoException
1271 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001272 } else {
1273 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001274 error = TelephonyManager.ModemActivityInfoException
1275 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001276 }
1277 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001278 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001279 if (ret != null) {
1280 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1281 } else {
1282 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1283 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001284 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001285 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001286 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001287 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001288
Meng Wang1a7c35a2016-05-05 20:56:15 -07001289 case CMD_SET_ALLOWED_CARRIERS:
1290 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001291 CarrierRestrictionRules argument =
1292 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001293 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001294 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001295 break;
1296
1297 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1298 ar = (AsyncResult) msg.obj;
1299 request = (MainThreadRequest) ar.userObj;
1300 if (ar.exception == null && ar.result != null) {
1301 request.result = ar.result;
1302 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001303 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1304 if (ar.exception instanceof CommandException) {
1305 loge("setAllowedCarriers: CommandException: " + ar.exception);
1306 CommandException.Error error =
1307 ((CommandException) (ar.exception)).getCommandError();
1308 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1309 request.result =
1310 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1311 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001312 } else {
1313 loge("setAllowedCarriers: Unknown exception");
1314 }
1315 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001316 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001317 break;
1318
1319 case CMD_GET_ALLOWED_CARRIERS:
1320 request = (MainThreadRequest) msg.obj;
1321 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001322 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001323 break;
1324
1325 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1326 ar = (AsyncResult) msg.obj;
1327 request = (MainThreadRequest) ar.userObj;
1328 if (ar.exception == null && ar.result != null) {
1329 request.result = ar.result;
1330 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001331 request.result = new IllegalStateException(
1332 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001333 if (ar.result == null) {
1334 loge("getAllowedCarriers: Empty response");
1335 } else if (ar.exception instanceof CommandException) {
1336 loge("getAllowedCarriers: CommandException: " +
1337 ar.exception);
1338 } else {
1339 loge("getAllowedCarriers: Unknown exception");
1340 }
1341 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001342 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001343 break;
1344
Nathan Haroldb3014052017-01-25 15:57:32 -08001345 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1346 ar = (AsyncResult) msg.obj;
1347 request = (MainThreadRequest) ar.userObj;
1348 if (ar.exception == null && ar.result != null) {
1349 request.result = ar.result;
1350 } else {
1351 request.result = new IllegalArgumentException(
1352 "Failed to retrieve Forbidden Plmns");
1353 if (ar.result == null) {
1354 loge("getForbiddenPlmns: Empty response");
1355 } else {
1356 loge("getForbiddenPlmns: Unknown exception");
1357 }
1358 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001359 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001360 break;
1361
1362 case CMD_GET_FORBIDDEN_PLMNS:
1363 request = (MainThreadRequest) msg.obj;
1364 uiccCard = getUiccCardFromRequest(request);
1365 if (uiccCard == null) {
1366 loge("getForbiddenPlmns() UiccCard is null");
1367 request.result = new IllegalArgumentException(
1368 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001369 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001370 break;
1371 }
1372 Integer appType = (Integer) request.argument;
1373 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1374 if (uiccApp == null) {
1375 loge("getForbiddenPlmns() no app with specified type -- "
1376 + appType);
1377 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001378 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001379 break;
1380 } else {
1381 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1382 + " specified type -- " + appType);
1383 }
1384 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1385 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1386 onCompleted);
1387 break;
1388
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001389 case CMD_SWITCH_SLOTS:
1390 request = (MainThreadRequest) msg.obj;
1391 int[] physicalSlots = (int[]) request.argument;
1392 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1393 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1394 break;
1395
1396 case EVENT_SWITCH_SLOTS_DONE:
1397 ar = (AsyncResult) msg.obj;
1398 request = (MainThreadRequest) ar.userObj;
1399 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001400 notifyRequester(request);
1401 break;
1402 case CMD_GET_NETWORK_SELECTION_MODE:
1403 request = (MainThreadRequest) msg.obj;
1404 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1405 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1406 break;
1407
1408 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 if (ar.exception != null) {
1412 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1413 } else {
1414 int mode = ((int[]) ar.result)[0];
1415 if (mode == 0) {
1416 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1417 } else {
1418 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1419 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001420 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001421 notifyRequester(request);
1422 break;
1423 case CMD_GET_CDMA_ROAMING_MODE:
1424 request = (MainThreadRequest) msg.obj;
1425 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1426 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1427 break;
1428 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1429 ar = (AsyncResult) msg.obj;
1430 request = (MainThreadRequest) ar.userObj;
1431 if (ar.exception != null) {
1432 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1433 } else {
1434 request.result = ((int[]) ar.result)[0];
1435 }
1436 notifyRequester(request);
1437 break;
1438 case CMD_SET_CDMA_ROAMING_MODE:
1439 request = (MainThreadRequest) msg.obj;
1440 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1441 int mode = (int) request.argument;
1442 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1443 break;
1444 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1445 ar = (AsyncResult) msg.obj;
1446 request = (MainThreadRequest) ar.userObj;
1447 request.result = ar.exception == null;
1448 notifyRequester(request);
1449 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001450 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1451 request = (MainThreadRequest) msg.obj;
1452 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1453 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1454 break;
1455 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1456 ar = (AsyncResult) msg.obj;
1457 request = (MainThreadRequest) ar.userObj;
1458 if (ar.exception != null) {
1459 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1460 } else {
1461 request.result = ((int[]) ar.result)[0];
1462 }
1463 notifyRequester(request);
1464 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001465 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1466 request = (MainThreadRequest) msg.obj;
1467 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1468 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001469 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1470 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001471 break;
1472 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1473 ar = (AsyncResult) msg.obj;
1474 request = (MainThreadRequest) ar.userObj;
1475 request.result = ar.exception == null;
1476 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001477 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001478 case CMD_GET_ALL_CELL_INFO:
1479 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001480 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001481 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001482 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001483 case EVENT_GET_ALL_CELL_INFO_DONE:
1484 ar = (AsyncResult) msg.obj;
1485 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001486 // If a timeout occurs, the response will be null
1487 request.result = (ar.exception == null && ar.result != null)
1488 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 synchronized (request) {
1490 request.notifyAll();
1491 }
1492 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001493 case CMD_REQUEST_CELL_INFO_UPDATE:
1494 request = (MainThreadRequest) msg.obj;
1495 request.phone.requestCellInfoUpdate(request.workSource,
1496 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1497 break;
1498 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
1501 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1502 try {
1503 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001504 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001505 cb.onError(
1506 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1507 ar.exception.getClass().getName(),
1508 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001509 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001510 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001511 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001512 } else {
1513 // use the result as returned
1514 cb.onCellInfo((List<CellInfo>) ar.result);
1515 }
1516 } catch (RemoteException re) {
1517 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1518 }
1519 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001520 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001521 request = (MainThreadRequest) msg.obj;
1522 WorkSource ws = (WorkSource) request.argument;
1523 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001524 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001525 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001526 }
1527 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 if (ar.exception == null) {
1531 request.result = ar.result;
1532 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001533 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001534 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001535 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001536 }
1537
1538 synchronized (request) {
1539 request.notifyAll();
1540 }
1541 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001542 }
chen xu6dac5ab2018-10-26 17:39:23 -07001543 case CMD_MODEM_REBOOT:
1544 request = (MainThreadRequest) msg.obj;
1545 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001546 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001547 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001548 case EVENT_CMD_MODEM_REBOOT_DONE:
1549 handleNullReturnEvent(msg, "rebootModem");
1550 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001551 case CMD_REQUEST_ENABLE_MODEM:
1552 request = (MainThreadRequest) msg.obj;
1553 boolean enable = (boolean) request.argument;
1554 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001555 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001556 PhoneConfigurationManager.getInstance()
1557 .enablePhone(request.phone, enable, onCompleted);
1558 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001559 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001560 ar = (AsyncResult) msg.obj;
1561 request = (MainThreadRequest) ar.userObj;
1562 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001563 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001564 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001565 if ((boolean) request.result) {
1566 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1567 updateModemStateMetrics();
1568 } else {
1569 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1570 + ar.exception);
1571 }
1572 notifyRequester(request);
1573 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001574 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001575 case CMD_GET_MODEM_STATUS:
1576 request = (MainThreadRequest) msg.obj;
1577 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1578 PhoneConfigurationManager.getInstance()
1579 .getPhoneStatusFromModem(request.phone, onCompleted);
1580 break;
1581 case EVENT_GET_MODEM_STATUS_DONE:
1582 ar = (AsyncResult) msg.obj;
1583 request = (MainThreadRequest) ar.userObj;
1584 int id = request.phone.getPhoneId();
1585 if (ar.exception == null && ar.result != null) {
1586 request.result = ar.result;
1587 //update the cache as modem status has changed
1588 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1589 (boolean) request.result);
1590 } else {
1591 // Return true if modem status cannot be retrieved. For most cases,
1592 // modem status is on. And for older version modems, GET_MODEM_STATUS
1593 // and disable modem are not supported. Modem is always on.
1594 // TODO: this should be fixed in R to support a third
1595 // status UNKNOWN b/131631629
1596 request.result = true;
1597 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1598 + ar.exception);
1599 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001600 notifyRequester(request);
1601 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001602 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1603 request = (MainThreadRequest) msg.obj;
1604 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1605 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1606 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1607 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1608 break;
1609 }
1610 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1614 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1615 args.second.accept(ar.exception == null);
1616 notifyRequester(request);
1617 break;
1618 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001619 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1622 Phone phone = getPhoneFromRequest(request);
1623 if (phone != null) {
1624 phone.getSystemSelectionChannels(onCompleted);
1625 } else {
1626 loge("getSystemSelectionChannels: No phone object");
1627 request.result = new ArrayList<RadioAccessSpecifier>();
1628 notifyRequester(request);
1629 }
1630 break;
1631 }
1632 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1633 ar = (AsyncResult) msg.obj;
1634 request = (MainThreadRequest) ar.userObj;
1635 if (ar.exception == null && ar.result != null) {
1636 request.result = ar.result;
1637 } else {
1638 request.result = new IllegalArgumentException(
1639 "Failed to retrieve system selection channels");
1640 if (ar.result == null) {
1641 loge("getSystemSelectionChannels: Empty response");
1642 } else {
1643 loge("getSystemSelectionChannels: Unknown exception");
1644 }
1645 }
1646 notifyRequester(request);
1647 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001648 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1649 ar = (AsyncResult) msg.obj;
1650 request = (MainThreadRequest) ar.userObj;
1651 if (ar.exception == null && ar.result != null) {
1652 request.result = ar.result;
1653 } else {
1654 request.result = -1;
1655 loge("Failed to set Forbidden Plmns");
1656 if (ar.result == null) {
1657 loge("setForbidenPlmns: Empty response");
1658 } else if (ar.exception != null) {
1659 loge("setForbiddenPlmns: Exception: " + ar.exception);
1660 request.result = -1;
1661 } else {
1662 loge("setForbiddenPlmns: Unknown exception");
1663 }
1664 }
1665 notifyRequester(request);
1666 break;
1667 case CMD_SET_FORBIDDEN_PLMNS:
1668 request = (MainThreadRequest) msg.obj;
1669 uiccCard = getUiccCardFromRequest(request);
1670 if (uiccCard == null) {
1671 loge("setForbiddenPlmns: UiccCard is null");
1672 request.result = -1;
1673 notifyRequester(request);
1674 break;
1675 }
1676 Pair<Integer, List<String>> setFplmnsArgs =
1677 (Pair<Integer, List<String>>) request.argument;
1678 appType = setFplmnsArgs.first;
1679 List<String> fplmns = setFplmnsArgs.second;
1680 uiccApp = uiccCard.getApplicationByType(appType);
1681 if (uiccApp == null) {
1682 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1683 request.result = -1;
1684 loge("Failed to get UICC App");
1685 notifyRequester(request);
1686 } else {
1687 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1688 ((SIMRecords) uiccApp.getIccRecords())
1689 .setForbiddenPlmns(onCompleted, fplmns);
1690 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001691 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001692 case CMD_ERASE_MODEM_CONFIG:
1693 request = (MainThreadRequest) msg.obj;
1694 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1695 defaultPhone.eraseModemConfig(onCompleted);
1696 break;
1697 case EVENT_ERASE_MODEM_CONFIG_DONE:
1698 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001699 break;
zoey chene02881a2019-12-30 16:11:23 +08001700
1701 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1702 request = (MainThreadRequest) msg.obj;
1703 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1704 Pair<String, String> changed = (Pair<String, String>) request.argument;
1705 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1706 changed.first, changed.second, onCompleted);
1707 break;
1708 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception == null) {
1712 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001713 // If the operation is successful, update the PIN storage
1714 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1715 int phoneId = getPhoneFromRequest(request).getPhoneId();
1716 UiccController.getInstance().getPinStorage()
1717 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001718 } else {
1719 request.result = msg.arg1;
1720 }
1721 notifyRequester(request);
1722 break;
1723
Michele Berionne5e411512020-11-13 02:36:59 +00001724 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1727 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1728 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1729 enabled.first, enabled.second, onCompleted);
1730 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001731 }
zoey chene02881a2019-12-30 16:11:23 +08001732 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 if (ar.exception == null) {
1736 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001737 // If the operation is successful, update the PIN storage
1738 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1739 int phoneId = getPhoneFromRequest(request).getPhoneId();
1740 if (enabled.first) {
1741 UiccController.getInstance().getPinStorage()
1742 .storePin(enabled.second, phoneId);
1743 } else {
1744 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1745 }
zoey chene02881a2019-12-30 16:11:23 +08001746 } else {
1747 request.result = msg.arg1;
1748 }
Michele Berionne5e411512020-11-13 02:36:59 +00001749
1750
zoey chene02881a2019-12-30 16:11:23 +08001751 notifyRequester(request);
1752 break;
1753
Peter Wangdafb9ac2020-01-15 14:13:38 -08001754 case MSG_NOTIFY_USER_ACTIVITY:
1755 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001756 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001757 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1758 getDefaultPhone().getContext().sendBroadcastAsUser(
1759 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1760 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001761
1762 case CMD_SET_DATA_THROTTLING: {
1763 request = (MainThreadRequest) msg.obj;
1764 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1765 DataThrottlingRequest dataThrottlingRequest =
1766 (DataThrottlingRequest) request.argument;
1767 Phone phone = getPhoneFromRequest(request);
1768 if (phone != null) {
1769 phone.setDataThrottling(onCompleted,
1770 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1771 dataThrottlingRequest.getCompletionDurationMillis());
1772 } else {
1773 loge("setDataThrottling: No phone object");
1774 request.result =
1775 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1776 notifyRequester(request);
1777 }
1778
1779 break;
1780 }
1781 case EVENT_SET_DATA_THROTTLING_DONE:
1782 ar = (AsyncResult) msg.obj;
1783 request = (MainThreadRequest) ar.userObj;
1784
1785 if (ar.exception == null) {
1786 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1787 } else if (ar.exception instanceof CommandException) {
1788 loge("setDataThrottling: CommandException: " + ar.exception);
1789 CommandException.Error error =
1790 ((CommandException) (ar.exception)).getCommandError();
1791
1792 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1793 request.result = TelephonyManager
1794 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1795 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1796 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1797 } else {
1798 request.result =
1799 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1800 }
1801 } else {
1802 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1803 }
1804 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1805 notifyRequester(request);
1806 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001807
1808 case CMD_SET_SIM_POWER: {
1809 request = (MainThreadRequest) msg.obj;
1810 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1811 request = (MainThreadRequest) msg.obj;
1812 int stateToSet =
1813 ((Pair<Integer, IIntegerConsumer>)
1814 request.argument).first;
1815 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1816 break;
1817 }
1818 case EVENT_SET_SIM_POWER_DONE: {
1819 ar = (AsyncResult) msg.obj;
1820 request = (MainThreadRequest) ar.userObj;
1821 IIntegerConsumer callback =
1822 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1823 if (ar.exception != null) {
1824 loge("setSimPower exception: " + ar.exception);
1825 int errorCode = TelephonyManager.CallForwardingInfoCallback
1826 .RESULT_ERROR_UNKNOWN;
1827 if (ar.exception instanceof CommandException) {
1828 CommandException.Error error =
1829 ((CommandException) (ar.exception)).getCommandError();
1830 if (error == CommandException.Error.SIM_ERR) {
1831 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1832 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1833 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1834 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1835 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1836 } else {
1837 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1838 }
1839 }
1840 try {
1841 callback.accept(errorCode);
1842 } catch (RemoteException e) {
1843 // Ignore if the remote process is no longer available to call back.
1844 Log.w(LOG_TAG, "setSimPower: callback not available.");
1845 }
1846 } else {
1847 try {
1848 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1849 } catch (RemoteException e) {
1850 // Ignore if the remote process is no longer available to call back.
1851 Log.w(LOG_TAG, "setSimPower: callback not available.");
1852 }
1853 }
1854 break;
1855 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001856 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1857 request = (MainThreadRequest) msg.obj;
1858
1859 final Phone phone = getPhoneFromRequest(request);
1860 if (phone == null || phone.getServiceStateTracker() == null) {
1861 request.result = new IllegalStateException("Phone or SST is null");
1862 notifyRequester(request);
1863 break;
1864 }
1865
1866 Pair<Integer, SignalStrengthUpdateRequest> pair =
1867 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1868 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1869 request);
1870 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1871 request.subId, pair.first /*callingUid*/,
1872 pair.second /*request*/, onCompleted);
1873 break;
1874 }
1875 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1876 ar = (AsyncResult) msg.obj;
1877 request = (MainThreadRequest) ar.userObj;
1878 // request.result will be the exception of ar if present, true otherwise.
1879 // Be cautious not to leave result null which will wait() forever
1880 request.result = ar.exception != null ? ar.exception : true;
1881 notifyRequester(request);
1882 break;
1883 }
1884 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1885 request = (MainThreadRequest) msg.obj;
1886
1887 Phone phone = getPhoneFromRequest(request);
1888 if (phone == null || phone.getServiceStateTracker() == null) {
1889 request.result = new IllegalStateException("Phone or SST is null");
1890 notifyRequester(request);
1891 break;
1892 }
1893
1894 Pair<Integer, SignalStrengthUpdateRequest> pair =
1895 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1896 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1897 request);
1898 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1899 request.subId, pair.first /*callingUid*/,
1900 pair.second /*request*/, onCompleted);
1901 break;
1902 }
1903 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1904 ar = (AsyncResult) msg.obj;
1905 request = (MainThreadRequest) ar.userObj;
1906 request.result = ar.exception != null ? ar.exception : true;
1907 notifyRequester(request);
1908 break;
1909 }
Jordan Liu109698e2020-11-24 14:50:34 -08001910
Michele Berionne5e411512020-11-13 02:36:59 +00001911 case CMD_PREPARE_UNATTENDED_REBOOT:
1912 request = (MainThreadRequest) msg.obj;
1913 request.result =
1914 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1915 notifyRequester(request);
1916 break;
1917
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 default:
1919 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1920 break;
1921 }
1922 }
Jake Hambye994d462014-02-03 13:10:13 -08001923
Pengquan Menga1bb6272018-09-06 09:59:22 -07001924 private void notifyRequester(MainThreadRequest request) {
1925 synchronized (request) {
1926 request.notifyAll();
1927 }
1928 }
1929
Jake Hambye994d462014-02-03 13:10:13 -08001930 private void handleNullReturnEvent(Message msg, String command) {
1931 AsyncResult ar = (AsyncResult) msg.obj;
1932 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1933 if (ar.exception == null) {
1934 request.result = true;
1935 } else {
1936 request.result = false;
1937 if (ar.exception instanceof CommandException) {
1938 loge(command + ": CommandException: " + ar.exception);
1939 } else {
1940 loge(command + ": Unknown exception");
1941 }
1942 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001943 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 }
1946
1947 /**
1948 * Posts the specified command to be executed on the main thread,
1949 * waits for the request to complete, and returns the result.
1950 * @see #sendRequestAsync
1951 */
1952 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001953 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1954 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001955 }
1956
1957 /**
1958 * Posts the specified command to be executed on the main thread,
1959 * waits for the request to complete, and returns the result.
1960 * @see #sendRequestAsync
1961 */
1962 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1963 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001964 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001965 }
1966
1967 /**
1968 * Posts the specified command to be executed on the main thread,
1969 * waits for the request to complete, and returns the result.
1970 * @see #sendRequestAsync
1971 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001972 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001973 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1974 }
1975
1976 /**
1977 * Posts the specified command to be executed on the main thread,
1978 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1979 * if not timeout or null otherwise.
1980 * @see #sendRequestAsync
1981 */
1982 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1983 long timeoutInMs) {
1984 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001985 }
1986
1987 /**
1988 * Posts the specified command to be executed on the main thread,
1989 * waits for the request to complete, and returns the result.
1990 * @see #sendRequestAsync
1991 */
Nathan Harold92bed182018-10-12 18:16:49 -07001992 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001993 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001994 }
1995
1996 /**
1997 * Posts the specified command to be executed on the main thread,
1998 * waits for the request to complete, and returns the result.
1999 * @see #sendRequestAsync
2000 */
2001 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002002 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2003 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002004 }
2005
2006 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002007 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2008 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2009 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002010 * @see #sendRequestAsync
2011 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002012 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2013 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002014 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2015 throw new RuntimeException("This method will deadlock if called from the main thread.");
2016 }
2017
Nathan Harold92bed182018-10-12 18:16:49 -07002018 MainThreadRequest request = null;
2019 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2020 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2021 } else if (phone != null) {
2022 request = new MainThreadRequest(argument, phone, workSource);
2023 } else {
2024 request = new MainThreadRequest(argument, subId, workSource);
2025 }
2026
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 Message msg = mMainThreadHandler.obtainMessage(command, request);
2028 msg.sendToTarget();
2029
Rambo Wang0f050d82021-02-12 11:43:36 -08002030
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002032 if (timeoutInMs >= 0) {
2033 // Wait for at least timeoutInMs before returning null request result
2034 long now = SystemClock.elapsedRealtime();
2035 long deadline = now + timeoutInMs;
2036 while (request == null && now < deadline) {
2037 try {
2038 request.wait(deadline - now);
2039 } catch (InterruptedException e) {
2040 // Do nothing, go back and check if request is completed or timeout
2041 } finally {
2042 now = SystemClock.elapsedRealtime();
2043 }
2044 }
2045 } else {
2046 // Wait for the request to complete
2047 while (request.result == null) {
2048 try {
2049 request.wait();
2050 } catch (InterruptedException e) {
2051 // Do nothing, go back and wait until the request is complete
2052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
2054 }
2055 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002056 if (request.result == null) {
2057 Log.wtf(LOG_TAG,
2058 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 return request.result;
2061 }
2062
2063 /**
2064 * Asynchronous ("fire and forget") version of sendRequest():
2065 * Posts the specified command to be executed on the main thread, and
2066 * returns immediately.
2067 * @see #sendRequest
2068 */
2069 private void sendRequestAsync(int command) {
2070 mMainThreadHandler.sendEmptyMessage(command);
2071 }
2072
2073 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002074 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002075 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002076 */
2077 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002078 sendRequestAsync(command, argument, null, null);
2079 }
2080
2081 /**
2082 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2083 * @see {@link #sendRequest(int,Object)}
2084 */
2085 private void sendRequestAsync(
2086 int command, Object argument, Phone phone, WorkSource workSource) {
2087 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002088 Message msg = mMainThreadHandler.obtainMessage(command, request);
2089 msg.sendToTarget();
2090 }
2091
2092 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 * Initialize the singleton PhoneInterfaceManager instance.
2094 * This is only done once, at startup, from PhoneApp.onCreate().
2095 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002096 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 synchronized (PhoneInterfaceManager.class) {
2098 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002099 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 } else {
2101 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2102 }
2103 return sInstance;
2104 }
2105 }
2106
2107 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002108 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002111 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002112 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2114 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002115 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002116 mTelephonySharedPreferences =
2117 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002118 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002119 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002120 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002121 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002122
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 publish();
2124 }
2125
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002126 private Phone getDefaultPhone() {
2127 Phone thePhone = getPhone(getDefaultSubscription());
2128 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2129 }
2130
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 private void publish() {
2132 if (DBG) log("publish: " + this);
2133
Peter Wangc035ce42020-01-08 21:00:22 -08002134 TelephonyFrameworkInitializer
2135 .getTelephonyServiceManager()
2136 .getTelephonyServiceRegisterer()
2137 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 }
2139
Stuart Scott584921c2015-01-15 17:10:34 -08002140 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002141 if (request.phone != null) {
2142 return request.phone;
2143 } else {
2144 return getPhoneFromSubId(request.subId);
2145 }
2146 }
2147
2148 private Phone getPhoneFromSubId(int subId) {
2149 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2150 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002151 }
2152
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002153 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2154 Phone phone = getPhoneFromRequest(request);
2155 return phone == null ? null :
2156 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2157 }
2158
Wink Saville36469e72014-06-11 15:17:00 -07002159 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002160 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002161 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163
Naina Nallurid63128d2019-09-17 14:10:30 -07002164 private void sendEraseModemConfig(Phone phone) {
2165 if (phone != null) {
2166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2167 mApp, phone.getSubId(), "eraseModemConfig");
2168 final long identity = Binder.clearCallingIdentity();
2169 try {
2170 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2171 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2172 } finally {
2173 Binder.restoreCallingIdentity(identity);
2174 }
2175 }
2176 }
2177
Peter Wang44b186e2020-01-13 23:33:09 -08002178 private boolean isImsAvailableOnDevice() {
2179 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2180 if (pm == null) {
2181 // For some reason package manger is not available.. This will fail internally anyway,
2182 // so do not throw error and allow.
2183 return true;
2184 }
2185 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2186 }
2187
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002189 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002190 }
2191
Wink Savilleb564aae2014-10-23 10:18:09 -07002192 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 if (DBG) log("dial: " + number);
2194 // No permission check needed here: This is just a wrapper around the
2195 // ACTION_DIAL intent, which is available to any app since it puts up
2196 // the UI before it does anything.
2197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002198 final long identity = Binder.clearCallingIdentity();
2199 try {
2200 String url = createTelUrl(number);
2201 if (url == null) {
2202 return;
2203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205 // PENDING: should we just silently fail if phone is offhook or ringing?
2206 PhoneConstants.State state = mCM.getState(subId);
2207 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2208 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2209 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2210 mApp.startActivity(intent);
2211 }
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 }
2215 }
2216
2217 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002218 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
2220
Wink Savilleb564aae2014-10-23 10:18:09 -07002221 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 if (DBG) log("call: " + number);
2223
2224 // This is just a wrapper around the ACTION_CALL intent, but we still
2225 // need to do a permission check since we're calling startActivity()
2226 // from the context of the phone app.
2227 enforceCallPermission();
2228
Jordan Liu1617b712019-07-10 15:06:26 -07002229 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 != AppOpsManager.MODE_ALLOWED) {
2231 return;
2232 }
2233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002234 final long identity = Binder.clearCallingIdentity();
2235 try {
2236 String url = createTelUrl(number);
2237 if (url == null) {
2238 return;
2239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241 boolean isValid = false;
2242 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2243 if (slist != null) {
2244 for (SubscriptionInfo subInfoRecord : slist) {
2245 if (subInfoRecord.getSubscriptionId() == subId) {
2246 isValid = true;
2247 break;
2248 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002249 }
Wink Saville08874612014-08-31 19:19:58 -07002250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002251 if (!isValid) {
2252 return;
2253 }
Wink Saville08874612014-08-31 19:19:58 -07002254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2256 intent.putExtra(SUBSCRIPTION_KEY, subId);
2257 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2258 mApp.startActivity(intent);
2259 } finally {
2260 Binder.restoreCallingIdentity(identity);
2261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 }
2263
Wink Savilleb564aae2014-10-23 10:18:09 -07002264 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002265 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002266 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2267 }
2268
Wink Savilleb564aae2014-10-23 10:18:09 -07002269 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002270 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002271 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2272 }
2273
Wink Savilleb564aae2014-10-23 10:18:09 -07002274 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276
2277 final long identity = Binder.clearCallingIdentity();
2278 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002279 Phone phone = getPhone(subId);
2280 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002281 checkSimPin.start();
2282 return checkSimPin.unlockSim(null, pin);
2283 } finally {
2284 Binder.restoreCallingIdentity(identity);
2285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 }
2287
Wink Savilleb564aae2014-10-23 10:18:09 -07002288 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290
2291 final long identity = Binder.clearCallingIdentity();
2292 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002293 Phone phone = getPhone(subId);
2294 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295 checkSimPuk.start();
2296 return checkSimPuk.unlockSim(puk, pin);
2297 } finally {
2298 Binder.restoreCallingIdentity(identity);
2299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
2302 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002303 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 * a synchronous one.
2305 */
2306 private static class UnlockSim extends Thread {
2307
2308 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002309 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310
2311 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002312 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2313 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314
2315 // For replies from SimCard interface
2316 private Handler mHandler;
2317
2318 // For async handler to identify request type
2319 private static final int SUPPLY_PIN_COMPLETE = 100;
2320
Michele Berionne5e411512020-11-13 02:36:59 +00002321 UnlockSim(int phoneId, IccCard simCard) {
2322 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 mSimCard = simCard;
2324 }
2325
2326 @Override
2327 public void run() {
2328 Looper.prepare();
2329 synchronized (UnlockSim.this) {
2330 mHandler = new Handler() {
2331 @Override
2332 public void handleMessage(Message msg) {
2333 AsyncResult ar = (AsyncResult) msg.obj;
2334 switch (msg.what) {
2335 case SUPPLY_PIN_COMPLETE:
2336 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2337 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002338 mRetryCount = msg.arg1;
2339 if (ar.exception != null) {
2340 if (ar.exception instanceof CommandException &&
2341 ((CommandException)(ar.exception)).getCommandError()
2342 == CommandException.Error.PASSWORD_INCORRECT) {
2343 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002344 } //When UiccCardApp dispose,handle message and return exception
2345 else if (ar.exception instanceof CommandException &&
2346 ((CommandException) (ar.exception)).getCommandError()
2347 == CommandException.Error.ABORTED) {
2348 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002349 } else {
2350 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2351 }
2352 } else {
2353 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 mDone = true;
2356 UnlockSim.this.notifyAll();
2357 }
2358 break;
2359 }
2360 }
2361 };
2362 UnlockSim.this.notifyAll();
2363 }
2364 Looper.loop();
2365 }
2366
2367 /*
2368 * Use PIN or PUK to unlock SIM card
2369 *
2370 * If PUK is null, unlock SIM card with PIN
2371 *
2372 * If PUK is not null, unlock SIM card with PUK and set PIN code
2373 */
Wink Saville9de0f752013-10-22 19:04:03 -07002374 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375
2376 while (mHandler == null) {
2377 try {
2378 wait();
2379 } catch (InterruptedException e) {
2380 Thread.currentThread().interrupt();
2381 }
2382 }
2383 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2384
2385 if (puk == null) {
2386 mSimCard.supplyPin(pin, callback);
2387 } else {
2388 mSimCard.supplyPuk(puk, pin, callback);
2389 }
2390
2391 while (!mDone) {
2392 try {
2393 Log.d(LOG_TAG, "wait for done");
2394 wait();
2395 } catch (InterruptedException e) {
2396 // Restore the interrupted status
2397 Thread.currentThread().interrupt();
2398 }
2399 }
2400 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002401 int[] resultArray = new int[2];
2402 resultArray[0] = mResult;
2403 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002404
2405 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2406 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2407 }
2408
Wink Saville9de0f752013-10-22 19:04:03 -07002409 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 }
2411 }
2412
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002413 /**
2414 * This method has been removed due to privacy and stability concerns.
2415 */
2416 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002418 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2419 return;
Wink Saville36469e72014-06-11 15:17:00 -07002420 }
2421
Nathan Harold1f889d82020-06-04 17:05:26 -07002422 @Override
2423 public void updateServiceLocationWithPackageName(String callingPackage) {
2424 mApp.getSystemService(AppOpsManager.class)
2425 .checkPackage(Binder.getCallingUid(), callingPackage);
2426
Nathan Haroldf096d982020-11-18 17:18:06 -08002427 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002428 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2429 // Callers targeting S have no business invoking this method.
2430 return;
2431 }
2432
2433 LocationAccessPolicy.LocationPermissionResult locationResult =
2434 LocationAccessPolicy.checkLocationPermission(mApp,
2435 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2436 .setCallingPackage(callingPackage)
2437 .setCallingFeatureId(null)
2438 .setCallingPid(Binder.getCallingPid())
2439 .setCallingUid(Binder.getCallingUid())
2440 .setMethod("updateServiceLocation")
2441 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2442 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2443 .build());
2444 // Apps that lack location permission have no business calling this method;
2445 // however, because no permission was declared in the public API, denials must
2446 // all be "soft".
2447 switch (locationResult) {
2448 case DENIED_HARD: /* fall through */
2449 case DENIED_SOFT:
2450 return;
2451 }
2452
2453 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454 final long identity = Binder.clearCallingIdentity();
2455 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002456 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002458 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 }
2460 } finally {
2461 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002465 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002466 @Override
2467 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002468 return isRadioOnWithFeature(callingPackage, null);
2469 }
2470
2471
2472 @Override
2473 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2474 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2475 callingFeatureId);
2476 }
2477
2478 @Deprecated
2479 @Override
2480 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2481 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002482 }
2483
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002484 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002485 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2486 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002488 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002489 return false;
2490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491
2492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 return isRadioOnForSubscriber(subId);
2495 } finally {
2496 Binder.restoreCallingIdentity(identity);
2497 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002498 }
2499
2500 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 final Phone phone = getPhone(subId);
2504 if (phone != null) {
2505 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2506 } else {
2507 return false;
2508 }
2509 } finally {
2510 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512 }
2513
2514 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002515 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 }
Wink Saville36469e72014-06-11 15:17:00 -07002517
Wink Savilleb564aae2014-10-23 10:18:09 -07002518 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002520
2521 final long identity = Binder.clearCallingIdentity();
2522 try {
2523 final Phone phone = getPhone(subId);
2524 if (phone != null) {
2525 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2526 }
2527 } finally {
2528 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002529 }
Wink Saville36469e72014-06-11 15:17:00 -07002530 }
2531
2532 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002533 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002534 }
2535
Wink Savilleb564aae2014-10-23 10:18:09 -07002536 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002537 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538
2539 final long identity = Binder.clearCallingIdentity();
2540 try {
2541 final Phone phone = getPhone(subId);
2542 if (phone == null) {
2543 return false;
2544 }
2545 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2546 toggleRadioOnOffForSubscriber(subId);
2547 }
2548 return true;
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 }
Wink Saville36469e72014-06-11 15:17:00 -07002553
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002554 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002555 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002556 /*
2557 * If any of the Radios are available, it will need to be
2558 * shutdown. So return true if any Radio is available.
2559 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560 final long identity = Binder.clearCallingIdentity();
2561 try {
2562 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2563 Phone phone = PhoneFactory.getPhone(i);
2564 if (phone != null && phone.isRadioAvailable()) return true;
2565 }
2566 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2567 return false;
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002570 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002571 }
2572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002574 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575 enforceModifyPermission();
2576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2580 logv("Shutting down Phone " + i);
2581 shutdownRadioUsingPhoneId(i);
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002585 }
2586 }
2587
2588 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002589 Phone phone = PhoneFactory.getPhone(phoneId);
2590 if (phone != null && phone.isRadioAvailable()) {
2591 phone.shutdownRadio();
2592 }
2593 }
2594
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002596 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2601 if (defaultPhone != null) {
2602 defaultPhone.setRadioPower(turnOn);
2603 return true;
2604 } else {
2605 loge("There's no default phone.");
2606 return false;
2607 }
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002610 }
Wink Saville36469e72014-06-11 15:17:00 -07002611 }
2612
Wink Savilleb564aae2014-10-23 10:18:09 -07002613 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615
2616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 final Phone phone = getPhone(subId);
2619 if (phone != null) {
2620 phone.setRadioPower(turnOn);
2621 return true;
2622 } else {
2623 return false;
2624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002628 }
2629
Wink Saville36469e72014-06-11 15:17:00 -07002630 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002631 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 public boolean enableDataConnectivity() {
2633 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634
2635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 int subId = mSubscriptionController.getDefaultDataSubId();
2638 final Phone phone = getPhone(subId);
2639 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002640 phone.getDataEnabledSettings().setDataEnabled(
2641 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 return true;
2643 } else {
2644 return false;
2645 }
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649 }
2650
Wink Saville36469e72014-06-11 15:17:00 -07002651 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002652 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 public boolean disableDataConnectivity() {
2654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 int subId = mSubscriptionController.getDefaultDataSubId();
2659 final Phone phone = getPhone(subId);
2660 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002661 phone.getDataEnabledSettings().setDataEnabled(
2662 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 return true;
2664 } else {
2665 return false;
2666 }
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002673 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674 final long identity = Binder.clearCallingIdentity();
2675 try {
2676 final Phone phone = getPhone(subId);
2677 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002678 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 } else {
2680 return false;
2681 }
2682 } finally {
2683 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 }
2686
2687 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002688 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002689 }
2690
pkanwarae03a6b2016-11-06 20:37:09 -08002691 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 enforceCallPermission();
2693
2694 final long identity = Binder.clearCallingIdentity();
2695 try {
2696 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2697 return;
2698 }
2699 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2700 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2701 } finally {
2702 Binder.restoreCallingIdentity(identity);
2703 }
pkanwar32d516d2016-10-14 19:37:38 -07002704 };
2705
Wink Savilleb564aae2014-10-23 10:18:09 -07002706 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708
2709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2712 return false;
2713 }
2714 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2715 } finally {
2716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
2719
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002721 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002722 }
2723
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002724 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 Phone phone = PhoneFactory.getPhone(slotIndex);
2728 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2729 PhoneConstantConversions.convertCallState(phone.getState());
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
2732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733 }
2734
Sanket Padawe356d7632015-06-22 14:03:32 -07002735 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002736 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002737 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2738 }
2739
2740 @Override
2741 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 final long identity = Binder.clearCallingIdentity();
2743 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002744 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745 if (phone != null) {
2746 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2747 } else {
2748 return PhoneConstantConversions.convertDataState(
2749 PhoneConstants.DataState.DISCONNECTED);
2750 }
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002753 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 }
2755
Sanket Padawe356d7632015-06-22 14:03:32 -07002756 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002757 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002758 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2759 }
2760
2761 @Override
2762 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763 final long identity = Binder.clearCallingIdentity();
2764 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002765 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766 if (phone != null) {
2767 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2768 } else {
2769 return TelephonyManager.DATA_ACTIVITY_NONE;
2770 }
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 }
2775
2776 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002777 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002778 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002779 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002780
2781 LocationAccessPolicy.LocationPermissionResult locationResult =
2782 LocationAccessPolicy.checkLocationPermission(mApp,
2783 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2784 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002785 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002786 .setCallingPid(Binder.getCallingPid())
2787 .setCallingUid(Binder.getCallingUid())
2788 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002789 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002790 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2791 .build());
2792 switch (locationResult) {
2793 case DENIED_HARD:
2794 throw new SecurityException("Not allowed to access cell location");
2795 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002796 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2797 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 }
2799
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002800 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002804 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002805 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 } finally {
2807 Binder.restoreCallingIdentity(identity);
2808 }
Svetoslav64fad262015-04-14 14:35:21 -07002809 }
2810
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002812 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002813 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2814 // registered cell info, so return a NULL country instead.
2815 final long identity = Binder.clearCallingIdentity();
2816 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002817 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2818 // Get default phone in this case.
2819 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2820 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002821 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002823 if (phone == null) return "";
2824 ServiceStateTracker sst = phone.getServiceStateTracker();
2825 if (sst == null) return "";
2826 LocaleTracker lt = sst.getLocaleTracker();
2827 if (lt == null) return "";
2828 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2829 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2830 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002831 } finally {
2832 Binder.restoreCallingIdentity(identity);
2833 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002834 }
2835
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002836 /**
2837 * This method was removed due to potential issues caused by performing partial
2838 * updates of service state, and lack of a credible use case.
2839 *
2840 * This has the ability to break the telephony implementation by disabling notification of
2841 * changes in device connectivity. DO NOT USE THIS!
2842 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002843 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 public void enableLocationUpdates() {
2845 mApp.enforceCallingOrSelfPermission(
2846 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002849 /**
2850 * This method was removed due to potential issues caused by performing partial
2851 * updates of service state, and lack of a credible use case.
2852 *
2853 * This has the ability to break the telephony implementation by disabling notification of
2854 * changes in device connectivity. DO NOT USE THIS!
2855 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856 @Override
2857 public void disableLocationUpdates() {
2858 mApp.enforceCallingOrSelfPermission(
2859 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
2862 @Override
2863 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002864 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2865 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002866 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002867 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2868 throw new SecurityException(
2869 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2870 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002871
Jordan Liu1617b712019-07-10 15:06:26 -07002872 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2874 return null;
2875 }
Svetoslav64fad262015-04-14 14:35:21 -07002876
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002877 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002879 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002880 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881
Nathan Haroldf180aac2018-06-01 18:43:55 -07002882 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2883 for (CellInfo ci : info) {
2884 if (ci instanceof CellInfoGsm) {
2885 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2886 } else if (ci instanceof CellInfoWcdma) {
2887 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002889 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002890 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
2892
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002893 private List<CellInfo> getCachedCellInfo() {
2894 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2895 for (Phone phone : PhoneFactory.getPhones()) {
2896 List<CellInfo> info = phone.getAllCellInfo();
2897 if (info != null) cellInfos.addAll(info);
2898 }
2899 return cellInfos;
2900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901
2902 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002903 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002904 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002905 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002906
2907 LocationAccessPolicy.LocationPermissionResult locationResult =
2908 LocationAccessPolicy.checkLocationPermission(mApp,
2909 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2910 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002911 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002912 .setCallingPid(Binder.getCallingPid())
2913 .setCallingUid(Binder.getCallingUid())
2914 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002915 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002916 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2917 .build());
2918 switch (locationResult) {
2919 case DENIED_HARD:
2920 throw new SecurityException("Not allowed to access cell info");
2921 case DENIED_SOFT:
2922 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002923 }
2924
Nathan Haroldf096d982020-11-18 17:18:06 -08002925 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002926 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2927 return getCachedCellInfo();
2928 }
2929
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002930 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002931 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2935 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002936 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002937 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 if (info != null) cellInfos.addAll(info);
2939 }
2940 return cellInfos;
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002943 }
2944 }
2945
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002946 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002947 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2948 String callingFeatureId) {
2949 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2950 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002951 }
2952
2953 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002954 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2955 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002956 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002957 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002958 }
2959
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002960 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2961 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002962 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002963 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002964
2965 LocationAccessPolicy.LocationPermissionResult locationResult =
2966 LocationAccessPolicy.checkLocationPermission(mApp,
2967 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2968 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002969 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002970 .setCallingPid(Binder.getCallingPid())
2971 .setCallingUid(Binder.getCallingUid())
2972 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002973 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2974 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002975 .build());
2976 switch (locationResult) {
2977 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002978 if (TelephonyPermissions
2979 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002980 // Safetynet logging for b/154934934
2981 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2982 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002983 throw new SecurityException("Not allowed to access cell info");
2984 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002985 if (TelephonyPermissions
2986 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002987 // Safetynet logging for b/154934934
2988 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2989 }
Nathan Harold5320c422019-05-09 10:26:08 -07002990 try {
2991 cb.onCellInfo(new ArrayList<CellInfo>());
2992 } catch (RemoteException re) {
2993 // Drop without consequences
2994 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002995 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002996 }
2997
Nathan Harolda939a962019-05-09 10:13:47 -07002998
2999 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003000 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3001
3002 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3003 }
3004
3005 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003007 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003008 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009
3010 final long identity = Binder.clearCallingIdentity();
3011 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003012 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 } finally {
3014 Binder.restoreCallingIdentity(identity);
3015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 }
3017
Shishir Agrawala9f32182016-04-12 12:00:16 -07003018 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003019 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003020 Phone phone = PhoneFactory.getPhone(slotIndex);
3021 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003022 return null;
3023 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003024 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003025 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003026 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003027 return null;
3028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029
3030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 return phone.getImei();
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
3035 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003036 }
3037
3038 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003039 public String getTypeAllocationCodeForSlot(int slotIndex) {
3040 Phone phone = PhoneFactory.getPhone(slotIndex);
3041 String tac = null;
3042 if (phone != null) {
3043 String imei = phone.getImei();
3044 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3045 }
3046 return tac;
3047 }
3048
3049 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003050 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003051 Phone phone = PhoneFactory.getPhone(slotIndex);
3052 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003053 return null;
3054 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003055
Jeff Davidson913390f2018-02-23 17:11:49 -08003056 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003057 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003058 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003059 return null;
3060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061
3062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 return phone.getMeid();
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
Jack Yu2af8d712017-03-15 17:14:14 -07003068 }
3069
3070 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003071 public String getManufacturerCodeForSlot(int slotIndex) {
3072 Phone phone = PhoneFactory.getPhone(slotIndex);
3073 String manufacturerCode = null;
3074 if (phone != null) {
3075 String meid = phone.getMeid();
3076 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3077 }
3078 return manufacturerCode;
3079 }
3080
3081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003082 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3083 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003084 Phone phone = PhoneFactory.getPhone(slotIndex);
3085 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003086 return null;
3087 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003088 int subId = phone.getSubId();
3089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003090 mApp, subId, callingPackage, callingFeatureId,
3091 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003092 return null;
3093 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094
3095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 return phone.getDeviceSvn();
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003101 }
3102
fionaxu43304da2017-11-27 22:51:16 -08003103 @Override
3104 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 final Phone phone = getPhone(subId);
3108 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
fionaxu43304da2017-11-27 22:51:16 -08003112 }
3113
3114 @Override
3115 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 final Phone phone = getPhone(subId);
3119 return phone == null ? null : phone.getCarrierName();
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
fionaxu43304da2017-11-27 22:51:16 -08003123 }
3124
calvinpanffe225e2018-11-01 19:43:06 +08003125 @Override
chen xu0026ca62019-03-06 15:28:50 -08003126 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003127 final long identity = Binder.clearCallingIdentity();
3128 try {
3129 final Phone phone = getPhone(subId);
3130 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003131 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
3137 @Override
chen xu0026ca62019-03-06 15:28:50 -08003138 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003142 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
3146 }
3147
chen xu651eec72018-11-11 19:03:44 -08003148 @Override
chen xu864e11c2018-12-06 22:10:03 -08003149 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3150 if (!isSubscriptionMccMnc) {
3151 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3152 }
chen xu651eec72018-11-11 19:03:44 -08003153 final Phone phone = PhoneFactory.getPhone(slotIndex);
3154 if (phone == null) {
3155 return TelephonyManager.UNKNOWN_CARRIER_ID;
3156 }
3157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
3162 }
3163 }
3164
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 //
3166 // Internal helper methods.
3167 //
3168
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003169 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3171 *
3172 * @throws SecurityException if the caller does not have the required permission
3173 */
3174 private void enforceModifyPermission() {
3175 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3176 }
3177
Shuo Qiancd19c462020-01-16 20:51:11 -08003178 /**
3179 * Make sure the caller is system.
3180 *
3181 * @throws SecurityException if the caller is not system.
3182 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003183 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003184 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3185 throw new SecurityException("Caller must be system");
3186 }
3187 }
3188
Shuo Qian3b6ee772019-11-13 17:43:31 -08003189 private void enforceActiveEmergencySessionPermission() {
3190 mApp.enforceCallingOrSelfPermission(
3191 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3192 }
3193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003194 /**
3195 * Make sure the caller has the CALL_PHONE permission.
3196 *
3197 * @throws SecurityException if the caller does not have the required permission
3198 */
3199 private void enforceCallPermission() {
3200 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3201 }
3202
paulhu5a773602019-08-23 19:17:33 +08003203 private void enforceSettingsPermission() {
3204 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003205 }
3206
Michele Berionne5e411512020-11-13 02:36:59 +00003207 private void enforceRebootPermission() {
3208 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3209 }
3210
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 private String createTelUrl(String number) {
3212 if (TextUtils.isEmpty(number)) {
3213 return null;
3214 }
3215
Jake Hambye994d462014-02-03 13:10:13 -08003216 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003217 }
3218
Ihab Awadf9e92732013-12-05 18:02:52 -08003219 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003220 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3221 }
3222
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003223 private static void logv(String msg) {
3224 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3225 }
3226
Ihab Awadf9e92732013-12-05 18:02:52 -08003227 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003228 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3229 }
3230
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003231 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003233 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003234 }
3235
Sanket Padawe356d7632015-06-22 14:03:32 -07003236 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003237 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003238 final long identity = Binder.clearCallingIdentity();
3239 try {
3240 final Phone phone = PhoneFactory.getPhone(slotIndex);
3241 if (phone == null) {
3242 return PhoneConstants.PHONE_TYPE_NONE;
3243 } else {
3244 return phone.getPhoneType();
3245 }
3246 } finally {
3247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003249 }
3250
3251 /**
3252 * Returns the CDMA ERI icon index to display
3253 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003254 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003255 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3256 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3257 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003258 }
3259
Sanket Padawe356d7632015-06-22 14:03:32 -07003260 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003261 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3262 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003264 mApp, subId, callingPackage, callingFeatureId,
3265 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003266 return -1;
3267 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268
3269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 final Phone phone = getPhone(subId);
3272 if (phone != null) {
3273 return phone.getCdmaEriIconIndex();
3274 } else {
3275 return -1;
3276 }
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 }
3281
3282 /**
3283 * Returns the CDMA ERI icon mode,
3284 * 0 - ON
3285 * 1 - FLASHING
3286 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003288 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3289 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3290 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003291 }
3292
Sanket Padawe356d7632015-06-22 14:03:32 -07003293 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003294 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3295 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003297 mApp, subId, callingPackage, callingFeatureId,
3298 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003299 return -1;
3300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003301
3302 final long identity = Binder.clearCallingIdentity();
3303 try {
3304 final Phone phone = getPhone(subId);
3305 if (phone != null) {
3306 return phone.getCdmaEriIconMode();
3307 } else {
3308 return -1;
3309 }
3310 } finally {
3311 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003313 }
3314
3315 /**
3316 * Returns the CDMA ERI text,
3317 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003319 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3320 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3321 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003322 }
3323
Sanket Padawe356d7632015-06-22 14:03:32 -07003324 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003325 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3326 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003328 mApp, subId, callingPackage, callingFeatureId,
3329 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003330 return null;
3331 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332
3333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 final Phone phone = getPhone(subId);
3336 if (phone != null) {
3337 return phone.getCdmaEriText();
3338 } else {
3339 return null;
3340 }
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003344 }
3345
3346 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003347 * Returns the CDMA MDN.
3348 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003349 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003350 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3352 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003357 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 return phone.getLine1Number();
3359 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003360 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003361 return null;
3362 }
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003365 }
3366 }
3367
3368 /**
3369 * Returns the CDMA MIN.
3370 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003371 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003372 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3374 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003375
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 final Phone phone = getPhone(subId);
3379 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3380 return phone.getCdmaMin();
3381 } else {
3382 return null;
3383 }
3384 } finally {
3385 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003386 }
3387 }
3388
Hall Liud892bec2018-11-30 14:51:45 -08003389 @Override
3390 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3391 INumberVerificationCallback callback, String callingPackage) {
3392 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3393 != PERMISSION_GRANTED) {
3394 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3395 }
3396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3397
3398 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3399 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003400 throw new SecurityException("Calling package must be configured in the device config: "
3401 + "calling package: " + callingPackage
3402 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003403 }
3404
3405 if (range == null) {
3406 throw new NullPointerException("Range must be non-null");
3407 }
3408
3409 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003410 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003411
3412 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3413 }
3414
Junda Liuca05d5d2014-08-14 22:36:34 -07003415 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003416 * Returns true if CDMA provisioning needs to run.
3417 */
3418 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419 final long identity = Binder.clearCallingIdentity();
3420 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003421 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003425 }
3426
3427 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003428 * Sets the voice mail number of a given subId.
3429 */
3430 @Override
3431 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003432 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3433 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3438 new Pair<String, String>(alphaTag, number), new Integer(subId));
3439 return success;
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
3442 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003443 }
3444
Ta-wei Yen87c49842016-05-13 21:19:52 -07003445 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003446 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3447 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003448 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3449 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003450 if (!TextUtils.equals(callingPackage, systemDialer)) {
3451 throw new SecurityException("caller must be system dialer");
3452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003453
3454 final long identity = Binder.clearCallingIdentity();
3455 try {
3456 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3457 if (phoneAccountHandle == null) {
3458 return null;
3459 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003460 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003463 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003464 }
3465
3466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003467 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3468 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003469 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003471 mApp, subId, callingPackage, callingFeatureId,
3472 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003473 return null;
3474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003475
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003476 final long identity = Binder.clearCallingIdentity();
3477 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003482 }
3483
3484 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003485 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3486 VisualVoicemailSmsFilterSettings settings) {
3487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003492 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003496 }
3497
3498 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003499 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003501
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003505 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003509 }
3510
3511 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003512 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3513 String callingPackage, int subId) {
3514 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003519 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520 } finally {
3521 Binder.restoreCallingIdentity(identity);
3522 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003523 }
3524
3525 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003526 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003527 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003532 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003536 }
3537
3538 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003539 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3540 String callingAttributionTag, int subId, String number, int port, String text,
3541 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003543 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003544 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003545 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003546 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3547 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003548 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003549
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003550 /**
fionaxu0152e512016-11-14 13:36:14 -08003551 * Sets the voice activation state of a given subId.
3552 */
3553 @Override
3554 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3556 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 final Phone phone = getPhone(subId);
3561 if (phone != null) {
3562 phone.setVoiceActivationState(activationState);
3563 } else {
3564 loge("setVoiceActivationState fails with invalid subId: " + subId);
3565 }
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003568 }
3569 }
3570
3571 /**
3572 * Sets the data activation state of a given subId.
3573 */
3574 @Override
3575 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3577 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578
3579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 final Phone phone = getPhone(subId);
3582 if (phone != null) {
3583 phone.setDataActivationState(activationState);
3584 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003585 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586 }
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003589 }
3590 }
3591
3592 /**
3593 * Returns the voice activation state of a given subId.
3594 */
3595 @Override
3596 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003597 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598
fionaxu0152e512016-11-14 13:36:14 -08003599 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 if (phone != null) {
3603 return phone.getVoiceActivationState();
3604 } else {
3605 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3606 }
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003609 }
3610 }
3611
3612 /**
3613 * Returns the data activation state of a given subId.
3614 */
3615 @Override
3616 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003617 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003618
fionaxu0152e512016-11-14 13:36:14 -08003619 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 if (phone != null) {
3623 return phone.getDataActivationState();
3624 } else {
3625 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3626 }
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003629 }
3630 }
3631
3632 /**
Wink Saville36469e72014-06-11 15:17:00 -07003633 * Returns the unread count of voicemails for a subId
3634 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003635 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003636 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3637 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003639 mApp, subId, callingPackage, callingFeatureId,
3640 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003641 return 0;
3642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 final Phone phone = getPhone(subId);
3646 if (phone != null) {
3647 return phone.getVoiceMessageCount();
3648 } else {
3649 return 0;
3650 }
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003654 }
3655
3656 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003657 * returns true, if the device is in a state where both voice and data
3658 * are supported simultaneously. This can change based on location or network condition.
3659 */
3660 @Override
3661 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 final Phone phone = getPhone(subId);
3665 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003669 }
3670
3671 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003672 * Send the dialer code if called from the current default dialer or the caller has
3673 * carrier privilege.
3674 * @param inputCode The dialer code to send
3675 */
3676 @Override
3677 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003678 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003679 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003680 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3681 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003682 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003683 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003684 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003689 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
fionaxu235cc5e2017-03-06 22:25:57 -08003693 }
3694
Pengquan Menga1bb6272018-09-06 09:59:22 -07003695 @Override
3696 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003697 TelephonyPermissions
3698 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3699 mApp, subId, "getNetworkSelectionMode");
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 if (!isActiveSubscription(subId)) {
3703 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3704 }
3705 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003708 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003709 }
3710
Brad Ebinger35c841c2018-10-01 10:40:55 -07003711 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003712 public boolean isInEmergencySmsMode() {
3713 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3714 final long identity = Binder.clearCallingIdentity();
3715 try {
3716 for (Phone phone : PhoneFactory.getPhones()) {
3717 if (phone.isInEmergencySmsMode()) {
3718 return true;
3719 }
3720 }
3721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
3724 return false;
3725 }
3726
shilu366312e2019-12-17 09:28:10 -08003727 /**
3728 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3729 * @param subId The subscription to use to check the configuration.
3730 * @param c The callback that will be used to send the result.
3731 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003732 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003733 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3734 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003735 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3736 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003737
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003738 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3739 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3740 "IMS not available on device.");
3741 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 final long token = Binder.clearCallingIdentity();
3743 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003744 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003745 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003747 } catch (ImsException e) {
3748 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003749 } finally {
3750 Binder.restoreCallingIdentity(token);
3751 }
3752 }
3753
shilu366312e2019-12-17 09:28:10 -08003754 /**
3755 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3756 * @param subId The subscription to use to check the configuration.
3757 * @param c The callback that will be used to send the result.
3758 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003759 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003760 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003761 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3762 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003763 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3764 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3765 }
Meng Wangafbc5852019-09-19 17:37:13 -07003766 final long token = Binder.clearCallingIdentity();
3767 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003768 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003769 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3770 .removeRegistrationCallbackForSubscription(c, subId);
3771 } catch (ImsException e) {
3772 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3773 + "is inactive, ignoring unregister.");
3774 // If the subscription is no longer active, just return, since the callback
3775 // will already have been removed internally.
3776 } finally {
3777 Binder.restoreCallingIdentity(token);
3778 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003779 }
3780
Brad Ebingera34a6c22019-10-22 17:36:18 -07003781 /**
3782 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3783 */
3784 @Override
3785 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3786 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3787 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3788 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3789 "IMS not available on device.");
3790 }
3791 final long token = Binder.clearCallingIdentity();
3792 try {
3793 Phone phone = getPhone(subId);
3794 if (phone == null) {
3795 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3796 + subId + "'");
3797 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3798 }
3799 phone.getImsRegistrationState(regState -> {
3800 try {
3801 consumer.accept((regState == null)
3802 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3803 } catch (RemoteException e) {
3804 // Ignore if the remote process is no longer available to call back.
3805 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3806 }
3807 });
3808 } finally {
3809 Binder.restoreCallingIdentity(token);
3810 }
3811 }
3812
3813 /**
3814 * Get the transport type for the IMS service registration state.
3815 */
3816 @Override
3817 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003818 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3819 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003820 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3821 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3822 "IMS not available on device.");
3823 }
3824 final long token = Binder.clearCallingIdentity();
3825 try {
3826 Phone phone = getPhone(subId);
3827 if (phone == null) {
3828 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3829 + subId + "'");
3830 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3831 }
3832 phone.getImsRegistrationTech(regTech -> {
3833 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3834 int regTechConverted = (regTech == null)
3835 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3836 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3837 regTechConverted);
3838 try {
3839 consumer.accept(regTechConverted);
3840 } catch (RemoteException e) {
3841 // Ignore if the remote process is no longer available to call back.
3842 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3843 }
3844 });
3845 } finally {
3846 Binder.restoreCallingIdentity(token);
3847 }
3848 }
3849
shilu366312e2019-12-17 09:28:10 -08003850 /**
3851 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3852 * @param subId The subscription to use to check the configuration.
3853 * @param c The callback that will be used to send the result.
3854 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003855 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003856 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3857 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003858 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3859 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003860 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3861 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3862 "IMS not available on device.");
3863 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003864 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3865 final long token = Binder.clearCallingIdentity();
3866 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003867 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003869 } catch (ImsException e) {
3870 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003871 } finally {
3872 Binder.restoreCallingIdentity(token);
3873 }
3874 }
3875
shilu366312e2019-12-17 09:28:10 -08003876 /**
3877 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3878 * @param subId The subscription to use to check the configuration.
3879 * @param c The callback that will be used to send the result.
3880 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003881 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003882 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003883 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3884 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003885 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3886 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3887 }
Meng Wangafbc5852019-09-19 17:37:13 -07003888
3889 final long token = Binder.clearCallingIdentity();
3890 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003891 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003892 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003893 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003894 } catch (ImsException e) {
3895 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3896 + "is inactive, ignoring unregister.");
3897 // If the subscription is no longer active, just return, since the callback
3898 // will already have been removed internally.
3899 } finally {
3900 Binder.restoreCallingIdentity(token);
3901 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 }
3903
3904 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003905 public boolean isCapable(int subId, int capability, int regTech) {
3906 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3908 final long token = Binder.clearCallingIdentity();
3909 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003910 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003911 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003912 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3914 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003915 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003916 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3917 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003918 } finally {
3919 Binder.restoreCallingIdentity(token);
3920 }
3921 }
3922
3923 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003924 public boolean isAvailable(int subId, int capability, int regTech) {
3925 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003926 final long token = Binder.clearCallingIdentity();
3927 try {
3928 Phone phone = getPhone(subId);
3929 if (phone == null) return false;
3930 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003931 } catch (com.android.ims.ImsException e) {
3932 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3933 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003934 } finally {
3935 Binder.restoreCallingIdentity(token);
3936 }
3937 }
3938
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003939 /**
3940 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3941 * subscription.
3942 * @param subId The subscription to use to check the configuration.
3943 * @param callback The callback that will be used to send the result.
3944 * @param capability The MmTelFeature capability that will be used to send the result.
3945 * @param transportType The transport type of the MmTelFeature capability.
3946 */
3947 @Override
3948 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3949 int transportType) {
3950 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3951 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3952 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3953 "IMS not available on device.");
3954 }
3955 final long token = Binder.clearCallingIdentity();
3956 try {
3957 int slotId = getSlotIndex(subId);
3958 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3959 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3960 + subId + "'");
3961 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3962 }
3963 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3964 transportType, aBoolean -> {
3965 try {
3966 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3967 } catch (RemoteException e) {
3968 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3969 + "running. Ignore");
3970 }
3971 });
3972 } finally {
3973 Binder.restoreCallingIdentity(token);
3974 }
3975 }
3976
shilu366312e2019-12-17 09:28:10 -08003977 /**
3978 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3979 * @param subId The subscription to use to check the configuration.
3980 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 @Override
3982 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003983 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3984 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003985
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3987 final long token = Binder.clearCallingIdentity();
3988 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003989 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003991 } catch (ImsException e) {
3992 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 } finally {
3994 Binder.restoreCallingIdentity(token);
3995 }
3996 }
3997
3998 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003999 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004001 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004005 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004007 } catch (ImsException e) {
4008 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
4012 }
4013
shilu366312e2019-12-17 09:28:10 -08004014 /**
4015 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4016 * @param subId The subscription to use to check the configuration.
4017 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004018 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004019 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004020 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4021 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004025 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4026 } catch (ImsException e) {
4027 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
4031 }
4032
4033 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004034 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004036 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004040 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004041 } catch (ImsException e) {
4042 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 } finally {
4044 Binder.restoreCallingIdentity(identity);
4045 }
4046 }
4047
shilu366312e2019-12-17 09:28:10 -08004048 /**
4049 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4050 * @param subId The subscription to use to check the configuration.
4051 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 @Override
4053 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004054 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4055 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 final long identity = Binder.clearCallingIdentity();
4057 try {
4058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004059 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004061 } catch (ImsException e) {
4062 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 } finally {
4064 Binder.restoreCallingIdentity(identity);
4065 }
4066 }
4067
4068 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004069 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004071 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004075 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004076 } catch (ImsException e) {
4077 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 } finally {
4079 Binder.restoreCallingIdentity(identity);
4080 }
4081 }
4082
shilu366312e2019-12-17 09:28:10 -08004083 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004084 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4085 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4086 * @param subId The subscription to use to check the configuration.
4087 */
4088 @Override
4089 public boolean isCrossSimCallingEnabledByUser(int subId) {
4090 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4091 mApp, subId, "isCrossSimCallingEnabledByUser");
4092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4095 return ImsManager.getInstance(mApp,
4096 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4097 } catch (ImsException e) {
4098 throw new ServiceSpecificException(e.getCode());
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
4101 }
4102 }
4103
4104 /**
4105 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4106 * Requires MODIFY_PHONE_STATE permission.
4107 * @param subId The subscription to use to check the configuration.
4108 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4109 * false otherwise
4110 */
4111 @Override
4112 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4114 "setCrossSimCallingEnabled");
4115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4118 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4119 .setCrossSimCallingEnabled(isEnabled);
4120 } catch (ImsException e) {
4121 throw new ServiceSpecificException(e.getCode());
4122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
4125 }
4126
4127 /**
shilu366312e2019-12-17 09:28:10 -08004128 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4129 * @param subId The subscription to use to check the configuration.
4130 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 @Override
4132 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004133 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4134 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004138 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004140 } catch (ImsException e) {
4141 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 } finally {
4143 Binder.restoreCallingIdentity(identity);
4144 }
4145 }
4146
4147 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004148 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004150 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004154 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004156 } catch (ImsException e) {
4157 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
4161 }
4162
4163 @Override
4164 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4166 "setVoWiFiNonPersistent");
4167 final long identity = Binder.clearCallingIdentity();
4168 try {
4169 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004170 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004171 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004172 } catch (ImsException e) {
4173 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004174 } finally {
4175 Binder.restoreCallingIdentity(identity);
4176 }
4177 }
4178
shilu366312e2019-12-17 09:28:10 -08004179 /**
4180 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4181 * @param subId The subscription to use to check the configuration.
4182 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004183 @Override
4184 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004185 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4186 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004190 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004192 } catch (ImsException e) {
4193 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 } finally {
4195 Binder.restoreCallingIdentity(identity);
4196 }
4197 }
4198
4199 @Override
4200 public void setVoWiFiModeSetting(int subId, int mode) {
4201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4202 "setVoWiFiModeSetting");
4203 final long identity = Binder.clearCallingIdentity();
4204 try {
4205 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004206 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004208 } catch (ImsException e) {
4209 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 } finally {
4211 Binder.restoreCallingIdentity(identity);
4212 }
4213 }
4214
4215 @Override
4216 public int getVoWiFiRoamingModeSetting(int subId) {
4217 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4218 final long identity = Binder.clearCallingIdentity();
4219 try {
4220 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004221 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004223 } catch (ImsException e) {
4224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
4228 }
4229
4230 @Override
4231 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4233 "setVoWiFiRoamingModeSetting");
4234 final long identity = Binder.clearCallingIdentity();
4235 try {
4236 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004237 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004238 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004239 } catch (ImsException e) {
4240 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 } finally {
4242 Binder.restoreCallingIdentity(identity);
4243 }
4244 }
4245
4246 @Override
4247 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4249 "setRttCapabilityEnabled");
4250 final long identity = Binder.clearCallingIdentity();
4251 try {
4252 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004253 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4254 } catch (ImsException e) {
4255 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
4259 }
4260
shilu366312e2019-12-17 09:28:10 -08004261 /**
4262 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4263 * @param subId The subscription to use to check the configuration.
4264 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004265 @Override
4266 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004267 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4268 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 final long identity = Binder.clearCallingIdentity();
4270 try {
4271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004272 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004274 } catch (ImsException e) {
4275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
4279 }
4280
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004281 @Override
4282 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4283 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004286 if (!isImsAvailableOnDevice()) {
4287 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4288 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004289 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004290 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004291 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004292 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004293 } catch (ImsException e) {
4294 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004295 } finally {
4296 Binder.restoreCallingIdentity(identity);
4297 }
4298 }
4299
4300 @Override
4301 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4302 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4303 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004304 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4305 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4306 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004307 try {
4308 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004309 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004310 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004311 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004312 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4313 + "is inactive, ignoring unregister.");
4314 // If the subscription is no longer active, just return, since the callback will already
4315 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
4319 }
4320
allenwtsu99c623b2020-01-03 18:24:23 +08004321
4322 private void checkModifyPhoneStatePermission(int subId, String message) {
4323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4324 message);
4325 }
4326
4327 private boolean isImsProvisioningRequired(int subId, int capability,
4328 boolean isMmtelCapability) {
4329 Phone phone = getPhone(subId);
4330 if (phone == null) {
4331 loge("phone instance null for subid " + subId);
4332 return false;
4333 }
4334 if (isMmtelCapability) {
4335 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4336 return false;
4337 }
4338 } else {
4339 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4340 return false;
4341 }
4342 }
4343 return true;
4344 }
4345
4346 @Override
4347 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4348 boolean isProvisioned) {
4349 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4350
4351 final long identity = Binder.clearCallingIdentity();
4352 try {
4353 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4354 if (!isImsProvisioningRequired(subId, capability, false)) {
4355 return;
4356 }
4357
4358 // this capability requires provisioning, route to the correct API.
4359 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4360 switch (capability) {
4361 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4362 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4363 ims.setEabProvisioned(isProvisioned);
4364 break;
4365 default: {
4366 throw new IllegalArgumentException("Tried to set provisioning for "
4367 + "rcs capability '" + capability + "', which does not require "
4368 + "provisioning.");
4369 }
4370 }
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
4374
4375 }
4376
4377
4378 @Override
4379 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4380 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4381 final long identity = Binder.clearCallingIdentity();
4382 try {
4383 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4384 if (!isImsProvisioningRequired(subId, capability, false)) {
4385 return true;
4386 }
4387
4388 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4389 switch (capability) {
4390 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4391 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4392 return ims.isEabProvisionedOnDevice();
4393
4394 default: {
4395 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4396 + "capability '" + capability + "', which does not require "
4397 + "provisioning.");
4398 }
4399 }
4400
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
4404 }
4405
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004406 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004407 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4408 boolean isProvisioned) {
4409 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4410 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4411 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4412 }
allenwtsu99c623b2020-01-03 18:24:23 +08004413 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004414 final long identity = Binder.clearCallingIdentity();
4415 try {
4416 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004417 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004418 return;
4419 }
4420
4421 // this capability requires provisioning, route to the correct API.
4422 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4423 switch (capability) {
4424 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4425 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4426 ims.setVolteProvisioned(isProvisioned);
4427 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4428 ims.setWfcProvisioned(isProvisioned);
4429 }
4430 break;
4431 }
4432 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4433 // There is currently no difference in VT provisioning type.
4434 ims.setVtProvisioned(isProvisioned);
4435 break;
4436 }
4437 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4438 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4439 // change the capability of the feature instead if needed.
4440 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4441 == isProvisioned) {
4442 // No change in provisioning.
4443 return;
4444 }
4445 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4446 try {
4447 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004448 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004449 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4450 + ", Exception" + e.getMessage());
4451 }
4452 break;
4453 }
4454 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004455 throw new IllegalArgumentException("Tried to set provisioning for "
4456 + "MmTel capability '" + capability + "', which does not require "
4457 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004458 }
4459 }
4460
4461 } finally {
4462 Binder.restoreCallingIdentity(identity);
4463 }
4464 }
4465
4466 @Override
4467 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4468 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4469 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4470 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4471 }
4472 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4473 final long identity = Binder.clearCallingIdentity();
4474 try {
4475 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004476 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004477 return true;
4478 }
4479
4480 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4481 switch (capability) {
4482 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4483 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4484 return ims.isVolteProvisionedOnDevice();
4485 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4486 return ims.isWfcProvisionedOnDevice();
4487 }
4488 // This should never happen, since we are checking tech above to make sure it
4489 // is either LTE or IWLAN.
4490 throw new IllegalArgumentException("Invalid radio technology for voice "
4491 + "capability.");
4492 }
4493 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4494 // There is currently no difference in VT provisioning type.
4495 return ims.isVtProvisionedOnDevice();
4496 }
4497 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4498 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4499 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4500 }
4501 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004502 throw new IllegalArgumentException(
4503 "Tried to get provisioning for MmTel capability '" + capability
4504 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004505 }
4506 }
4507
4508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
4511 }
4512
4513 @Override
4514 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4515 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4516 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4517 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4518 }
4519 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4520 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4521 return (provisionedBits & capability) > 0;
4522 }
4523
4524 @Override
4525 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4526 boolean isProvisioned) {
4527 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4528 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4529 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4530 }
4531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4532 "setProvisioningStatusForCapability");
4533 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4534 // If the current provisioning status for capability already matches isProvisioned,
4535 // do nothing.
4536 if (((provisionedBits & capability) > 0) == isProvisioned) {
4537 return;
4538 }
4539 if (isProvisioned) {
4540 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4541 } else {
4542 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4543 }
4544 }
4545
4546 /**
4547 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4548 * technology. The bitfield should mirror the bitfield defined by
4549 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4550 */
4551 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4552 String key = getMmTelProvisioningKey(subId, tech);
4553 // Default is no capabilities are provisioned.
4554 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4555 }
4556
4557 /**
4558 * Sets the MmTel capability provisioning bitfield (defined by
4559 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4560 * technology specified.
4561 *
4562 * Note: This is a synchronous command and should not be called on UI thread.
4563 */
4564 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4565 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4566 String key = getMmTelProvisioningKey(subId, tech);
4567 editor.putInt(key, newField);
4568 editor.commit();
4569 }
4570
4571 private static String getMmTelProvisioningKey(int subId, int tech) {
4572 // resulting key is provision_ims_mmtel_{subId}_{tech}
4573 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4574 }
4575
4576 /**
4577 * Query CarrierConfig to see if the specified capability requires provisioning for the
4578 * carrier associated with the subscription id.
4579 */
4580 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4581 int capability) {
4582 CarrierConfigManager configManager = new CarrierConfigManager(context);
4583 PersistableBundle c = configManager.getConfigForSubId(subId);
4584 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004585 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004586 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4587 false);
4588 boolean requireVoiceVtProvisioning = c.getBoolean(
4589 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4590
4591 // First check to make sure that the capability requires provisioning.
4592 switch (capability) {
4593 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4594 // intentional fallthrough
4595 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4596 if (requireVoiceVtProvisioning) {
4597 // Voice and Video requires provisioning
4598 return true;
4599 }
4600 break;
4601 }
4602 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4603 if (requireUtProvisioning) {
4604 // UT requires provisioning
4605 return true;
4606 }
4607 break;
4608 }
4609 }
4610 return false;
4611 }
4612
allenwtsu99c623b2020-01-03 18:24:23 +08004613 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4614 int capability) {
4615 CarrierConfigManager configManager = new CarrierConfigManager(context);
4616 PersistableBundle c = configManager.getConfigForSubId(subId);
4617
4618 boolean requireRcsProvisioning = c.getBoolean(
4619 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4620
4621 // First check to make sure that the capability requires provisioning.
4622 switch (capability) {
4623 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4624 // intentional fallthrough
4625 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4626 if (requireRcsProvisioning) {
4627 // OPTION or PRESENCE requires provisioning
4628 return true;
4629 }
4630 break;
4631 }
4632 }
4633 return false;
4634 }
4635
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004636 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004637 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004638 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4639 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4640 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004641 enforceReadPrivilegedPermission("getImsProvisioningInt");
4642 final long identity = Binder.clearCallingIdentity();
4643 try {
4644 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004645 int slotId = getSlotIndex(subId);
4646 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4647 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4648 + subId + "' for key:" + key);
4649 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4650 }
calvinpanb5a34062021-02-08 19:59:36 +08004651 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004652 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004653 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4654 + subId + "' for key:" + key);
4655 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004656 } finally {
4657 Binder.restoreCallingIdentity(identity);
4658 }
4659 }
4660
4661 @Override
4662 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004663 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4664 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4665 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004666 enforceReadPrivilegedPermission("getImsProvisioningString");
4667 final long identity = Binder.clearCallingIdentity();
4668 try {
4669 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004670 int slotId = getSlotIndex(subId);
4671 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4672 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4673 + subId + "' for key:" + key);
4674 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4675 }
calvinpanb5a34062021-02-08 19:59:36 +08004676 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004677 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004678 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4679 + subId + "' for key:" + key);
4680 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004681 } finally {
4682 Binder.restoreCallingIdentity(identity);
4683 }
4684 }
4685
4686 @Override
4687 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004688 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4689 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4690 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4692 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004693 final long identity = Binder.clearCallingIdentity();
4694 try {
4695 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004696 int slotId = getSlotIndex(subId);
4697 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4698 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4699 + subId + "' for key:" + key);
4700 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4701 }
calvinpanb5a34062021-02-08 19:59:36 +08004702 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4703 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004704 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004705 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004706 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004707 } finally {
4708 Binder.restoreCallingIdentity(identity);
4709 }
4710 }
4711
4712 @Override
4713 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004714 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4715 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4716 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4718 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004719 final long identity = Binder.clearCallingIdentity();
4720 try {
4721 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004722 int slotId = getSlotIndex(subId);
4723 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4724 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4725 + subId + "' for key:" + key);
4726 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4727 }
calvinpanb5a34062021-02-08 19:59:36 +08004728 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4729 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004730 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004731 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004732 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004733 } finally {
4734 Binder.restoreCallingIdentity(identity);
4735 }
4736 }
4737
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004738 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004739 int slotId = SubscriptionManager.getSlotIndex(subId);
4740 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004741 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4742 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004743 }
4744 return slotId;
4745 }
4746
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004747 private int getSlotIndex(int subId) {
4748 int slotId = SubscriptionManager.getSlotIndex(subId);
4749 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4750 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4751 }
4752 return slotId;
4753 }
4754
Wink Saville36469e72014-06-11 15:17:00 -07004755 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004756 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004757 */
4758 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004759 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4760 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004761 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004762 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004763 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004764 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004765 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004766 mApp, subId, callingPackage, callingFeatureId,
4767 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004768 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4769 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004771 final long identity = Binder.clearCallingIdentity();
4772 try {
4773 final Phone phone = getPhone(subId);
4774 if (phone != null) {
4775 return phone.getServiceState().getDataNetworkType();
4776 } else {
4777 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4778 }
4779 } finally {
4780 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004782 }
4783
4784 /**
4785 * Returns the data network type
4786 */
4787 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004788 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4789 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4790 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004791 }
4792
4793 /**
4794 * Returns the data network type for a subId
4795 */
4796 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004797 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4798 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004799 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004800 mApp, subId, callingPackage, callingFeatureId,
4801 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004802 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4803 }
4804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805 final long identity = Binder.clearCallingIdentity();
4806 try {
4807 final Phone phone = getPhone(subId);
4808 if (phone != null) {
4809 return phone.getServiceState().getDataNetworkType();
4810 } else {
4811 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4812 }
4813 } finally {
4814 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004816 }
4817
4818 /**
Wink Saville36469e72014-06-11 15:17:00 -07004819 * Returns the Voice network type for a subId
4820 */
4821 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004822 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4823 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004825 mApp, subId, callingPackage, callingFeatureId,
4826 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004827 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4828 }
4829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830 final long identity = Binder.clearCallingIdentity();
4831 try {
4832 final Phone phone = getPhone(subId);
4833 if (phone != null) {
4834 return phone.getServiceState().getVoiceNetworkType();
4835 } else {
4836 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4837 }
4838 } finally {
4839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004841 }
4842
4843 /**
4844 * @return true if a ICC card is present
4845 */
4846 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004847 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004848 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4849 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004850 }
4851
4852 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004853 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004854 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004855 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004856 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 final long identity = Binder.clearCallingIdentity();
4858 try {
4859 final Phone phone = PhoneFactory.getPhone(slotIndex);
4860 if (phone != null) {
4861 return phone.getIccCard().hasIccCard();
4862 } else {
4863 return false;
4864 }
4865 } finally {
4866 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004868 }
4869
4870 /**
4871 * Return if the current radio is LTE on CDMA. This
4872 * is a tri-state return value as for a period of time
4873 * the mode may be unknown.
4874 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004875 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004876 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004877 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004878 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004879 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004880 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4881 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4882 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004883 }
4884
Sanket Padawe356d7632015-06-22 14:03:32 -07004885 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004886 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4887 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004888 try {
4889 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4890 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004891 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4892 }
4893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 final Phone phone = getPhone(subId);
4897 if (phone == null) {
4898 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4899 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004900 return TelephonyProperties.lte_on_cdma_device()
4901 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 }
4903 } finally {
4904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004905 }
Wink Saville36469e72014-06-11 15:17:00 -07004906 }
4907
Wink Saville36469e72014-06-11 15:17:00 -07004908 /**
4909 * {@hide}
4910 * Returns Default subId, 0 in the case of single standby.
4911 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004912 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004913 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004914 }
4915
Shishir Agrawala9f32182016-04-12 12:00:16 -07004916 private int getSlotForDefaultSubscription() {
4917 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4918 }
4919
Wink Savilleb564aae2014-10-23 10:18:09 -07004920 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004921 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004922 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004923
Pengquan Menge92a50d2018-09-21 15:54:48 -07004924 private boolean isActiveSubscription(int subId) {
4925 return mSubscriptionController.isActiveSubId(subId);
4926 }
4927
Ihab Awadf2177b72013-11-25 13:33:23 -08004928 /**
4929 * @see android.telephony.TelephonyManager.WifiCallingChoices
4930 */
4931 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 final long identity = Binder.clearCallingIdentity();
4933 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004934 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4936 getWhenToMakeWifiCallsDefaultPreference());
4937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004940 }
4941
4942 /**
4943 * @see android.telephony.TelephonyManager.WifiCallingChoices
4944 */
4945 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 final long identity = Binder.clearCallingIdentity();
4947 try {
4948 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004949 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004954 }
4955
Sailesh Nepald1e68152013-12-12 19:08:02 -08004956 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004957 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004958 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004959 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004960
Jordan Liu4c733742019-02-28 12:03:40 -08004961 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4962 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4963 if (phoneId == -1) {
4964 throw new IllegalArgumentException("Given slot index: " + slotIndex
4965 + " does not correspond to an active phone");
4966 }
4967 return PhoneFactory.getPhone(phoneId);
4968 }
4969
Shishir Agrawal566b7612013-10-28 14:41:00 -07004970 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004971 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4972 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4974 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004976 if (DBG) {
4977 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4978 }
4979 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4980 p2);
4981 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004982
Jordan Liu4c733742019-02-28 12:03:40 -08004983
4984 @Override
4985 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4986 int slotIndex, String callingPackage, String aid, int p2) {
4987 enforceModifyPermission();
4988 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4989 if (DBG) {
4990 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4991 }
4992 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4993 callingPackage, aid, p2);
4994 }
4995
4996 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4997 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 final long identity = Binder.clearCallingIdentity();
4999 try {
5000 if (TextUtils.equals(ISDR_AID, aid)) {
5001 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005002 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5003 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 if (bestComponent == null
5005 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5006 loge("The calling package is not allowed to access ISD-R.");
5007 throw new SecurityException(
5008 "The calling package is not allowed to access ISD-R.");
5009 }
Derek Tan740e1672017-06-27 14:56:27 -07005010 }
Derek Tan740e1672017-06-27 14:56:27 -07005011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005013 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5014 null /* workSource */);
5015 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 return response;
5017 } finally {
5018 Binder.restoreCallingIdentity(identity);
5019 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005020 }
5021
5022 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005023 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5025 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005026 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5027 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5028 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005029
Jordan Liu4c733742019-02-28 12:03:40 -08005030 @Override
5031 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5032 enforceModifyPermission();
5033 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5034 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5035 channel);
5036 }
5037
5038 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039 final long identity = Binder.clearCallingIdentity();
5040 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 if (channel < 0) {
5042 return false;
5043 }
Jordan Liu4c733742019-02-28 12:03:40 -08005044 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5045 null /* workSource */);
5046 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 return success;
5048 } finally {
5049 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005050 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005051 }
5052
5053 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005054 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005055 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5057 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005058 if (DBG) {
5059 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5060 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5061 + p3 + " data=" + data);
5062 }
5063 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5064 command, p1, p2, p3, data);
5065 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005066
Jordan Liu4c733742019-02-28 12:03:40 -08005067 @Override
5068 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5069 int command, int p1, int p2, int p3, String data) {
5070 enforceModifyPermission();
5071 if (DBG) {
5072 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5073 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5074 + p3 + " data=" + data);
5075 }
5076 return iccTransmitApduLogicalChannelWithPermission(
5077 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5078 data);
5079 }
5080
5081 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5082 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 final long identity = Binder.clearCallingIdentity();
5084 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005085 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 return "";
5087 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005090 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5091 null /* workSource */);
5092 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 // Append the returned status code to the end of the response payload.
5095 String s = Integer.toHexString(
5096 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5097 if (response.payload != null) {
5098 s = IccUtils.bytesToHexString(response.payload) + s;
5099 }
5100 return s;
5101 } finally {
5102 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005103 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005104 }
Jake Hambye994d462014-02-03 13:10:13 -08005105
Evan Charltonc66da362014-05-16 14:06:40 -07005106 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005107 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5108 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5110 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005112 if (DBG) {
5113 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5114 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5115 }
5116 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5117 cla, command, p1, p2, p3, data);
5118 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005119
Jordan Liu4c733742019-02-28 12:03:40 -08005120 @Override
5121 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5122 int command, int p1, int p2, int p3, String data) {
5123 enforceModifyPermission();
5124 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5125 if (DBG) {
5126 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5127 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5128 + " data=" + data);
5129 }
5130
5131 return iccTransmitApduBasicChannelWithPermission(
5132 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5133 p2, p3, data);
5134 }
5135
5136 // open APDU basic channel assuming the caller has sufficient permissions
5137 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5138 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 final long identity = Binder.clearCallingIdentity();
5140 try {
5141 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5142 && TextUtils.equals(ISDR_AID, data)) {
5143 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005144 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5145 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146 if (bestComponent == null
5147 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5148 loge("The calling package is not allowed to select ISD-R.");
5149 throw new SecurityException(
5150 "The calling package is not allowed to select ISD-R.");
5151 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005152 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005155 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5156 null /* workSource */);
5157 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 // Append the returned status code to the end of the response payload.
5160 String s = Integer.toHexString(
5161 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5162 if (response.payload != null) {
5163 s = IccUtils.bytesToHexString(response.payload) + s;
5164 }
5165 return s;
5166 } finally {
5167 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005168 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005169 }
5170
5171 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005172 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005173 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5175 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177 final long identity = Binder.clearCallingIdentity();
5178 try {
5179 if (DBG) {
5180 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5181 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5182 }
5183
5184 IccIoResult response =
5185 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5186 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5187 subId);
5188
5189 if (DBG) {
5190 log("Exchange SIM_IO [R]" + response);
5191 }
5192
5193 byte[] result = null;
5194 int length = 2;
5195 if (response.payload != null) {
5196 length = 2 + response.payload.length;
5197 result = new byte[length];
5198 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5199 } else {
5200 result = new byte[length];
5201 }
5202
5203 result[length - 1] = (byte) response.sw2;
5204 result[length - 2] = (byte) response.sw1;
5205 return result;
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005208 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005209 }
5210
Nathan Haroldb3014052017-01-25 15:57:32 -08005211 /**
5212 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5213 * on a particular subscription
5214 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005215 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5216 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005218 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005219 return null;
5220 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221
5222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 if (appType != TelephonyManager.APPTYPE_USIM
5225 && appType != TelephonyManager.APPTYPE_SIM) {
5226 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5227 return null;
5228 }
5229 Object response = sendRequest(
5230 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5231 if (response instanceof String[]) {
5232 return (String[]) response;
5233 }
yincheng zhao2737e882019-09-06 17:06:54 -07005234 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005236 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 } finally {
5238 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005239 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005240 }
5241
yincheng zhao2737e882019-09-06 17:06:54 -07005242 /**
5243 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5244 * subscription.
5245 *
5246 * @param subId the id of the subscription.
5247 * @param appType the uicc app type, must be USIM or SIM.
5248 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5249 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005250 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005251 * @return number of fplmns that is successfully written to the SIM.
5252 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005253 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5254 String callingFeatureId) {
5255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5256 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005257 if (DBG) logv("no permissions for setForbiddenplmns");
5258 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5259 }
5260 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5261 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5262 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5263 }
5264 if (fplmns == null) {
5265 throw new IllegalArgumentException("Fplmn List provided is null");
5266 }
5267 for (String fplmn : fplmns) {
5268 if (!CellIdentity.isValidPlmn(fplmn)) {
5269 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5270 }
5271 }
5272 final long identity = Binder.clearCallingIdentity();
5273 try {
5274 Object response = sendRequest(
5275 CMD_SET_FORBIDDEN_PLMNS,
5276 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5277 subId);
5278 return (int) response;
5279 } finally {
5280 Binder.restoreCallingIdentity(identity);
5281 }
5282 }
5283
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005284 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005285 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5287 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 final long identity = Binder.clearCallingIdentity();
5290 try {
5291 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5292 if (response.payload == null) {
5293 return "";
5294 }
Evan Charltonc66da362014-05-16 14:06:40 -07005295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 // Append the returned status code to the end of the response payload.
5297 String s = Integer.toHexString(
5298 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5299 s = IccUtils.bytesToHexString(response.payload) + s;
5300 return s;
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
5303 }
Evan Charltonc66da362014-05-16 14:06:40 -07005304 }
5305
Jake Hambye994d462014-02-03 13:10:13 -08005306 /**
5307 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5308 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5309 *
5310 * @param itemID the ID of the item to read
5311 * @return the NV item as a String, or null on error.
5312 */
5313 @Override
5314 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005315 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5317 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005318
5319 final long identity = Binder.clearCallingIdentity();
5320 try {
5321 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005322 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5324 return value;
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
Jake Hambye994d462014-02-03 13:10:13 -08005328 }
5329
5330 /**
5331 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5332 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5333 *
5334 * @param itemID the ID of the item to read
5335 * @param itemValue the value to write, as a String
5336 * @return true on success; false on any failure
5337 */
5338 @Override
5339 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005340 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5342 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343
5344 final long identity = Binder.clearCallingIdentity();
5345 try {
5346 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5347 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005348 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5350 return success;
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
Jake Hambye994d462014-02-03 13:10:13 -08005354 }
5355
5356 /**
5357 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5358 * Used for device configuration by some CDMA operators.
5359 *
5360 * @param preferredRoamingList byte array containing the new PRL
5361 * @return true on success; false on any failure
5362 */
5363 @Override
5364 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5366 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367
5368 final long identity = Binder.clearCallingIdentity();
5369 try {
5370 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5371 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5372 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5373 return success;
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
5376 }
Jake Hambye994d462014-02-03 13:10:13 -08005377 }
5378
5379 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005380 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005381 * Used for device configuration by some CDMA operators.
5382 *
chen xu6dac5ab2018-10-26 17:39:23 -07005383 * @param slotIndex - device slot.
5384 *
Jake Hambye994d462014-02-03 13:10:13 -08005385 * @return true on success; false on any failure
5386 */
5387 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005388 public boolean resetModemConfig(int slotIndex) {
5389 Phone phone = PhoneFactory.getPhone(slotIndex);
5390 if (phone != null) {
5391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5392 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393
chen xu6dac5ab2018-10-26 17:39:23 -07005394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5397 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5398 return success;
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 }
chen xu6dac5ab2018-10-26 17:39:23 -07005403 return false;
5404 }
5405
5406 /**
5407 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5408 *
5409 * @param slotIndex - device slot.
5410 *
5411 * @return true on success; false on any failure
5412 */
5413 @Override
5414 public boolean rebootModem(int slotIndex) {
5415 Phone phone = PhoneFactory.getPhone(slotIndex);
5416 if (phone != null) {
5417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5418 mApp, phone.getSubId(), "rebootModem");
5419
5420 final long identity = Binder.clearCallingIdentity();
5421 try {
5422 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5423 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5424 return success;
5425 } finally {
5426 Binder.restoreCallingIdentity(identity);
5427 }
5428 }
5429 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005430 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005431
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005432 public String[] getPcscfAddress(String apnType, String callingPackage,
5433 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005434 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005435 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5436 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005437 return new String[0];
5438 }
5439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 final long identity = Binder.clearCallingIdentity();
5441 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005442 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 } finally {
5444 Binder.restoreCallingIdentity(identity);
5445 }
Wink Saville36469e72014-06-11 15:17:00 -07005446 }
5447
Brad Ebinger51f743a2017-01-23 13:50:20 -08005448 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005449 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5450 * {@link #disableIms(int)}.
5451 * @param slotIndex device slot.
5452 */
5453 public void resetIms(int slotIndex) {
5454 enforceModifyPermission();
5455
5456 final long identity = Binder.clearCallingIdentity();
5457 try {
5458 if (mImsResolver == null) {
5459 // may happen if the does not support IMS.
5460 return;
5461 }
5462 mImsResolver.disableIms(slotIndex);
5463 mImsResolver.enableIms(slotIndex);
5464 } finally {
5465 Binder.restoreCallingIdentity(identity);
5466 }
5467 }
5468
5469 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005470 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5471 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005472 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005473 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005474 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475
5476 final long identity = Binder.clearCallingIdentity();
5477 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005478 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005479 // may happen if the device does not support IMS.
5480 return;
5481 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005482 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005486 }
5487
5488 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005489 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5490 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005491 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005492 public void disableIms(int slotId) {
5493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494
5495 final long identity = Binder.clearCallingIdentity();
5496 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005497 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005498 // may happen if the device does not support IMS.
5499 return;
5500 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005501 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005505 }
5506
5507 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005508 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5509 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005510 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005511 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005512 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005513 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514
5515 final long identity = Binder.clearCallingIdentity();
5516 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005517 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005518 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5519 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005520 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005521 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 } finally {
5523 Binder.restoreCallingIdentity(identity);
5524 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005525 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005526 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005527 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5528 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005529 @Override
5530 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005531 enforceModifyPermission();
5532
5533 final long identity = Binder.clearCallingIdentity();
5534 try {
5535 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005536 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005537 } finally {
5538 Binder.restoreCallingIdentity(identity);
5539 }
5540 }
5541
5542 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005543 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005544 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005545 */
5546 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5547 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548
5549 final long identity = Binder.clearCallingIdentity();
5550 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005551 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005552 // may happen if the device does not support IMS.
5553 return null;
5554 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005555 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556 } finally {
5557 Binder.restoreCallingIdentity(identity);
5558 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005559 }
5560
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005561 /**
5562 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005563 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005564 */
5565 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5566 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567
5568 final long identity = Binder.clearCallingIdentity();
5569 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005570 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005571 // may happen if the device does not support IMS.
5572 return null;
5573 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005574 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 } finally {
5576 Binder.restoreCallingIdentity(identity);
5577 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005578 }
5579
Brad Ebinger884c07b2018-02-15 16:17:40 -08005580 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005581 * Sets the ImsService Package Name that Telephony will bind to.
5582 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005583 * @param slotIndex the slot ID that the ImsService should bind for.
5584 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005585 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005586 * @param featureTypes An integer array of feature types associated with a packageName.
5587 * @param packageName The name of the package that the current configuration will be replaced
5588 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005589 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005590 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005591 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5592 int[] featureTypes, String packageName) {
5593 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5594 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5596 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005597 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 final long identity = Binder.clearCallingIdentity();
5600 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005601 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005602 // may happen if the device does not support IMS.
5603 return false;
5604 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005605 Map<Integer, String> featureConfig = new HashMap<>();
5606 for (int featureType : featureTypes) {
5607 featureConfig.put(featureType, packageName);
5608 }
5609 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5610 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005614 }
5615
5616 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005617 * Clears any carrier ImsService overrides for the slot index specified that were previously
5618 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5619 *
5620 * This should only be used for testing.
5621 *
5622 * @param slotIndex the slot ID that the ImsService should bind for.
5623 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5624 */
5625 @Override
5626 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5627 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5629 "clearCarrierImsServiceOverride");
5630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5631 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5632 "clearCarrierImsServiceOverride");
5633
5634 final long identity = Binder.clearCallingIdentity();
5635 try {
5636 if (mImsResolver == null) {
5637 // may happen if the device does not support IMS.
5638 return false;
5639 }
5640 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
5644 }
5645
5646 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005647 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005648 *
5649 * @param slotId The slot that the ImsService is associated with.
5650 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5651 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005652 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005653 * @return the package name of the ImsService configuration.
5654 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005655 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5656 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005657 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005658 TelephonyPermissions
5659 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5660 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5661 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 final long identity = Binder.clearCallingIdentity();
5664 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005665 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005666 // may happen if the device does not support IMS.
5667 return "";
5668 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005669 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005670 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5671 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005675 }
5676
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005677 /**
5678 * Get the MmTelFeature state associated with the requested subscription id.
5679 * @param subId The subscription that the MmTelFeature is associated with.
5680 * @param callback A callback with an integer containing the
5681 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5682 */
5683 @Override
5684 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5685 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5686 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5687 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5688 "IMS not available on device.");
5689 }
5690 final long token = Binder.clearCallingIdentity();
5691 try {
5692 int slotId = getSlotIndex(subId);
5693 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5694 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5695 + subId + "'");
5696 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5697 }
5698 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5699 try {
5700 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5701 } catch (RemoteException e) {
5702 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5703 + "Ignore");
5704 }
5705 });
5706 } finally {
5707 Binder.restoreCallingIdentity(token);
5708 }
5709 }
5710
Daniel Brightbb5840b2021-01-12 15:48:18 -08005711 /**
5712 * Sets the ims registration state on all valid {@link Phone}s.
5713 */
5714 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005715 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716
5717 final long identity = Binder.clearCallingIdentity();
5718 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005719 // NOTE: Before S, this method only set the default phone.
5720 for (final Phone phone : PhoneFactory.getPhones()) {
5721 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5722 phone.setImsRegistrationState(registered);
5723 }
5724 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 } finally {
5726 Binder.restoreCallingIdentity(identity);
5727 }
Wink Saville36469e72014-06-11 15:17:00 -07005728 }
5729
5730 /**
Stuart Scott54788802015-03-30 13:18:01 -07005731 * Set the network selection mode to automatic.
5732 *
5733 */
5734 @Override
5735 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5737 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738
5739 final long identity = Binder.clearCallingIdentity();
5740 try {
shilufc958392020-01-20 11:36:01 -08005741 if (!isActiveSubscription(subId)) {
5742 return;
5743 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005745 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5746 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
Stuart Scott54788802015-03-30 13:18:01 -07005750 }
5751
Jack Yud10cdd42020-09-28 20:28:01 -07005752 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005753 * Ask the radio to connect to the input network and change selection mode to manual.
5754 *
5755 * @param subId the id of the subscription.
5756 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5757 * the operator to attach to.
5758 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5759 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5760 * normal network selection next time.
5761 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005762 */
5763 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005764 public boolean setNetworkSelectionModeManual(
5765 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5767 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005768
5769 if (!isActiveSubscription(subId)) {
5770 return false;
5771 }
5772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 final long identity = Binder.clearCallingIdentity();
5774 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005775 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005777 if (DBG) {
5778 log("setNetworkSelectionModeManual: subId: " + subId
5779 + " operator: " + operatorInfo);
5780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005785 }
shilu84f6e8b2019-12-19 13:58:01 -08005786 /**
5787 * Get the manual network selection
5788 *
5789 * @param subId the id of the subscription.
5790 *
5791 * @return the previously saved user selected PLMN
5792 */
5793 @Override
5794 public String getManualNetworkSelectionPlmn(int subId) {
5795 TelephonyPermissions
5796 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5797 mApp, subId, "getManualNetworkSelectionPlmn");
5798
5799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005802 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005803 }
5804
5805 final Phone phone = getPhone(subId);
5806 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005807 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005808 }
5809 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5810 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5811 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5812 } finally {
5813 Binder.restoreCallingIdentity(identity);
5814 }
5815 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005816
5817 /**
5818 * Scans for available networks.
5819 */
5820 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005821 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5822 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5824 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005825 LocationAccessPolicy.LocationPermissionResult locationResult =
5826 LocationAccessPolicy.checkLocationPermission(mApp,
5827 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5828 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005829 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005830 .setCallingPid(Binder.getCallingPid())
5831 .setCallingUid(Binder.getCallingUid())
5832 .setMethod("getCellNetworkScanResults")
5833 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005834 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5835 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005836 .build());
5837 switch (locationResult) {
5838 case DENIED_HARD:
5839 throw new SecurityException("Not allowed to access scan results -- location");
5840 case DENIED_SOFT:
5841 return null;
5842 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005843
Pengquan Menga1bb6272018-09-06 09:59:22 -07005844 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005845 try {
5846 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005847 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005849 } finally {
5850 Binder.restoreCallingIdentity(identity);
5851 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005852 }
5853
5854 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005855 * Get the call forwarding info, given the call forwarding reason.
5856 */
5857 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005858 public void getCallForwarding(int subId, int callForwardingReason,
5859 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005860 enforceReadPrivilegedPermission("getCallForwarding");
5861 long identity = Binder.clearCallingIdentity();
5862 try {
5863 if (DBG) {
5864 log("getCallForwarding: subId " + subId
5865 + " callForwardingReason" + callForwardingReason);
5866 }
Hall Liu27d24262020-09-18 19:04:59 -07005867
5868 Phone phone = getPhone(subId);
5869 if (phone == null) {
5870 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005871 callback.onError(
5872 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005873 } catch (RemoteException e) {
5874 // ignore
5875 }
5876 return;
5877 }
5878
5879 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5880 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5881 @Override
5882 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5883 try {
5884 callback.onCallForwardingInfoAvailable(info);
5885 } catch (RemoteException e) {
5886 // ignore
5887 }
5888 }
5889
5890 @Override
5891 public void onError(int error) {
5892 try {
5893 callback.onError(error);
5894 } catch (RemoteException e) {
5895 // ignore
5896 }
5897 }
5898 });
5899 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
5903 }
5904
5905 /**
5906 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5907 * reason, the number to forward, and the timeout before the forwarding is attempted.
5908 */
5909 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005910 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5911 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005912 enforceModifyPermission();
5913 long identity = Binder.clearCallingIdentity();
5914 try {
5915 if (DBG) {
5916 log("setCallForwarding: subId " + subId
5917 + " callForwardingInfo" + callForwardingInfo);
5918 }
Hall Liu27d24262020-09-18 19:04:59 -07005919
5920 Phone phone = getPhone(subId);
5921 if (phone == null) {
5922 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005923 callback.accept(
5924 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005925 } catch (RemoteException e) {
5926 // ignore
5927 }
5928 return;
5929 }
5930
5931 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5932 FunctionalUtils.ignoreRemoteException(callback::accept));
5933
5934 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005935 } finally {
5936 Binder.restoreCallingIdentity(identity);
5937 }
5938 }
5939
5940 /**
Hall Liu27d24262020-09-18 19:04:59 -07005941 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005942 */
5943 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005944 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005945 enforceReadPrivilegedPermission("getCallForwarding");
5946 long identity = Binder.clearCallingIdentity();
5947 try {
Hall Liu27d24262020-09-18 19:04:59 -07005948
5949 Phone phone = getPhone(subId);
5950 if (phone == null) {
5951 try {
5952 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5953 } catch (RemoteException e) {
5954 // ignore
5955 }
5956 return;
5957 }
5958
5959 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5960
Shuo Qian4a594052020-01-23 11:59:30 -08005961 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005962 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
5966 }
5967
5968 /**
Hall Liu27d24262020-09-18 19:04:59 -07005969 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005970 */
5971 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005972 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005973 enforceModifyPermission();
5974 long identity = Binder.clearCallingIdentity();
5975 try {
Hall Liu27d24262020-09-18 19:04:59 -07005976 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5977
5978 Phone phone = getPhone(subId);
5979 if (phone == null) {
5980 try {
5981 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5982 } catch (RemoteException e) {
5983 // ignore
5984 }
5985 return;
5986 }
5987
5988 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5989 FunctionalUtils.ignoreRemoteException(callback::accept));
5990
5991 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005992 } finally {
5993 Binder.restoreCallingIdentity(identity);
5994 }
5995 }
5996
5997 /**
yinxub1bed742017-04-17 11:45:04 -07005998 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005999 *
yinxub1bed742017-04-17 11:45:04 -07006000 * @param subId id of the subscription
6001 * @param request contains the radio access networks with bands/channels to scan
6002 * @param messenger callback messenger for scan results or errors
6003 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006004 * @return the id of the requested scan which can be used to stop the scan.
6005 */
6006 @Override
6007 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006008 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6010 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006011 LocationAccessPolicy.LocationPermissionResult locationResult =
6012 LocationAccessPolicy.checkLocationPermission(mApp,
6013 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6014 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006015 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006016 .setCallingPid(Binder.getCallingPid())
6017 .setCallingUid(Binder.getCallingUid())
6018 .setMethod("requestNetworkScan")
6019 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006020 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6021 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006022 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006023 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006024 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6025 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006026 if (e != null) {
6027 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6028 throw e;
6029 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006030 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006031 return TelephonyScanManager.INVALID_SCAN_ID;
6032 }
6033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 }
Hall Liu912dfd32019-04-25 14:02:26 -07006035 int callingUid = Binder.getCallingUid();
6036 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006037 final long identity = Binder.clearCallingIdentity();
6038 try {
6039 return mNetworkScanRequestTracker.startNetworkScan(
6040 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006041 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006042 } finally {
6043 Binder.restoreCallingIdentity(identity);
6044 }
yinxu504e1392017-04-12 16:03:22 -07006045 }
6046
Hall Liub2ac8ef2019-02-28 15:56:23 -08006047 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006048 NetworkScanRequest request, int subId, String callingPackage) {
6049 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006050 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6051 boolean hasNetworkScanPermission =
6052 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6053 == PERMISSION_GRANTED;
6054
6055 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6056 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6057 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006058 }
6059
6060 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6061 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006062 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6063 return new SecurityException("Specific channels must not be"
6064 + " scanned without location access.");
6065 }
6066 }
6067 }
6068
Hall Liub2ac8ef2019-02-28 15:56:23 -08006069 return null;
6070 }
6071
yinxu504e1392017-04-12 16:03:22 -07006072 /**
6073 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006074 *
6075 * @param subId id of the subscription
6076 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006077 */
6078 @Override
6079 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6081 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082
Hall Liu912dfd32019-04-25 14:02:26 -07006083 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 final long identity = Binder.clearCallingIdentity();
6085 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006086 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
yinxu504e1392017-04-12 16:03:22 -07006090 }
6091
6092 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006093 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006094 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006095 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006096 */
6097 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006098 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006099 TelephonyPermissions
6100 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006101 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102
6103 final long identity = Binder.clearCallingIdentity();
6104 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006105 if (DBG) log("getAllowedNetworkTypesBitmask");
6106 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6107 int networkTypesBitmask = (result != null ? result[0] : -1);
6108 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6109 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006113 }
6114
6115 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006116 * Get the allowed network types for certain reason.
6117 *
6118 * @param subId the id of the subscription.
6119 * @param reason the reason the allowed network type change is taking place
6120 * @return the allowed network types.
6121 */
6122 @Override
6123 public long getAllowedNetworkTypesForReason(int subId,
6124 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6125 TelephonyPermissions
6126 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6127 mApp, subId, "getAllowedNetworkTypesForReason");
6128 final long identity = Binder.clearCallingIdentity();
6129 try {
6130 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6131 } finally {
6132 Binder.restoreCallingIdentity(identity);
6133 }
6134 }
6135
6136 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006137 * Enable/Disable E-UTRA-NR Dual Connectivity
6138 * @param subId subscription id of the sim card
6139 * @param nrDualConnectivityState expected NR dual connectivity state
6140 * This can be passed following states
6141 * <ol>
6142 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6143 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6144 * <li>Disable NR dual connectivity and force secondary cell to be released
6145 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6146 * </ol>
6147 * @return operation result.
6148 */
6149 @Override
6150 public int setNrDualConnectivityState(int subId,
6151 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6153 mApp, subId, "enableNRDualConnectivity");
6154 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6155 final long identity = Binder.clearCallingIdentity();
6156 try {
6157 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6158 nrDualConnectivityState, subId,
6159 workSource);
6160 if (DBG) log("enableNRDualConnectivity result: " + result);
6161 return result;
6162 } finally {
6163 Binder.restoreCallingIdentity(identity);
6164 }
6165 }
6166
6167 /**
6168 * Is E-UTRA-NR Dual Connectivity enabled
6169 * @return true if dual connectivity is enabled else false
6170 */
6171 @Override
6172 public boolean isNrDualConnectivityEnabled(int subId) {
6173 TelephonyPermissions
6174 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6175 mApp, subId, "isNRDualConnectivityEnabled");
6176 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6177 final long identity = Binder.clearCallingIdentity();
6178 try {
6179 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6180 null, subId, workSource);
6181 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6182 return isEnabled;
6183 } finally {
6184 Binder.restoreCallingIdentity(identity);
6185 }
6186 }
6187
6188 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006189 * get carrier bandwidth per primary and secondary carrier
6190 * @param subId subscription id of the sim card
6191 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6192 */
6193 @Override
6194 public CarrierBandwidth getCarrierBandwidth(int subId) {
6195 TelephonyPermissions
6196 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6197 mApp, subId, "isNRDualConnectivityEnabled");
6198 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6199 final long identity = Binder.clearCallingIdentity();
6200 try {
6201 CarrierBandwidth carrierBandwidth =
6202 getPhoneFromSubId(subId).getCarrierBandwidth();
6203 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6204 return carrierBandwidth;
6205 } finally {
6206 Binder.restoreCallingIdentity(identity);
6207 }
6208 }
6209
6210 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006211 * Set the allowed network types of the device and
6212 * provide the reason triggering the allowed network change.
6213 *
6214 * @param subId the id of the subscription.
6215 * @param reason the reason the allowed network type change is taking place
6216 * @param allowedNetworkTypes the allowed network types.
6217 * @return true on success; false on any failure.
6218 */
6219 @Override
6220 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006221 @TelephonyManager.AllowedNetworkTypesReason int reason,
6222 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6224 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006225 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6226 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6227 return false;
6228 }
6229
6230 if (DBG) {
6231 log("setAllowedNetworkTypesForReason: " + reason
6232 + " value: " + allowedNetworkTypes);
6233 }
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006234 final long identity = Binder.clearCallingIdentity();
6235 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006236 Boolean success = (Boolean) sendRequest(
6237 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6238 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6239
6240 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6241 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006242 } finally {
6243 Binder.restoreCallingIdentity(identity);
6244 }
6245 }
6246
6247 /**
Miaoa84611c2019-03-15 09:21:10 +08006248 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006249 *
Miaoa84611c2019-03-15 09:21:10 +08006250 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006251 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006252 * @hide
6253 */
6254 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006255 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006258 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 try {
Miaoa84611c2019-03-15 09:21:10 +08006260 if (phone != null) {
6261 return phone.hasMatchedTetherApnSetting();
6262 } else {
6263 return false;
6264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 } finally {
6266 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006267 }
Junda Liu475951f2014-11-07 16:45:03 -08006268 }
6269
6270 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006271 * Enable or disable always reporting signal strength changes from radio.
6272 *
6273 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6274 */
6275 @Override
6276 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6277 enforceModifyPermission();
6278 enforceSystemCaller();
6279
6280 final long identity = Binder.clearCallingIdentity();
6281 final Phone phone = getPhone(subId);
6282 try {
6283 if (phone != null) {
6284 if (DBG) {
6285 log("setAlwaysReportSignalStrength: subId=" + subId
6286 + " isEnable=" + isEnable);
6287 }
6288 phone.setAlwaysReportSignalStrength(isEnable);
6289 } else {
6290 loge("setAlwaysReportSignalStrength: no phone found for subId="
6291 + subId);
6292 }
6293 } finally {
6294 Binder.restoreCallingIdentity(identity);
6295 }
6296 }
6297
6298 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006299 * Get the user enabled state of Mobile Data.
6300 *
6301 * TODO: remove and use isUserDataEnabled.
6302 * This can't be removed now because some vendor codes
6303 * calls through ITelephony directly while they should
6304 * use TelephonyManager.
6305 *
6306 * @return true on enabled
6307 */
6308 @Override
6309 public boolean getDataEnabled(int subId) {
6310 return isUserDataEnabled(subId);
6311 }
6312
6313 /**
6314 * Get whether mobile data is enabled per user setting.
6315 *
6316 * There are other factors deciding whether mobile data is actually enabled, but they are
6317 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006318 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006319 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006320 *
6321 * @return {@code true} if data is enabled else {@code false}
6322 */
6323 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006324 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006325 try {
6326 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6327 null);
6328 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6330 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006331 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332
6333 final long identity = Binder.clearCallingIdentity();
6334 try {
6335 int phoneId = mSubscriptionController.getPhoneId(subId);
6336 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6337 Phone phone = PhoneFactory.getPhone(phoneId);
6338 if (phone != null) {
6339 boolean retVal = phone.isUserDataEnabled();
6340 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6341 return retVal;
6342 } else {
6343 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6344 return false;
6345 }
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006348 }
6349 }
6350
6351 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006352 * Checks if the device is capable of mobile data by considering whether whether the
6353 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6354 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006355 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006356 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006357 */
6358 @Override
6359 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006360 try {
6361 try {
6362 mApp.enforceCallingOrSelfPermission(
6363 android.Manifest.permission.ACCESS_NETWORK_STATE,
6364 null);
6365 } catch (Exception e) {
6366 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6367 "isDataEnabled");
6368 }
6369 } catch (Exception e) {
6370 enforceReadPrivilegedPermission("isDataEnabled");
6371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372
6373 final long identity = Binder.clearCallingIdentity();
6374 try {
6375 int phoneId = mSubscriptionController.getPhoneId(subId);
6376 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6377 Phone phone = PhoneFactory.getPhone(phoneId);
6378 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006379 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6381 return retVal;
6382 } else {
6383 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6384 return false;
6385 }
6386 } finally {
6387 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006388 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006389 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006390
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006391 /**
6392 * Check if data is enabled for a specific reason
6393 * @param subId Subscription index
6394 * @param reason the reason the data enable change is taking place
6395 * @return {@code true} if the overall data is enabled; {@code false} if not.
6396 */
6397 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006398 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006399 @TelephonyManager.DataEnabledReason int reason) {
6400 try {
6401 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6402 null);
6403 } catch (Exception e) {
6404 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006405 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006406 }
6407
6408
6409 final long identity = Binder.clearCallingIdentity();
6410 try {
6411 int phoneId = mSubscriptionController.getPhoneId(subId);
6412 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006413 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006414 + " reason=" + reason);
6415 }
6416 Phone phone = PhoneFactory.getPhone(phoneId);
6417 if (phone != null) {
6418 boolean retVal;
6419 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6420 retVal = phone.isUserDataEnabled();
6421 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006422 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006423 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006424 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006425 return retVal;
6426 } else {
6427 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006428 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006429 + subId + " retVal=false");
6430 }
6431 return false;
6432 }
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
6436 }
6437
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006438 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006439 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006440 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6441 // Skip the check if it's one of these special uids
6442 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6443 }
6444
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006445 //load access rules from carrier configs, and check those as well: b/139133814
6446 SubscriptionController subController = SubscriptionController.getInstance();
6447 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6448 || subController == null) return privilegeFromSim;
6449
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006450 PackageManager pkgMgr = phone.getContext().getPackageManager();
6451 String[] packages = pkgMgr.getPackagesForUid(uid);
6452
6453 final long identity = Binder.clearCallingIdentity();
6454 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006455 int subId = phone.getSubId();
6456 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6457 // A test override is in place for the privileges for this subId, so don't try to
6458 // read the subscription privileges.
6459 return privilegeFromSim;
6460 }
6461 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006462 SubscriptionManager subManager = (SubscriptionManager)
6463 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6464 for (String pkg : packages) {
6465 if (subManager.canManageSubscription(subInfo, pkg)) {
6466 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6467 }
6468 }
6469 return privilegeFromSim;
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
6473 }
6474
6475 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6476 String pkgName) {
6477 //load access rules from carrier configs, and check those as well: b/139133814
6478 SubscriptionController subController = SubscriptionController.getInstance();
6479 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6480 || subController == null) return privilegeFromSim;
6481
6482 final long identity = Binder.clearCallingIdentity();
6483 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006484 int subId = phone.getSubId();
6485 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6486 // A test override is in place for the privileges for this subId, so don't try to
6487 // read the subscription privileges.
6488 return privilegeFromSim;
6489 }
6490 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006491 SubscriptionManager subManager = (SubscriptionManager)
6492 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6493 return subManager.canManageSubscription(subInfo, pkgName)
6494 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
6498 }
6499
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006500 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006501 public int getCarrierPrivilegeStatus(int subId) {
6502 final Phone phone = getPhone(subId);
6503 if (phone == null) {
6504 loge("getCarrierPrivilegeStatus: Invalid subId");
6505 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6506 }
6507 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006508 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006509 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006510 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6511 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006512
6513 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6514 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006515 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006516 }
Junda Liu29340342014-07-10 15:23:27 -07006517
6518 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006519 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006520 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006521 final Phone phone = getPhone(subId);
6522 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006523 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006524 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6525 }
6526 UiccProfile profile =
6527 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6528 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006529 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006530 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6531 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006532 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006533 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006534 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006535 }
6536
6537 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006538 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6539 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006540 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006541 }
6542
6543 int phoneId = SubscriptionManager.getPhoneId(subId);
6544 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006545 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006546 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006547 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6548 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006549 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6550 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6551 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006552 }
6553
6554 @Override
6555 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006556 if (TextUtils.isEmpty(pkgName))
6557 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006558 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6559 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6560 UiccCard card = UiccController.getInstance().getUiccCard(i);
6561 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006562 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006563 continue;
6564 }
6565
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006566 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6567 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6568 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006569 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6570 break;
6571 }
6572 }
6573
6574 return result;
Junda Liu29340342014-07-10 15:23:27 -07006575 }
Derek Tan89e89d42014-07-08 17:00:10 -07006576
6577 @Override
Junda Liue64de782015-04-16 17:19:16 -07006578 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6579 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6580 loge("phoneId " + phoneId + " is not valid.");
6581 return null;
6582 }
6583 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006584 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006585 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006586 return null ;
6587 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006588 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006589 }
6590
Amith Yamasani6e118872016-02-19 12:53:51 -08006591 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006592 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006593 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006594 List<String> privilegedPackages = new ArrayList<>();
6595 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006596 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6597 // has UICC in that slot.
6598 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006599 if (card.hasCarrierPrivilegeRules()) {
6600 if (packages == null) {
6601 // Only check packages in user 0 for now
6602 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006603 PackageManager.MATCH_DISABLED_COMPONENTS
6604 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006605 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006606 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006607 }
6608 for (int p = packages.size() - 1; p >= 0; p--) {
6609 PackageInfo pkgInfo = packages.get(p);
6610 if (pkgInfo != null && pkgInfo.packageName != null
6611 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006612 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006613 privilegedPackages.add(pkgInfo.packageName);
6614 }
6615 }
6616 }
6617 }
6618 return privilegedPackages;
6619 }
6620
chen xuf7e9fe82019-05-09 19:31:02 -07006621 @Override
6622 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006623 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6624
6625 final long identity = Binder.clearCallingIdentity();
6626
chen xuf7e9fe82019-05-09 19:31:02 -07006627 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006628 try {
6629 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6630 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6631 }
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006634 }
6635 return privilegedPackages;
6636 }
6637
Wink Savilleb564aae2014-10-23 10:18:09 -07006638 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006639 final Phone phone = getPhone(subId);
6640 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006641 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006642 return null;
6643 }
6644 String iccId = card.getIccId();
6645 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006646 return null;
6647 }
6648 return iccId;
6649 }
6650
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006651 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006652 public void setCallComposerStatus(int subId, int status) {
6653 enforceModifyPermission();
6654
6655 final long identity = Binder.clearCallingIdentity();
6656 try {
6657 Phone phone = getPhone(subId);
6658 if (phone != null) {
6659 Phone defaultPhone = phone.getImsPhone();
6660 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6661 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6662 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006663 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6664 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006665 }
6666 }
Shuo Qian284ae752020-12-22 19:10:14 -08006667 } catch (ImsException e) {
6668 throw new ServiceSpecificException(e.getCode());
6669 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006670 Binder.restoreCallingIdentity(identity);
6671 }
6672 }
6673
6674 @Override
6675 public int getCallComposerStatus(int subId) {
6676 enforceReadPrivilegedPermission("getCallComposerStatus");
6677
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 Phone phone = getPhone(subId);
6681 if (phone != null) {
6682 Phone defaultPhone = phone.getImsPhone();
6683 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6684 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6685 return imsPhone.getCallComposerStatus();
6686 }
6687 }
6688 } finally {
6689 Binder.restoreCallingIdentity(identity);
6690 }
6691 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6692 }
6693
6694 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006695 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6696 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006697 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006698 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 final long identity = Binder.clearCallingIdentity();
6701 try {
6702 final String iccId = getIccId(subId);
6703 final Phone phone = getPhone(subId);
6704 if (phone == null) {
6705 return false;
6706 }
6707 final String subscriberId = phone.getSubscriberId();
6708
6709 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006710 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 + subscriberId + " to " + number);
6712 }
6713
6714 if (TextUtils.isEmpty(iccId)) {
6715 return false;
6716 }
6717
6718 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6719
6720 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6721 if (alphaTag == null) {
6722 editor.remove(alphaTagPrefKey);
6723 } else {
6724 editor.putString(alphaTagPrefKey, alphaTag);
6725 }
6726
6727 // Record both the line number and IMSI for this ICCID, since we need to
6728 // track all merged IMSIs based on line number
6729 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6730 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6731 if (number == null) {
6732 editor.remove(numberPrefKey);
6733 editor.remove(subscriberPrefKey);
6734 } else {
6735 editor.putString(numberPrefKey, number);
6736 editor.putString(subscriberPrefKey, subscriberId);
6737 }
6738
6739 editor.commit();
6740 return true;
6741 } finally {
6742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006743 }
Derek Tan7226c842014-07-02 17:42:23 -07006744 }
6745
6746 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006747 public String getLine1NumberForDisplay(int subId, String callingPackage,
6748 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006749 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006750 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006751 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006752 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006753 return null;
6754 }
Derek Tan97ebb422014-09-05 16:55:38 -07006755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756 final long identity = Binder.clearCallingIdentity();
6757 try {
6758 String iccId = getIccId(subId);
6759 if (iccId != null) {
6760 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6761 if (DBG_MERGE) {
6762 log("getLine1NumberForDisplay returning "
6763 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6764 }
6765 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6768 return null;
6769 } finally {
6770 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006771 }
Derek Tan7226c842014-07-02 17:42:23 -07006772 }
6773
6774 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006775 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6776 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006777 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006778 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006779 return null;
6780 }
Derek Tan97ebb422014-09-05 16:55:38 -07006781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 final long identity = Binder.clearCallingIdentity();
6783 try {
6784 String iccId = getIccId(subId);
6785 if (iccId != null) {
6786 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6787 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6788 }
6789 return null;
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006792 }
Derek Tan7226c842014-07-02 17:42:23 -07006793 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006794
6795 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006796 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6797 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006798 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6799 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006801 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006802 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006803 return null;
6804 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006805
Jordan Liub49b04b2019-05-06 14:45:15 -07006806 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6807 // the process, where TelephonyManager was instantiated.
6808 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006809 final long identity = Binder.clearCallingIdentity();
6810 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006811 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006812 final TelephonyManager tele = TelephonyManager.from(context);
6813 final SubscriptionManager sub = SubscriptionManager.from(context);
6814
6815 // Figure out what subscribers are currently active
6816 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006817
Jordan Liub49b04b2019-05-06 14:45:15 -07006818 // Only consider subs which match the current subId
6819 // This logic can be simplified. See b/131189269 for progress.
6820 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006821 activeSubscriberIds.add(tele.getSubscriberId(subId));
6822 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823
6824 // First pass, find a number override for an active subscriber
6825 String mergeNumber = null;
6826 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6827 for (String key : prefs.keySet()) {
6828 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6829 final String subscriberId = (String) prefs.get(key);
6830 if (activeSubscriberIds.contains(subscriberId)) {
6831 final String iccId = key.substring(
6832 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6833 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6834 mergeNumber = (String) prefs.get(numberKey);
6835 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006836 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837 + " for active subscriber " + subscriberId);
6838 }
6839 if (!TextUtils.isEmpty(mergeNumber)) {
6840 break;
6841 }
6842 }
6843 }
6844 }
6845
6846 // Shortcut when no active merged subscribers
6847 if (TextUtils.isEmpty(mergeNumber)) {
6848 return null;
6849 }
6850
6851 // Second pass, find all subscribers under that line override
6852 final ArraySet<String> result = new ArraySet<>();
6853 for (String key : prefs.keySet()) {
6854 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6855 final String number = (String) prefs.get(key);
6856 if (mergeNumber.equals(number)) {
6857 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6858 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6859 final String subscriberId = (String) prefs.get(subscriberKey);
6860 if (!TextUtils.isEmpty(subscriberId)) {
6861 result.add(subscriberId);
6862 }
6863 }
6864 }
6865 }
6866
6867 final String[] resultArray = result.toArray(new String[result.size()]);
6868 Arrays.sort(resultArray);
6869 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006870 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6872 }
6873 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006874 } finally {
6875 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006876 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006877 }
6878
6879 @Override
zoey chen38003472019-12-13 17:16:31 +08006880 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6881 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006882
6883 final long identity = Binder.clearCallingIdentity();
6884 try {
6885 final TelephonyManager telephonyManager = mApp.getSystemService(
6886 TelephonyManager.class);
6887 String subscriberId = telephonyManager.getSubscriberId(subId);
6888 if (subscriberId == null) {
6889 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006890 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006891 + subId);
6892 }
6893 return null;
6894 }
6895
6896 final SubscriptionInfo info = SubscriptionController.getInstance()
6897 .getSubscriptionInfo(subId);
6898 final ParcelUuid groupUuid = info.getGroupUuid();
6899 // If it doesn't belong to any group, return just subscriberId of itself.
6900 if (groupUuid == null) {
6901 return new String[]{subscriberId};
6902 }
6903
6904 // Get all subscriberIds from the group.
6905 final List<String> mergedSubscriberIds = new ArrayList<>();
6906 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006907 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006908 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006909 for (SubscriptionInfo subInfo : groupInfos) {
6910 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6911 if (subscriberId != null) {
6912 mergedSubscriberIds.add(subscriberId);
6913 }
6914 }
6915
6916 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6917 } finally {
6918 Binder.restoreCallingIdentity(identity);
6919
6920 }
6921 }
6922
6923 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006924 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006925 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006926 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927
6928 final long identity = Binder.clearCallingIdentity();
6929 try {
6930 final Phone phone = getPhone(subId);
6931 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6932 } finally {
6933 Binder.restoreCallingIdentity(identity);
6934 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006935 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006936
6937 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006938 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006939 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6940 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006941 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6942 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943
6944 final long identity = Binder.clearCallingIdentity();
6945 try {
6946 final Phone phone = getPhone(subId);
6947 if (phone == null) {
6948 return false;
6949 }
6950 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6951 cdmaNonRoamingList);
6952 } finally {
6953 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006954 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006955 }
6956
6957 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006958 @Deprecated
6959 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6960 enforceModifyPermission();
6961
6962 int returnValue = 0;
6963 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006964 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006965 if(result.exception == null) {
6966 if (result.result != null) {
6967 byte[] responseData = (byte[])(result.result);
6968 if(responseData.length > oemResp.length) {
6969 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6970 responseData.length + "bytes. Buffer Size is " +
6971 oemResp.length + "bytes.");
6972 }
6973 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6974 returnValue = responseData.length;
6975 }
6976 } else {
6977 CommandException ex = (CommandException) result.exception;
6978 returnValue = ex.getCommandError().ordinal();
6979 if(returnValue > 0) returnValue *= -1;
6980 }
6981 } catch (RuntimeException e) {
6982 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6983 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6984 if(returnValue > 0) returnValue *= -1;
6985 }
6986
6987 return returnValue;
6988 }
6989
6990 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006991 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006992 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006993 try {
6994 TelephonyPermissions
6995 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6996 mApp, phone.getSubId(), "getRadioAccessFamily");
6997 } catch (SecurityException e) {
6998 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6999 throw e;
7000 }
chen xub97461a2018-10-26 14:17:57 -07007001 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007002 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007003 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 final long identity = Binder.clearCallingIdentity();
7006 try {
chen xub97461a2018-10-26 14:17:57 -07007007 TelephonyPermissions
7008 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7009 mApp, phone.getSubId(), "getRadioAccessFamily");
7010 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007011 } finally {
7012 Binder.restoreCallingIdentity(identity);
7013 }
chen xub97461a2018-10-26 14:17:57 -07007014 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007015 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007016
7017 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007018 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007019 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007020 try {
7021 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7022 Binder.getCallingUid())) {
7023 throw new SecurityException("Package uid and package name do not match: "
7024 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7025 }
7026 } catch (PackageManager.NameNotFoundException e) {
7027 throw new SecurityException("Package name invalid:" + callingPackage);
7028 }
7029 RoleManager rm = mApp.getSystemService(RoleManager.class);
7030 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7031 if (!dialerRoleHolders.contains(callingPackage)) {
7032 throw new SecurityException("App must be the dialer role holder to"
7033 + " upload a call composer pic");
7034 }
7035
7036 Executors.newSingleThreadExecutor().execute(() -> {
7037 ByteArrayOutputStream output = new ByteArrayOutputStream(
7038 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7039 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7040 boolean readUntilEnd = false;
7041 int totalBytesRead = 0;
7042 byte[] buffer = new byte[16 * 1024];
7043 while (true) {
7044 int numRead;
7045 try {
7046 numRead = input.read(buffer);
7047 } catch (IOException e) {
7048 try {
7049 fd.checkError();
7050 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7051 null);
7052 } catch (IOException e1) {
7053 // This means that the other side closed explicitly with an error. If this
7054 // happens, log and ignore.
7055 loge("Remote end of call composer picture pipe closed: " + e1);
7056 }
7057 break;
7058 }
7059 if (numRead == -1) {
7060 readUntilEnd = true;
7061 break;
7062 }
7063 totalBytesRead += numRead;
7064 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7065 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7066 try {
7067 input.close();
7068 } catch (IOException e) {
7069 // ignore
7070 }
7071 break;
7072 }
7073 output.write(buffer, 0, numRead);
7074 }
7075 // Generally, the remote end will close the file descriptors. The only case where we
7076 // close is above, where the picture size is too big.
7077
7078 try {
7079 fd.checkError();
7080 } catch (IOException e) {
7081 loge("Remote end for call composer closed with an error: " + e);
7082 return;
7083 }
7084
Hall Liuaa4211e2021-01-20 15:43:39 -08007085 if (!readUntilEnd) {
7086 loge("Did not finish reading entire image; aborting");
7087 return;
7088 }
Hall Liu82694d52020-12-11 18:22:04 -08007089
Hall Liuaa4211e2021-01-20 15:43:39 -08007090 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7091 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7092 new CallComposerPictureTransfer.Factory() {},
7093 imageData,
7094 (result) -> {
7095 if (result.first != null) {
7096 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7097 Bundle outputResult = new Bundle();
7098 outputResult.putParcelable(
7099 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7100 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7101 outputResult);
7102 } else {
7103 callback.send(result.second, null);
7104 }
7105 }
7106 );
Hall Liu82694d52020-12-11 18:22:04 -08007107 });
7108 }
7109
7110 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007111 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007112 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007113 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114
7115 final long identity = Binder.clearCallingIdentity();
7116 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007117 ImsManager.getInstance(defaultPhone.getContext(),
7118 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 } finally {
7120 Binder.restoreCallingIdentity(identity);
7121 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007122 }
7123
7124 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007125 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007126 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7128 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007129 return false;
7130 }
Svet Ganovb320e182015-04-16 12:30:10 -07007131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007132 final long identity = Binder.clearCallingIdentity();
7133 try {
7134 // Check the user preference and the system-level IMS setting. Even if the user has
7135 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7136 // In the long run, we may instead need to check if there exists a connection service
7137 // which can support video calling.
7138 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007139 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 return imsManager.isVtEnabledByPlatform()
7141 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7142 && imsManager.isVtEnabledByUser();
7143 } finally {
7144 Binder.restoreCallingIdentity(identity);
7145 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007146 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007147
Andrew Leea1239f22015-03-02 17:44:07 -08007148 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007149 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7150 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007152 mApp, subId, callingPackage, callingFeatureId,
7153 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154 return false;
7155 }
7156
7157 final long identity = Binder.clearCallingIdentity();
7158 try {
7159 CarrierConfigManager configManager =
7160 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007161 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
Andrew Leea1239f22015-03-02 17:44:07 -08007166 }
7167
7168 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007169 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007171 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 return false;
7173 }
7174
7175 final long identity = Binder.clearCallingIdentity();
7176 try {
7177 CarrierConfigManager configManager =
7178 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007179 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7181 } finally {
7182 Binder.restoreCallingIdentity(identity);
7183 }
Andrew Leea1239f22015-03-02 17:44:07 -08007184 }
7185
Andrew Lee9431b832015-03-09 18:46:45 -07007186 @Override
7187 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007188 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007189 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007190 }
7191
7192 @Override
7193 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194 final long identity = Binder.clearCallingIdentity();
7195 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007196 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 } finally {
7198 Binder.restoreCallingIdentity(identity);
7199 }
Andrew Lee9431b832015-03-09 18:46:45 -07007200 }
7201
Hall Liuf6668912018-10-31 17:05:23 -07007202 /**
7203 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7204 * support for the feature and device firmware support.
7205 *
7206 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7207 */
7208 @Override
7209 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007211 final Phone phone = getPhone(subscriptionId);
7212 if (phone == null) {
7213 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7214 return false;
7215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007217 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007218 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7219 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007220 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007221 return isCarrierSupported && isDeviceSupported;
7222 } finally {
7223 Binder.restoreCallingIdentity(identity);
7224 }
Hall Liu98187582018-01-22 19:15:32 -08007225 }
7226
Hall Liuf6668912018-10-31 17:05:23 -07007227 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007228 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7229 * RTT setting, will return true if the device and carrier both support RTT.
7230 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007231 */
7232 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 final long identity = Binder.clearCallingIdentity();
7234 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007235 boolean isRttSupported = isRttSupported(subscriptionId);
7236 boolean isUserRttSettingOn = Settings.Secure.getInt(
7237 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7238 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7239 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7240 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007244 }
7245
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007246 @Deprecated
7247 @Override
7248 public String getDeviceId(String callingPackage) {
7249 return getDeviceIdWithFeature(callingPackage, null);
7250 }
7251
Sanket Padawe7310cc72015-01-14 09:53:20 -08007252 /**
7253 * Returns the unique device ID of phone, for example, the IMEI for
7254 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7255 *
7256 * <p>Requires Permission:
7257 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7258 */
7259 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007260 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007261 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007262 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007263 return null;
7264 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007265 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007266 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007267 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007268 return null;
7269 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270
7271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 return phone.getDeviceId();
7274 } finally {
7275 Binder.restoreCallingIdentity(identity);
7276 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007277 }
7278
Ping Sunc67b7c22016-03-02 19:16:45 +08007279 /**
7280 * {@hide}
7281 * Returns the IMS Registration Status on a particular subid
7282 *
7283 * @param subId
7284 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007285 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007286 Phone phone = getPhone(subId);
7287 if (phone != null) {
7288 return phone.isImsRegistered();
7289 } else {
7290 return false;
7291 }
7292 }
7293
Santos Cordon7a1885b2015-02-03 11:15:19 -08007294 @Override
7295 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007296 final long identity = Binder.clearCallingIdentity();
7297 try {
7298 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007302 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007303
Tyler Gunnf70ed162019-04-03 15:28:53 -07007304 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007305 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007306 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007308 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007309 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7310 }
7311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
7317 }
7318
7319 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007320 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007321 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7322 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007323 final long identity = Binder.clearCallingIdentity();
7324 try {
7325 Phone phone = getPhone(subscriptionId);
7326 if (phone == null) {
7327 return null;
7328 }
7329 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7330 } finally {
7331 Binder.restoreCallingIdentity(identity);
7332 }
7333 }
7334
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007335 /**
7336 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007337 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007338 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007339 final long identity = Binder.clearCallingIdentity();
7340 try {
7341 Phone phone = getPhone(subId);
7342 if (phone != null) {
7343 return phone.isWifiCallingEnabled();
7344 } else {
7345 return false;
7346 }
7347 } finally {
7348 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007349 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007350 }
7351
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007352 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007353 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007354 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007355 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 final long identity = Binder.clearCallingIdentity();
7357 try {
7358 Phone phone = getPhone(subId);
7359 if (phone != null) {
7360 return phone.isVideoEnabled();
7361 } else {
7362 return false;
7363 }
7364 } finally {
7365 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007366 }
7367 }
7368
7369 /**
7370 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7371 * defined in {@link ImsRegistrationImplBase}.
7372 */
7373 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 final long identity = Binder.clearCallingIdentity();
7375 try {
7376 Phone phone = getPhone(subId);
7377 if (phone != null) {
7378 return phone.getImsRegistrationTech();
7379 } else {
7380 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7381 }
7382 } finally {
7383 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007384 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007385 }
7386
Stuart Scott8eef64f2015-04-08 15:13:54 -07007387 @Override
7388 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007389 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007390 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7391 return;
7392 }
7393
Svet Ganovcc087f82015-05-12 20:35:54 -07007394 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007395
Svet Ganovcc087f82015-05-12 20:35:54 -07007396 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007397 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7398 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007399 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007400 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007401 setNetworkSelectionModeAutomatic(subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007402 setAllowedNetworkTypesForReason(subId,
7403 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7404 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7405 setAllowedNetworkTypesForReason(subId,
7406 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7407 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7408 setAllowedNetworkTypesForReason(subId,
7409 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7410 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Yomna Nasser3f777b62021-02-17 03:38:52 +00007411 setAllowedNetworkTypesForReason(subId,
7412 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G,
7413 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007414 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7415 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007416 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007417 // There has been issues when Sms raw table somehow stores orphan
7418 // fragments. They lead to garbled message when new fragments come
7419 // in and combined with those stale ones. In case this happens again,
7420 // user can reset all network settings which will clean up this table.
7421 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007422 // Clean up IMS settings as well here.
7423 int slotId = getSlotIndex(subId);
7424 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7425 ImsManager.getInstance(mApp, slotId).factoryReset();
7426 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007427
7428 // Erase modem config if erase modem on network setting is enabled.
7429 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7430 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7431 if (configValue != null && Boolean.parseBoolean(configValue)) {
7432 sendEraseModemConfig(getDefaultPhone());
7433 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007434 } finally {
7435 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007436 }
7437 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007438
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007439 private void cleanUpSmsRawTable(Context context) {
7440 ContentResolver resolver = context.getContentResolver();
7441 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7442 resolver.delete(uri, null, null);
7443 }
7444
Narayan Kamath1c496c22015-04-16 14:40:19 +01007445 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007446 public String getSimLocaleForSubscriber(int subId) {
7447 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7448 final Phone phone = getPhone(subId);
7449 if (phone == null) {
7450 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007451 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 final long identity = Binder.clearCallingIdentity();
7454 try {
chen xu5d3637b2019-01-21 23:31:38 -08007455 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007456 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007457 if (info == null) {
7458 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7459 return null;
7460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 // Try and fetch the locale from the carrier properties or from the SIM language
7462 // preferences (EF-PL and EF-LI)...
7463 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007465 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7466 if (localeFromDefaultSim != null) {
7467 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7468 if (DBG) log("Using locale from subId: " + subId + " locale: "
7469 + localeFromDefaultSim);
7470 return localeFromDefaultSim.toLanguageTag();
7471 } else {
7472 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473 }
7474 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 // The SIM language preferences only store a language (e.g. fr = French), not an
7477 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7478 // the SIM and carrier preferences does not include a country we add the country
7479 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007480 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007482 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 return mccLocale.toLanguageTag();
7484 }
7485
7486 if (DBG) log("No locale found - returning null");
7487 return null;
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007491 }
7492
7493 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007494 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007495 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007496 }
7497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498 /**
7499 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7500 */
7501 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007502 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007503 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007504 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007505
Chenjie Yu1ba97252018-01-11 18:16:20 -08007506 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007507 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007508
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007509 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007510 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7511 * representing the state of the modem.
7512 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007513 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7514 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007515 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007516 */
7517 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007518 public void requestModemActivityInfo(ResultReceiver result) {
7519 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007520 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521
7522 final long identity = Binder.clearCallingIdentity();
7523 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007524 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 } finally {
7526 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007527 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007528 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007529
Siddharth Rayb8114062018-06-17 15:02:38 -07007530 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7531 // less than total activity duration.
7532 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7533 if (info == null) {
7534 return false;
7535 }
7536 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007537 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7538 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7539
Siddharth Rayb8114062018-06-17 15:02:38 -07007540 return (info.isValid()
7541 && (info.getSleepTimeMillis() <= activityDurationMs)
7542 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007543 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007544 && (totalTxTimeMs <= activityDurationMs));
7545 }
7546
Jack Yu85bd38a2015-11-09 11:34:32 -08007547 /**
7548 * {@hide}
7549 * Returns the service state information on specified subscription.
7550 */
7551 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007552 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7553 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007554 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007555 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007556 return null;
7557 }
7558
Hall Liuf19c44f2018-11-27 14:38:17 -08007559 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7560 LocationAccessPolicy.checkLocationPermission(mApp,
7561 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7562 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007563 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007564 .setCallingPid(Binder.getCallingPid())
7565 .setCallingUid(Binder.getCallingUid())
7566 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007567 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007568 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007569 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7570 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007571 .build());
7572
7573 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7574 LocationAccessPolicy.checkLocationPermission(mApp,
7575 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7576 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007577 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007578 .setCallingPid(Binder.getCallingPid())
7579 .setCallingUid(Binder.getCallingUid())
7580 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007581 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007582 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007583 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7584 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007585 .build());
7586 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7587 boolean hasFinePermission =
7588 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7589 boolean hasCoarsePermission =
7590 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7591
Jack Yu479f40e2020-10-27 21:29:25 -07007592 final Phone phone = getPhone(subId);
7593 if (phone == null) {
7594 return null;
7595 }
7596
Jordan Liu0f2bc442020-11-18 16:47:37 -08007597 final long identity = Binder.clearCallingIdentity();
7598
Jack Yu479f40e2020-10-27 21:29:25 -07007599 boolean isCallingPackageDataService = phone.getDataServicePackages()
7600 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007602 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7603 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7604 Rlog.d(LOG_TAG,
7605 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7606 return null;
7607 }
7608
Hall Liuf19c44f2018-11-27 14:38:17 -08007609 ServiceState ss = phone.getServiceState();
7610
7611 // Scrub out the location info in ServiceState depending on what level of access
7612 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007613 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007614 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7615 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007616 } finally {
7617 Binder.restoreCallingIdentity(identity);
7618 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007619 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007620
7621 /**
7622 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7623 *
7624 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7625 * voicemail ringtone.
7626 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7627 * PhoneAccount.
7628 */
7629 @Override
7630 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631 final long identity = Binder.clearCallingIdentity();
7632 try {
7633 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7634 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007635 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007636 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007638 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7639 } finally {
7640 Binder.restoreCallingIdentity(identity);
7641 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007642 }
7643
7644 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007645 * Sets the per-account voicemail ringtone.
7646 *
7647 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7648 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7649 *
7650 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7651 * voicemail ringtone.
7652 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7653 * PhoneAccount.
7654 */
7655 @Override
7656 public void setVoicemailRingtoneUri(String callingPackage,
7657 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007658 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007659 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007660 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7661 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7663 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7664 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666
7667 final long identity = Binder.clearCallingIdentity();
7668 try {
7669 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7670 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007671 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672 }
7673 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7674 } finally {
7675 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007676 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007677 }
7678
7679 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007680 * Returns whether vibration is set for voicemail notification in Phone settings.
7681 *
7682 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7683 * voicemail vibration setting.
7684 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7685 */
7686 @Override
7687 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7691 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007692 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7696 } finally {
7697 Binder.restoreCallingIdentity(identity);
7698 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007699 }
7700
Youhan Wange64578a2016-05-02 15:32:42 -07007701 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007702 * Sets the per-account voicemail vibration.
7703 *
7704 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7705 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7706 *
7707 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7708 * voicemail vibration setting.
7709 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7710 * specific PhoneAccount.
7711 */
7712 @Override
7713 public void setVoicemailVibrationEnabled(String callingPackage,
7714 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007715 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007716 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007717 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7718 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7720 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7721 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007722 }
7723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7727 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007728 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729 }
7730 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7731 } finally {
7732 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007733 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007734 }
7735
7736 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007737 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7738 *
7739 * @throws SecurityException if the caller does not have the required permission
7740 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007741 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007742 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007743 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007744 }
7745
7746 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007747 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7748 * permission.
7749 *
7750 * @throws SecurityException if the caller does not have the required permission
7751 */
7752 private void enforceSendSmsPermission() {
7753 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7754 }
7755
7756 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007757 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007758 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007759 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007760 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007761 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007762 final long identity = Binder.clearCallingIdentity();
7763 try {
7764 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007765 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766 if (componentName == null) {
7767 throw new SecurityException(
7768 "Caller not current active visual voicemail package[null]");
7769 }
7770 String vvmPackage = componentName.getPackageName();
7771 if (!callingPackage.equals(vvmPackage)) {
7772 throw new SecurityException("Caller not current active visual voicemail package["
7773 + vvmPackage + "]");
7774 }
7775 } finally {
7776 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007777 }
7778 }
7779
7780 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007781 * Return the application ID for the app type.
7782 *
7783 * @param subId the subscription ID that this request applies to.
7784 * @param appType the uicc app type.
7785 * @return Application ID for specificied app type, or null if no uicc.
7786 */
7787 @Override
7788 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007789 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007790 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791
7792 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007793 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 if (phone == null) {
7795 return null;
7796 }
7797 String aid = null;
7798 try {
7799 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7800 .getApplicationByType(appType).getAid();
7801 } catch (Exception e) {
7802 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7803 }
7804 return aid;
7805 } finally {
7806 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007807 }
Youhan Wange64578a2016-05-02 15:32:42 -07007808 }
7809
Youhan Wang4001d252016-05-11 10:29:41 -07007810 /**
7811 * Return the Electronic Serial Number.
7812 *
7813 * @param subId the subscription ID that this request applies to.
7814 * @return ESN or null if error.
7815 */
7816 @Override
7817 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007818 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007819 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820
7821 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007822 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 if (phone == null) {
7824 return null;
7825 }
7826 String esn = null;
7827 try {
7828 esn = phone.getEsn();
7829 } catch (Exception e) {
7830 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7831 }
7832 return esn;
7833 } finally {
7834 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007835 }
Youhan Wang4001d252016-05-11 10:29:41 -07007836 }
7837
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007838 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007839 * Return the Preferred Roaming List Version.
7840 *
7841 * @param subId the subscription ID that this request applies to.
7842 * @return PRLVersion or null if error.
7843 */
7844 @Override
7845 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007846 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007847 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848
7849 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007850 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 if (phone == null) {
7852 return null;
7853 }
7854 String cdmaPrlVersion = null;
7855 try {
7856 cdmaPrlVersion = phone.getCdmaPrlVersion();
7857 } catch (Exception e) {
7858 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7859 }
7860 return cdmaPrlVersion;
7861 } finally {
7862 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007863 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007864 }
7865
7866 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007867 * Get snapshot of Telephony histograms
7868 * @return List of Telephony histograms
7869 * @hide
7870 */
7871 @Override
7872 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7874 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875
7876 final long identity = Binder.clearCallingIdentity();
7877 try {
7878 return RIL.getTelephonyRILTimingHistograms();
7879 } finally {
7880 Binder.restoreCallingIdentity(identity);
7881 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007882 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007883
7884 /**
7885 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007886 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7887 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007888 * Require system privileges. In the future we may add this to carrier APIs.
7889 *
Michele Berionne482f8202018-11-27 18:57:59 -08007890 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007891 */
7892 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007893 @TelephonyManager.SetCarrierRestrictionResult
7894 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007895 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007896 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007897
Michele Berionne482f8202018-11-27 18:57:59 -08007898 if (carrierRestrictionRules == null) {
7899 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007900 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007902 final long identity = Binder.clearCallingIdentity();
7903 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007904 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007905 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007906 } finally {
7907 Binder.restoreCallingIdentity(identity);
7908 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007909 }
7910
7911 /**
7912 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007913 * Get the allowed carrier list and the excluded carrier list, including the priority between
7914 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007915 * Require system privileges. In the future we may add this to carrier APIs.
7916 *
Michele Berionne482f8202018-11-27 18:57:59 -08007917 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007918 */
7919 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007920 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007921 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007922 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923
7924 final long identity = Binder.clearCallingIdentity();
7925 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007926 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7927 if (response instanceof CarrierRestrictionRules) {
7928 return (CarrierRestrictionRules) response;
7929 }
7930 // Response is an Exception of some kind,
7931 // which is signalled to the user as a NULL retval
7932 return null;
7933 } catch (Exception e) {
7934 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7935 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936 } finally {
7937 Binder.restoreCallingIdentity(identity);
7938 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007939 }
7940
fionaxu59545b42016-05-25 15:53:37 -07007941 /**
fionaxu59545b42016-05-25 15:53:37 -07007942 * Action set from carrier signalling broadcast receivers to enable/disable radio
7943 * @param subId the subscription ID that this action applies to.
7944 * @param enabled control enable or disable radio.
7945 * {@hide}
7946 */
7947 @Override
7948 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7949 enforceModifyPermission();
7950 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951
7952 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007953 if (phone == null) {
7954 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7955 return;
7956 }
7957 try {
7958 phone.carrierActionSetRadioEnabled(enabled);
7959 } catch (Exception e) {
7960 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961 } finally {
7962 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007963 }
7964 }
7965
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007966 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007967 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7968 * network status based on which carrier apps could apply actions accordingly,
7969 * enable/disable default url handler for example.
7970 *
7971 * @param subId the subscription ID that this action applies to.
7972 * @param report control start/stop reporting the default network status.
7973 * {@hide}
7974 */
7975 @Override
7976 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7977 enforceModifyPermission();
7978 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007979
7980 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007981 if (phone == null) {
7982 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7983 return;
7984 }
7985 try {
7986 phone.carrierActionReportDefaultNetworkStatus(report);
7987 } catch (Exception e) {
7988 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989 } finally {
7990 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007991 }
7992 }
7993
7994 /**
fionaxud9622282017-07-17 17:51:30 -07007995 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7996 * @param subId the subscription ID that this action applies to.
7997 * {@hide}
7998 */
7999 @Override
8000 public void carrierActionResetAll(int subId) {
8001 enforceModifyPermission();
8002 final Phone phone = getPhone(subId);
8003 if (phone == null) {
8004 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8005 return;
8006 }
8007 try {
8008 phone.carrierActionResetAll();
8009 } catch (Exception e) {
8010 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8011 }
8012 }
8013
8014 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008015 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8016 * bug report is being generated.
8017 */
8018 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008019 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008020 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8021 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008022 writer.println("Permission Denial: can't dump Phone from pid="
8023 + Binder.getCallingPid()
8024 + ", uid=" + Binder.getCallingUid()
8025 + "without permission "
8026 + android.Manifest.permission.DUMP);
8027 return;
8028 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008029 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008030 }
Jack Yueb89b242016-06-22 13:27:47 -07008031
Brad Ebingerdac2f002018-04-03 15:17:52 -07008032 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008033 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8034 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8035 @NonNull String[] args) {
8036 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8037 this, in.getFileDescriptor(), out.getFileDescriptor(),
8038 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008039 }
8040
Jack Yueb89b242016-06-22 13:27:47 -07008041 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008042 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008043 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008044 * @param reason the reason the data enable change is taking place
8045 * @param enabled True if enabling the data, otherwise disabling.
8046 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008047 */
8048 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008049 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008050 boolean enabled) {
8051 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8052 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8053 try {
8054 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008055 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008056 } catch (SecurityException se) {
8057 enforceModifyPermission();
8058 }
8059 } else {
8060 enforceModifyPermission();
8061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008062
8063 final long identity = Binder.clearCallingIdentity();
8064 try {
8065 Phone phone = getPhone(subId);
8066 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008067 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8068 phone.carrierActionSetMeteredApnsEnabled(enabled);
8069 } else {
8070 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072 }
8073 } finally {
8074 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008075 }
8076 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008077
8078 /**
8079 * Get Client request stats
8080 * @return List of Client Request Stats
8081 * @hide
8082 */
8083 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008084 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8085 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008087 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008088 return null;
8089 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008090 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008092 final long identity = Binder.clearCallingIdentity();
8093 try {
8094 if (phone != null) {
8095 return phone.getClientRequestStats();
8096 }
8097
8098 return null;
8099 } finally {
8100 Binder.restoreCallingIdentity(identity);
8101 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008102 }
8103
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008104 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008105 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008106 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008107 }
Jack Yueb4124c2017-02-16 15:32:43 -08008108
8109 /**
Grace Chen70990072017-03-24 17:21:30 -07008110 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008111 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008112 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008113 * @param state State of SIM (power down, power up, pass through)
8114 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8115 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8116 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008117 *
8118 **/
8119 @Override
Grace Chen70990072017-03-24 17:21:30 -07008120 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008121 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008122 Phone phone = PhoneFactory.getPhone(slotIndex);
8123
vagdeviaf9a5b92018-08-15 16:01:53 -07008124 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8125
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 final long identity = Binder.clearCallingIdentity();
8127 try {
8128 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008129 phone.setSimPowerState(state, null, workSource);
8130 }
8131 } finally {
8132 Binder.restoreCallingIdentity(identity);
8133 }
8134 }
8135
8136 /**
8137 * Set SIM card power state.
8138 *
8139 * @param slotIndex SIM slot id.
8140 * @param state State of SIM (power down, power up, pass through)
8141 * @param callback callback to trigger after success or failure
8142 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8143 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8144 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8145 *
8146 **/
8147 @Override
8148 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8149 IIntegerConsumer callback) {
8150 enforceModifyPermission();
8151 Phone phone = PhoneFactory.getPhone(slotIndex);
8152
8153 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8154
8155 final long identity = Binder.clearCallingIdentity();
8156 try {
8157 if (phone != null) {
8158 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8159 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008160 }
8161 } finally {
8162 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008163 }
8164 }
Shuo Qiandd210312017-04-12 22:11:33 +00008165
Tyler Gunn65d45c22017-06-05 11:22:26 -07008166 private boolean isUssdApiAllowed(int subId) {
8167 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008168 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008169 if (configManager == null) {
8170 return false;
8171 }
8172 PersistableBundle pb = configManager.getConfigForSubId(subId);
8173 if (pb == null) {
8174 return false;
8175 }
8176 return pb.getBoolean(
8177 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8178 }
8179
Shuo Qiandd210312017-04-12 22:11:33 +00008180 /**
8181 * Check if phone is in emergency callback mode
8182 * @return true if phone is in emergency callback mode
8183 * @param subId sub id
8184 */
goneil9c5f4872017-12-05 14:07:56 -08008185 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008186 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008187 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008188 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189
8190 final long identity = Binder.clearCallingIdentity();
8191 try {
8192 if (phone != null) {
8193 return phone.isInEcm();
8194 } else {
8195 return false;
8196 }
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008199 }
8200 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008201
8202 /**
8203 * Get the current signal strength information for the given subscription.
8204 * Because this information is not updated when the device is in a low power state
8205 * it should not be relied-upon to be current.
8206 * @param subId Subscription index
8207 * @return the most recent cached signal strength info from the modem
8208 */
8209 @Override
8210 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008211 final long identity = Binder.clearCallingIdentity();
8212 try {
8213 Phone p = getPhone(subId);
8214 if (p == null) {
8215 return null;
8216 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218 return p.getSignalStrength();
8219 } finally {
8220 Binder.restoreCallingIdentity(identity);
8221 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008222 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008223
Pengquan Meng77b7f132018-08-22 14:49:57 -07008224 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008225 * Get the current modem radio state for the given slot.
8226 * @param slotIndex slot index.
8227 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008228 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008229 * @return the current radio power state from the modem
8230 */
8231 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008232 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008233 Phone phone = PhoneFactory.getPhone(slotIndex);
8234 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8236 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008237 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8238 }
8239
8240 final long identity = Binder.clearCallingIdentity();
8241 try {
8242 return phone.getRadioPowerState();
8243 } finally {
8244 Binder.restoreCallingIdentity(identity);
8245 }
8246 }
8247 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8248 }
8249
8250 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008251 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8252 *
8253 * <p>Requires one of the following permissions:
8254 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8255 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8256 * privileges.
8257 *
8258 * @param subId subscription id
8259 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8260 * {@code false}.
8261 */
8262 @Override
8263 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008264 try {
8265 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8266 null);
8267 } catch (Exception e) {
8268 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8269 mApp, subId, "isDataRoamingEnabled");
8270 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008271
Pengquan Menga1bb6272018-09-06 09:59:22 -07008272 boolean isEnabled = false;
8273 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008274 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008275 Phone phone = getPhone(subId);
8276 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008277 } finally {
8278 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008279 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008280 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008281 }
8282
8283
8284 /**
8285 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8286 *
8287 * <p> Requires permission:
8288 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8289 * privileges.
8290 *
8291 * @param subId subscription id
8292 * @param isEnabled {@code true} means enable, {@code false} means disable.
8293 */
8294 @Override
8295 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8297 mApp, subId, "setDataRoamingEnabled");
8298
Pengquan Menga1bb6272018-09-06 09:59:22 -07008299 final long identity = Binder.clearCallingIdentity();
8300 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008301 Phone phone = getPhone(subId);
8302 if (phone != null) {
8303 phone.setDataRoamingEnabled(isEnabled);
8304 }
8305 } finally {
8306 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008307 }
8308 }
8309
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008310 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008311 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008312 TelephonyPermissions
8313 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008314 mApp, subId, "isManualNetworkSelectionAllowed");
8315
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008316 boolean isAllowed = true;
8317 final long identity = Binder.clearCallingIdentity();
8318 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008319 Phone phone = getPhone(subId);
8320 if (phone != null) {
8321 isAllowed = phone.isCspPlmnEnabled();
8322 }
8323 } finally {
8324 Binder.restoreCallingIdentity(identity);
8325 }
8326 return isAllowed;
8327 }
8328
8329 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008330 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008331 // Verify that tha callingPackage belongs to the calling UID
8332 mApp.getSystemService(AppOpsManager.class)
8333 .checkPackage(Binder.getCallingUid(), callingPackage);
8334
Jordan Liu1e142fc2019-04-22 15:10:43 -07008335 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008336 try {
8337 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008338 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008339 } catch (SecurityException e) {
8340 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8341 // has carrier privileges on an active UICC
8342 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8343 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008344 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008345 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008346 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008347
8348 final long identity = Binder.clearCallingIdentity();
8349 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008350 UiccController uiccController = UiccController.getInstance();
8351 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008352 if (hasReadPermission) {
8353 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008354 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008355
8356 // Remove private info if the caller doesn't have access
8357 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8358 for (UiccCardInfo cardInfo : cardInfos) {
8359 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8360 // is available
8361 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8362 if (card == null || card.getUiccProfile() == null) {
8363 // assume no access if the card or profile is unavailable
8364 filteredInfos.add(cardInfo.getUnprivileged());
8365 continue;
8366 }
8367 UiccProfile profile = card.getUiccProfile();
8368 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8369 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8370 filteredInfos.add(cardInfo);
8371 } else {
8372 filteredInfos.add(cardInfo.getUnprivileged());
8373 }
8374 }
8375 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008376 } finally {
8377 Binder.restoreCallingIdentity(identity);
8378 }
8379 }
8380
8381 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008382 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008383 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385 final long identity = Binder.clearCallingIdentity();
8386 try {
8387 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8388 if (slots == null) {
8389 Rlog.i(LOG_TAG, "slots is null.");
8390 return null;
8391 }
8392
8393 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8394 for (int i = 0; i < slots.length; i++) {
8395 UiccSlot slot = slots[i];
8396 if (slot == null) {
8397 continue;
8398 }
8399
Jordan Liu7be7e652019-05-06 18:55:02 +00008400 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008401 UiccCard card = slot.getUiccCard();
8402 if (card != null) {
8403 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008404 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008405 cardId = slot.getEid();
8406 if (TextUtils.isEmpty(cardId)) {
8407 cardId = slot.getIccId();
8408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008409 }
8410
Jordan Liu857451f2019-05-09 16:35:35 -07008411 if (cardId != null) {
8412 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8413 // if cardId is an EID, it's all digits so this is fine
8414 cardId = IccUtils.stripTrailingFs(cardId);
8415 }
8416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008417 int cardState = 0;
8418 switch (slot.getCardState()) {
8419 case CARDSTATE_ABSENT:
8420 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8421 break;
8422 case CARDSTATE_PRESENT:
8423 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8424 break;
8425 case CARDSTATE_ERROR:
8426 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8427 break;
8428 case CARDSTATE_RESTRICTED:
8429 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8430 break;
8431 default:
8432 break;
8433
8434 }
8435
8436 infos[i] = new UiccSlotInfo(
8437 slot.isActive(),
8438 slot.isEuicc(),
8439 cardId,
8440 cardState,
8441 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008442 slot.isExtendedApduSupported(),
8443 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008444 }
8445 return infos;
8446 } finally {
8447 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008448 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008449 }
8450
8451 @Override
8452 public boolean switchSlots(int[] physicalSlots) {
8453 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008454
8455 final long identity = Binder.clearCallingIdentity();
8456 try {
8457 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8458 } finally {
8459 Binder.restoreCallingIdentity(identity);
8460 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008461 }
Jack Yu4c988042018-02-27 15:30:01 -08008462
8463 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008464 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008465 final long identity = Binder.clearCallingIdentity();
8466 try {
8467 return UiccController.getInstance().getCardIdForDefaultEuicc();
8468 } finally {
8469 Binder.restoreCallingIdentity(identity);
8470 }
8471 }
8472
Pengquan Meng85728fb2018-03-12 16:31:21 -07008473 /**
goneil47ffb6e2018-04-06 15:40:58 -07008474 * A test API to reload the UICC profile.
8475 *
8476 * <p>Requires that the calling app has permission
8477 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8478 * @hide
8479 */
8480 @Override
8481 public void refreshUiccProfile(int subId) {
8482 enforceModifyPermission();
8483
8484 final long identity = Binder.clearCallingIdentity();
8485 try {
8486 Phone phone = getPhone(subId);
8487 if (phone == null) {
8488 return;
8489 }
8490 UiccCard uiccCard = phone.getUiccCard();
8491 if (uiccCard == null) {
8492 return;
8493 }
8494 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8495 if (uiccProfile == null) {
8496 return;
8497 }
8498 uiccProfile.refresh();
8499 } finally {
8500 Binder.restoreCallingIdentity(identity);
8501 }
8502 }
8503
8504 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008505 * Returns false if the mobile data is disabled by default, otherwise return true.
8506 */
8507 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008508 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008509 }
8510
8511 /**
8512 * Returns true if the data roaming is enabled by default, i.e the system property
8513 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8514 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8515 */
8516 private boolean getDefaultDataRoamingEnabled(int subId) {
8517 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008518 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008519 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008520 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8521 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8522 return isDataRoamingEnabled;
8523 }
8524
8525 /**
8526 * Returns the default network type for the given {@code subId}, if the default network type is
8527 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8528 */
8529 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008530 List<Integer> list = TelephonyProperties.default_network();
8531 int phoneId = mSubscriptionController.getPhoneId(subId);
8532 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8533 return list.get(phoneId);
8534 }
8535 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008536 }
fionaxua13278b2018-03-21 00:08:13 -07008537
8538 @Override
8539 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008540 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008542
8543 final long identity = Binder.clearCallingIdentity();
8544 try {
8545 final Phone phone = getPhone(subId);
8546 if (phone == null) {
8547 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8548 return;
8549 }
chen xueaba88a2019-03-15 13:15:10 -07008550 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8551 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008552 if (carrierPrivilegeRules == null) {
8553 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8554 } else {
8555 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008557 } finally {
8558 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008559 }
fionaxua13278b2018-03-21 00:08:13 -07008560 }
8561
8562 @Override
8563 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008564 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008565
8566 final long identity = Binder.clearCallingIdentity();
8567 try {
8568 final Phone phone = getPhone(subId);
8569 if (phone == null) {
8570 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8571 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8572 }
8573 return phone.getCarrierIdListVersion();
8574 } finally {
8575 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008576 }
fionaxua13278b2018-03-21 00:08:13 -07008577 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008578
8579 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008580 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8581 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008583 mApp, subId, callingPackage, callingFeatureId,
8584 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008585 return -1;
8586 }
8587
8588 final long identity = Binder.clearCallingIdentity();
8589 try {
8590 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8591 } finally {
8592 Binder.restoreCallingIdentity(identity);
8593 }
8594 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008595
8596 @Override
8597 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008598 TelephonyPermissions
8599 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008600 mApp, subId, "getCdmaRoamingMode");
8601
8602 final long identity = Binder.clearCallingIdentity();
8603 try {
8604 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8605 } finally {
8606 Binder.restoreCallingIdentity(identity);
8607 }
8608 }
8609
8610 @Override
8611 public boolean setCdmaRoamingMode(int subId, int mode) {
8612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8613 mApp, subId, "setCdmaRoamingMode");
8614
8615 final long identity = Binder.clearCallingIdentity();
8616 try {
8617 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8618 } finally {
8619 Binder.restoreCallingIdentity(identity);
8620 }
8621 }
8622
8623 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008624 public int getCdmaSubscriptionMode(int subId) {
8625 TelephonyPermissions
8626 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8627 mApp, subId, "getCdmaSubscriptionMode");
8628
8629 final long identity = Binder.clearCallingIdentity();
8630 try {
8631 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8632 } finally {
8633 Binder.restoreCallingIdentity(identity);
8634 }
8635 }
8636
8637 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008638 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8640 mApp, subId, "setCdmaSubscriptionMode");
8641
8642 final long identity = Binder.clearCallingIdentity();
8643 try {
8644 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8645 } finally {
8646 Binder.restoreCallingIdentity(identity);
8647 }
8648 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008649
sqianc5eccab2018-10-19 18:46:41 -07008650 @Override
sqian8c685422019-02-22 15:55:18 -08008651 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008652 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008654 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8655 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008656 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8657 }
8658 final long identity = Binder.clearCallingIdentity();
8659 try {
sqian854d44b2018-12-12 16:48:18 -08008660 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8661 for (Phone phone: PhoneFactory.getPhones()) {
8662 if (phone.getEmergencyNumberTracker() != null
8663 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8664 emergencyNumberListInternal.put(
8665 phone.getSubId(),
8666 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8667 }
sqian11b7a0e2018-12-05 18:48:28 -08008668 }
sqian854d44b2018-12-12 16:48:18 -08008669 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008670 } finally {
8671 Binder.restoreCallingIdentity(identity);
8672 }
sqianc5eccab2018-10-19 18:46:41 -07008673 }
8674
8675 @Override
sqian8c685422019-02-22 15:55:18 -08008676 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008677 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008678 if (!exactMatch) {
8679 TelephonyPermissions
8680 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008681 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008682 }
8683 final long identity = Binder.clearCallingIdentity();
8684 try {
sqian854d44b2018-12-12 16:48:18 -08008685 for (Phone phone: PhoneFactory.getPhones()) {
8686 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008687 && phone.getEmergencyNumberTracker()
8688 .isEmergencyNumber(number, exactMatch)) {
8689 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008690 }
sqian11b7a0e2018-12-05 18:48:28 -08008691 }
8692 return false;
8693 } finally {
8694 Binder.restoreCallingIdentity(identity);
8695 }
8696 }
8697
sqianf4ca7ed2019-01-15 18:32:07 -08008698 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008699 * Start emergency callback mode for GsmCdmaPhone for testing.
8700 */
8701 @Override
8702 public void startEmergencyCallbackMode() {
8703 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8704 "startEmergencyCallbackMode");
8705 enforceModifyPermission();
8706 final long identity = Binder.clearCallingIdentity();
8707 try {
8708 for (Phone phone : PhoneFactory.getPhones()) {
8709 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8710 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8711 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8712 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8713 gsmCdmaPhone.obtainMessage(
8714 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8715 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8716 }
8717 }
8718 } finally {
8719 Binder.restoreCallingIdentity(identity);
8720 }
8721 }
8722
8723 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008724 * Update emergency number list for test mode.
8725 */
8726 @Override
8727 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8728 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8729 "updateEmergencyNumberListTestMode");
8730
8731 final long identity = Binder.clearCallingIdentity();
8732 try {
8733 for (Phone phone: PhoneFactory.getPhones()) {
8734 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8735 if (tracker != null) {
8736 tracker.executeEmergencyNumberTestModeCommand(action, num);
8737 }
8738 }
8739 } finally {
8740 Binder.restoreCallingIdentity(identity);
8741 }
8742 }
8743
8744 /**
8745 * Get the full emergency number list for test mode.
8746 */
8747 @Override
8748 public List<String> getEmergencyNumberListTestMode() {
8749 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8750 "getEmergencyNumberListTestMode");
8751
8752 final long identity = Binder.clearCallingIdentity();
8753 try {
8754 Set<String> emergencyNumbers = new HashSet<>();
8755 for (Phone phone: PhoneFactory.getPhones()) {
8756 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8757 if (tracker != null) {
8758 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8759 emergencyNumbers.add(num.getNumber());
8760 }
8761 }
8762 }
8763 return new ArrayList<>(emergencyNumbers);
8764 } finally {
8765 Binder.restoreCallingIdentity(identity);
8766 }
8767 }
8768
chen xud6b45bd2018-10-30 22:27:10 -07008769 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008770 public int getEmergencyNumberDbVersion(int subId) {
8771 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8772
8773 final long identity = Binder.clearCallingIdentity();
8774 try {
8775 final Phone phone = getPhone(subId);
8776 if (phone == null) {
8777 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8778 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8779 }
8780 return phone.getEmergencyNumberDbVersion();
8781 } finally {
8782 Binder.restoreCallingIdentity(identity);
8783 }
8784 }
8785
8786 @Override
8787 public void notifyOtaEmergencyNumberDbInstalled() {
8788 enforceModifyPermission();
8789
8790 final long identity = Binder.clearCallingIdentity();
8791 try {
8792 for (Phone phone: PhoneFactory.getPhones()) {
8793 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8794 if (tracker != null) {
8795 tracker.updateOtaEmergencyNumberDatabase();
8796 }
8797 }
8798 } finally {
8799 Binder.restoreCallingIdentity(identity);
8800 }
8801 }
8802
8803 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008804 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008805 enforceActiveEmergencySessionPermission();
8806
8807 final long identity = Binder.clearCallingIdentity();
8808 try {
8809 for (Phone phone: PhoneFactory.getPhones()) {
8810 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8811 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008812 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8813 }
8814 }
8815 } finally {
8816 Binder.restoreCallingIdentity(identity);
8817 }
8818 }
8819
8820 @Override
8821 public void resetOtaEmergencyNumberDbFilePath() {
8822 enforceActiveEmergencySessionPermission();
8823
8824 final long identity = Binder.clearCallingIdentity();
8825 try {
8826 for (Phone phone: PhoneFactory.getPhones()) {
8827 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8828 if (tracker != null) {
8829 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008830 }
8831 }
8832 } finally {
8833 Binder.restoreCallingIdentity(identity);
8834 }
8835 }
8836
8837 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008838 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8839 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8840 Phone phone = getPhone(subId);
8841 if (phone == null) {
8842 return null;
8843 }
8844 final long identity = Binder.clearCallingIdentity();
8845 try {
8846 UiccProfile profile = UiccController.getInstance()
8847 .getUiccProfileForPhone(phone.getPhoneId());
8848 if (profile != null) {
8849 return profile.getCertsFromCarrierPrivilegeAccessRules();
8850 }
8851 } finally {
8852 Binder.restoreCallingIdentity(identity);
8853 }
8854 return null;
8855 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008856
8857 /**
8858 * Enable or disable a modem stack.
8859 */
8860 @Override
8861 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8862 enforceModifyPermission();
8863
8864 final long identity = Binder.clearCallingIdentity();
8865 try {
8866 Phone phone = PhoneFactory.getPhone(slotIndex);
8867 if (phone == null) {
8868 return false;
8869 } else {
8870 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8871 }
8872 } finally {
8873 Binder.restoreCallingIdentity(identity);
8874 }
8875 }
Michelecea4cf22018-12-21 15:00:11 -08008876
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008877 /**
8878 * Whether a modem stack is enabled or not.
8879 */
8880 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008881 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8882 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008883 Phone phone = PhoneFactory.getPhone(slotIndex);
8884 if (phone == null) return false;
8885
8886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008887 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8888 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008889 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8890 }
8891
8892 final long identity = Binder.clearCallingIdentity();
8893 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008894 try {
8895 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8896 } catch (NoSuchElementException ex) {
8897 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8898 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008899 } finally {
8900 Binder.restoreCallingIdentity(identity);
8901 }
8902 }
8903
Michelecea4cf22018-12-21 15:00:11 -08008904 @Override
Michele0ea7d782019-03-19 14:58:42 -07008905 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008906 enforceModifyPermission();
8907
8908 final long identity = Binder.clearCallingIdentity();
8909 try {
8910 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008911 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008912 .commit();
8913 } finally {
8914 Binder.restoreCallingIdentity(identity);
8915 }
8916 }
8917
8918 @Override
Michele0ea7d782019-03-19 14:58:42 -07008919 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008920 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008922 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8923 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008924 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008925 }
Michelecea4cf22018-12-21 15:00:11 -08008926
8927 final long identity = Binder.clearCallingIdentity();
8928 try {
Michele0ea7d782019-03-19 14:58:42 -07008929 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008930 } finally {
8931 Binder.restoreCallingIdentity(identity);
8932 }
8933 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008934
Michele0ea7d782019-03-19 14:58:42 -07008935 @TelephonyManager.IsMultiSimSupportedResult
8936 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008937 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8938 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8939 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008940 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8941 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008942 }
8943 // Check if the hardware supports multisim functionality. If usage of multisim is not
8944 // supported by the modem, indicate that it is restricted.
8945 PhoneCapability staticCapability =
8946 mPhoneConfigurationManager.getStaticPhoneCapability();
8947 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008948 loge("isMultiSimSupportedInternal: no static configuration available");
8949 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008950 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008951 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008952 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8953 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008954 }
8955 // Check if support of multiple SIMs is restricted by carrier
8956 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008957 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008958 }
8959
Michele0ea7d782019-03-19 14:58:42 -07008960 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008961 }
8962
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008963 /**
8964 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008965 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8966 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8967 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008968 * @param numOfSims number of active sims we want to switch to
8969 */
8970 @Override
8971 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008972 if (numOfSims == 1) {
8973 enforceModifyPermission();
8974 } else {
8975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8976 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8977 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008978 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008979
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008980 try {
Michele30b57b22019-03-01 12:01:14 -08008981 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008982 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008983 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8984 return;
8985 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008986 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8987 } finally {
8988 Binder.restoreCallingIdentity(identity);
8989 }
8990 }
8991
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008992 @Override
8993 public boolean isApplicationOnUicc(int subId, int appType) {
8994 enforceReadPrivilegedPermission("isApplicationOnUicc");
8995 Phone phone = getPhone(subId);
8996 if (phone == null) {
8997 return false;
8998 }
8999 final long identity = Binder.clearCallingIdentity();
9000 try {
9001 UiccCard uiccCard = phone.getUiccCard();
9002 if (uiccCard == null) {
9003 return false;
9004 }
9005 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9006 if (uiccProfile == null) {
9007 return false;
9008 }
9009 if (TelephonyManager.APPTYPE_SIM <= appType
9010 && appType <= TelephonyManager.APPTYPE_ISIM) {
9011 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9012 }
9013 return false;
9014 } finally {
9015 Binder.restoreCallingIdentity(identity);
9016 }
9017 }
9018
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009019 /**
chen xub4baa772019-04-03 10:23:41 -07009020 * Get whether making changes to modem configurations will trigger reboot.
9021 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009022 */
9023 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009024 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9025 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009027 mApp, subId, callingPackage, callingFeatureId,
9028 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009029 return false;
9030 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009031 final long identity = Binder.clearCallingIdentity();
9032 try {
9033 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9034 } finally {
9035 Binder.restoreCallingIdentity(identity);
9036 }
9037 }
9038
Nathan Harold29f5f052019-02-15 13:41:57 -08009039 private void updateModemStateMetrics() {
9040 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9041 // TODO: check the state for each modem if the api is ready.
9042 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9043 }
9044
Pengquan Meng3889a572019-01-23 11:16:29 -08009045 @Override
9046 public int[] getSlotsMapping() {
9047 enforceReadPrivilegedPermission("getSlotsMapping");
9048
9049 final long identity = Binder.clearCallingIdentity();
9050 try {
9051 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9052 // All logical slots should have a mapping to a physical slot.
9053 int[] logicalSlotsMapping = new int[phoneCount];
9054 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9055 for (int i = 0; i < slotInfos.length; i++) {
9056 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9057 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9058 }
9059 }
9060 return logicalSlotsMapping;
9061 } finally {
9062 Binder.restoreCallingIdentity(identity);
9063 }
9064 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009065
9066 /**
9067 * Get the IRadio HAL Version
9068 */
9069 @Override
9070 public int getRadioHalVersion() {
9071 Phone phone = getDefaultPhone();
9072 if (phone == null) return -1;
9073 HalVersion hv = phone.getHalVersion();
9074 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9075 return hv.major * 100 + hv.minor;
9076 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009077
9078 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009079 * Get the current calling package name.
9080 * @return the current calling package name
9081 */
9082 @Override
9083 public String getCurrentPackageName() {
9084 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9085 }
9086
9087 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009088 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9089 * corresponding network requests on a subId.
9090 *
9091 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009092 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009093 * 2) APN is un-metered for this subscription, or
9094 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009095 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009096 *
9097 * @return whether data is allowed for a apn type.
9098 *
9099 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009100 */
9101 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009102 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009103 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9104 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009105
9106 // Now that all security checks passes, perform the operation as ourselves.
9107 final long identity = Binder.clearCallingIdentity();
9108 try {
9109 Phone phone = getPhone(subId);
9110 if (phone == null) return false;
9111
Jack Yu41407ee2019-05-13 16:54:09 -07009112 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009113 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9114 } finally {
9115 Binder.restoreCallingIdentity(identity);
9116 }
9117 }
9118
9119 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009120 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009121 enforceReadPrivilegedPermission("isApnMetered");
9122
9123 // Now that all security checks passes, perform the operation as ourselves.
9124 final long identity = Binder.clearCallingIdentity();
9125 try {
9126 Phone phone = getPhone(subId);
9127 if (phone == null) return true; // By default return true.
9128
Jack Yu41407ee2019-05-13 16:54:09 -07009129 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009130 } finally {
9131 Binder.restoreCallingIdentity(identity);
9132 }
9133 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009134
9135 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009136 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9137 int subscriptionId, IBooleanConsumer resultCallback) {
9138 enforceModifyPermission();
9139 long token = Binder.clearCallingIdentity();
9140 try {
9141 Phone phone = getPhone(subscriptionId);
9142 if (phone == null) {
9143 try {
9144 if (resultCallback != null) {
9145 resultCallback.accept(false);
9146 }
9147 } catch (RemoteException e) {
9148 // ignore
9149 }
9150 return;
9151 }
9152 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9153 Pair.create(specifiers, (x) -> {
9154 try {
9155 if (resultCallback != null) {
9156 resultCallback.accept(x);
9157 }
9158 } catch (RemoteException e) {
9159 // ignore
9160 }
9161 });
9162 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9163 } finally {
9164 Binder.restoreCallingIdentity(token);
9165 }
9166 }
9167
9168 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009169 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9170 TelephonyPermissions
9171 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9172 mApp, subId, "getSystemSelectionChannels");
9173 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9174 final long identity = Binder.clearCallingIdentity();
9175 try {
9176 List<RadioAccessSpecifier> specifiers =
9177 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9178 null, subId, workSource);
9179 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9180 return specifiers;
9181 } finally {
9182 Binder.restoreCallingIdentity(identity);
9183 }
9184 }
9185
9186 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009187 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009188 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009189 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9190 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9191 if (iccRecords == null) {
9192 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9193 return false;
9194 }
9195 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9196 }
9197
9198 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009199 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9200 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009201 if (callingPackage == null) {
9202 callingPackage = getCurrentPackageName();
9203 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009204 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9205 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009206 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9207 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009208 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9209 }
9210 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9211 Intent intent = new Intent();
9212 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9213 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9214 // Bring up choose default SMS subscription dialog right now
9215 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9216 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9217 mApp.startActivity(intent);
9218 }
chen xud5ca2d52019-05-28 15:20:57 -07009219
9220 @Override
9221 public String getMmsUAProfUrl(int subId) {
9222 //TODO investigate if this API should require proper permission check in R b/133791609
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009225 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9226 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9227 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9228 return carrierUAProfUrl;
9229 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009230 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9231 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009232 } finally {
9233 Binder.restoreCallingIdentity(identity);
9234 }
9235 }
9236
9237 @Override
9238 public String getMmsUserAgent(int subId) {
9239 //TODO investigate if this API should require proper permission check in R b/133791609
9240 final long identity = Binder.clearCallingIdentity();
9241 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009242 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9243 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9244 if (!TextUtils.isEmpty(carrierUserAgent)) {
9245 return carrierUserAgent;
9246 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009247 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9248 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
9252 }
Jack Yub07d4972019-05-28 16:12:25 -07009253
9254 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009255 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9256 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009257
Jack Yub07d4972019-05-28 16:12:25 -07009258 final long identity = Binder.clearCallingIdentity();
9259 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009260 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009261 if (phone == null) return false;
9262
Hall Liua62f5da2020-09-25 10:42:19 -07009263 switch (policy) {
9264 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9265 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9266 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9267 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9268 default:
9269 throw new IllegalArgumentException(policy + " is not a valid policy");
9270 }
Jack Yub07d4972019-05-28 16:12:25 -07009271 } finally {
9272 Binder.restoreCallingIdentity(identity);
9273 }
9274 }
9275
9276 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009277 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009278 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009279 enforceModifyPermission();
9280
changbettyd5c246e2019-12-24 15:40:37 +08009281 final long identity = Binder.clearCallingIdentity();
9282 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009283 Phone phone = getPhone(subscriptionId);
9284 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009285
Hall Liua62f5da2020-09-25 10:42:19 -07009286 switch (policy) {
9287 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9288 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9289 break;
9290 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9291 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9292 break;
9293 default:
9294 throw new IllegalArgumentException(policy + " is not a valid policy");
9295 }
changbettyd5c246e2019-12-24 15:40:37 +08009296 } finally {
9297 Binder.restoreCallingIdentity(identity);
9298 }
9299 }
9300
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009301 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009302 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009303 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9304 * otherwise.
9305 */
9306 @Override
9307 public void setCepEnabled(boolean isCepEnabled) {
9308 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9309
9310 final long identity = Binder.clearCallingIdentity();
9311 try {
9312 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9313 for (Phone phone : PhoneFactory.getPhones()) {
9314 Phone defaultPhone = phone.getImsPhone();
9315 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9316 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9317 ImsPhoneCallTracker imsPhoneCallTracker =
9318 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9319 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9320 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9321 + imsPhone.getMsisdn());
9322 }
9323 }
9324 } finally {
9325 Binder.restoreCallingIdentity(identity);
9326 }
9327 }
allenwtsu46dcc572020-01-08 18:24:03 +08009328
9329 /**
9330 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9331 *
9332 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9333 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9334 * before being read.
9335 */
9336 @Override
9337 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9338 isCompressed) {
9339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9340 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009341 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9342 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9343 }
9344 if (!isImsAvailableOnDevice()) {
9345 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9346 "IMS not available on device.");
9347 }
9348
9349 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009350 try {
Hui Wang761a6682020-10-31 05:12:53 +00009351 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9352 } finally {
9353 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009354 }
9355 }
zoey chene02881a2019-12-30 16:11:23 +08009356
9357 @Override
9358 public boolean isIccLockEnabled(int subId) {
9359 enforceReadPrivilegedPermission("isIccLockEnabled");
9360
9361 // Now that all security checks passes, perform the operation as ourselves.
9362 final long identity = Binder.clearCallingIdentity();
9363 try {
9364 Phone phone = getPhone(subId);
9365 if (phone != null && phone.getIccCard() != null) {
9366 return phone.getIccCard().getIccLockEnabled();
9367 } else {
9368 return false;
9369 }
9370 } finally {
9371 Binder.restoreCallingIdentity(identity);
9372 }
9373 }
9374
9375 /**
9376 * Set the ICC pin lock enabled or disabled.
9377 *
9378 * @return an integer representing the status of IccLock enabled or disabled in the following
9379 * three cases:
9380 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9381 * successfully.
9382 * - Positive number and zero for remaining password attempts.
9383 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9384 *
9385 */
9386 @Override
9387 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9388 enforceModifyPermission();
9389
9390 Phone phone = getPhone(subId);
9391 if (phone == null) {
9392 return 0;
9393 }
9394 // Now that all security checks passes, perform the operation as ourselves.
9395 final long identity = Binder.clearCallingIdentity();
9396 try {
9397 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9398 new Pair<Boolean, String>(enabled, password), phone, null);
9399 return attemptsRemaining;
9400
9401 } catch (Exception e) {
9402 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
9405 }
9406 return 0;
9407 }
9408
9409 /**
9410 * Change the ICC password used in ICC pin lock.
9411 *
9412 * @return an integer representing the status of IccLock changed in the following three cases:
9413 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9414 * - Positive number and zero for remaining password attempts.
9415 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9416 *
9417 */
9418 @Override
9419 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9420 enforceModifyPermission();
9421
9422 Phone phone = getPhone(subId);
9423 if (phone == null) {
9424 return 0;
9425 }
9426 // Now that all security checks passes, perform the operation as ourselves.
9427 final long identity = Binder.clearCallingIdentity();
9428 try {
9429 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9430 new Pair<String, String>(oldPassword, newPassword), phone, null);
9431 return attemptsRemaining;
9432
9433 } catch (Exception e) {
9434 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9435 } finally {
9436 Binder.restoreCallingIdentity(identity);
9437 }
9438 return 0;
9439 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009440
9441 /**
9442 * Request for receiving user activity notification
9443 */
9444 @Override
9445 public void requestUserActivityNotification() {
9446 if (!mNotifyUserActivity.get()
9447 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9448 mNotifyUserActivity.set(true);
9449 }
9450 }
9451
9452 /**
9453 * Called when userActivity is signalled in the power manager.
9454 * This is safe to call from any thread, with any window manager locks held or not.
9455 */
9456 @Override
9457 public void userActivity() {
9458 // ***************************************
9459 // * Inherited from PhoneWindowManager *
9460 // ***************************************
9461 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9462 // WITH ITS LOCKS HELD.
9463 //
9464 // This code must be VERY careful about the locks
9465 // it acquires.
9466 // In fact, the current code acquires way too many,
9467 // and probably has lurking deadlocks.
9468
9469 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9470 throw new SecurityException("Only the OS may call notifyUserActivity()");
9471 }
9472
9473 if (mNotifyUserActivity.getAndSet(false)) {
9474 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9475 USER_ACTIVITY_NOTIFICATION_DELAY);
9476 }
9477 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009478
9479 @Override
9480 public boolean canConnectTo5GInDsdsMode() {
9481 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9482 }
Jack Yud10cdd42020-09-28 20:28:01 -07009483
9484 @Override
9485 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9486 String callingFeatureId) {
9487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9488 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9489 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9490 }
9491
9492 Phone phone = getPhone(subId);
9493 if (phone == null) {
9494 throw new RuntimeException("phone is not available");
9495 }
9496 // Now that all security checks passes, perform the operation as ourselves.
9497 final long identity = Binder.clearCallingIdentity();
9498 try {
9499 return phone.getEquivalentHomePlmns();
9500 } finally {
9501 Binder.restoreCallingIdentity(identity);
9502 }
9503 }
Daniel Bright59e67312020-11-13 11:49:37 -08009504
9505 @Override
9506 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009507 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9508 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009509 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009510 if (radioInterfaceCapabilities == null) {
9511 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009512 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009513 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009514 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009515
Hui Wang641e81c2020-10-12 12:14:23 -07009516 @Override
9517 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9518 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009519 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9520 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9521 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9522 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9523 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009524 if (DBG) {
9525 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9526 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9527 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9528 }
9529
9530 if (!SubscriptionManager.isValidSubscriptionId(subId)
9531 || appType < TelephonyManager.APPTYPE_UNKNOWN
9532 || appType > TelephonyManager.APPTYPE_ISIM
9533 || nafUrl == null || securityProtocol == null || callback == null) {
9534 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9535 if (callback != null) {
9536 try {
9537 callback.onAuthenticationFailure(
9538 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9539 } catch (RemoteException exception) {
9540 log("Fail to notify onAuthenticationFailure due to " + exception);
9541 }
9542 return;
9543 }
9544 }
9545
9546 final long token = Binder.clearCallingIdentity();
9547 try {
9548 getGbaManager(subId).bootstrapAuthenticationRequest(
9549 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9550 forceBootStrapping, callback));
9551 } finally {
9552 Binder.restoreCallingIdentity(token);
9553 }
9554 }
9555
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009556 /**
9557 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9558 * requested radio power state will actually be set. See {@link
9559 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9560 *
9561 * @param subId the subscription ID of the phone requesting to set the radio power state.
9562 * @param enable {@code true} if trying to turn radio on.
9563 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9564 * false}.
9565 */
9566 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9567 Phone phone = getPhone(subId);
9568 if (phone != null) {
9569 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9570 return true;
9571 }
9572 return false;
9573 }
9574
9575 private int handleDataThrottlingRequest(int subId,
9576 DataThrottlingRequest dataThrottlingRequest) {
9577 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9578 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9579 if (!setRadioPowerForThermal(subId, true)) {
9580 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9581 }
9582
9583 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9584
9585 int thermalMitigationResult =
9586 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9587 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9588 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9589 }
9590 return thermalMitigationResult;
9591 }
9592
9593 /**
9594 * Thermal mitigation request to control functionalities at modem.
9595 *
9596 * @param subId the id of the subscription.
9597 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9598 *
9599 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9600 */
9601 @Override
9602 @ThermalMitigationResult
9603 public int sendThermalMitigationRequest(
9604 int subId,
9605 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9606 enforceModifyPermission();
9607
9608 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9609 final long identity = Binder.clearCallingIdentity();
9610
9611 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9612 try {
9613 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9614 switch (thermalMitigationAction) {
9615 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9616 thermalMitigationResult =
9617 handleDataThrottlingRequest(subId,
9618 thermalMitigationRequest.getDataThrottlingRequest());
9619 break;
9620 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9621 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9622 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9623 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9624 }
9625
9626 // Ensure that radio is on. If not able to power on due to phone being
9627 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9628 if (!setRadioPowerForThermal(subId, true)) {
9629 thermalMitigationResult =
9630 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9631 break;
9632 }
9633
9634 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9635 false);
9636 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9637 break;
9638 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9639 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9640 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9641 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9642 }
9643
9644 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9645 if (registry != null) {
9646 TelephonyConnectionService service =
9647 registry.getTelephonyConnectionService();
9648 Phone phone = getPhone(subId);
9649 if (phone == null) {
9650 thermalMitigationResult =
9651 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9652 break;
9653 }
9654
9655 if (PhoneConstantConversions.convertCallState(phone.getState())
9656 != TelephonyManager.CALL_STATE_IDLE
9657 || phone.isInEmergencySmsMode() || phone.isInEcm()
9658 || (service != null && service.isEmergencyCallPending())) {
9659 String errorMessage = "Phone state is not valid. call state = "
9660 + PhoneConstantConversions.convertCallState(phone.getState())
9661 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9662 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9663 errorMessage += service == null
9664 ? " TelephonyConnectionService is null"
9665 : " isEmergencyCallPending = "
9666 + service.isEmergencyCallPending();
9667 Log.e(LOG_TAG, errorMessage);
9668 thermalMitigationResult =
9669 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9670 break;
9671 }
9672 } else {
9673 thermalMitigationResult =
9674 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9675 break;
9676 }
9677
9678 // Turn radio off. If not able to power off due to phone being unavailable,
9679 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9680 if (!setRadioPowerForThermal(subId, false)) {
9681 thermalMitigationResult =
9682 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9683 break;
9684 }
9685 thermalMitigationResult =
9686 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9687 break;
9688 default:
9689 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9690 + "not exist. Requested action: " + thermalMitigationAction);
9691 }
9692 } catch (IllegalArgumentException e) {
9693 throw e;
9694 } catch (Exception e) {
9695 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9696 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9697 } finally {
9698 Binder.restoreCallingIdentity(identity);
9699 }
9700
9701 if (DBG) {
9702 log("thermalMitigationRequest returning with thermalMitigationResult: "
9703 + thermalMitigationResult);
9704 }
9705
9706 return thermalMitigationResult;
9707 }
Hui Wang641e81c2020-10-12 12:14:23 -07009708
9709 /**
9710 * Set the GbaService Package Name that Telephony will bind to.
9711 *
9712 * @param subId The sim that the GbaService is associated with.
9713 * @param packageName The name of the package to be replaced with.
9714 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9715 */
9716 @Override
9717 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9718 enforceModifyPermission();
9719
9720 final long identity = Binder.clearCallingIdentity();
9721 try {
9722 return getGbaManager(subId).overrideServicePackage(packageName);
9723 } finally {
9724 Binder.restoreCallingIdentity(identity);
9725 }
9726 }
9727
9728 /**
9729 * Return the package name of the currently bound GbaService.
9730 *
9731 * @param subId The sim that the GbaService is associated with.
9732 * @return the package name of the GbaService configuration, null if GBA is not supported.
9733 */
9734 @Override
9735 public String getBoundGbaService(int subId) {
9736 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9737
9738 final long identity = Binder.clearCallingIdentity();
9739 try {
9740 return getGbaManager(subId).getServicePackage();
9741 } finally {
9742 Binder.restoreCallingIdentity(identity);
9743 }
9744 }
9745
9746 /**
9747 * Set the release time for telephony to unbind GbaService.
9748 *
9749 * @param subId The sim that the GbaService is associated with.
9750 * @param interval The release time to unbind GbaService by millisecond.
9751 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9752 */
9753 @Override
9754 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9755 enforceModifyPermission();
9756
9757 final long identity = Binder.clearCallingIdentity();
9758 try {
9759 return getGbaManager(subId).overrideReleaseTime(interval);
9760 } finally {
9761 Binder.restoreCallingIdentity(identity);
9762 }
9763 }
9764
9765 /**
9766 * Return the release time for telephony to unbind GbaService.
9767 *
9768 * @param subId The sim that the GbaService is associated with.
9769 * @return The release time to unbind GbaService by millisecond.
9770 */
9771 @Override
9772 public int getGbaReleaseTime(int subId) {
9773 enforceReadPrivilegedPermission("getGbaReleaseTime");
9774
9775 final long identity = Binder.clearCallingIdentity();
9776 try {
9777 return getGbaManager(subId).getReleaseTime();
9778 } finally {
9779 Binder.restoreCallingIdentity(identity);
9780 }
9781 }
9782
9783 private GbaManager getGbaManager(int subId) {
9784 GbaManager instance = GbaManager.getInstance(subId);
9785 if (instance == null) {
9786 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9787 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9788 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9789 }
9790 return instance;
9791 }
Hui Wang761a6682020-10-31 05:12:53 +00009792
9793 /**
9794 * indicate whether the device and the carrier can support
9795 * RCS VoLTE single registration.
9796 */
9797 @Override
9798 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009799 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9800 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9801 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9802 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009803
9804 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9805 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9806 }
9807
9808 final long identity = Binder.clearCallingIdentity();
9809 try {
9810 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9811 if (rpm != null) {
9812 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9813 }
9814 return false;
9815 } finally {
9816 Binder.restoreCallingIdentity(identity);
9817 }
9818 }
9819
9820 /**
9821 * Register RCS provisioning callback.
9822 */
9823 @Override
9824 public void registerRcsProvisioningChangedCallback(int subId,
9825 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009826 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9827 Binder.getCallingUid(), "registerRcsProvisioningChangedCallback",
9828 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9829 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009830
9831 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9832 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9833 }
9834 if (!isImsAvailableOnDevice()) {
9835 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9836 "IMS not available on device.");
9837 }
9838
9839 final long identity = Binder.clearCallingIdentity();
9840 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009841 if (!RcsProvisioningMonitor.getInstance()
9842 .registerRcsProvisioningChangedCallback(subId, callback)) {
9843 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9844 "Service not available for the subscription.");
9845 }
Hui Wang761a6682020-10-31 05:12:53 +00009846 } finally {
9847 Binder.restoreCallingIdentity(identity);
9848 }
9849 }
9850
9851 /**
9852 * Unregister RCS provisioning callback.
9853 */
9854 @Override
9855 public void unregisterRcsProvisioningChangedCallback(int subId,
9856 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009857 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9858 Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback",
9859 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9860 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009861
9862 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9863 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9864 }
9865 if (!isImsAvailableOnDevice()) {
9866 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9867 "IMS not available on device.");
9868 }
9869
9870 final long identity = Binder.clearCallingIdentity();
9871 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009872 RcsProvisioningMonitor.getInstance()
9873 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009874 } finally {
9875 Binder.restoreCallingIdentity(identity);
9876 }
9877 }
9878
9879 /**
9880 * trigger RCS reconfiguration.
9881 */
9882 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009883 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9884 "triggerRcsReconfiguration",
9885 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009886
9887 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9888 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9889 }
9890 if (!isImsAvailableOnDevice()) {
9891 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9892 "IMS not available on device.");
9893 }
9894
9895 final long identity = Binder.clearCallingIdentity();
9896 try {
9897 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9898 } finally {
9899 Binder.restoreCallingIdentity(identity);
9900 }
9901 }
9902
9903 /**
9904 * Provide the client configuration parameters of the RCS application.
9905 */
9906 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009907 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9908 "setRcsClientConfiguration",
9909 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009910
9911 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9912 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9913 }
9914 if (!isImsAvailableOnDevice()) {
9915 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9916 "IMS not available on device.");
9917 }
9918
9919 final long identity = Binder.clearCallingIdentity();
9920
9921 try {
9922 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9923 if (configBinder == null) {
9924 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9925 } else {
9926 configBinder.setRcsClientConfiguration(rcc);
9927 }
9928 } catch (RemoteException e) {
9929 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9930 } finally {
9931 Binder.restoreCallingIdentity(identity);
9932 }
9933 }
9934
9935 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -08009936 * Enables or disables the test mode for RCS VoLTE single registration.
9937 */
9938 @Override
9939 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9941 "setRcsSingleRegistrationTestModeEnabled");
9942
9943 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9944 }
9945
9946 /**
9947 * Gets the test mode for RCS VoLTE single registration.
9948 */
9949 @Override
9950 public boolean getRcsSingleRegistrationTestModeEnabled() {
9951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9952 "getRcsSingleRegistrationTestModeEnabled");
9953
9954 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9955 }
9956
9957 /**
Hui Wang761a6682020-10-31 05:12:53 +00009958 * Overrides the config of RCS VoLTE single registration enabled for the device.
9959 */
9960 @Override
9961 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9962 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9963 "setDeviceSingleRegistrationEnabledOverride");
9964 enforceModifyPermission();
9965
9966 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9967 : Boolean.parseBoolean(enabledStr);
9968 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009969 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +00009970 }
9971
9972 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009973 * Sends a device to device communication message. Only usable via shell.
9974 * @param message message to send.
9975 * @param value message value.
9976 */
9977 @Override
9978 public void sendDeviceToDeviceMessage(int message, int value) {
9979 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -08009980 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -08009981 enforceModifyPermission();
9982
9983 final long identity = Binder.clearCallingIdentity();
9984 try {
9985 TelephonyConnectionService service =
9986 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9987 if (service == null) {
9988 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9989 return;
9990 }
9991 service.sendTestDeviceToDeviceMessage(message, value);
9992 } finally {
9993 Binder.restoreCallingIdentity(identity);
9994 }
9995 }
9996
Tyler Gunnbabbda02021-02-10 11:05:02 -08009997 /**
9998 * Sets the specified device to device transport active.
9999 * @param transport The transport to set active.
10000 */
10001 @Override
10002 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10003 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10004 "setActiveDeviceToDeviceTransport");
10005 enforceModifyPermission();
10006
10007 final long identity = Binder.clearCallingIdentity();
10008 try {
10009 TelephonyConnectionService service =
10010 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10011 if (service == null) {
10012 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10013 return;
10014 }
10015 service.setActiveDeviceToDeviceTransport(transport);
10016 } finally {
10017 Binder.restoreCallingIdentity(identity);
10018 }
10019 }
Tyler Gunn92479152021-01-20 16:30:10 -080010020
10021 /**
Hui Wang761a6682020-10-31 05:12:53 +000010022 * Gets the config of RCS VoLTE single registration enabled for the device.
10023 */
10024 @Override
10025 public boolean getDeviceSingleRegistrationEnabled() {
10026 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10027 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10028 }
10029
10030 /**
10031 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10032 */
10033 @Override
10034 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10035 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10036 "setCarrierSingleRegistrationEnabledOverride");
10037 enforceModifyPermission();
10038
10039 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10040 : Boolean.parseBoolean(enabledStr);
10041 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10042 subId, enabled);
10043 }
10044
10045 /**
10046 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10047 */
10048 @Override
10049 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10050 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10051 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10052 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010053
10054 /**
10055 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10056 * their mobile plan.
10057 */
10058 @Override
10059 public String getMobileProvisioningUrl() {
10060 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10061 final long identity = Binder.clearCallingIdentity();
10062 try {
10063 return getDefaultPhone().getMobileProvisioningUrl();
10064 } finally {
10065 Binder.restoreCallingIdentity(identity);
10066 }
10067 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010068
James.cf Linbcdf8b32021-01-14 16:44:13 +080010069 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010070 * Get the EAB contact from the EAB database.
10071 */
10072 @Override
10073 public String getContactFromEab(String contact) {
10074 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10075 enforceModifyPermission();
10076 final long identity = Binder.clearCallingIdentity();
10077 try {
10078 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10079 } finally {
10080 Binder.restoreCallingIdentity(identity);
10081 }
10082 }
10083
10084 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010085 * Remove the EAB contacts from the EAB database.
10086 */
10087 @Override
10088 public int removeContactFromEab(int subId, String contacts) {
10089 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10090 enforceModifyPermission();
10091 final long identity = Binder.clearCallingIdentity();
10092 try {
10093 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10094 } finally {
10095 Binder.restoreCallingIdentity(identity);
10096 }
10097 }
10098
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010099 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010100 public boolean getDeviceUceEnabled() {
10101 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10102 final long identity = Binder.clearCallingIdentity();
10103 try {
10104 return mApp.getDeviceUceEnabled();
10105 } finally {
10106 Binder.restoreCallingIdentity(identity);
10107 }
10108 }
10109
10110 @Override
10111 public void setDeviceUceEnabled(boolean isEnabled) {
10112 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10113 final long identity = Binder.clearCallingIdentity();
10114 try {
10115 mApp.setDeviceUceEnabled(isEnabled);
10116 } finally {
10117 Binder.restoreCallingIdentity(identity);
10118 }
10119 }
10120
10121 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010122 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10123 String callingPackage) {
10124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10125 mApp, subId, "setSignalStrengthUpdateRequest");
10126
10127 final int callingUid = Binder.getCallingUid();
10128 // Verify that tha callingPackage belongs to the calling UID
10129 mApp.getSystemService(AppOpsManager.class)
10130 .checkPackage(callingUid, callingPackage);
10131
10132 validateSignalStrengthUpdateRequest(request, callingUid);
10133
10134 final long identity = Binder.clearCallingIdentity();
10135 try {
10136 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10137 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10138
10139 if (result instanceof IllegalStateException) {
10140 throw (IllegalStateException) result;
10141 }
10142 } finally {
10143 Binder.restoreCallingIdentity(identity);
10144 }
10145 }
10146
10147 @Override
10148 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10149 String callingPackage) {
10150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10151 mApp, subId, "clearSignalStrengthUpdateRequest");
10152
10153 final int callingUid = Binder.getCallingUid();
10154 // Verify that tha callingPackage belongs to the calling UID
10155 mApp.getSystemService(AppOpsManager.class)
10156 .checkPackage(callingUid, callingPackage);
10157
10158 final long identity = Binder.clearCallingIdentity();
10159 try {
10160 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10161 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10162
10163 if (result instanceof IllegalStateException) {
10164 throw (IllegalStateException) result;
10165 }
10166 } finally {
10167 Binder.restoreCallingIdentity(identity);
10168 }
10169 }
10170
10171 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10172 int callingUid) {
10173 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10174 // phone/system process do not have further restriction on request
10175 return;
10176 }
10177
10178 // Applications has restrictions on how to use the request:
10179 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10180 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10181 // This is not system caller which has been checked above
10182 throw new IllegalArgumentException(
10183 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10184 }
10185
10186 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10187 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10188 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10189 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10190 || info.isEnabled()) {
10191 throw new IllegalArgumentException(
10192 "Only system can set hide fields in SignalThresholdInfo");
10193 }
10194
10195 // Thresholds length for each RAN need in range. This has been validated in
10196 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10197 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10198 final int[] thresholds = info.getThresholds();
10199 Objects.requireNonNull(thresholds);
10200 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10201 || thresholds.length
10202 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10203 throw new IllegalArgumentException(
10204 "thresholds length is out of range: " + thresholds.length);
10205 }
10206 }
10207 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010208
10209 /**
10210 * Gets the current phone capability.
10211 *
10212 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10213 * @return the PhoneCapability which describes the data connection capability of modem.
10214 * It's used to evaluate possible phone config change, for example from single
10215 * SIM device to multi-SIM device.
10216 */
10217 @Override
10218 public PhoneCapability getPhoneCapability() {
10219 enforceReadPrivilegedPermission("getPhoneCapability");
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
10222 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10223 } finally {
10224 Binder.restoreCallingIdentity(identity);
10225 }
10226 }
Michele Berionne5e411512020-11-13 02:36:59 +000010227
10228 /**
10229 * Prepare TelephonyManager for an unattended reboot. The reboot is
10230 * required to be done shortly after the API is invoked.
10231 */
10232 @Override
10233 @TelephonyManager.PrepareUnattendedRebootResult
10234 public int prepareForUnattendedReboot() {
10235 enforceRebootPermission();
10236
10237 final long identity = Binder.clearCallingIdentity();
10238 try {
10239 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10240 } finally {
10241 Binder.restoreCallingIdentity(identity);
10242 }
10243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010244}