blob: 5f475aa2445b49d69a26e9e327b6ee3c9da88214 [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
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700108import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700109import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800110import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800111import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700116import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800122import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800129import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700133import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700134import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800135import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800137import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700138import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700139import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700142import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800143import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700144import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700145import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700146import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700147import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700148import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700149import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700150import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700151import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800152import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800153import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700155import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800156import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700157import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800158import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700159import com.android.internal.telephony.imsphone.ImsPhone;
160import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800161import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800164import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700167import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800170import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000171import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800172import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700173import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700174import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800194import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800284 private static final int CMD_GET_CALL_FORWARDING = 83;
285 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
286 private static final int CMD_SET_CALL_FORWARDING = 85;
287 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
288 private static final int CMD_GET_CALL_WAITING = 87;
289 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
290 private static final int CMD_SET_CALL_WAITING = 89;
291 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700292 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
293 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
294 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
295 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700296 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
297 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800299 // Parameters of select command.
300 private static final int SELECT_COMMAND = 0xA4;
301 private static final int SELECT_P1 = 0x04;
302 private static final int SELECT_P2 = 0;
303 private static final int SELECT_P3 = 0x10;
304
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305 /** The singleton instance. */
306 private static PhoneInterfaceManager sInstance;
307
Wink Saville3ab207e2014-11-20 13:07:20 -0800308 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800310 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700311 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800312 private AppOpsManager mAppOps;
313 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800314 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800315 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700316 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317
Peter Wangdafb9ac2020-01-15 14:13:38 -0800318 /** User Activity */
319 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800320 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
321
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700322 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
323
Derek Tan97ebb422014-09-05 16:55:38 -0700324 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
325 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800326 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800327 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700328
Michelecea4cf22018-12-21 15:00:11 -0800329 // String to store multi SIM allowed
330 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
331
Derek Tan740e1672017-06-27 14:56:27 -0700332 // The AID of ISD-R.
333 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
334
yinxub1bed742017-04-17 11:45:04 -0700335 private NetworkScanRequestTracker mNetworkScanRequestTracker;
336
David Kelly5e06a7f2018-03-12 14:10:59 +0000337 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
338 private static final int MANUFACTURER_CODE_LENGTH = 8;
339
Derek Tan89e89d42014-07-08 17:00:10 -0700340 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700341 * Experiment flag to enable erase modem config on reset network, default value is false
342 */
343 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
344 "reset_network_erase_modem_config_enabled";
345
346 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700347 * A request object to use for transmitting data to an ICC.
348 */
349 private static final class IccAPDUArgument {
350 public int channel, cla, command, p1, p2, p3;
351 public String data;
352
353 public IccAPDUArgument(int channel, int cla, int command,
354 int p1, int p2, int p3, String data) {
355 this.channel = channel;
356 this.cla = cla;
357 this.command = command;
358 this.p1 = p1;
359 this.p2 = p2;
360 this.p3 = p3;
361 this.data = data;
362 }
363 }
364
365 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700366 * A request object to use for transmitting data to an ICC.
367 */
368 private static final class ManualNetworkSelectionArgument {
369 public OperatorInfo operatorInfo;
370 public boolean persistSelection;
371
372 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
373 this.operatorInfo = operatorInfo;
374 this.persistSelection = persistSelection;
375 }
376 }
377
378 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
380 * request after sending. The main thread will notify the request when it is complete.
381 */
382 private static final class MainThreadRequest {
383 /** The argument to use for the request */
384 public Object argument;
385 /** The result of the request that is run on the main thread */
386 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800387 // The subscriber id that this request applies to. Defaults to
388 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
389 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390
Nathan Harold92bed182018-10-12 18:16:49 -0700391 // In cases where subId is unavailable, the caller needs to specify the phone.
392 public Phone phone;
393
vagdeviaf9a5b92018-08-15 16:01:53 -0700394 public WorkSource workSource;
395
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 public MainThreadRequest(Object argument) {
397 this.argument = argument;
398 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800399
Nathan Harold92bed182018-10-12 18:16:49 -0700400 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
401 this.argument = argument;
402 if (phone != null) {
403 this.phone = phone;
404 }
405 this.workSource = workSource;
406 }
407
vagdeviaf9a5b92018-08-15 16:01:53 -0700408 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800409 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800410 if (subId != null) {
411 this.subId = subId;
412 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700413 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 }
416
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800417 private static final class IncomingThirdPartyCallArgs {
418 public final ComponentName component;
419 public final String callId;
420 public final String callerDisplayName;
421
422 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
423 String callerDisplayName) {
424 this.component = component;
425 this.callId = callId;
426 this.callerDisplayName = callerDisplayName;
427 }
428 }
429
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 /**
431 * A handler that processes messages on the main thread in the phone process. Since many
432 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
433 * inbound binder threads to the main thread in the phone process. The Binder thread
434 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
435 * on, which will be notified when the operation completes and will contain the result of the
436 * request.
437 *
438 * <p>If a MainThreadRequest object is provided in the msg.obj field,
439 * note that request.result must be set to something non-null for the calling thread to
440 * unblock.
441 */
442 private final class MainThreadHandler extends Handler {
443 @Override
444 public void handleMessage(Message msg) {
445 MainThreadRequest request;
446 Message onCompleted;
447 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800448 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800450 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451
452 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 case CMD_HANDLE_USSD_REQUEST: {
454 request = (MainThreadRequest) msg.obj;
455 final Phone phone = getPhoneFromRequest(request);
456 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
457 String ussdRequest = ussdObject.first;
458 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700459
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 if (!isUssdApiAllowed(request.subId)) {
461 // Carrier does not support use of this API, return failure.
462 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
463 UssdResponse response = new UssdResponse(ussdRequest, null);
464 Bundle returnData = new Bundle();
465 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
466 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700467
Pengquan Menga1bb6272018-09-06 09:59:22 -0700468 request.result = true;
469 notifyRequester(request);
470 return;
471 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700472
Pengquan Menga1bb6272018-09-06 09:59:22 -0700473 try {
474 request.result = phone != null
475 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
476 } catch (CallStateException cse) {
477 request.result = false;
478 }
479 // Wake up the requesting thread
480 notifyRequester(request);
481 break;
pkanwar32d516d2016-10-14 19:37:38 -0700482 }
483
Yorke Lee716f67e2015-06-17 15:39:16 -0700484 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700486 final Phone phone = getPhoneFromRequest(request);
487 request.result = phone != null ?
488 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
489 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700491 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700499 if (uiccCard == null) {
500 loge("iccTransmitApduLogicalChannel: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700503 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
505 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700506 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 iccArgument.channel, iccArgument.cla, iccArgument.command,
508 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700509 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700510 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700511 break;
512
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700514 ar = (AsyncResult) msg.obj;
515 request = (MainThreadRequest) ar.userObj;
516 if (ar.exception == null && ar.result != null) {
517 request.result = ar.result;
518 } else {
519 request.result = new IccIoResult(0x6F, 0, (byte[])null);
520 if (ar.result == null) {
521 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800522 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700523 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800524 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700525 } else {
526 loge("iccTransmitApduLogicalChannel: Unknown exception");
527 }
528 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 break;
531
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
533 request = (MainThreadRequest) msg.obj;
534 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800535 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 if (uiccCard == null) {
537 loge("iccTransmitApduBasicChannel: No UICC");
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 } else {
541 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
542 request);
543 uiccCard.iccTransmitApduBasicChannel(
544 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
545 iccArgument.p3, iccArgument.data, onCompleted);
546 }
547 break;
548
549 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
550 ar = (AsyncResult) msg.obj;
551 request = (MainThreadRequest) ar.userObj;
552 if (ar.exception == null && ar.result != null) {
553 request.result = ar.result;
554 } else {
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
556 if (ar.result == null) {
557 loge("iccTransmitApduBasicChannel: Empty response");
558 } else if (ar.exception instanceof CommandException) {
559 loge("iccTransmitApduBasicChannel: CommandException: " +
560 ar.exception);
561 } else {
562 loge("iccTransmitApduBasicChannel: Unknown exception");
563 }
564 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 break;
567
568 case CMD_EXCHANGE_SIM_IO:
569 request = (MainThreadRequest) msg.obj;
570 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800571 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 if (uiccCard == null) {
573 loge("iccExchangeSimIO: No UICC");
574 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700575 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 } else {
577 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
578 request);
579 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
580 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
581 iccArgument.data, onCompleted);
582 }
583 break;
584
585 case EVENT_EXCHANGE_SIM_IO_DONE:
586 ar = (AsyncResult) msg.obj;
587 request = (MainThreadRequest) ar.userObj;
588 if (ar.exception == null && ar.result != null) {
589 request.result = ar.result;
590 } else {
591 request.result = new IccIoResult(0x6f, 0, (byte[])null);
592 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 break;
595
Derek Tan4d5e5c12014-02-04 11:54:58 -0800596 case CMD_SEND_ENVELOPE:
597 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800598 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 if (uiccCard == null) {
600 loge("sendEnvelopeWithStatus: No UICC");
601 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700603 } else {
604 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
605 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
606 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800607 break;
608
609 case EVENT_SEND_ENVELOPE_DONE:
610 ar = (AsyncResult) msg.obj;
611 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700612 if (ar.exception == null && ar.result != null) {
613 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800614 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
616 if (ar.result == null) {
617 loge("sendEnvelopeWithStatus: Empty response");
618 } else if (ar.exception instanceof CommandException) {
619 loge("sendEnvelopeWithStatus: CommandException: " +
620 ar.exception);
621 } else {
622 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
623 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800624 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800626 break;
627
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 case CMD_OPEN_CHANNEL:
629 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800630 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800631 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 if (uiccCard == null) {
633 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800634 request.result = new IccOpenLogicalChannelResponse(-1,
635 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700637 } else {
638 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800639 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
640 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700641 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 break;
643
644 case EVENT_OPEN_CHANNEL_DONE:
645 ar = (AsyncResult) msg.obj;
646 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700649 int[] result = (int[]) ar.result;
650 int channelId = result[0];
651 byte[] selectResponse = null;
652 if (result.length > 1) {
653 selectResponse = new byte[result.length - 1];
654 for (int i = 1; i < result.length; ++i) {
655 selectResponse[i - 1] = (byte) result[i];
656 }
657 }
658 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700659 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 if (ar.result == null) {
662 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 if (ar.exception != null) {
665 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
666 }
667
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700668 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700669 if (ar.exception instanceof CommandException) {
670 CommandException.Error error =
671 ((CommandException) (ar.exception)).getCommandError();
672 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700673 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700674 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700675 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 }
677 }
678 openChannelResp = new IccOpenLogicalChannelResponse(
679 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700681 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700682 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 break;
684
685 case CMD_CLOSE_CHANNEL:
686 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800687 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700688 if (uiccCard == null) {
689 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900690 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 } else {
693 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
694 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
695 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 break;
697
698 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800699 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
700 break;
701
702 case CMD_NV_READ_ITEM:
703 request = (MainThreadRequest) msg.obj;
704 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800705 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
706 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800707 break;
708
709 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 ar = (AsyncResult) msg.obj;
711 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800712 if (ar.exception == null && ar.result != null) {
713 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800715 request.result = "";
716 if (ar.result == null) {
717 loge("nvReadItem: Empty response");
718 } else if (ar.exception instanceof CommandException) {
719 loge("nvReadItem: CommandException: " +
720 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800722 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700723 }
724 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700725 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700726 break;
727
Jake Hambye994d462014-02-03 13:10:13 -0800728 case CMD_NV_WRITE_ITEM:
729 request = (MainThreadRequest) msg.obj;
730 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
731 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800732 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700733 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800734 break;
735
736 case EVENT_NV_WRITE_ITEM_DONE:
737 handleNullReturnEvent(msg, "nvWriteItem");
738 break;
739
740 case CMD_NV_WRITE_CDMA_PRL:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800743 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800744 break;
745
746 case EVENT_NV_WRITE_CDMA_PRL_DONE:
747 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
748 break;
749
chen xu6dac5ab2018-10-26 17:39:23 -0700750 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800751 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700752 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800753 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800754 break;
755
chen xu6dac5ab2018-10-26 17:39:23 -0700756 case EVENT_RESET_MODEM_CONFIG_DONE:
757 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800758 break;
759
Sooraj Sasindran37444802020-08-11 10:40:43 -0700760 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
763 request);
764 Phone phone = getPhoneFromRequest(request);
765 if (phone != null) {
766 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
767 } else {
768 loge("isNRDualConnectivityEnabled: No phone object");
769 request.result = false;
770 notifyRequester(request);
771 }
772 break;
773 }
774
775 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
776 ar = (AsyncResult) msg.obj;
777 request = (MainThreadRequest) ar.userObj;
778 if (ar.exception == null && ar.result != null) {
779 request.result = ar.result;
780 } else {
781 // request.result must be set to something non-null
782 // for the calling thread to unblock
783 if (request.result != null) {
784 request.result = ar.result;
785 } else {
786 request.result = false;
787 }
788 if (ar.result == null) {
789 loge("isNRDualConnectivityEnabled: Empty response");
790 } else if (ar.exception instanceof CommandException) {
791 loge("isNRDualConnectivityEnabled: CommandException: "
792 + ar.exception);
793 } else {
794 loge("isNRDualConnectivityEnabled: Unknown exception");
795 }
796 }
797 notifyRequester(request);
798 break;
799
800 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
803 Phone phone = getPhoneFromRequest(request);
804 if (phone != null) {
805 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
806 request.workSource);
807 } else {
808 loge("enableNrDualConnectivity: No phone object");
809 request.result =
810 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
811 notifyRequester(request);
812 }
813 break;
814 }
815
816 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
817 ar = (AsyncResult) msg.obj;
818 request = (MainThreadRequest) ar.userObj;
819 if (ar.exception == null) {
820 request.result =
821 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
822 } else {
823 request.result =
824 TelephonyManager
825 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
826 if (ar.exception instanceof CommandException) {
827 CommandException.Error error =
828 ((CommandException) (ar.exception)).getCommandError();
829 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
830 request.result =
831 TelephonyManager
832 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
833 }
834 loge("enableNrDualConnectivity" + ": CommandException: "
835 + ar.exception);
836 } else {
837 loge("enableNrDualConnectivity" + ": Unknown exception");
838 }
839 }
840 notifyRequester(request);
841 break;
842 }
843
Jake Hamby7c27be32014-03-03 13:25:59 -0800844 case CMD_GET_PREFERRED_NETWORK_TYPE:
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700847 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800848 break;
849
850 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
853 if (ar.exception == null && ar.result != null) {
854 request.result = ar.result; // Integer
855 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530856 // request.result must be set to something non-null
857 // for the calling thread to unblock
858 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800859 if (ar.result == null) {
860 loge("getPreferredNetworkType: Empty response");
861 } else if (ar.exception instanceof CommandException) {
862 loge("getPreferredNetworkType: CommandException: " +
863 ar.exception);
864 } else {
865 loge("getPreferredNetworkType: Unknown exception");
866 }
867 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700868 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800869 break;
870
871 case CMD_SET_PREFERRED_NETWORK_TYPE:
872 request = (MainThreadRequest) msg.obj;
873 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
874 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700875 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800876 break;
877
878 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
879 handleNullReturnEvent(msg, "setPreferredNetworkType");
880 break;
881
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000882 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
883 request = (MainThreadRequest)msg.obj;
884 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800885 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000886 break;
887
888 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
889 ar = (AsyncResult)msg.obj;
890 request = (MainThreadRequest)ar.userObj;
891 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700892 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000893 break;
894
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800895 case CMD_SET_VOICEMAIL_NUMBER:
896 request = (MainThreadRequest) msg.obj;
897 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
898 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800899 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
900 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800901 break;
902
903 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
904 handleNullReturnEvent(msg, "setVoicemailNumber");
905 break;
906
Stuart Scott54788802015-03-30 13:18:01 -0700907 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
908 request = (MainThreadRequest) msg.obj;
909 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
910 request);
911 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
912 break;
913
914 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
915 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
916 break;
917
Shishir Agrawal302c8692015-06-19 13:49:39 -0700918 case CMD_PERFORM_NETWORK_SCAN:
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
921 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
922 break;
923
Hall Liu27d24262020-09-18 19:04:59 -0700924 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800925 request = (MainThreadRequest) msg.obj;
926 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700927 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
928 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
929 request.argument;
930 int callForwardingReason = args.first;
931 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800932 break;
Hall Liu27d24262020-09-18 19:04:59 -0700933 }
934 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700937 TelephonyManager.CallForwardingInfoCallback callback =
938 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
939 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800940 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700941 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800942 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
943 for (CallForwardInfo callForwardInfo : callForwardInfos) {
944 // Service Class is a bit mask per 3gpp 27.007. Search for
945 // any service for voice call.
946 if ((callForwardInfo.serviceClass
947 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700948 callForwardingInfo = new CallForwardingInfo(true,
949 callForwardInfo.reason,
950 callForwardInfo.number,
951 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800952 break;
953 }
954 }
955 // Didn't find a call forward info for voice call.
956 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700957 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
958 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800959 }
Hall Liu27d24262020-09-18 19:04:59 -0700960 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800961 } else {
962 if (ar.result == null) {
963 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
964 }
965 if (ar.exception != null) {
966 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
967 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700968 int errorCode = TelephonyManager
969 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800970 if (ar.exception instanceof CommandException) {
971 CommandException.Error error =
972 ((CommandException) (ar.exception)).getCommandError();
973 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700974 errorCode = TelephonyManager
975 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800976 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700977 errorCode = TelephonyManager
978 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800979 }
980 }
Hall Liu27d24262020-09-18 19:04:59 -0700981 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -0800982 }
Shuo Qian4a594052020-01-23 11:59:30 -0800983 break;
Hall Liu27d24262020-09-18 19:04:59 -0700984 }
Shuo Qian4a594052020-01-23 11:59:30 -0800985
Hall Liu27d24262020-09-18 19:04:59 -0700986 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700989 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -0800990 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -0700991 ((Pair<CallForwardingInfo, Consumer<Integer>>)
992 request.argument).first;
993 request.phone.setCallForwardingOption(
994 callForwardingInfoToSet.isEnabled()
995 ? CommandsInterface.CF_ACTION_ENABLE
996 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -0800997 callForwardingInfoToSet.getReason(),
998 callForwardingInfoToSet.getNumber(),
999 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1000 break;
Hall Liu27d24262020-09-18 19:04:59 -07001001 }
Shuo Qian4a594052020-01-23 11:59:30 -08001002
Hall Liu27d24262020-09-18 19:04:59 -07001003 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001004 ar = (AsyncResult) msg.obj;
1005 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001006 Consumer<Integer> callback =
1007 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1008 request.argument).second;
1009 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001010 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001011 int errorCode = TelephonyManager.CallForwardingInfoCallback
1012 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001013 if (ar.exception instanceof CommandException) {
1014 CommandException.Error error =
1015 ((CommandException) (ar.exception)).getCommandError();
1016 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001017 errorCode = TelephonyManager.CallForwardingInfoCallback
1018 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001019 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001020 errorCode = TelephonyManager.CallForwardingInfoCallback
1021 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001022 }
1023 }
1024 callback.accept(errorCode);
1025 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001026 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001027 }
Shuo Qian4a594052020-01-23 11:59:30 -08001028 break;
Hall Liu27d24262020-09-18 19:04:59 -07001029 }
Shuo Qian4a594052020-01-23 11:59:30 -08001030
Hall Liu27d24262020-09-18 19:04:59 -07001031 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001032 request = (MainThreadRequest) msg.obj;
1033 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1034 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1035 break;
Hall Liu27d24262020-09-18 19:04:59 -07001036 }
Shuo Qian4a594052020-01-23 11:59:30 -08001037
Hall Liu27d24262020-09-18 19:04:59 -07001038 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001041 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001042 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1043 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001044 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001045 // Service Class is a bit mask per 3gpp 27.007.
1046 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001047 if (callForwardResults.length > 1
1048 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001049 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001050 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001051 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1052 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001053 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001054 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001055 }
1056 } else {
1057 if (ar.result == null) {
1058 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1059 }
1060 if (ar.exception != null) {
1061 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1062 }
1063 if (ar.exception instanceof CommandException) {
1064 CommandException.Error error =
1065 ((CommandException) (ar.exception)).getCommandError();
1066 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1067 callForwardingStatus =
1068 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1069 }
1070 }
1071 }
Hall Liu27d24262020-09-18 19:04:59 -07001072 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001073 break;
Hall Liu27d24262020-09-18 19:04:59 -07001074 }
Shuo Qian4a594052020-01-23 11:59:30 -08001075
Hall Liu27d24262020-09-18 19:04:59 -07001076 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001077 request = (MainThreadRequest) msg.obj;
1078 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001079 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1080 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001081 break;
Hall Liu27d24262020-09-18 19:04:59 -07001082 }
Shuo Qian4a594052020-01-23 11:59:30 -08001083
Hall Liu27d24262020-09-18 19:04:59 -07001084 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001085 ar = (AsyncResult) msg.obj;
1086 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001087 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1088 Consumer<Integer> callback =
1089 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1090 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001091 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001092 if (ar.exception instanceof CommandException) {
1093 CommandException.Error error =
1094 ((CommandException) (ar.exception)).getCommandError();
1095 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1096 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1097 } else {
1098 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1099 }
1100 } else {
1101 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1102 }
1103 } else {
1104 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1105 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001106 }
Shuo Qian4a594052020-01-23 11:59:30 -08001107 break;
Hall Liu27d24262020-09-18 19:04:59 -07001108 }
Shuo Qian4a594052020-01-23 11:59:30 -08001109
Shishir Agrawal302c8692015-06-19 13:49:39 -07001110 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1111 ar = (AsyncResult) msg.obj;
1112 request = (MainThreadRequest) ar.userObj;
1113 CellNetworkScanResult cellScanResult;
1114 if (ar.exception == null && ar.result != null) {
1115 cellScanResult = new CellNetworkScanResult(
1116 CellNetworkScanResult.STATUS_SUCCESS,
1117 (List<OperatorInfo>) ar.result);
1118 } else {
1119 if (ar.result == null) {
1120 loge("getCellNetworkScanResults: Empty response");
1121 }
1122 if (ar.exception != null) {
1123 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1124 }
1125 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1126 if (ar.exception instanceof CommandException) {
1127 CommandException.Error error =
1128 ((CommandException) (ar.exception)).getCommandError();
1129 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1130 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1131 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1132 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1133 }
1134 }
1135 cellScanResult = new CellNetworkScanResult(errorCode, null);
1136 }
1137 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001138 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001139 break;
1140
1141 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1142 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001143 ManualNetworkSelectionArgument selArg =
1144 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001145 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1146 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001147 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1148 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001149 break;
1150
1151 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001152 ar = (AsyncResult) msg.obj;
1153 request = (MainThreadRequest) ar.userObj;
1154 if (ar.exception == null) {
1155 request.result = true;
1156 } else {
1157 request.result = false;
1158 loge("setNetworkSelectionModeManual " + ar.exception);
1159 }
1160 notifyRequester(request);
1161 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001162 break;
1163
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001164 case CMD_GET_MODEM_ACTIVITY_INFO:
1165 request = (MainThreadRequest) msg.obj;
1166 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001167 if (defaultPhone != null) {
1168 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001169 } else {
1170 ResultReceiver result = (ResultReceiver) request.argument;
1171 Bundle bundle = new Bundle();
1172 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001173 new ModemActivityInfo(0, 0, 0,
1174 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001175 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001176 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001177 break;
1178
Hall Liud0f208c2020-10-14 16:54:44 -07001179 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001180 ar = (AsyncResult) msg.obj;
1181 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001182 ResultReceiver result = (ResultReceiver) request.argument;
1183
Hall Liud0f208c2020-10-14 16:54:44 -07001184 ModemActivityInfo ret = null;
1185 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001186 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001187 // Update the last modem activity info and the result of the request.
1188 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1189 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001190 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001191 int[] txTimeMs = info.getTransmitTimeMillis();
1192 int[] lastModemTxTimeMs = mLastModemActivityInfo
1193 .getTransmitTimeMillis();
1194 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1195 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1196 }
Hall Liu49656c02020-10-09 19:00:11 -07001197 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001198 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1199 + mLastModemActivityInfo.getSleepTimeMillis());
1200 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1201 + mLastModemActivityInfo.getIdleTimeMillis());
1202 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1203 mLastModemActivityInfo.setReceiveTimeMillis(
1204 info.getReceiveTimeMillis()
1205 + mLastModemActivityInfo.getReceiveTimeMillis());
1206 }
Hall Liu49656c02020-10-09 19:00:11 -07001207 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001208 mLastModemActivityInfo.getSleepTimeMillis(),
1209 mLastModemActivityInfo.getIdleTimeMillis(),
1210 mLastModemActivityInfo.getTransmitTimeMillis(),
1211 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001212 } else {
1213 if (ar.result == null) {
1214 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001215 error = TelephonyManager.ModemActivityInfoException
1216 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001217 } else if (ar.exception instanceof CommandException) {
1218 loge("queryModemActivityInfo: CommandException: " +
1219 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001220 error = TelephonyManager.ModemActivityInfoException
1221 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001222 } else {
1223 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001224 error = TelephonyManager.ModemActivityInfoException
1225 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001226 }
1227 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001228 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001229 if (ret != null) {
1230 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1231 } else {
1232 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1233 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001234 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001235 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001236 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001237 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001238
Meng Wang1a7c35a2016-05-05 20:56:15 -07001239 case CMD_SET_ALLOWED_CARRIERS:
1240 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001241 CarrierRestrictionRules argument =
1242 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001243 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001244 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001245 break;
1246
1247 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1248 ar = (AsyncResult) msg.obj;
1249 request = (MainThreadRequest) ar.userObj;
1250 if (ar.exception == null && ar.result != null) {
1251 request.result = ar.result;
1252 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001253 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1254 if (ar.exception instanceof CommandException) {
1255 loge("setAllowedCarriers: CommandException: " + ar.exception);
1256 CommandException.Error error =
1257 ((CommandException) (ar.exception)).getCommandError();
1258 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1259 request.result =
1260 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1261 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001262 } else {
1263 loge("setAllowedCarriers: Unknown exception");
1264 }
1265 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001266 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001267 break;
1268
1269 case CMD_GET_ALLOWED_CARRIERS:
1270 request = (MainThreadRequest) msg.obj;
1271 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001272 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001273 break;
1274
1275 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1276 ar = (AsyncResult) msg.obj;
1277 request = (MainThreadRequest) ar.userObj;
1278 if (ar.exception == null && ar.result != null) {
1279 request.result = ar.result;
1280 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001281 request.result = new IllegalStateException(
1282 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001283 if (ar.result == null) {
1284 loge("getAllowedCarriers: Empty response");
1285 } else if (ar.exception instanceof CommandException) {
1286 loge("getAllowedCarriers: CommandException: " +
1287 ar.exception);
1288 } else {
1289 loge("getAllowedCarriers: Unknown exception");
1290 }
1291 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001292 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001293 break;
1294
Nathan Haroldb3014052017-01-25 15:57:32 -08001295 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1296 ar = (AsyncResult) msg.obj;
1297 request = (MainThreadRequest) ar.userObj;
1298 if (ar.exception == null && ar.result != null) {
1299 request.result = ar.result;
1300 } else {
1301 request.result = new IllegalArgumentException(
1302 "Failed to retrieve Forbidden Plmns");
1303 if (ar.result == null) {
1304 loge("getForbiddenPlmns: Empty response");
1305 } else {
1306 loge("getForbiddenPlmns: Unknown exception");
1307 }
1308 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001309 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001310 break;
1311
1312 case CMD_GET_FORBIDDEN_PLMNS:
1313 request = (MainThreadRequest) msg.obj;
1314 uiccCard = getUiccCardFromRequest(request);
1315 if (uiccCard == null) {
1316 loge("getForbiddenPlmns() UiccCard is null");
1317 request.result = new IllegalArgumentException(
1318 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001319 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001320 break;
1321 }
1322 Integer appType = (Integer) request.argument;
1323 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1324 if (uiccApp == null) {
1325 loge("getForbiddenPlmns() no app with specified type -- "
1326 + appType);
1327 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001328 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001329 break;
1330 } else {
1331 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1332 + " specified type -- " + appType);
1333 }
1334 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1335 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1336 onCompleted);
1337 break;
1338
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001339 case CMD_SWITCH_SLOTS:
1340 request = (MainThreadRequest) msg.obj;
1341 int[] physicalSlots = (int[]) request.argument;
1342 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1343 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1344 break;
1345
1346 case EVENT_SWITCH_SLOTS_DONE:
1347 ar = (AsyncResult) msg.obj;
1348 request = (MainThreadRequest) ar.userObj;
1349 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001350 notifyRequester(request);
1351 break;
1352 case CMD_GET_NETWORK_SELECTION_MODE:
1353 request = (MainThreadRequest) msg.obj;
1354 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1355 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1356 break;
1357
1358 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1359 ar = (AsyncResult) msg.obj;
1360 request = (MainThreadRequest) ar.userObj;
1361 if (ar.exception != null) {
1362 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1363 } else {
1364 int mode = ((int[]) ar.result)[0];
1365 if (mode == 0) {
1366 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1367 } else {
1368 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1369 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001370 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001371 notifyRequester(request);
1372 break;
1373 case CMD_GET_CDMA_ROAMING_MODE:
1374 request = (MainThreadRequest) msg.obj;
1375 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1376 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1377 break;
1378 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1379 ar = (AsyncResult) msg.obj;
1380 request = (MainThreadRequest) ar.userObj;
1381 if (ar.exception != null) {
1382 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1383 } else {
1384 request.result = ((int[]) ar.result)[0];
1385 }
1386 notifyRequester(request);
1387 break;
1388 case CMD_SET_CDMA_ROAMING_MODE:
1389 request = (MainThreadRequest) msg.obj;
1390 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1391 int mode = (int) request.argument;
1392 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1393 break;
1394 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1395 ar = (AsyncResult) msg.obj;
1396 request = (MainThreadRequest) ar.userObj;
1397 request.result = ar.exception == null;
1398 notifyRequester(request);
1399 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001400 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1401 request = (MainThreadRequest) msg.obj;
1402 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1403 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1404 break;
1405 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1406 ar = (AsyncResult) msg.obj;
1407 request = (MainThreadRequest) ar.userObj;
1408 if (ar.exception != null) {
1409 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1410 } else {
1411 request.result = ((int[]) ar.result)[0];
1412 }
1413 notifyRequester(request);
1414 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001415 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1416 request = (MainThreadRequest) msg.obj;
1417 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1418 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001419 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1420 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001421 break;
1422 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1423 ar = (AsyncResult) msg.obj;
1424 request = (MainThreadRequest) ar.userObj;
1425 request.result = ar.exception == null;
1426 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001427 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001428 case CMD_GET_ALL_CELL_INFO:
1429 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001430 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001431 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001432 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001433 case EVENT_GET_ALL_CELL_INFO_DONE:
1434 ar = (AsyncResult) msg.obj;
1435 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001436 // If a timeout occurs, the response will be null
1437 request.result = (ar.exception == null && ar.result != null)
1438 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001439 synchronized (request) {
1440 request.notifyAll();
1441 }
1442 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001443 case CMD_REQUEST_CELL_INFO_UPDATE:
1444 request = (MainThreadRequest) msg.obj;
1445 request.phone.requestCellInfoUpdate(request.workSource,
1446 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1447 break;
1448 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1452 try {
1453 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001454 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001455 cb.onError(
1456 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1457 ar.exception.getClass().getName(),
1458 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001459 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001460 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001461 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001462 } else {
1463 // use the result as returned
1464 cb.onCellInfo((List<CellInfo>) ar.result);
1465 }
1466 } catch (RemoteException re) {
1467 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1468 }
1469 break;
1470 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001471 request = (MainThreadRequest) msg.obj;
1472 WorkSource ws = (WorkSource) request.argument;
1473 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001474 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001475 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001476 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001477 ar = (AsyncResult) msg.obj;
1478 request = (MainThreadRequest) ar.userObj;
1479 if (ar.exception == null) {
1480 request.result = ar.result;
1481 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001482 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001483 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001484 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001485 }
1486
1487 synchronized (request) {
1488 request.notifyAll();
1489 }
1490 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001491 case CMD_MODEM_REBOOT:
1492 request = (MainThreadRequest) msg.obj;
1493 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001494 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001495 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001496 case EVENT_CMD_MODEM_REBOOT_DONE:
1497 handleNullReturnEvent(msg, "rebootModem");
1498 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001499 case CMD_REQUEST_ENABLE_MODEM:
1500 request = (MainThreadRequest) msg.obj;
1501 boolean enable = (boolean) request.argument;
1502 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001503 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001504 PhoneConfigurationManager.getInstance()
1505 .enablePhone(request.phone, enable, onCompleted);
1506 break;
1507 case EVENT_ENABLE_MODEM_DONE:
1508 ar = (AsyncResult) msg.obj;
1509 request = (MainThreadRequest) ar.userObj;
1510 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001511 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001512 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001513 if ((boolean) request.result) {
1514 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1515 updateModemStateMetrics();
1516 } else {
1517 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1518 + ar.exception);
1519 }
1520 notifyRequester(request);
1521 break;
1522 case CMD_GET_MODEM_STATUS:
1523 request = (MainThreadRequest) msg.obj;
1524 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1525 PhoneConfigurationManager.getInstance()
1526 .getPhoneStatusFromModem(request.phone, onCompleted);
1527 break;
1528 case EVENT_GET_MODEM_STATUS_DONE:
1529 ar = (AsyncResult) msg.obj;
1530 request = (MainThreadRequest) ar.userObj;
1531 int id = request.phone.getPhoneId();
1532 if (ar.exception == null && ar.result != null) {
1533 request.result = ar.result;
1534 //update the cache as modem status has changed
1535 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1536 (boolean) request.result);
1537 } else {
1538 // Return true if modem status cannot be retrieved. For most cases,
1539 // modem status is on. And for older version modems, GET_MODEM_STATUS
1540 // and disable modem are not supported. Modem is always on.
1541 // TODO: this should be fixed in R to support a third
1542 // status UNKNOWN b/131631629
1543 request.result = true;
1544 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1545 + ar.exception);
1546 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001547 notifyRequester(request);
1548 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001549 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1550 request = (MainThreadRequest) msg.obj;
1551 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1552 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1553 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1554 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1555 break;
1556 }
1557 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
1560 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1561 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1562 args.second.accept(ar.exception == null);
1563 notifyRequester(request);
1564 break;
1565 }
yincheng zhao2737e882019-09-06 17:06:54 -07001566 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1567 ar = (AsyncResult) msg.obj;
1568 request = (MainThreadRequest) ar.userObj;
1569 if (ar.exception == null && ar.result != null) {
1570 request.result = ar.result;
1571 } else {
1572 request.result = -1;
1573 loge("Failed to set Forbidden Plmns");
1574 if (ar.result == null) {
1575 loge("setForbidenPlmns: Empty response");
1576 } else if (ar.exception != null) {
1577 loge("setForbiddenPlmns: Exception: " + ar.exception);
1578 request.result = -1;
1579 } else {
1580 loge("setForbiddenPlmns: Unknown exception");
1581 }
1582 }
1583 notifyRequester(request);
1584 break;
1585 case CMD_SET_FORBIDDEN_PLMNS:
1586 request = (MainThreadRequest) msg.obj;
1587 uiccCard = getUiccCardFromRequest(request);
1588 if (uiccCard == null) {
1589 loge("setForbiddenPlmns: UiccCard is null");
1590 request.result = -1;
1591 notifyRequester(request);
1592 break;
1593 }
1594 Pair<Integer, List<String>> setFplmnsArgs =
1595 (Pair<Integer, List<String>>) request.argument;
1596 appType = setFplmnsArgs.first;
1597 List<String> fplmns = setFplmnsArgs.second;
1598 uiccApp = uiccCard.getApplicationByType(appType);
1599 if (uiccApp == null) {
1600 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1601 request.result = -1;
1602 loge("Failed to get UICC App");
1603 notifyRequester(request);
1604 } else {
1605 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1606 ((SIMRecords) uiccApp.getIccRecords())
1607 .setForbiddenPlmns(onCompleted, fplmns);
1608 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001609 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001610 case CMD_ERASE_MODEM_CONFIG:
1611 request = (MainThreadRequest) msg.obj;
1612 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1613 defaultPhone.eraseModemConfig(onCompleted);
1614 break;
1615 case EVENT_ERASE_MODEM_CONFIG_DONE:
1616 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001617 break;
zoey chene02881a2019-12-30 16:11:23 +08001618
1619 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1622 Pair<String, String> changed = (Pair<String, String>) request.argument;
1623 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1624 changed.first, changed.second, onCompleted);
1625 break;
1626 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1627 ar = (AsyncResult) msg.obj;
1628 request = (MainThreadRequest) ar.userObj;
1629 if (ar.exception == null) {
1630 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1631 } else {
1632 request.result = msg.arg1;
1633 }
1634 notifyRequester(request);
1635 break;
1636
1637 case CMD_SET_ICC_LOCK_ENABLED:
1638 request = (MainThreadRequest) msg.obj;
1639 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1640 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1641 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1642 enabled.first, enabled.second, onCompleted);
1643 break;
1644 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1645 ar = (AsyncResult) msg.obj;
1646 request = (MainThreadRequest) ar.userObj;
1647 if (ar.exception == null) {
1648 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1649 } else {
1650 request.result = msg.arg1;
1651 }
1652 notifyRequester(request);
1653 break;
1654
Peter Wangdafb9ac2020-01-15 14:13:38 -08001655 case MSG_NOTIFY_USER_ACTIVITY:
1656 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001657 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001658 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1659 getDefaultPhone().getContext().sendBroadcastAsUser(
1660 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1661 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 default:
1663 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1664 break;
1665 }
1666 }
Jake Hambye994d462014-02-03 13:10:13 -08001667
Pengquan Menga1bb6272018-09-06 09:59:22 -07001668 private void notifyRequester(MainThreadRequest request) {
1669 synchronized (request) {
1670 request.notifyAll();
1671 }
1672 }
1673
Jake Hambye994d462014-02-03 13:10:13 -08001674 private void handleNullReturnEvent(Message msg, String command) {
1675 AsyncResult ar = (AsyncResult) msg.obj;
1676 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1677 if (ar.exception == null) {
1678 request.result = true;
1679 } else {
1680 request.result = false;
1681 if (ar.exception instanceof CommandException) {
1682 loge(command + ": CommandException: " + ar.exception);
1683 } else {
1684 loge(command + ": Unknown exception");
1685 }
1686 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001687 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 }
1690
1691 /**
1692 * Posts the specified command to be executed on the main thread,
1693 * waits for the request to complete, and returns the result.
1694 * @see #sendRequestAsync
1695 */
1696 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001697 return sendRequest(
1698 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001699 }
1700
1701 /**
1702 * Posts the specified command to be executed on the main thread,
1703 * waits for the request to complete, and returns the result.
1704 * @see #sendRequestAsync
1705 */
1706 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1707 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001708 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001709 }
1710
1711 /**
1712 * Posts the specified command to be executed on the main thread,
1713 * waits for the request to complete, and returns the result.
1714 * @see #sendRequestAsync
1715 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001716 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001717 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001718 }
1719
1720 /**
1721 * Posts the specified command to be executed on the main thread,
1722 * waits for the request to complete, and returns the result.
1723 * @see #sendRequestAsync
1724 */
Nathan Harold92bed182018-10-12 18:16:49 -07001725 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1726 return sendRequest(command, argument, subId, null, workSource);
1727 }
1728
1729 /**
1730 * Posts the specified command to be executed on the main thread,
1731 * waits for the request to complete, and returns the result.
1732 * @see #sendRequestAsync
1733 */
1734 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1735 return sendRequest(
1736 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1737 }
1738
1739 /**
1740 * Posts the specified command to be executed on the main thread,
1741 * waits for the request to complete, and returns the result.
1742 * @see #sendRequestAsync
1743 */
1744 private Object sendRequest(
1745 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1747 throw new RuntimeException("This method will deadlock if called from the main thread.");
1748 }
1749
Nathan Harold92bed182018-10-12 18:16:49 -07001750 MainThreadRequest request = null;
1751 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1752 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1753 } else if (phone != null) {
1754 request = new MainThreadRequest(argument, phone, workSource);
1755 } else {
1756 request = new MainThreadRequest(argument, subId, workSource);
1757 }
1758
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 Message msg = mMainThreadHandler.obtainMessage(command, request);
1760 msg.sendToTarget();
1761
1762 // Wait for the request to complete
1763 synchronized (request) {
1764 while (request.result == null) {
1765 try {
1766 request.wait();
1767 } catch (InterruptedException e) {
1768 // Do nothing, go back and wait until the request is complete
1769 }
1770 }
1771 }
1772 return request.result;
1773 }
1774
1775 /**
1776 * Asynchronous ("fire and forget") version of sendRequest():
1777 * Posts the specified command to be executed on the main thread, and
1778 * returns immediately.
1779 * @see #sendRequest
1780 */
1781 private void sendRequestAsync(int command) {
1782 mMainThreadHandler.sendEmptyMessage(command);
1783 }
1784
1785 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001786 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001787 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001788 */
1789 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001790 sendRequestAsync(command, argument, null, null);
1791 }
1792
1793 /**
1794 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1795 * @see {@link #sendRequest(int,Object)}
1796 */
1797 private void sendRequestAsync(
1798 int command, Object argument, Phone phone, WorkSource workSource) {
1799 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001800 Message msg = mMainThreadHandler.obtainMessage(command, request);
1801 msg.sendToTarget();
1802 }
1803
1804 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 * Initialize the singleton PhoneInterfaceManager instance.
1806 * This is only done once, at startup, from PhoneApp.onCreate().
1807 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001808 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 synchronized (PhoneInterfaceManager.class) {
1810 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001811 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 } else {
1813 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1814 }
1815 return sInstance;
1816 }
1817 }
1818
1819 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001820 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001823 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001824 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1826 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001827 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001828 mTelephonySharedPreferences =
1829 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001830 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001831 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001832 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001833
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 publish();
1835 }
1836
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001837 private Phone getDefaultPhone() {
1838 Phone thePhone = getPhone(getDefaultSubscription());
1839 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1840 }
1841
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 private void publish() {
1843 if (DBG) log("publish: " + this);
1844
Peter Wangc035ce42020-01-08 21:00:22 -08001845 TelephonyFrameworkInitializer
1846 .getTelephonyServiceManager()
1847 .getTelephonyServiceRegisterer()
1848 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 }
1850
Stuart Scott584921c2015-01-15 17:10:34 -08001851 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001852 if (request.phone != null) {
1853 return request.phone;
1854 } else {
1855 return getPhoneFromSubId(request.subId);
1856 }
1857 }
1858
1859 private Phone getPhoneFromSubId(int subId) {
1860 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1861 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001862 }
1863
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001864 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1865 Phone phone = getPhoneFromRequest(request);
1866 return phone == null ? null :
1867 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1868 }
1869
Wink Saville36469e72014-06-11 15:17:00 -07001870 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001871 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001872 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874
Naina Nallurid63128d2019-09-17 14:10:30 -07001875 private void sendEraseModemConfig(Phone phone) {
1876 if (phone != null) {
1877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1878 mApp, phone.getSubId(), "eraseModemConfig");
1879 final long identity = Binder.clearCallingIdentity();
1880 try {
1881 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1882 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1883 } finally {
1884 Binder.restoreCallingIdentity(identity);
1885 }
1886 }
1887 }
1888
Peter Wang44b186e2020-01-13 23:33:09 -08001889 private boolean isImsAvailableOnDevice() {
1890 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1891 if (pm == null) {
1892 // For some reason package manger is not available.. This will fail internally anyway,
1893 // so do not throw error and allow.
1894 return true;
1895 }
1896 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1897 }
1898
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001900 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001901 }
1902
Wink Savilleb564aae2014-10-23 10:18:09 -07001903 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 if (DBG) log("dial: " + number);
1905 // No permission check needed here: This is just a wrapper around the
1906 // ACTION_DIAL intent, which is available to any app since it puts up
1907 // the UI before it does anything.
1908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001909 final long identity = Binder.clearCallingIdentity();
1910 try {
1911 String url = createTelUrl(number);
1912 if (url == null) {
1913 return;
1914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001916 // PENDING: should we just silently fail if phone is offhook or ringing?
1917 PhoneConstants.State state = mCM.getState(subId);
1918 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1919 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1920 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1921 mApp.startActivity(intent);
1922 }
1923 } finally {
1924 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926 }
1927
1928 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001929 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001930 }
1931
Wink Savilleb564aae2014-10-23 10:18:09 -07001932 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 if (DBG) log("call: " + number);
1934
1935 // This is just a wrapper around the ACTION_CALL intent, but we still
1936 // need to do a permission check since we're calling startActivity()
1937 // from the context of the phone app.
1938 enforceCallPermission();
1939
Jordan Liu1617b712019-07-10 15:06:26 -07001940 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 != AppOpsManager.MODE_ALLOWED) {
1942 return;
1943 }
1944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945 final long identity = Binder.clearCallingIdentity();
1946 try {
1947 String url = createTelUrl(number);
1948 if (url == null) {
1949 return;
1950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001952 boolean isValid = false;
1953 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1954 if (slist != null) {
1955 for (SubscriptionInfo subInfoRecord : slist) {
1956 if (subInfoRecord.getSubscriptionId() == subId) {
1957 isValid = true;
1958 break;
1959 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001960 }
Wink Saville08874612014-08-31 19:19:58 -07001961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001962 if (!isValid) {
1963 return;
1964 }
Wink Saville08874612014-08-31 19:19:58 -07001965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1967 intent.putExtra(SUBSCRIPTION_KEY, subId);
1968 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1969 mApp.startActivity(intent);
1970 } finally {
1971 Binder.restoreCallingIdentity(identity);
1972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 }
1974
Wink Savilleb564aae2014-10-23 10:18:09 -07001975 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001976 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001977 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1978 }
1979
Wink Savilleb564aae2014-10-23 10:18:09 -07001980 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001981 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001982 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1983 }
1984
Wink Savilleb564aae2014-10-23 10:18:09 -07001985 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001986 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987
1988 final long identity = Binder.clearCallingIdentity();
1989 try {
1990 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1991 checkSimPin.start();
1992 return checkSimPin.unlockSim(null, pin);
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
1995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997
Wink Savilleb564aae2014-10-23 10:18:09 -07001998 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000
2001 final long identity = Binder.clearCallingIdentity();
2002 try {
2003 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2004 checkSimPuk.start();
2005 return checkSimPuk.unlockSim(puk, pin);
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
2008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
2011 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002012 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 * a synchronous one.
2014 */
2015 private static class UnlockSim extends Thread {
2016
2017 private final IccCard mSimCard;
2018
2019 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002020 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2021 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002022
2023 // For replies from SimCard interface
2024 private Handler mHandler;
2025
2026 // For async handler to identify request type
2027 private static final int SUPPLY_PIN_COMPLETE = 100;
2028
2029 public UnlockSim(IccCard simCard) {
2030 mSimCard = simCard;
2031 }
2032
2033 @Override
2034 public void run() {
2035 Looper.prepare();
2036 synchronized (UnlockSim.this) {
2037 mHandler = new Handler() {
2038 @Override
2039 public void handleMessage(Message msg) {
2040 AsyncResult ar = (AsyncResult) msg.obj;
2041 switch (msg.what) {
2042 case SUPPLY_PIN_COMPLETE:
2043 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2044 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002045 mRetryCount = msg.arg1;
2046 if (ar.exception != null) {
2047 if (ar.exception instanceof CommandException &&
2048 ((CommandException)(ar.exception)).getCommandError()
2049 == CommandException.Error.PASSWORD_INCORRECT) {
2050 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002051 } //When UiccCardApp dispose,handle message and return exception
2052 else if (ar.exception instanceof CommandException &&
2053 ((CommandException) (ar.exception)).getCommandError()
2054 == CommandException.Error.ABORTED) {
2055 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002056 } else {
2057 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2058 }
2059 } else {
2060 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062 mDone = true;
2063 UnlockSim.this.notifyAll();
2064 }
2065 break;
2066 }
2067 }
2068 };
2069 UnlockSim.this.notifyAll();
2070 }
2071 Looper.loop();
2072 }
2073
2074 /*
2075 * Use PIN or PUK to unlock SIM card
2076 *
2077 * If PUK is null, unlock SIM card with PIN
2078 *
2079 * If PUK is not null, unlock SIM card with PUK and set PIN code
2080 */
Wink Saville9de0f752013-10-22 19:04:03 -07002081 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082
2083 while (mHandler == null) {
2084 try {
2085 wait();
2086 } catch (InterruptedException e) {
2087 Thread.currentThread().interrupt();
2088 }
2089 }
2090 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2091
2092 if (puk == null) {
2093 mSimCard.supplyPin(pin, callback);
2094 } else {
2095 mSimCard.supplyPuk(puk, pin, callback);
2096 }
2097
2098 while (!mDone) {
2099 try {
2100 Log.d(LOG_TAG, "wait for done");
2101 wait();
2102 } catch (InterruptedException e) {
2103 // Restore the interrupted status
2104 Thread.currentThread().interrupt();
2105 }
2106 }
2107 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002108 int[] resultArray = new int[2];
2109 resultArray[0] = mResult;
2110 resultArray[1] = mRetryCount;
2111 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113 }
2114
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002115 /**
2116 * This method has been removed due to privacy and stability concerns.
2117 */
2118 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002120 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2121 return;
Wink Saville36469e72014-06-11 15:17:00 -07002122 }
2123
Nathan Harold1f889d82020-06-04 17:05:26 -07002124 @Override
2125 public void updateServiceLocationWithPackageName(String callingPackage) {
2126 mApp.getSystemService(AppOpsManager.class)
2127 .checkPackage(Binder.getCallingUid(), callingPackage);
2128
2129 final int targetSdk = getTargetSdk(callingPackage);
2130 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2131 // Callers targeting S have no business invoking this method.
2132 return;
2133 }
2134
2135 LocationAccessPolicy.LocationPermissionResult locationResult =
2136 LocationAccessPolicy.checkLocationPermission(mApp,
2137 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2138 .setCallingPackage(callingPackage)
2139 .setCallingFeatureId(null)
2140 .setCallingPid(Binder.getCallingPid())
2141 .setCallingUid(Binder.getCallingUid())
2142 .setMethod("updateServiceLocation")
2143 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2144 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2145 .build());
2146 // Apps that lack location permission have no business calling this method;
2147 // however, because no permission was declared in the public API, denials must
2148 // all be "soft".
2149 switch (locationResult) {
2150 case DENIED_HARD: /* fall through */
2151 case DENIED_SOFT:
2152 return;
2153 }
2154
2155 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 final long identity = Binder.clearCallingIdentity();
2157 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002158 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002159 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002160 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002161 }
2162 } finally {
2163 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002167 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002168 @Override
2169 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002170 return isRadioOnWithFeature(callingPackage, null);
2171 }
2172
2173
2174 @Override
2175 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2176 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2177 callingFeatureId);
2178 }
2179
2180 @Deprecated
2181 @Override
2182 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2183 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002184 }
2185
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002186 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002187 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2188 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002190 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002191 return false;
2192 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002193
2194 final long identity = Binder.clearCallingIdentity();
2195 try {
2196 return isRadioOnForSubscriber(subId);
2197 } finally {
2198 Binder.restoreCallingIdentity(identity);
2199 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002200 }
2201
2202 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002203 final long identity = Binder.clearCallingIdentity();
2204 try {
2205 final Phone phone = getPhone(subId);
2206 if (phone != null) {
2207 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2208 } else {
2209 return false;
2210 }
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 }
2215
2216 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002217 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
Wink Saville36469e72014-06-11 15:17:00 -07002219
Wink Savilleb564aae2014-10-23 10:18:09 -07002220 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222
2223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 final Phone phone = getPhone(subId);
2226 if (phone != null) {
2227 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2228 }
2229 } finally {
2230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002231 }
Wink Saville36469e72014-06-11 15:17:00 -07002232 }
2233
2234 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002235 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002236 }
2237
Wink Savilleb564aae2014-10-23 10:18:09 -07002238 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002239 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240
2241 final long identity = Binder.clearCallingIdentity();
2242 try {
2243 final Phone phone = getPhone(subId);
2244 if (phone == null) {
2245 return false;
2246 }
2247 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2248 toggleRadioOnOffForSubscriber(subId);
2249 }
2250 return true;
2251 } finally {
2252 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 }
Wink Saville36469e72014-06-11 15:17:00 -07002255
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002256 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002257 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002258 /*
2259 * If any of the Radios are available, it will need to be
2260 * shutdown. So return true if any Radio is available.
2261 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262 final long identity = Binder.clearCallingIdentity();
2263 try {
2264 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2265 Phone phone = PhoneFactory.getPhone(i);
2266 if (phone != null && phone.isRadioAvailable()) return true;
2267 }
2268 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2269 return false;
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002272 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002273 }
2274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002276 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277 enforceModifyPermission();
2278
2279 final long identity = Binder.clearCallingIdentity();
2280 try {
2281 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2282 logv("Shutting down Phone " + i);
2283 shutdownRadioUsingPhoneId(i);
2284 }
2285 } finally {
2286 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002287 }
2288 }
2289
2290 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002291 Phone phone = PhoneFactory.getPhone(phoneId);
2292 if (phone != null && phone.isRadioAvailable()) {
2293 phone.shutdownRadio();
2294 }
2295 }
2296
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002298 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002299
2300 final long identity = Binder.clearCallingIdentity();
2301 try {
2302 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2303 if (defaultPhone != null) {
2304 defaultPhone.setRadioPower(turnOn);
2305 return true;
2306 } else {
2307 loge("There's no default phone.");
2308 return false;
2309 }
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002312 }
Wink Saville36469e72014-06-11 15:17:00 -07002313 }
2314
Wink Savilleb564aae2014-10-23 10:18:09 -07002315 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002317
2318 final long identity = Binder.clearCallingIdentity();
2319 try {
2320 final Phone phone = getPhone(subId);
2321 if (phone != null) {
2322 phone.setRadioPower(turnOn);
2323 return true;
2324 } else {
2325 return false;
2326 }
2327 } finally {
2328 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 }
2331
Wink Saville36469e72014-06-11 15:17:00 -07002332 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002333 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 public boolean enableDataConnectivity() {
2335 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002336
2337 final long identity = Binder.clearCallingIdentity();
2338 try {
2339 int subId = mSubscriptionController.getDefaultDataSubId();
2340 final Phone phone = getPhone(subId);
2341 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002342 phone.getDataEnabledSettings().setDataEnabled(
2343 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344 return true;
2345 } else {
2346 return false;
2347 }
2348 } finally {
2349 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 }
2352
Wink Saville36469e72014-06-11 15:17:00 -07002353 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002354 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 public boolean disableDataConnectivity() {
2356 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002357
2358 final long identity = Binder.clearCallingIdentity();
2359 try {
2360 int subId = mSubscriptionController.getDefaultDataSubId();
2361 final Phone phone = getPhone(subId);
2362 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002363 phone.getDataEnabledSettings().setDataEnabled(
2364 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002365 return true;
2366 } else {
2367 return false;
2368 }
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
Sanket Padawe356d7632015-06-22 14:03:32 -07002374 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002375 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376 final long identity = Binder.clearCallingIdentity();
2377 try {
2378 final Phone phone = getPhone(subId);
2379 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002380 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002381 } else {
2382 return false;
2383 }
2384 } finally {
2385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 }
2388
2389 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002390 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002391 }
2392
pkanwarae03a6b2016-11-06 20:37:09 -08002393 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002394 enforceCallPermission();
2395
2396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2399 return;
2400 }
2401 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2402 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
2405 }
pkanwar32d516d2016-10-14 19:37:38 -07002406 };
2407
Wink Savilleb564aae2014-10-23 10:18:09 -07002408 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002410
2411 final long identity = Binder.clearCallingIdentity();
2412 try {
2413 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2414 return false;
2415 }
2416 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2417 } finally {
2418 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 }
2421
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002423 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002424 }
2425
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002426 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 Phone phone = PhoneFactory.getPhone(slotIndex);
2430 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2431 PhoneConstantConversions.convertCallState(phone.getState());
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
2434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
2436
Sanket Padawe356d7632015-06-22 14:03:32 -07002437 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002438 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002439 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2440 }
2441
2442 @Override
2443 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002444 final long identity = Binder.clearCallingIdentity();
2445 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002446 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447 if (phone != null) {
2448 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2449 } else {
2450 return PhoneConstantConversions.convertDataState(
2451 PhoneConstants.DataState.DISCONNECTED);
2452 }
2453 } finally {
2454 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 }
2457
Sanket Padawe356d7632015-06-22 14:03:32 -07002458 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002459 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002460 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2461 }
2462
2463 @Override
2464 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465 final long identity = Binder.clearCallingIdentity();
2466 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002467 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468 if (phone != null) {
2469 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2470 } else {
2471 return TelephonyManager.DATA_ACTIVITY_NONE;
2472 }
2473 } finally {
2474 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 }
2477
2478 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002479 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002480 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002481 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002482
2483 LocationAccessPolicy.LocationPermissionResult locationResult =
2484 LocationAccessPolicy.checkLocationPermission(mApp,
2485 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2486 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002487 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002488 .setCallingPid(Binder.getCallingPid())
2489 .setCallingUid(Binder.getCallingUid())
2490 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002491 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002492 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2493 .build());
2494 switch (locationResult) {
2495 case DENIED_HARD:
2496 throw new SecurityException("Not allowed to access cell location");
2497 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002498 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2499 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002502 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002506 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002507 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 } finally {
2509 Binder.restoreCallingIdentity(identity);
2510 }
Svetoslav64fad262015-04-14 14:35:21 -07002511 }
2512
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002514 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002515 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2516 // registered cell info, so return a NULL country instead.
2517 final long identity = Binder.clearCallingIdentity();
2518 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002519 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2520 // Get default phone in this case.
2521 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2522 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002523 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002525 if (phone == null) return "";
2526 ServiceStateTracker sst = phone.getServiceStateTracker();
2527 if (sst == null) return "";
2528 LocaleTracker lt = sst.getLocaleTracker();
2529 if (lt == null) return "";
2530 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2531 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2532 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002533 } finally {
2534 Binder.restoreCallingIdentity(identity);
2535 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002536 }
2537
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002538 /**
2539 * This method was removed due to potential issues caused by performing partial
2540 * updates of service state, and lack of a credible use case.
2541 *
2542 * This has the ability to break the telephony implementation by disabling notification of
2543 * changes in device connectivity. DO NOT USE THIS!
2544 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002545 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 public void enableLocationUpdates() {
2547 mApp.enforceCallingOrSelfPermission(
2548 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002549 }
2550
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002551 /**
2552 * This method was removed due to potential issues caused by performing partial
2553 * updates of service state, and lack of a credible use case.
2554 *
2555 * This has the ability to break the telephony implementation by disabling notification of
2556 * changes in device connectivity. DO NOT USE THIS!
2557 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 @Override
2559 public void disableLocationUpdates() {
2560 mApp.enforceCallingOrSelfPermission(
2561 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 }
2563
Nathan Harold31d7ff32018-10-15 20:20:30 -07002564 /**
2565 * Returns the target SDK version number for a given package name.
2566 *
Nathan Haroldec184742019-07-10 17:04:16 -07002567 * This call MUST be invoked before clearing the calling UID.
2568 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002569 * @return target SDK if the package is found or INT_MAX.
2570 */
2571 private int getTargetSdk(String packageName) {
2572 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002573 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002574 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002575 if (ai != null) return ai.targetSdkVersion;
2576 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002577 loge("Failed to get package info for pkg="
2578 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002579 }
2580 return Integer.MAX_VALUE;
2581 }
2582
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 @Override
2584 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002585 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2586 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002587 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002588 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2589 throw new SecurityException(
2590 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2591 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002592
Jordan Liu1617b712019-07-10 15:06:26 -07002593 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2595 return null;
2596 }
Svetoslav64fad262015-04-14 14:35:21 -07002597
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002598 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002600 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002601 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602
Nathan Haroldf180aac2018-06-01 18:43:55 -07002603 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2604 for (CellInfo ci : info) {
2605 if (ci instanceof CellInfoGsm) {
2606 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2607 } else if (ci instanceof CellInfoWcdma) {
2608 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002611 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612 }
2613
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002614 private List<CellInfo> getCachedCellInfo() {
2615 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2616 for (Phone phone : PhoneFactory.getPhones()) {
2617 List<CellInfo> info = phone.getAllCellInfo();
2618 if (info != null) cellInfos.addAll(info);
2619 }
2620 return cellInfos;
2621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622
2623 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002624 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002625 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002626 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002627
2628 LocationAccessPolicy.LocationPermissionResult locationResult =
2629 LocationAccessPolicy.checkLocationPermission(mApp,
2630 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2631 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002632 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002633 .setCallingPid(Binder.getCallingPid())
2634 .setCallingUid(Binder.getCallingUid())
2635 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002636 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002637 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2638 .build());
2639 switch (locationResult) {
2640 case DENIED_HARD:
2641 throw new SecurityException("Not allowed to access cell info");
2642 case DENIED_SOFT:
2643 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 }
2645
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002646 final int targetSdk = getTargetSdk(callingPackage);
2647 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2648 return getCachedCellInfo();
2649 }
2650
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002651 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002652 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2656 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002657 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002658 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 if (info != null) cellInfos.addAll(info);
2660 }
2661 return cellInfos;
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 }
2665 }
2666
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002667 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002668 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2669 String callingFeatureId) {
2670 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2671 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002672 }
2673
2674 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002675 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2676 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002677 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002678 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002679 }
2680
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002681 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2682 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002683 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002684 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002685
2686 LocationAccessPolicy.LocationPermissionResult locationResult =
2687 LocationAccessPolicy.checkLocationPermission(mApp,
2688 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2689 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002690 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002691 .setCallingPid(Binder.getCallingPid())
2692 .setCallingUid(Binder.getCallingUid())
2693 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002694 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2695 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002696 .build());
2697 switch (locationResult) {
2698 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002699 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2700 // Safetynet logging for b/154934934
2701 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2702 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002703 throw new SecurityException("Not allowed to access cell info");
2704 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002705 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2706 // Safetynet logging for b/154934934
2707 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2708 }
Nathan Harold5320c422019-05-09 10:26:08 -07002709 try {
2710 cb.onCellInfo(new ArrayList<CellInfo>());
2711 } catch (RemoteException re) {
2712 // Drop without consequences
2713 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002714 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002715 }
2716
Nathan Harolda939a962019-05-09 10:13:47 -07002717
2718 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002719 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2720
2721 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2722 }
2723
2724 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002726 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002727 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002728
2729 final long identity = Binder.clearCallingIdentity();
2730 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002731 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 } finally {
2733 Binder.restoreCallingIdentity(identity);
2734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 }
2736
Shishir Agrawala9f32182016-04-12 12:00:16 -07002737 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002738 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002739 Phone phone = PhoneFactory.getPhone(slotIndex);
2740 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002741 return null;
2742 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002743 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002744 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002745 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002746 return null;
2747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002748
2749 final long identity = Binder.clearCallingIdentity();
2750 try {
2751 return phone.getImei();
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
2754 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002755 }
2756
2757 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002758 public String getTypeAllocationCodeForSlot(int slotIndex) {
2759 Phone phone = PhoneFactory.getPhone(slotIndex);
2760 String tac = null;
2761 if (phone != null) {
2762 String imei = phone.getImei();
2763 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2764 }
2765 return tac;
2766 }
2767
2768 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002769 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002770 Phone phone = PhoneFactory.getPhone(slotIndex);
2771 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002772 return null;
2773 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002774
Jeff Davidson913390f2018-02-23 17:11:49 -08002775 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002776 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002777 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002778 return null;
2779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780
2781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 return phone.getMeid();
2784 } finally {
2785 Binder.restoreCallingIdentity(identity);
2786 }
Jack Yu2af8d712017-03-15 17:14:14 -07002787 }
2788
2789 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002790 public String getManufacturerCodeForSlot(int slotIndex) {
2791 Phone phone = PhoneFactory.getPhone(slotIndex);
2792 String manufacturerCode = null;
2793 if (phone != null) {
2794 String meid = phone.getMeid();
2795 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2796 }
2797 return manufacturerCode;
2798 }
2799
2800 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002801 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2802 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002803 Phone phone = PhoneFactory.getPhone(slotIndex);
2804 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002805 return null;
2806 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002807 int subId = phone.getSubId();
2808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002809 mApp, subId, callingPackage, callingFeatureId,
2810 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002811 return null;
2812 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813
2814 final long identity = Binder.clearCallingIdentity();
2815 try {
2816 return phone.getDeviceSvn();
2817 } finally {
2818 Binder.restoreCallingIdentity(identity);
2819 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002820 }
2821
fionaxu43304da2017-11-27 22:51:16 -08002822 @Override
2823 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 final Phone phone = getPhone(subId);
2827 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
2830 }
fionaxu43304da2017-11-27 22:51:16 -08002831 }
2832
2833 @Override
2834 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 final Phone phone = getPhone(subId);
2838 return phone == null ? null : phone.getCarrierName();
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
2841 }
fionaxu43304da2017-11-27 22:51:16 -08002842 }
2843
calvinpanffe225e2018-11-01 19:43:06 +08002844 @Override
chen xu0026ca62019-03-06 15:28:50 -08002845 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 final Phone phone = getPhone(subId);
2849 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002850 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002851 } finally {
2852 Binder.restoreCallingIdentity(identity);
2853 }
2854 }
2855
2856 @Override
chen xu0026ca62019-03-06 15:28:50 -08002857 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002861 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002862 } finally {
2863 Binder.restoreCallingIdentity(identity);
2864 }
2865 }
2866
chen xu651eec72018-11-11 19:03:44 -08002867 @Override
chen xu864e11c2018-12-06 22:10:03 -08002868 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2869 if (!isSubscriptionMccMnc) {
2870 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2871 }
chen xu651eec72018-11-11 19:03:44 -08002872 final Phone phone = PhoneFactory.getPhone(slotIndex);
2873 if (phone == null) {
2874 return TelephonyManager.UNKNOWN_CARRIER_ID;
2875 }
2876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
2881 }
2882 }
2883
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 //
2885 // Internal helper methods.
2886 //
2887
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002888 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002889 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2890 *
2891 * @throws SecurityException if the caller does not have the required permission
2892 */
2893 private void enforceModifyPermission() {
2894 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2895 }
2896
Shuo Qiancd19c462020-01-16 20:51:11 -08002897 /**
2898 * Make sure the caller is system.
2899 *
2900 * @throws SecurityException if the caller is not system.
2901 */
2902 private void enforceSystemCaller() {
2903 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2904 throw new SecurityException("Caller must be system");
2905 }
2906 }
2907
Shuo Qian3b6ee772019-11-13 17:43:31 -08002908 private void enforceActiveEmergencySessionPermission() {
2909 mApp.enforceCallingOrSelfPermission(
2910 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2911 }
2912
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 /**
2914 * Make sure the caller has the CALL_PHONE permission.
2915 *
2916 * @throws SecurityException if the caller does not have the required permission
2917 */
2918 private void enforceCallPermission() {
2919 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2920 }
2921
paulhu5a773602019-08-23 19:17:33 +08002922 private void enforceSettingsPermission() {
2923 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002924 }
2925
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 private String createTelUrl(String number) {
2927 if (TextUtils.isEmpty(number)) {
2928 return null;
2929 }
2930
Jake Hambye994d462014-02-03 13:10:13 -08002931 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 }
2933
Ihab Awadf9e92732013-12-05 18:02:52 -08002934 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002935 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2936 }
2937
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002938 private static void logv(String msg) {
2939 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2940 }
2941
Ihab Awadf9e92732013-12-05 18:02:52 -08002942 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002943 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2944 }
2945
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002946 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002948 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002949 }
2950
Sanket Padawe356d7632015-06-22 14:03:32 -07002951 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002952 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 final Phone phone = PhoneFactory.getPhone(slotIndex);
2956 if (phone == null) {
2957 return PhoneConstants.PHONE_TYPE_NONE;
2958 } else {
2959 return phone.getPhoneType();
2960 }
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964 }
2965
2966 /**
2967 * Returns the CDMA ERI icon index to display
2968 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002969 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002970 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2971 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2972 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002973 }
2974
Sanket Padawe356d7632015-06-22 14:03:32 -07002975 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002976 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2977 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002979 mApp, subId, callingPackage, callingFeatureId,
2980 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002981 return -1;
2982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 final Phone phone = getPhone(subId);
2987 if (phone != null) {
2988 return phone.getCdmaEriIconIndex();
2989 } else {
2990 return -1;
2991 }
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002995 }
2996
2997 /**
2998 * Returns the CDMA ERI icon mode,
2999 * 0 - ON
3000 * 1 - FLASHING
3001 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003002 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003003 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3004 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3005 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003006 }
3007
Sanket Padawe356d7632015-06-22 14:03:32 -07003008 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003009 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3010 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003012 mApp, subId, callingPackage, callingFeatureId,
3013 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003014 return -1;
3015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 final Phone phone = getPhone(subId);
3020 if (phone != null) {
3021 return phone.getCdmaEriIconMode();
3022 } else {
3023 return -1;
3024 }
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003028 }
3029
3030 /**
3031 * Returns the CDMA ERI text,
3032 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003033 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003034 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3035 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3036 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003037 }
3038
Sanket Padawe356d7632015-06-22 14:03:32 -07003039 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003040 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3041 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003043 mApp, subId, callingPackage, callingFeatureId,
3044 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003045 return null;
3046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047
3048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 final Phone phone = getPhone(subId);
3051 if (phone != null) {
3052 return phone.getCdmaEriText();
3053 } else {
3054 return null;
3055 }
3056 } finally {
3057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 }
3060
3061 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003062 * Returns the CDMA MDN.
3063 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003064 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003065 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3067 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003068
3069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003072 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073 return phone.getLine1Number();
3074 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003075 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003076 return null;
3077 }
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003080 }
3081 }
3082
3083 /**
3084 * Returns the CDMA MIN.
3085 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003086 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003087 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3089 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003090
3091 final long identity = Binder.clearCallingIdentity();
3092 try {
3093 final Phone phone = getPhone(subId);
3094 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3095 return phone.getCdmaMin();
3096 } else {
3097 return null;
3098 }
3099 } finally {
3100 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003101 }
3102 }
3103
Hall Liud892bec2018-11-30 14:51:45 -08003104 @Override
3105 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3106 INumberVerificationCallback callback, String callingPackage) {
3107 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3108 != PERMISSION_GRANTED) {
3109 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3110 }
3111 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3112
3113 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3114 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3115 throw new SecurityException("Calling package must be configured in the device config");
3116 }
3117
3118 if (range == null) {
3119 throw new NullPointerException("Range must be non-null");
3120 }
3121
3122 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003123 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003124
3125 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3126 }
3127
Junda Liuca05d5d2014-08-14 22:36:34 -07003128 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 * Returns true if CDMA provisioning needs to run.
3130 */
3131 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 final long identity = Binder.clearCallingIdentity();
3133 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003134 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 } finally {
3136 Binder.restoreCallingIdentity(identity);
3137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003138 }
3139
3140 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003141 * Sets the voice mail number of a given subId.
3142 */
3143 @Override
3144 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003145 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3146 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147
3148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3151 new Pair<String, String>(alphaTag, number), new Integer(subId));
3152 return success;
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003156 }
3157
Ta-wei Yen87c49842016-05-13 21:19:52 -07003158 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003159 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3160 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003161 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3162 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003163 if (!TextUtils.equals(callingPackage, systemDialer)) {
3164 throw new SecurityException("caller must be system dialer");
3165 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166
3167 final long identity = Binder.clearCallingIdentity();
3168 try {
3169 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3170 if (phoneAccountHandle == null) {
3171 return null;
3172 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003173 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174 } finally {
3175 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003176 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003177 }
3178
3179 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003180 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3181 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003183 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003184 mApp, subId, callingPackage, callingFeatureId,
3185 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003186 return null;
3187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003189 final long identity = Binder.clearCallingIdentity();
3190 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003191 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003195 }
3196
3197 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003198 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3199 VisualVoicemailSmsFilterSettings settings) {
3200 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201
3202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003205 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 } finally {
3207 Binder.restoreCallingIdentity(identity);
3208 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003209 }
3210
3211 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003212 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3213 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003218 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003222 }
3223
3224 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003225 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3226 String callingPackage, int subId) {
3227 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228
3229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003232 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003236 }
3237
3238 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003239 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241
3242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003245 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246 } finally {
3247 Binder.restoreCallingIdentity(identity);
3248 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003249 }
3250
3251 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003252 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3253 String callingAttributionTag, int subId, String number, int port, String text,
3254 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003255 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003256 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003257 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003258 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003259 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3260 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003261 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003262
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003263 /**
fionaxu0152e512016-11-14 13:36:14 -08003264 * Sets the voice activation state of a given subId.
3265 */
3266 @Override
3267 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3269 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270
3271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 final Phone phone = getPhone(subId);
3274 if (phone != null) {
3275 phone.setVoiceActivationState(activationState);
3276 } else {
3277 loge("setVoiceActivationState fails with invalid subId: " + subId);
3278 }
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003281 }
3282 }
3283
3284 /**
3285 * Sets the data activation state of a given subId.
3286 */
3287 @Override
3288 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3290 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003291
3292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 final Phone phone = getPhone(subId);
3295 if (phone != null) {
3296 phone.setDataActivationState(activationState);
3297 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003298 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003299 }
3300 } finally {
3301 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003302 }
3303 }
3304
3305 /**
3306 * Returns the voice activation state of a given subId.
3307 */
3308 @Override
3309 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003310 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311
fionaxu0152e512016-11-14 13:36:14 -08003312 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 if (phone != null) {
3316 return phone.getVoiceActivationState();
3317 } else {
3318 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3319 }
3320 } finally {
3321 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003322 }
3323 }
3324
3325 /**
3326 * Returns the data activation state of a given subId.
3327 */
3328 @Override
3329 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003330 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331
fionaxu0152e512016-11-14 13:36:14 -08003332 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 if (phone != null) {
3336 return phone.getDataActivationState();
3337 } else {
3338 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3339 }
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003342 }
3343 }
3344
3345 /**
Wink Saville36469e72014-06-11 15:17:00 -07003346 * Returns the unread count of voicemails for a subId
3347 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003348 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003349 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3350 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003352 mApp, subId, callingPackage, callingFeatureId,
3353 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003354 return 0;
3355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 final Phone phone = getPhone(subId);
3359 if (phone != null) {
3360 return phone.getVoiceMessageCount();
3361 } else {
3362 return 0;
3363 }
3364 } finally {
3365 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003367 }
3368
3369 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003370 * returns true, if the device is in a state where both voice and data
3371 * are supported simultaneously. This can change based on location or network condition.
3372 */
3373 @Override
3374 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003375 final long identity = Binder.clearCallingIdentity();
3376 try {
3377 final Phone phone = getPhone(subId);
3378 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3379 } finally {
3380 Binder.restoreCallingIdentity(identity);
3381 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003382 }
3383
3384 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003385 * Send the dialer code if called from the current default dialer or the caller has
3386 * carrier privilege.
3387 * @param inputCode The dialer code to send
3388 */
3389 @Override
3390 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003391 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003393 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3394 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003395 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003396 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003397 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003398 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399
3400 final long identity = Binder.clearCallingIdentity();
3401 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003402 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
fionaxu235cc5e2017-03-06 22:25:57 -08003406 }
3407
Pengquan Menga1bb6272018-09-06 09:59:22 -07003408 @Override
3409 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003410 TelephonyPermissions
3411 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3412 mApp, subId, "getNetworkSelectionMode");
3413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 if (!isActiveSubscription(subId)) {
3416 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3417 }
3418 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3419 } finally {
3420 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003421 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003422 }
3423
Brad Ebinger35c841c2018-10-01 10:40:55 -07003424 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003425 public boolean isInEmergencySmsMode() {
3426 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 for (Phone phone : PhoneFactory.getPhones()) {
3430 if (phone.isInEmergencySmsMode()) {
3431 return true;
3432 }
3433 }
3434 } finally {
3435 Binder.restoreCallingIdentity(identity);
3436 }
3437 return false;
3438 }
3439
shilu366312e2019-12-17 09:28:10 -08003440 /**
3441 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3442 * @param subId The subscription to use to check the configuration.
3443 * @param c The callback that will be used to send the result.
3444 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003445 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003446 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3447 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003448 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3449 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003450
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003451 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3452 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3453 "IMS not available on device.");
3454 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003455 final long token = Binder.clearCallingIdentity();
3456 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003457 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003458 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003459 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003460 } catch (ImsException e) {
3461 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 } finally {
3463 Binder.restoreCallingIdentity(token);
3464 }
3465 }
3466
shilu366312e2019-12-17 09:28:10 -08003467 /**
3468 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3469 * @param subId The subscription to use to check the configuration.
3470 * @param c The callback that will be used to send the result.
3471 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003472 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003473 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003474 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3475 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003476 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3477 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3478 }
Meng Wangafbc5852019-09-19 17:37:13 -07003479 final long token = Binder.clearCallingIdentity();
3480 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003481 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003482 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3483 .removeRegistrationCallbackForSubscription(c, subId);
3484 } catch (ImsException e) {
3485 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3486 + "is inactive, ignoring unregister.");
3487 // If the subscription is no longer active, just return, since the callback
3488 // will already have been removed internally.
3489 } finally {
3490 Binder.restoreCallingIdentity(token);
3491 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003492 }
3493
Brad Ebingera34a6c22019-10-22 17:36:18 -07003494 /**
3495 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3496 */
3497 @Override
3498 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3499 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3500 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3501 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3502 "IMS not available on device.");
3503 }
3504 final long token = Binder.clearCallingIdentity();
3505 try {
3506 Phone phone = getPhone(subId);
3507 if (phone == null) {
3508 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3509 + subId + "'");
3510 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3511 }
3512 phone.getImsRegistrationState(regState -> {
3513 try {
3514 consumer.accept((regState == null)
3515 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3516 } catch (RemoteException e) {
3517 // Ignore if the remote process is no longer available to call back.
3518 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3519 }
3520 });
3521 } finally {
3522 Binder.restoreCallingIdentity(token);
3523 }
3524 }
3525
3526 /**
3527 * Get the transport type for the IMS service registration state.
3528 */
3529 @Override
3530 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003531 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3532 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003533 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3534 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3535 "IMS not available on device.");
3536 }
3537 final long token = Binder.clearCallingIdentity();
3538 try {
3539 Phone phone = getPhone(subId);
3540 if (phone == null) {
3541 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3542 + subId + "'");
3543 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3544 }
3545 phone.getImsRegistrationTech(regTech -> {
3546 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3547 int regTechConverted = (regTech == null)
3548 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3549 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3550 regTechConverted);
3551 try {
3552 consumer.accept(regTechConverted);
3553 } catch (RemoteException e) {
3554 // Ignore if the remote process is no longer available to call back.
3555 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3556 }
3557 });
3558 } finally {
3559 Binder.restoreCallingIdentity(token);
3560 }
3561 }
3562
shilu366312e2019-12-17 09:28:10 -08003563 /**
3564 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3565 * @param subId The subscription to use to check the configuration.
3566 * @param c The callback that will be used to send the result.
3567 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003569 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3570 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003571 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3572 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003573 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3574 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3575 "IMS not available on device.");
3576 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003577 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3578 final long token = Binder.clearCallingIdentity();
3579 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003580 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003581 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003582 } catch (ImsException e) {
3583 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 } finally {
3585 Binder.restoreCallingIdentity(token);
3586 }
3587 }
3588
shilu366312e2019-12-17 09:28:10 -08003589 /**
3590 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3591 * @param subId The subscription to use to check the configuration.
3592 * @param c The callback that will be used to send the result.
3593 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003594 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003595 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003596 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3597 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003598 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3599 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3600 }
Meng Wangafbc5852019-09-19 17:37:13 -07003601
3602 final long token = Binder.clearCallingIdentity();
3603 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003604 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003605 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003606 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003607 } catch (ImsException e) {
3608 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3609 + "is inactive, ignoring unregister.");
3610 // If the subscription is no longer active, just return, since the callback
3611 // will already have been removed internally.
3612 } finally {
3613 Binder.restoreCallingIdentity(token);
3614 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003615 }
3616
3617 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003618 public boolean isCapable(int subId, int capability, int regTech) {
3619 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3621 final long token = Binder.clearCallingIdentity();
3622 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003623 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003624 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003625 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003626 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3627 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003628 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003629 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3630 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003631 } finally {
3632 Binder.restoreCallingIdentity(token);
3633 }
3634 }
3635
3636 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003637 public boolean isAvailable(int subId, int capability, int regTech) {
3638 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 final long token = Binder.clearCallingIdentity();
3640 try {
3641 Phone phone = getPhone(subId);
3642 if (phone == null) return false;
3643 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003644 } catch (com.android.ims.ImsException e) {
3645 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3646 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003647 } finally {
3648 Binder.restoreCallingIdentity(token);
3649 }
3650 }
3651
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003652 /**
3653 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3654 * subscription.
3655 * @param subId The subscription to use to check the configuration.
3656 * @param callback The callback that will be used to send the result.
3657 * @param capability The MmTelFeature capability that will be used to send the result.
3658 * @param transportType The transport type of the MmTelFeature capability.
3659 */
3660 @Override
3661 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3662 int transportType) {
3663 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3664 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3665 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3666 "IMS not available on device.");
3667 }
3668 final long token = Binder.clearCallingIdentity();
3669 try {
3670 int slotId = getSlotIndex(subId);
3671 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3672 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3673 + subId + "'");
3674 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3675 }
3676 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3677 transportType, aBoolean -> {
3678 try {
3679 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3680 } catch (RemoteException e) {
3681 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3682 + "running. Ignore");
3683 }
3684 });
3685 } finally {
3686 Binder.restoreCallingIdentity(token);
3687 }
3688 }
3689
shilu366312e2019-12-17 09:28:10 -08003690 /**
3691 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3692 * @param subId The subscription to use to check the configuration.
3693 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003694 @Override
3695 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003696 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3697 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003698
Brad Ebinger35c841c2018-10-01 10:40:55 -07003699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3700 final long token = Binder.clearCallingIdentity();
3701 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003702 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003703 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003704 } catch (ImsException e) {
3705 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003706 } finally {
3707 Binder.restoreCallingIdentity(token);
3708 }
3709 }
3710
3711 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003712 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003714 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003715 final long identity = Binder.clearCallingIdentity();
3716 try {
3717 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003718 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003719 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003720 } catch (ImsException e) {
3721 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003722 } finally {
3723 Binder.restoreCallingIdentity(identity);
3724 }
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 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003732 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003733 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3734 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003738 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3739 } catch (ImsException e) {
3740 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003741 } finally {
3742 Binder.restoreCallingIdentity(identity);
3743 }
3744 }
3745
3746 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003747 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003749 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003753 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003754 } catch (ImsException e) {
3755 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 } finally {
3757 Binder.restoreCallingIdentity(identity);
3758 }
3759 }
3760
shilu366312e2019-12-17 09:28:10 -08003761 /**
3762 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3763 * @param subId The subscription to use to check the configuration.
3764 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003765 @Override
3766 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003767 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3768 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003769 final long identity = Binder.clearCallingIdentity();
3770 try {
3771 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003772 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003774 } catch (ImsException e) {
3775 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
3779 }
3780
3781 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003782 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003784 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003788 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003789 } catch (ImsException e) {
3790 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003791 } finally {
3792 Binder.restoreCallingIdentity(identity);
3793 }
3794 }
3795
shilu366312e2019-12-17 09:28:10 -08003796 /**
3797 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3798 * @param subId The subscription to use to check the configuration.
3799 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003800 @Override
3801 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003802 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3803 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003807 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003808 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003809 } catch (ImsException e) {
3810 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003811 } finally {
3812 Binder.restoreCallingIdentity(identity);
3813 }
3814 }
3815
3816 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003817 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003819 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003823 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003825 } catch (ImsException e) {
3826 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003827 } finally {
3828 Binder.restoreCallingIdentity(identity);
3829 }
3830 }
3831
3832 @Override
3833 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3835 "setVoWiFiNonPersistent");
3836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003839 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003840 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003841 } catch (ImsException e) {
3842 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 } finally {
3844 Binder.restoreCallingIdentity(identity);
3845 }
3846 }
3847
shilu366312e2019-12-17 09:28:10 -08003848 /**
3849 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3850 * @param subId The subscription to use to check the configuration.
3851 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 @Override
3853 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003854 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3855 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003859 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003860 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003861 } catch (ImsException e) {
3862 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003863 } finally {
3864 Binder.restoreCallingIdentity(identity);
3865 }
3866 }
3867
3868 @Override
3869 public void setVoWiFiModeSetting(int subId, int mode) {
3870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3871 "setVoWiFiModeSetting");
3872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003875 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003876 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003877 } catch (ImsException e) {
3878 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 } finally {
3880 Binder.restoreCallingIdentity(identity);
3881 }
3882 }
3883
3884 @Override
3885 public int getVoWiFiRoamingModeSetting(int subId) {
3886 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3887 final long identity = Binder.clearCallingIdentity();
3888 try {
3889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003890 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003891 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003892 } catch (ImsException e) {
3893 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 } finally {
3895 Binder.restoreCallingIdentity(identity);
3896 }
3897 }
3898
3899 @Override
3900 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3902 "setVoWiFiRoamingModeSetting");
3903 final long identity = Binder.clearCallingIdentity();
3904 try {
3905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003906 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003908 } catch (ImsException e) {
3909 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 } finally {
3911 Binder.restoreCallingIdentity(identity);
3912 }
3913 }
3914
3915 @Override
3916 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3918 "setRttCapabilityEnabled");
3919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003922 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3923 } catch (ImsException e) {
3924 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003925 } finally {
3926 Binder.restoreCallingIdentity(identity);
3927 }
3928 }
3929
shilu366312e2019-12-17 09:28:10 -08003930 /**
3931 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3932 * @param subId The subscription to use to check the configuration.
3933 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003934 @Override
3935 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003936 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3937 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003941 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003942 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003943 } catch (ImsException e) {
3944 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 } finally {
3946 Binder.restoreCallingIdentity(identity);
3947 }
3948 }
3949
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003950 @Override
3951 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3952 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3953 final long identity = Binder.clearCallingIdentity();
3954 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003955 if (!isImsAvailableOnDevice()) {
3956 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3957 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003958 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003960 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003961 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003962 } catch (ImsException e) {
3963 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
3967 }
3968
3969 @Override
3970 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3971 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3972 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003973 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3974 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3975 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003976 try {
3977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003978 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003979 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003980 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003981 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3982 + "is inactive, ignoring unregister.");
3983 // If the subscription is no longer active, just return, since the callback will already
3984 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
3988 }
3989
allenwtsu99c623b2020-01-03 18:24:23 +08003990
3991 private void checkModifyPhoneStatePermission(int subId, String message) {
3992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3993 message);
3994 }
3995
3996 private boolean isImsProvisioningRequired(int subId, int capability,
3997 boolean isMmtelCapability) {
3998 Phone phone = getPhone(subId);
3999 if (phone == null) {
4000 loge("phone instance null for subid " + subId);
4001 return false;
4002 }
4003 if (isMmtelCapability) {
4004 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4005 return false;
4006 }
4007 } else {
4008 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4009 return false;
4010 }
4011 }
4012 return true;
4013 }
4014
4015 @Override
4016 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4017 boolean isProvisioned) {
4018 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4019
4020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4023 if (!isImsProvisioningRequired(subId, capability, false)) {
4024 return;
4025 }
4026
4027 // this capability requires provisioning, route to the correct API.
4028 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4029 switch (capability) {
4030 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4031 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4032 ims.setEabProvisioned(isProvisioned);
4033 break;
4034 default: {
4035 throw new IllegalArgumentException("Tried to set provisioning for "
4036 + "rcs capability '" + capability + "', which does not require "
4037 + "provisioning.");
4038 }
4039 }
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
4043
4044 }
4045
4046
4047 @Override
4048 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4049 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4053 if (!isImsProvisioningRequired(subId, capability, false)) {
4054 return true;
4055 }
4056
4057 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4058 switch (capability) {
4059 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4060 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4061 return ims.isEabProvisionedOnDevice();
4062
4063 default: {
4064 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4065 + "capability '" + capability + "', which does not require "
4066 + "provisioning.");
4067 }
4068 }
4069
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
4073 }
4074
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004075 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004076 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4077 boolean isProvisioned) {
4078 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4079 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4080 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4081 }
allenwtsu99c623b2020-01-03 18:24:23 +08004082 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004086 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004087 return;
4088 }
4089
4090 // this capability requires provisioning, route to the correct API.
4091 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4092 switch (capability) {
4093 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4094 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4095 ims.setVolteProvisioned(isProvisioned);
4096 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4097 ims.setWfcProvisioned(isProvisioned);
4098 }
4099 break;
4100 }
4101 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4102 // There is currently no difference in VT provisioning type.
4103 ims.setVtProvisioned(isProvisioned);
4104 break;
4105 }
4106 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4107 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4108 // change the capability of the feature instead if needed.
4109 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4110 == isProvisioned) {
4111 // No change in provisioning.
4112 return;
4113 }
4114 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4115 try {
4116 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004117 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004118 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4119 + ", Exception" + e.getMessage());
4120 }
4121 break;
4122 }
4123 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004124 throw new IllegalArgumentException("Tried to set provisioning for "
4125 + "MmTel capability '" + capability + "', which does not require "
4126 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004127 }
4128 }
4129
4130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
4133 }
4134
4135 @Override
4136 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4137 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4138 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4139 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4140 }
4141 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004145 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004146 return true;
4147 }
4148
4149 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4150 switch (capability) {
4151 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4152 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4153 return ims.isVolteProvisionedOnDevice();
4154 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4155 return ims.isWfcProvisionedOnDevice();
4156 }
4157 // This should never happen, since we are checking tech above to make sure it
4158 // is either LTE or IWLAN.
4159 throw new IllegalArgumentException("Invalid radio technology for voice "
4160 + "capability.");
4161 }
4162 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4163 // There is currently no difference in VT provisioning type.
4164 return ims.isVtProvisionedOnDevice();
4165 }
4166 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4167 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4168 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4169 }
4170 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004171 throw new IllegalArgumentException(
4172 "Tried to get provisioning for MmTel capability '" + capability
4173 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004174 }
4175 }
4176
4177 } finally {
4178 Binder.restoreCallingIdentity(identity);
4179 }
4180 }
4181
4182 @Override
4183 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4184 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4185 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4186 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4187 }
4188 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4189 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4190 return (provisionedBits & capability) > 0;
4191 }
4192
4193 @Override
4194 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4195 boolean isProvisioned) {
4196 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4197 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4198 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4199 }
4200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4201 "setProvisioningStatusForCapability");
4202 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4203 // If the current provisioning status for capability already matches isProvisioned,
4204 // do nothing.
4205 if (((provisionedBits & capability) > 0) == isProvisioned) {
4206 return;
4207 }
4208 if (isProvisioned) {
4209 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4210 } else {
4211 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4212 }
4213 }
4214
4215 /**
4216 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4217 * technology. The bitfield should mirror the bitfield defined by
4218 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4219 */
4220 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4221 String key = getMmTelProvisioningKey(subId, tech);
4222 // Default is no capabilities are provisioned.
4223 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4224 }
4225
4226 /**
4227 * Sets the MmTel capability provisioning bitfield (defined by
4228 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4229 * technology specified.
4230 *
4231 * Note: This is a synchronous command and should not be called on UI thread.
4232 */
4233 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4234 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4235 String key = getMmTelProvisioningKey(subId, tech);
4236 editor.putInt(key, newField);
4237 editor.commit();
4238 }
4239
4240 private static String getMmTelProvisioningKey(int subId, int tech) {
4241 // resulting key is provision_ims_mmtel_{subId}_{tech}
4242 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4243 }
4244
4245 /**
4246 * Query CarrierConfig to see if the specified capability requires provisioning for the
4247 * carrier associated with the subscription id.
4248 */
4249 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4250 int capability) {
4251 CarrierConfigManager configManager = new CarrierConfigManager(context);
4252 PersistableBundle c = configManager.getConfigForSubId(subId);
4253 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004254 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004255 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4256 false);
4257 boolean requireVoiceVtProvisioning = c.getBoolean(
4258 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4259
4260 // First check to make sure that the capability requires provisioning.
4261 switch (capability) {
4262 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4263 // intentional fallthrough
4264 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4265 if (requireVoiceVtProvisioning) {
4266 // Voice and Video requires provisioning
4267 return true;
4268 }
4269 break;
4270 }
4271 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4272 if (requireUtProvisioning) {
4273 // UT requires provisioning
4274 return true;
4275 }
4276 break;
4277 }
4278 }
4279 return false;
4280 }
4281
allenwtsu99c623b2020-01-03 18:24:23 +08004282 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4283 int capability) {
4284 CarrierConfigManager configManager = new CarrierConfigManager(context);
4285 PersistableBundle c = configManager.getConfigForSubId(subId);
4286
4287 boolean requireRcsProvisioning = c.getBoolean(
4288 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4289
4290 // First check to make sure that the capability requires provisioning.
4291 switch (capability) {
4292 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4293 // intentional fallthrough
4294 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4295 if (requireRcsProvisioning) {
4296 // OPTION or PRESENCE requires provisioning
4297 return true;
4298 }
4299 break;
4300 }
4301 }
4302 return false;
4303 }
4304
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004305 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004306 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004307 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4308 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4309 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004310 enforceReadPrivilegedPermission("getImsProvisioningInt");
4311 final long identity = Binder.clearCallingIdentity();
4312 try {
4313 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004314 int slotId = getSlotIndex(subId);
4315 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4316 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4317 + subId + "' for key:" + key);
4318 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4319 }
4320 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004321 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004322 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4323 + subId + "' for key:" + key);
4324 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
4328 }
4329
4330 @Override
4331 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004332 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4333 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4334 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004335 enforceReadPrivilegedPermission("getImsProvisioningString");
4336 final long identity = Binder.clearCallingIdentity();
4337 try {
4338 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004339 int slotId = getSlotIndex(subId);
4340 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4341 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4342 + subId + "' for key:" + key);
4343 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4344 }
4345 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004346 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004347 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4348 + subId + "' for key:" + key);
4349 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
4353 }
4354
4355 @Override
4356 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004357 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4358 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4359 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4361 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004365 int slotId = getSlotIndex(subId);
4366 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4367 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4368 + subId + "' for key:" + key);
4369 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4370 }
4371 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004372 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004373 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4374 + "' for key:" + key);
4375 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
4379 }
4380
4381 @Override
4382 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004383 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4384 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4385 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4387 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004388 final long identity = Binder.clearCallingIdentity();
4389 try {
4390 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004391 int slotId = getSlotIndex(subId);
4392 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4393 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4394 + subId + "' for key:" + key);
4395 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4396 }
4397 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004398 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004399 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4400 + "' for key:" + key);
4401 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
4405 }
4406
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004407 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004408 int slotId = SubscriptionManager.getSlotIndex(subId);
4409 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004410 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4411 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004412 }
4413 return slotId;
4414 }
4415
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004416 private int getSlotIndex(int subId) {
4417 int slotId = SubscriptionManager.getSlotIndex(subId);
4418 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4419 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4420 }
4421 return slotId;
4422 }
4423
Wink Saville36469e72014-06-11 15:17:00 -07004424 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004425 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004426 */
4427 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004428 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4429 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004430 final int targetSdk = getTargetSdk(callingPackage);
4431 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004432 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004433 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004434 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004435 mApp, subId, callingPackage, callingFeatureId,
4436 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004437 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4438 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 final long identity = Binder.clearCallingIdentity();
4441 try {
4442 final Phone phone = getPhone(subId);
4443 if (phone != null) {
4444 return phone.getServiceState().getDataNetworkType();
4445 } else {
4446 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4447 }
4448 } finally {
4449 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004451 }
4452
4453 /**
4454 * Returns the data network type
4455 */
4456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004457 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4458 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4459 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004460 }
4461
4462 /**
4463 * Returns the data network type for a subId
4464 */
4465 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004466 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4467 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004469 mApp, subId, callingPackage, callingFeatureId,
4470 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004471 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4472 }
4473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 final long identity = Binder.clearCallingIdentity();
4475 try {
4476 final Phone phone = getPhone(subId);
4477 if (phone != null) {
4478 return phone.getServiceState().getDataNetworkType();
4479 } else {
4480 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4481 }
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004485 }
4486
4487 /**
Wink Saville36469e72014-06-11 15:17:00 -07004488 * Returns the Voice network type for a subId
4489 */
4490 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004491 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4492 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004494 mApp, subId, callingPackage, callingFeatureId,
4495 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004496 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4497 }
4498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 final long identity = Binder.clearCallingIdentity();
4500 try {
4501 final Phone phone = getPhone(subId);
4502 if (phone != null) {
4503 return phone.getServiceState().getVoiceNetworkType();
4504 } else {
4505 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4506 }
4507 } finally {
4508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004510 }
4511
4512 /**
4513 * @return true if a ICC card is present
4514 */
4515 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004516 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004517 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4518 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004519 }
4520
4521 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004522 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004523 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004524 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004525 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 final long identity = Binder.clearCallingIdentity();
4527 try {
4528 final Phone phone = PhoneFactory.getPhone(slotIndex);
4529 if (phone != null) {
4530 return phone.getIccCard().hasIccCard();
4531 } else {
4532 return false;
4533 }
4534 } finally {
4535 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004537 }
4538
4539 /**
4540 * Return if the current radio is LTE on CDMA. This
4541 * is a tri-state return value as for a period of time
4542 * the mode may be unknown.
4543 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004544 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004545 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004546 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004547 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004548 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004549 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4550 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4551 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004552 }
4553
Sanket Padawe356d7632015-06-22 14:03:32 -07004554 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004555 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4556 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004557 try {
4558 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4559 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004560 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4561 }
4562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004563 final long identity = Binder.clearCallingIdentity();
4564 try {
4565 final Phone phone = getPhone(subId);
4566 if (phone == null) {
4567 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4568 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004569 return TelephonyProperties.lte_on_cdma_device()
4570 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 }
4572 } finally {
4573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004574 }
Wink Saville36469e72014-06-11 15:17:00 -07004575 }
4576
Wink Saville36469e72014-06-11 15:17:00 -07004577 /**
4578 * {@hide}
4579 * Returns Default subId, 0 in the case of single standby.
4580 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004581 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004582 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004583 }
4584
Shishir Agrawala9f32182016-04-12 12:00:16 -07004585 private int getSlotForDefaultSubscription() {
4586 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4587 }
4588
Wink Savilleb564aae2014-10-23 10:18:09 -07004589 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004590 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004591 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004592
Pengquan Menge92a50d2018-09-21 15:54:48 -07004593 private boolean isActiveSubscription(int subId) {
4594 return mSubscriptionController.isActiveSubId(subId);
4595 }
4596
Ihab Awadf2177b72013-11-25 13:33:23 -08004597 /**
4598 * @see android.telephony.TelephonyManager.WifiCallingChoices
4599 */
4600 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 final long identity = Binder.clearCallingIdentity();
4602 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004603 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004604 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4605 getWhenToMakeWifiCallsDefaultPreference());
4606 } finally {
4607 Binder.restoreCallingIdentity(identity);
4608 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004609 }
4610
4611 /**
4612 * @see android.telephony.TelephonyManager.WifiCallingChoices
4613 */
4614 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 final long identity = Binder.clearCallingIdentity();
4616 try {
4617 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004618 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004619 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004623 }
4624
Sailesh Nepald1e68152013-12-12 19:08:02 -08004625 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004626 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004627 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004628 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004629
Jordan Liu4c733742019-02-28 12:03:40 -08004630 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4631 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4632 if (phoneId == -1) {
4633 throw new IllegalArgumentException("Given slot index: " + slotIndex
4634 + " does not correspond to an active phone");
4635 }
4636 return PhoneFactory.getPhone(phoneId);
4637 }
4638
Shishir Agrawal566b7612013-10-28 14:41:00 -07004639 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004640 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4641 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4643 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004645 if (DBG) {
4646 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4647 }
4648 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4649 p2);
4650 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004651
Jordan Liu4c733742019-02-28 12:03:40 -08004652
4653 @Override
4654 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4655 int slotIndex, String callingPackage, String aid, int p2) {
4656 enforceModifyPermission();
4657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4658 if (DBG) {
4659 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4660 }
4661 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4662 callingPackage, aid, p2);
4663 }
4664
4665 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4666 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667 final long identity = Binder.clearCallingIdentity();
4668 try {
4669 if (TextUtils.equals(ISDR_AID, aid)) {
4670 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004671 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4672 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673 if (bestComponent == null
4674 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4675 loge("The calling package is not allowed to access ISD-R.");
4676 throw new SecurityException(
4677 "The calling package is not allowed to access ISD-R.");
4678 }
Derek Tan740e1672017-06-27 14:56:27 -07004679 }
Derek Tan740e1672017-06-27 14:56:27 -07004680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004682 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4683 null /* workSource */);
4684 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 return response;
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
4688 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004689 }
4690
4691 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004692 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4694 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004695 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4696 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4697 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004698
Jordan Liu4c733742019-02-28 12:03:40 -08004699 @Override
4700 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4701 enforceModifyPermission();
4702 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4703 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4704 channel);
4705 }
4706
4707 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004708 final long identity = Binder.clearCallingIdentity();
4709 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004710 if (channel < 0) {
4711 return false;
4712 }
Jordan Liu4c733742019-02-28 12:03:40 -08004713 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4714 null /* workSource */);
4715 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004716 return success;
4717 } finally {
4718 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004719 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004720 }
4721
4722 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004723 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004724 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4726 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004727 if (DBG) {
4728 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4729 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4730 + p3 + " data=" + data);
4731 }
4732 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4733 command, p1, p2, p3, data);
4734 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004735
Jordan Liu4c733742019-02-28 12:03:40 -08004736 @Override
4737 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4738 int command, int p1, int p2, int p3, String data) {
4739 enforceModifyPermission();
4740 if (DBG) {
4741 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4742 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4743 + p3 + " data=" + data);
4744 }
4745 return iccTransmitApduLogicalChannelWithPermission(
4746 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4747 data);
4748 }
4749
4750 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4751 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752 final long identity = Binder.clearCallingIdentity();
4753 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004754 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004755 return "";
4756 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004758 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004759 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4760 null /* workSource */);
4761 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 // Append the returned status code to the end of the response payload.
4764 String s = Integer.toHexString(
4765 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4766 if (response.payload != null) {
4767 s = IccUtils.bytesToHexString(response.payload) + s;
4768 }
4769 return s;
4770 } finally {
4771 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004772 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004773 }
Jake Hambye994d462014-02-03 13:10:13 -08004774
Evan Charltonc66da362014-05-16 14:06:40 -07004775 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004776 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4777 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4779 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004781 if (DBG) {
4782 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4783 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4784 }
4785 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4786 cla, command, p1, p2, p3, data);
4787 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004788
Jordan Liu4c733742019-02-28 12:03:40 -08004789 @Override
4790 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4791 int command, int p1, int p2, int p3, String data) {
4792 enforceModifyPermission();
4793 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4794 if (DBG) {
4795 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4796 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4797 + " data=" + data);
4798 }
4799
4800 return iccTransmitApduBasicChannelWithPermission(
4801 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4802 p2, p3, data);
4803 }
4804
4805 // open APDU basic channel assuming the caller has sufficient permissions
4806 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4807 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004808 final long identity = Binder.clearCallingIdentity();
4809 try {
4810 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4811 && TextUtils.equals(ISDR_AID, data)) {
4812 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004813 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4814 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 if (bestComponent == null
4816 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4817 loge("The calling package is not allowed to select ISD-R.");
4818 throw new SecurityException(
4819 "The calling package is not allowed to select ISD-R.");
4820 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004821 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004824 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4825 null /* workSource */);
4826 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004828 // Append the returned status code to the end of the response payload.
4829 String s = Integer.toHexString(
4830 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4831 if (response.payload != null) {
4832 s = IccUtils.bytesToHexString(response.payload) + s;
4833 }
4834 return s;
4835 } finally {
4836 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004837 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004838 }
4839
4840 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004841 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004842 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4844 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 if (DBG) {
4849 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4850 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4851 }
4852
4853 IccIoResult response =
4854 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4855 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4856 subId);
4857
4858 if (DBG) {
4859 log("Exchange SIM_IO [R]" + response);
4860 }
4861
4862 byte[] result = null;
4863 int length = 2;
4864 if (response.payload != null) {
4865 length = 2 + response.payload.length;
4866 result = new byte[length];
4867 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4868 } else {
4869 result = new byte[length];
4870 }
4871
4872 result[length - 1] = (byte) response.sw2;
4873 result[length - 2] = (byte) response.sw1;
4874 return result;
4875 } finally {
4876 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004877 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004878 }
4879
Nathan Haroldb3014052017-01-25 15:57:32 -08004880 /**
4881 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4882 * on a particular subscription
4883 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004884 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4885 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004887 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004888 return null;
4889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890
4891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 if (appType != TelephonyManager.APPTYPE_USIM
4894 && appType != TelephonyManager.APPTYPE_SIM) {
4895 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4896 return null;
4897 }
4898 Object response = sendRequest(
4899 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4900 if (response instanceof String[]) {
4901 return (String[]) response;
4902 }
yincheng zhao2737e882019-09-06 17:06:54 -07004903 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004905 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 } finally {
4907 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004908 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004909 }
4910
yincheng zhao2737e882019-09-06 17:06:54 -07004911 /**
4912 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4913 * subscription.
4914 *
4915 * @param subId the id of the subscription.
4916 * @param appType the uicc app type, must be USIM or SIM.
4917 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4918 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004919 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004920 * @return number of fplmns that is successfully written to the SIM.
4921 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004922 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4923 String callingFeatureId) {
4924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4925 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004926 if (DBG) logv("no permissions for setForbiddenplmns");
4927 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4928 }
4929 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4930 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4931 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4932 }
4933 if (fplmns == null) {
4934 throw new IllegalArgumentException("Fplmn List provided is null");
4935 }
4936 for (String fplmn : fplmns) {
4937 if (!CellIdentity.isValidPlmn(fplmn)) {
4938 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4939 }
4940 }
4941 final long identity = Binder.clearCallingIdentity();
4942 try {
4943 Object response = sendRequest(
4944 CMD_SET_FORBIDDEN_PLMNS,
4945 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4946 subId);
4947 return (int) response;
4948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
4951 }
4952
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004953 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004954 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4956 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4961 if (response.payload == null) {
4962 return "";
4963 }
Evan Charltonc66da362014-05-16 14:06:40 -07004964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965 // Append the returned status code to the end of the response payload.
4966 String s = Integer.toHexString(
4967 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4968 s = IccUtils.bytesToHexString(response.payload) + s;
4969 return s;
4970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
Evan Charltonc66da362014-05-16 14:06:40 -07004973 }
4974
Jake Hambye994d462014-02-03 13:10:13 -08004975 /**
4976 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4977 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4978 *
4979 * @param itemID the ID of the item to read
4980 * @return the NV item as a String, or null on error.
4981 */
4982 @Override
4983 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004984 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4986 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987
4988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004991 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4993 return value;
4994 } finally {
4995 Binder.restoreCallingIdentity(identity);
4996 }
Jake Hambye994d462014-02-03 13:10:13 -08004997 }
4998
4999 /**
5000 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5001 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5002 *
5003 * @param itemID the ID of the item to read
5004 * @param itemValue the value to write, as a String
5005 * @return true on success; false on any failure
5006 */
5007 @Override
5008 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005009 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5011 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012
5013 final long identity = Binder.clearCallingIdentity();
5014 try {
5015 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5016 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005017 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5019 return success;
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
5022 }
Jake Hambye994d462014-02-03 13:10:13 -08005023 }
5024
5025 /**
5026 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5027 * Used for device configuration by some CDMA operators.
5028 *
5029 * @param preferredRoamingList byte array containing the new PRL
5030 * @return true on success; false on any failure
5031 */
5032 @Override
5033 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5035 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036
5037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5040 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5041 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5042 return success;
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
5045 }
Jake Hambye994d462014-02-03 13:10:13 -08005046 }
5047
5048 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005049 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005050 * Used for device configuration by some CDMA operators.
5051 *
chen xu6dac5ab2018-10-26 17:39:23 -07005052 * @param slotIndex - device slot.
5053 *
Jake Hambye994d462014-02-03 13:10:13 -08005054 * @return true on success; false on any failure
5055 */
5056 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005057 public boolean resetModemConfig(int slotIndex) {
5058 Phone phone = PhoneFactory.getPhone(slotIndex);
5059 if (phone != null) {
5060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5061 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062
chen xu6dac5ab2018-10-26 17:39:23 -07005063 final long identity = Binder.clearCallingIdentity();
5064 try {
5065 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5066 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5067 return success;
5068 } finally {
5069 Binder.restoreCallingIdentity(identity);
5070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 }
chen xu6dac5ab2018-10-26 17:39:23 -07005072 return false;
5073 }
5074
5075 /**
5076 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5077 *
5078 * @param slotIndex - device slot.
5079 *
5080 * @return true on success; false on any failure
5081 */
5082 @Override
5083 public boolean rebootModem(int slotIndex) {
5084 Phone phone = PhoneFactory.getPhone(slotIndex);
5085 if (phone != null) {
5086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5087 mApp, phone.getSubId(), "rebootModem");
5088
5089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5092 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5093 return success;
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
5097 }
5098 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005099 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005100
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005101 public String[] getPcscfAddress(String apnType, String callingPackage,
5102 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005103 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005104 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5105 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005106 return new String[0];
5107 }
5108
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109 final long identity = Binder.clearCallingIdentity();
5110 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005111 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 } finally {
5113 Binder.restoreCallingIdentity(identity);
5114 }
Wink Saville36469e72014-06-11 15:17:00 -07005115 }
5116
Brad Ebinger51f743a2017-01-23 13:50:20 -08005117 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005118 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5119 * {@link #disableIms(int)}.
5120 * @param slotIndex device slot.
5121 */
5122 public void resetIms(int slotIndex) {
5123 enforceModifyPermission();
5124
5125 final long identity = Binder.clearCallingIdentity();
5126 try {
5127 if (mImsResolver == null) {
5128 // may happen if the does not support IMS.
5129 return;
5130 }
5131 mImsResolver.disableIms(slotIndex);
5132 mImsResolver.enableIms(slotIndex);
5133 } finally {
5134 Binder.restoreCallingIdentity(identity);
5135 }
5136 }
5137
5138 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005139 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5140 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005141 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005142 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005143 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144
5145 final long identity = Binder.clearCallingIdentity();
5146 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005147 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005148 // may happen if the device does not support IMS.
5149 return;
5150 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005151 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005155 }
5156
5157 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005158 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5159 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005160 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005161 public void disableIms(int slotId) {
5162 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163
5164 final long identity = Binder.clearCallingIdentity();
5165 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005166 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005167 // may happen if the device does not support IMS.
5168 return;
5169 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005170 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 } finally {
5172 Binder.restoreCallingIdentity(identity);
5173 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005174 }
5175
5176 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005177 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5178 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005179 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005180 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005181 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005182 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183
5184 final long identity = Binder.clearCallingIdentity();
5185 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005186 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005187 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5188 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005189 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005190 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 } finally {
5192 Binder.restoreCallingIdentity(identity);
5193 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005194 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005195 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005196 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5197 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005198 @Override
5199 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005200 enforceModifyPermission();
5201
5202 final long identity = Binder.clearCallingIdentity();
5203 try {
5204 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005205 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005206 } finally {
5207 Binder.restoreCallingIdentity(identity);
5208 }
5209 }
5210
5211 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005212 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005213 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005214 */
5215 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217
5218 final long identity = Binder.clearCallingIdentity();
5219 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005220 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005221 // may happen if the device does not support IMS.
5222 return null;
5223 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005224 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 } finally {
5226 Binder.restoreCallingIdentity(identity);
5227 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005228 }
5229
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005230 /**
5231 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005232 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005233 */
5234 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5235 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236
5237 final long identity = Binder.clearCallingIdentity();
5238 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005239 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005240 // may happen if the device does not support IMS.
5241 return null;
5242 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005243 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 } finally {
5245 Binder.restoreCallingIdentity(identity);
5246 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005247 }
5248
Brad Ebinger884c07b2018-02-15 16:17:40 -08005249 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005250 * Sets the ImsService Package Name that Telephony will bind to.
5251 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005252 * @param slotIndex the slot ID that the ImsService should bind for.
5253 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005254 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005255 * @param featureTypes An integer array of feature types associated with a packageName.
5256 * @param packageName The name of the package that the current configuration will be replaced
5257 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005258 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005259 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005260 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5261 int[] featureTypes, String packageName) {
5262 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5263 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5265 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005266 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 final long identity = Binder.clearCallingIdentity();
5269 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005270 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005271 // may happen if the device does not support IMS.
5272 return false;
5273 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005274 Map<Integer, String> featureConfig = new HashMap<>();
5275 for (int featureType : featureTypes) {
5276 featureConfig.put(featureType, packageName);
5277 }
5278 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5279 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005283 }
5284
5285 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005286 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005287 *
5288 * @param slotId The slot that the ImsService is associated with.
5289 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5290 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005291 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005292 * @return the package name of the ImsService configuration.
5293 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005294 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5295 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005296 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005297 TelephonyPermissions
5298 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5299 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5300 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 final long identity = Binder.clearCallingIdentity();
5303 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005304 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005305 // may happen if the device does not support IMS.
5306 return "";
5307 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005308 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005309 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5310 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005314 }
5315
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005316 /**
5317 * Get the MmTelFeature state associated with the requested subscription id.
5318 * @param subId The subscription that the MmTelFeature is associated with.
5319 * @param callback A callback with an integer containing the
5320 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5321 */
5322 @Override
5323 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5324 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5325 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5326 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5327 "IMS not available on device.");
5328 }
5329 final long token = Binder.clearCallingIdentity();
5330 try {
5331 int slotId = getSlotIndex(subId);
5332 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5333 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5334 + subId + "'");
5335 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5336 }
5337 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5338 try {
5339 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5340 } catch (RemoteException e) {
5341 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5342 + "Ignore");
5343 }
5344 });
5345 } finally {
5346 Binder.restoreCallingIdentity(token);
5347 }
5348 }
5349
Wink Saville36469e72014-06-11 15:17:00 -07005350 public void setImsRegistrationState(boolean registered) {
5351 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352
5353 final long identity = Binder.clearCallingIdentity();
5354 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005355 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 } finally {
5357 Binder.restoreCallingIdentity(identity);
5358 }
Wink Saville36469e72014-06-11 15:17:00 -07005359 }
5360
5361 /**
Stuart Scott54788802015-03-30 13:18:01 -07005362 * Set the network selection mode to automatic.
5363 *
5364 */
5365 @Override
5366 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5368 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369
5370 final long identity = Binder.clearCallingIdentity();
5371 try {
shilufc958392020-01-20 11:36:01 -08005372 if (!isActiveSubscription(subId)) {
5373 return;
5374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5376 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5377 } finally {
5378 Binder.restoreCallingIdentity(identity);
5379 }
Stuart Scott54788802015-03-30 13:18:01 -07005380 }
5381
Jack Yud10cdd42020-09-28 20:28:01 -07005382 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005383 * Ask the radio to connect to the input network and change selection mode to manual.
5384 *
5385 * @param subId the id of the subscription.
5386 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5387 * the operator to attach to.
5388 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5389 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5390 * normal network selection next time.
5391 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005392 */
5393 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005394 public boolean setNetworkSelectionModeManual(
5395 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5397 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005398
5399 if (!isActiveSubscription(subId)) {
5400 return false;
5401 }
5402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 final long identity = Binder.clearCallingIdentity();
5404 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005405 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005407 if (DBG) {
5408 log("setNetworkSelectionModeManual: subId: " + subId
5409 + " operator: " + operatorInfo);
5410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5412 } finally {
5413 Binder.restoreCallingIdentity(identity);
5414 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005415 }
shilu84f6e8b2019-12-19 13:58:01 -08005416 /**
5417 * Get the manual network selection
5418 *
5419 * @param subId the id of the subscription.
5420 *
5421 * @return the previously saved user selected PLMN
5422 */
5423 @Override
5424 public String getManualNetworkSelectionPlmn(int subId) {
5425 TelephonyPermissions
5426 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5427 mApp, subId, "getManualNetworkSelectionPlmn");
5428
5429 final long identity = Binder.clearCallingIdentity();
5430 try {
5431 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005432 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005433 }
5434
5435 final Phone phone = getPhone(subId);
5436 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005437 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005438 }
5439 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5440 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5441 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
5444 }
5445 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005446
5447 /**
5448 * Scans for available networks.
5449 */
5450 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005451 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5452 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5454 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005455 LocationAccessPolicy.LocationPermissionResult locationResult =
5456 LocationAccessPolicy.checkLocationPermission(mApp,
5457 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5458 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005459 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005460 .setCallingPid(Binder.getCallingPid())
5461 .setCallingUid(Binder.getCallingUid())
5462 .setMethod("getCellNetworkScanResults")
5463 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005464 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5465 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005466 .build());
5467 switch (locationResult) {
5468 case DENIED_HARD:
5469 throw new SecurityException("Not allowed to access scan results -- location");
5470 case DENIED_SOFT:
5471 return null;
5472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473
Pengquan Menga1bb6272018-09-06 09:59:22 -07005474 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 try {
5476 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005477 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005482 }
5483
5484 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005485 * Get the call forwarding info, given the call forwarding reason.
5486 */
5487 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005488 public void getCallForwarding(int subId, int callForwardingReason,
5489 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005490 enforceReadPrivilegedPermission("getCallForwarding");
5491 long identity = Binder.clearCallingIdentity();
5492 try {
5493 if (DBG) {
5494 log("getCallForwarding: subId " + subId
5495 + " callForwardingReason" + callForwardingReason);
5496 }
Hall Liu27d24262020-09-18 19:04:59 -07005497
5498 Phone phone = getPhone(subId);
5499 if (phone == null) {
5500 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005501 callback.onError(
5502 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005503 } catch (RemoteException e) {
5504 // ignore
5505 }
5506 return;
5507 }
5508
5509 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5510 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5511 @Override
5512 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5513 try {
5514 callback.onCallForwardingInfoAvailable(info);
5515 } catch (RemoteException e) {
5516 // ignore
5517 }
5518 }
5519
5520 @Override
5521 public void onError(int error) {
5522 try {
5523 callback.onError(error);
5524 } catch (RemoteException e) {
5525 // ignore
5526 }
5527 }
5528 });
5529 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
5533 }
5534
5535 /**
5536 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5537 * reason, the number to forward, and the timeout before the forwarding is attempted.
5538 */
5539 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005540 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5541 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005542 enforceModifyPermission();
5543 long identity = Binder.clearCallingIdentity();
5544 try {
5545 if (DBG) {
5546 log("setCallForwarding: subId " + subId
5547 + " callForwardingInfo" + callForwardingInfo);
5548 }
Hall Liu27d24262020-09-18 19:04:59 -07005549
5550 Phone phone = getPhone(subId);
5551 if (phone == null) {
5552 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005553 callback.accept(
5554 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005555 } catch (RemoteException e) {
5556 // ignore
5557 }
5558 return;
5559 }
5560
5561 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5562 FunctionalUtils.ignoreRemoteException(callback::accept));
5563
5564 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
5568 }
5569
5570 /**
Hall Liu27d24262020-09-18 19:04:59 -07005571 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005572 */
5573 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005574 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005575 enforceReadPrivilegedPermission("getCallForwarding");
5576 long identity = Binder.clearCallingIdentity();
5577 try {
Hall Liu27d24262020-09-18 19:04:59 -07005578
5579 Phone phone = getPhone(subId);
5580 if (phone == null) {
5581 try {
5582 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5583 } catch (RemoteException e) {
5584 // ignore
5585 }
5586 return;
5587 }
5588
5589 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5590
Shuo Qian4a594052020-01-23 11:59:30 -08005591 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005592 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
5596 }
5597
5598 /**
Hall Liu27d24262020-09-18 19:04:59 -07005599 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005600 */
5601 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005602 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005603 enforceModifyPermission();
5604 long identity = Binder.clearCallingIdentity();
5605 try {
Hall Liu27d24262020-09-18 19:04:59 -07005606 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5607
5608 Phone phone = getPhone(subId);
5609 if (phone == null) {
5610 try {
5611 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5612 } catch (RemoteException e) {
5613 // ignore
5614 }
5615 return;
5616 }
5617
5618 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5619 FunctionalUtils.ignoreRemoteException(callback::accept));
5620
5621 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005622 } finally {
5623 Binder.restoreCallingIdentity(identity);
5624 }
5625 }
5626
5627 /**
yinxub1bed742017-04-17 11:45:04 -07005628 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005629 *
yinxub1bed742017-04-17 11:45:04 -07005630 * @param subId id of the subscription
5631 * @param request contains the radio access networks with bands/channels to scan
5632 * @param messenger callback messenger for scan results or errors
5633 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005634 * @return the id of the requested scan which can be used to stop the scan.
5635 */
5636 @Override
5637 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005638 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5640 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005641 LocationAccessPolicy.LocationPermissionResult locationResult =
5642 LocationAccessPolicy.checkLocationPermission(mApp,
5643 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5644 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005645 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005646 .setCallingPid(Binder.getCallingPid())
5647 .setCallingUid(Binder.getCallingUid())
5648 .setMethod("requestNetworkScan")
5649 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005650 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5651 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005652 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005653 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005654 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5655 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005656 if (e != null) {
5657 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5658 throw e;
5659 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005660 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005661 return TelephonyScanManager.INVALID_SCAN_ID;
5662 }
5663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 }
Hall Liu912dfd32019-04-25 14:02:26 -07005665 int callingUid = Binder.getCallingUid();
5666 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005667 final long identity = Binder.clearCallingIdentity();
5668 try {
5669 return mNetworkScanRequestTracker.startNetworkScan(
5670 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005671 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
yinxu504e1392017-04-12 16:03:22 -07005675 }
5676
Hall Liub2ac8ef2019-02-28 15:56:23 -08005677 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005678 NetworkScanRequest request, int subId, String callingPackage) {
5679 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005680 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5681 boolean hasNetworkScanPermission =
5682 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5683 == PERMISSION_GRANTED;
5684
5685 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5686 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5687 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005688 }
5689
5690 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5691 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005692 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5693 return new SecurityException("Specific channels must not be"
5694 + " scanned without location access.");
5695 }
5696 }
5697 }
5698
Hall Liub2ac8ef2019-02-28 15:56:23 -08005699 return null;
5700 }
5701
yinxu504e1392017-04-12 16:03:22 -07005702 /**
5703 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005704 *
5705 * @param subId id of the subscription
5706 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005707 */
5708 @Override
5709 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5711 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712
Hall Liu912dfd32019-04-25 14:02:26 -07005713 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 final long identity = Binder.clearCallingIdentity();
5715 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005716 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
yinxu504e1392017-04-12 16:03:22 -07005720 }
5721
5722 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005723 * Get the calculated preferred network type.
5724 * Used for debugging incorrect network type.
5725 *
5726 * @return the preferred network type, defined in RILConstants.java.
5727 */
5728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005729 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005730 final Phone defaultPhone = getDefaultPhone();
5731 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005732 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005733 return RILConstants.PREFERRED_NETWORK_MODE;
5734 }
5735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 final long identity = Binder.clearCallingIdentity();
5737 try {
5738 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005739 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
Junda Liu84d15a22014-07-02 11:21:04 -07005743 }
5744
5745 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005746 * Get the preferred network type.
5747 * Used for device configuration by some CDMA operators.
5748 *
5749 * @return the preferred network type, defined in RILConstants.java.
5750 */
5751 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005752 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005753 TelephonyPermissions
5754 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5755 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756
5757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 if (DBG) log("getPreferredNetworkType");
5760 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5761 int networkType = (result != null ? result[0] : -1);
5762 if (DBG) log("getPreferredNetworkType: " + networkType);
5763 return networkType;
5764 } finally {
5765 Binder.restoreCallingIdentity(identity);
5766 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005767 }
5768
5769 /**
5770 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005771 *
5772 * @param networkType the preferred network type, defined in RILConstants.java.
5773 * @return true on success; false on any failure.
5774 */
5775 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005776 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5778 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779
5780 final long identity = Binder.clearCallingIdentity();
5781 try {
calvinpan8ed33732020-03-12 14:17:55 +08005782 Boolean success = (Boolean) sendRequest(
5783 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005784
5785 if (success) {
5786 Settings.Global.putInt(mApp.getContentResolver(),
5787 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5788 }
calvinpan8ed33732020-03-12 14:17:55 +08005789 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5790 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 } finally {
5792 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005793 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005794 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005795
5796 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005797 * Get the allowed network types that store in the telephony provider.
5798 *
5799 * @param subId the id of the subscription.
5800 * @return allowedNetworkTypes the allowed network types.
5801 */
5802 @Override
5803 public long getAllowedNetworkTypes(int subId) {
5804 TelephonyPermissions
5805 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5806 mApp, subId, "getAllowedNetworkTypes");
5807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 return SubscriptionManager.getLongSubscriptionProperty(
5811 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5812 } finally {
5813 Binder.restoreCallingIdentity(identity);
5814 }
5815 }
5816
5817 /**
5818 * Set the allowed network types.
5819 *
5820 * @param subId the id of the subscription.
5821 * @param allowedNetworkTypes the allowed network types.
5822 * @return true on success; false on any failure.
5823 */
5824 @Override
5825 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5827 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005828
calvinpan8ed33732020-03-12 14:17:55 +08005829 SubscriptionManager.setSubscriptionProperty(subId,
5830 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5831 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005832
calvinpan8ed33732020-03-12 14:17:55 +08005833 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5834 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5835 RILConstants.PREFERRED_NETWORK_MODE);
5836 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005837 }
5838
5839 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005840 * Get the allowed network types for certain reason.
5841 *
5842 * @param subId the id of the subscription.
5843 * @param reason the reason the allowed network type change is taking place
5844 * @return the allowed network types.
5845 */
5846 @Override
5847 public long getAllowedNetworkTypesForReason(int subId,
5848 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5849 TelephonyPermissions
5850 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5851 mApp, subId, "getAllowedNetworkTypesForReason");
5852 final long identity = Binder.clearCallingIdentity();
5853 try {
5854 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
5857 }
5858 }
5859
5860 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07005861 * Enable/Disable E-UTRA-NR Dual Connectivity
5862 * @param subId subscription id of the sim card
5863 * @param nrDualConnectivityState expected NR dual connectivity state
5864 * This can be passed following states
5865 * <ol>
5866 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5867 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5868 * <li>Disable NR dual connectivity and force secondary cell to be released
5869 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5870 * </ol>
5871 * @return operation result.
5872 */
5873 @Override
5874 public int setNrDualConnectivityState(int subId,
5875 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5877 mApp, subId, "enableNRDualConnectivity");
5878 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5879 final long identity = Binder.clearCallingIdentity();
5880 try {
5881 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5882 nrDualConnectivityState, subId,
5883 workSource);
5884 if (DBG) log("enableNRDualConnectivity result: " + result);
5885 return result;
5886 } finally {
5887 Binder.restoreCallingIdentity(identity);
5888 }
5889 }
5890
5891 /**
5892 * Is E-UTRA-NR Dual Connectivity enabled
5893 * @return true if dual connectivity is enabled else false
5894 */
5895 @Override
5896 public boolean isNrDualConnectivityEnabled(int subId) {
5897 TelephonyPermissions
5898 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5899 mApp, subId, "isNRDualConnectivityEnabled");
5900 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5901 final long identity = Binder.clearCallingIdentity();
5902 try {
5903 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
5904 null, subId, workSource);
5905 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
5906 return isEnabled;
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
5910 }
5911
5912 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005913 * Get the effective allowed network types on the device.
5914 * This API will return an intersection of allowed network types for all reasons,
5915 * including the configuration done through setAllowedNetworkTypes
5916 *
5917 * @param subId the id of the subscription.
5918 * @return the allowed network types
5919 */
5920 @Override
5921 public long getEffectiveAllowedNetworkTypes(int subId) {
5922 TelephonyPermissions
5923 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5924 mApp, subId, "getEffectiveAllowedNetworkTypes");
5925 final long identity = Binder.clearCallingIdentity();
5926 try {
5927 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5928 } finally {
5929 Binder.restoreCallingIdentity(identity);
5930 }
5931 }
5932
5933 /**
5934 * Set the allowed network types of the device and
5935 * provide the reason triggering the allowed network change.
5936 *
5937 * @param subId the id of the subscription.
5938 * @param reason the reason the allowed network type change is taking place
5939 * @param allowedNetworkTypes the allowed network types.
5940 * @return true on success; false on any failure.
5941 */
5942 @Override
5943 public boolean setAllowedNetworkTypesForReason(int subId,
5944 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5946 mApp, subId, "setAllowedNetworkTypesForReason");
5947 final long identity = Binder.clearCallingIdentity();
5948 try {
5949 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5950 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5951 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5952 RILConstants.PREFERRED_NETWORK_MODE);
5953 return setPreferredNetworkType(subId, preferredNetworkMode);
5954 } finally {
5955 Binder.restoreCallingIdentity(identity);
5956 }
5957 }
5958
5959 /**
Miaoa84611c2019-03-15 09:21:10 +08005960 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005961 *
Miaoa84611c2019-03-15 09:21:10 +08005962 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005963 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005964 * @hide
5965 */
5966 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005967 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005968 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005970 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 try {
Miaoa84611c2019-03-15 09:21:10 +08005972 if (phone != null) {
5973 return phone.hasMatchedTetherApnSetting();
5974 } else {
5975 return false;
5976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977 } finally {
5978 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005979 }
Junda Liu475951f2014-11-07 16:45:03 -08005980 }
5981
5982 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005983 * Enable or disable always reporting signal strength changes from radio.
5984 *
5985 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5986 */
5987 @Override
5988 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5989 enforceModifyPermission();
5990 enforceSystemCaller();
5991
5992 final long identity = Binder.clearCallingIdentity();
5993 final Phone phone = getPhone(subId);
5994 try {
5995 if (phone != null) {
5996 if (DBG) {
5997 log("setAlwaysReportSignalStrength: subId=" + subId
5998 + " isEnable=" + isEnable);
5999 }
6000 phone.setAlwaysReportSignalStrength(isEnable);
6001 } else {
6002 loge("setAlwaysReportSignalStrength: no phone found for subId="
6003 + subId);
6004 }
6005 } finally {
6006 Binder.restoreCallingIdentity(identity);
6007 }
6008 }
6009
6010 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006011 * Get the user enabled state of Mobile Data.
6012 *
6013 * TODO: remove and use isUserDataEnabled.
6014 * This can't be removed now because some vendor codes
6015 * calls through ITelephony directly while they should
6016 * use TelephonyManager.
6017 *
6018 * @return true on enabled
6019 */
6020 @Override
6021 public boolean getDataEnabled(int subId) {
6022 return isUserDataEnabled(subId);
6023 }
6024
6025 /**
6026 * Get whether mobile data is enabled per user setting.
6027 *
6028 * There are other factors deciding whether mobile data is actually enabled, but they are
6029 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006030 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006031 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006032 *
6033 * @return {@code true} if data is enabled else {@code false}
6034 */
6035 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006036 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006037 try {
6038 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6039 null);
6040 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6042 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044
6045 final long identity = Binder.clearCallingIdentity();
6046 try {
6047 int phoneId = mSubscriptionController.getPhoneId(subId);
6048 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6049 Phone phone = PhoneFactory.getPhone(phoneId);
6050 if (phone != null) {
6051 boolean retVal = phone.isUserDataEnabled();
6052 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6053 return retVal;
6054 } else {
6055 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6056 return false;
6057 }
6058 } finally {
6059 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006060 }
6061 }
6062
6063 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006064 * Checks if the device is capable of mobile data by considering whether whether the
6065 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6066 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006067 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006068 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006069 */
6070 @Override
6071 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006072 try {
6073 try {
6074 mApp.enforceCallingOrSelfPermission(
6075 android.Manifest.permission.ACCESS_NETWORK_STATE,
6076 null);
6077 } catch (Exception e) {
6078 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6079 "isDataEnabled");
6080 }
6081 } catch (Exception e) {
6082 enforceReadPrivilegedPermission("isDataEnabled");
6083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084
6085 final long identity = Binder.clearCallingIdentity();
6086 try {
6087 int phoneId = mSubscriptionController.getPhoneId(subId);
6088 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6089 Phone phone = PhoneFactory.getPhone(phoneId);
6090 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006091 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6093 return retVal;
6094 } else {
6095 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6096 return false;
6097 }
6098 } finally {
6099 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006100 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006101 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006102
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006103 /**
6104 * Check if data is enabled for a specific reason
6105 * @param subId Subscription index
6106 * @param reason the reason the data enable change is taking place
6107 * @return {@code true} if the overall data is enabled; {@code false} if not.
6108 */
6109 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006110 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006111 @TelephonyManager.DataEnabledReason int reason) {
6112 try {
6113 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6114 null);
6115 } catch (Exception e) {
6116 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006117 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006118 }
6119
6120
6121 final long identity = Binder.clearCallingIdentity();
6122 try {
6123 int phoneId = mSubscriptionController.getPhoneId(subId);
6124 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006125 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006126 + " reason=" + reason);
6127 }
6128 Phone phone = PhoneFactory.getPhone(phoneId);
6129 if (phone != null) {
6130 boolean retVal;
6131 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6132 retVal = phone.isUserDataEnabled();
6133 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006134 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006135 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006136 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006137 return retVal;
6138 } else {
6139 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006140 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006141 + subId + " retVal=false");
6142 }
6143 return false;
6144 }
6145 } finally {
6146 Binder.restoreCallingIdentity(identity);
6147 }
6148 }
6149
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006150 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006151 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006152 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6153 // Skip the check if it's one of these special uids
6154 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6155 }
6156
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006157 //load access rules from carrier configs, and check those as well: b/139133814
6158 SubscriptionController subController = SubscriptionController.getInstance();
6159 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6160 || subController == null) return privilegeFromSim;
6161
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006162 PackageManager pkgMgr = phone.getContext().getPackageManager();
6163 String[] packages = pkgMgr.getPackagesForUid(uid);
6164
6165 final long identity = Binder.clearCallingIdentity();
6166 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006167 int subId = phone.getSubId();
6168 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6169 // A test override is in place for the privileges for this subId, so don't try to
6170 // read the subscription privileges.
6171 return privilegeFromSim;
6172 }
6173 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006174 SubscriptionManager subManager = (SubscriptionManager)
6175 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6176 for (String pkg : packages) {
6177 if (subManager.canManageSubscription(subInfo, pkg)) {
6178 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6179 }
6180 }
6181 return privilegeFromSim;
6182 } finally {
6183 Binder.restoreCallingIdentity(identity);
6184 }
6185 }
6186
6187 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6188 String pkgName) {
6189 //load access rules from carrier configs, and check those as well: b/139133814
6190 SubscriptionController subController = SubscriptionController.getInstance();
6191 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6192 || subController == null) return privilegeFromSim;
6193
6194 final long identity = Binder.clearCallingIdentity();
6195 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006196 int subId = phone.getSubId();
6197 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6198 // A test override is in place for the privileges for this subId, so don't try to
6199 // read the subscription privileges.
6200 return privilegeFromSim;
6201 }
6202 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006203 SubscriptionManager subManager = (SubscriptionManager)
6204 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6205 return subManager.canManageSubscription(subInfo, pkgName)
6206 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6207 } finally {
6208 Binder.restoreCallingIdentity(identity);
6209 }
6210 }
6211
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006212 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006213 public int getCarrierPrivilegeStatus(int subId) {
6214 final Phone phone = getPhone(subId);
6215 if (phone == null) {
6216 loge("getCarrierPrivilegeStatus: Invalid subId");
6217 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6218 }
6219 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006220 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006221 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006222 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6223 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006224
6225 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6226 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006227 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006228 }
Junda Liu29340342014-07-10 15:23:27 -07006229
6230 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006231 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006232 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006233 final Phone phone = getPhone(subId);
6234 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006235 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006236 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6237 }
6238 UiccProfile profile =
6239 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6240 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006241 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006242 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6243 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006244 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006245 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006246 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006247 }
6248
6249 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006250 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6251 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006252 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006253 }
6254
6255 int phoneId = SubscriptionManager.getPhoneId(subId);
6256 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006257 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006258 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006259 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6260 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006261 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6262 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6263 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006264 }
6265
6266 @Override
6267 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006268 if (TextUtils.isEmpty(pkgName))
6269 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006270 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6271 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6272 UiccCard card = UiccController.getInstance().getUiccCard(i);
6273 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006274 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006275 continue;
6276 }
6277
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006278 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6279 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6280 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006281 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6282 break;
6283 }
6284 }
6285
6286 return result;
Junda Liu29340342014-07-10 15:23:27 -07006287 }
Derek Tan89e89d42014-07-08 17:00:10 -07006288
6289 @Override
Junda Liue64de782015-04-16 17:19:16 -07006290 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6291 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6292 loge("phoneId " + phoneId + " is not valid.");
6293 return null;
6294 }
6295 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006296 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006297 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006298 return null ;
6299 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006300 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006301 }
6302
Amith Yamasani6e118872016-02-19 12:53:51 -08006303 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006304 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006305 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006306 List<String> privilegedPackages = new ArrayList<>();
6307 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006308 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6309 // has UICC in that slot.
6310 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006311 if (card.hasCarrierPrivilegeRules()) {
6312 if (packages == null) {
6313 // Only check packages in user 0 for now
6314 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006315 PackageManager.MATCH_DISABLED_COMPONENTS
6316 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006317 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006318 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006319 }
6320 for (int p = packages.size() - 1; p >= 0; p--) {
6321 PackageInfo pkgInfo = packages.get(p);
6322 if (pkgInfo != null && pkgInfo.packageName != null
6323 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006324 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006325 privilegedPackages.add(pkgInfo.packageName);
6326 }
6327 }
6328 }
6329 }
6330 return privilegedPackages;
6331 }
6332
chen xuf7e9fe82019-05-09 19:31:02 -07006333 @Override
6334 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006335 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6336
6337 final long identity = Binder.clearCallingIdentity();
6338
chen xuf7e9fe82019-05-09 19:31:02 -07006339 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006340 try {
6341 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6342 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6343 }
6344 } finally {
6345 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006346 }
6347 return privilegedPackages;
6348 }
6349
Wink Savilleb564aae2014-10-23 10:18:09 -07006350 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006351 final Phone phone = getPhone(subId);
6352 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006353 if (card == null) {
6354 loge("getIccId: No UICC");
6355 return null;
6356 }
6357 String iccId = card.getIccId();
6358 if (TextUtils.isEmpty(iccId)) {
6359 loge("getIccId: ICC ID is null or empty.");
6360 return null;
6361 }
6362 return iccId;
6363 }
6364
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006365 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006366 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6367 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006368 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006369 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 final long identity = Binder.clearCallingIdentity();
6372 try {
6373 final String iccId = getIccId(subId);
6374 final Phone phone = getPhone(subId);
6375 if (phone == null) {
6376 return false;
6377 }
6378 final String subscriberId = phone.getSubscriberId();
6379
6380 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006381 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 + subscriberId + " to " + number);
6383 }
6384
6385 if (TextUtils.isEmpty(iccId)) {
6386 return false;
6387 }
6388
6389 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6390
6391 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6392 if (alphaTag == null) {
6393 editor.remove(alphaTagPrefKey);
6394 } else {
6395 editor.putString(alphaTagPrefKey, alphaTag);
6396 }
6397
6398 // Record both the line number and IMSI for this ICCID, since we need to
6399 // track all merged IMSIs based on line number
6400 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6401 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6402 if (number == null) {
6403 editor.remove(numberPrefKey);
6404 editor.remove(subscriberPrefKey);
6405 } else {
6406 editor.putString(numberPrefKey, number);
6407 editor.putString(subscriberPrefKey, subscriberId);
6408 }
6409
6410 editor.commit();
6411 return true;
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006414 }
Derek Tan7226c842014-07-02 17:42:23 -07006415 }
6416
6417 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006418 public String getLine1NumberForDisplay(int subId, String callingPackage,
6419 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006420 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006422 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006423 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006424 return null;
6425 }
Derek Tan97ebb422014-09-05 16:55:38 -07006426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 final long identity = Binder.clearCallingIdentity();
6428 try {
6429 String iccId = getIccId(subId);
6430 if (iccId != null) {
6431 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6432 if (DBG_MERGE) {
6433 log("getLine1NumberForDisplay returning "
6434 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6435 }
6436 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006437 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006438 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6439 return null;
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006442 }
Derek Tan7226c842014-07-02 17:42:23 -07006443 }
6444
6445 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006446 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6447 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006449 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006450 return null;
6451 }
Derek Tan97ebb422014-09-05 16:55:38 -07006452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 final long identity = Binder.clearCallingIdentity();
6454 try {
6455 String iccId = getIccId(subId);
6456 if (iccId != null) {
6457 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6458 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6459 }
6460 return null;
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006463 }
Derek Tan7226c842014-07-02 17:42:23 -07006464 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006465
6466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006467 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6468 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006469 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6470 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006472 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006473 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006474 return null;
6475 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006476
Jordan Liub49b04b2019-05-06 14:45:15 -07006477 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6478 // the process, where TelephonyManager was instantiated.
6479 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006480 final long identity = Binder.clearCallingIdentity();
6481 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006482 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483 final TelephonyManager tele = TelephonyManager.from(context);
6484 final SubscriptionManager sub = SubscriptionManager.from(context);
6485
6486 // Figure out what subscribers are currently active
6487 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488
Jordan Liub49b04b2019-05-06 14:45:15 -07006489 // Only consider subs which match the current subId
6490 // This logic can be simplified. See b/131189269 for progress.
6491 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006492 activeSubscriberIds.add(tele.getSubscriberId(subId));
6493 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006494
6495 // First pass, find a number override for an active subscriber
6496 String mergeNumber = null;
6497 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6498 for (String key : prefs.keySet()) {
6499 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6500 final String subscriberId = (String) prefs.get(key);
6501 if (activeSubscriberIds.contains(subscriberId)) {
6502 final String iccId = key.substring(
6503 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6504 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6505 mergeNumber = (String) prefs.get(numberKey);
6506 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006507 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508 + " for active subscriber " + subscriberId);
6509 }
6510 if (!TextUtils.isEmpty(mergeNumber)) {
6511 break;
6512 }
6513 }
6514 }
6515 }
6516
6517 // Shortcut when no active merged subscribers
6518 if (TextUtils.isEmpty(mergeNumber)) {
6519 return null;
6520 }
6521
6522 // Second pass, find all subscribers under that line override
6523 final ArraySet<String> result = new ArraySet<>();
6524 for (String key : prefs.keySet()) {
6525 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6526 final String number = (String) prefs.get(key);
6527 if (mergeNumber.equals(number)) {
6528 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6529 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6530 final String subscriberId = (String) prefs.get(subscriberKey);
6531 if (!TextUtils.isEmpty(subscriberId)) {
6532 result.add(subscriberId);
6533 }
6534 }
6535 }
6536 }
6537
6538 final String[] resultArray = result.toArray(new String[result.size()]);
6539 Arrays.sort(resultArray);
6540 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006541 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6543 }
6544 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006545 } finally {
6546 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006547 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006548 }
6549
6550 @Override
zoey chen38003472019-12-13 17:16:31 +08006551 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6552 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006553
6554 final long identity = Binder.clearCallingIdentity();
6555 try {
6556 final TelephonyManager telephonyManager = mApp.getSystemService(
6557 TelephonyManager.class);
6558 String subscriberId = telephonyManager.getSubscriberId(subId);
6559 if (subscriberId == null) {
6560 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006561 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006562 + subId);
6563 }
6564 return null;
6565 }
6566
6567 final SubscriptionInfo info = SubscriptionController.getInstance()
6568 .getSubscriptionInfo(subId);
6569 final ParcelUuid groupUuid = info.getGroupUuid();
6570 // If it doesn't belong to any group, return just subscriberId of itself.
6571 if (groupUuid == null) {
6572 return new String[]{subscriberId};
6573 }
6574
6575 // Get all subscriberIds from the group.
6576 final List<String> mergedSubscriberIds = new ArrayList<>();
6577 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006578 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006579 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006580 for (SubscriptionInfo subInfo : groupInfos) {
6581 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6582 if (subscriberId != null) {
6583 mergedSubscriberIds.add(subscriberId);
6584 }
6585 }
6586
6587 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6588 } finally {
6589 Binder.restoreCallingIdentity(identity);
6590
6591 }
6592 }
6593
6594 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006595 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006596 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006597 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
6601 final Phone phone = getPhone(subId);
6602 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6603 } finally {
6604 Binder.restoreCallingIdentity(identity);
6605 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006606 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006607
6608 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006609 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006610 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6611 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006612 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6613 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614
6615 final long identity = Binder.clearCallingIdentity();
6616 try {
6617 final Phone phone = getPhone(subId);
6618 if (phone == null) {
6619 return false;
6620 }
6621 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6622 cdmaNonRoamingList);
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006625 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006626 }
6627
6628 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006629 @Deprecated
6630 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6631 enforceModifyPermission();
6632
6633 int returnValue = 0;
6634 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006635 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006636 if(result.exception == null) {
6637 if (result.result != null) {
6638 byte[] responseData = (byte[])(result.result);
6639 if(responseData.length > oemResp.length) {
6640 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6641 responseData.length + "bytes. Buffer Size is " +
6642 oemResp.length + "bytes.");
6643 }
6644 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6645 returnValue = responseData.length;
6646 }
6647 } else {
6648 CommandException ex = (CommandException) result.exception;
6649 returnValue = ex.getCommandError().ordinal();
6650 if(returnValue > 0) returnValue *= -1;
6651 }
6652 } catch (RuntimeException e) {
6653 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6654 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6655 if(returnValue > 0) returnValue *= -1;
6656 }
6657
6658 return returnValue;
6659 }
6660
6661 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006662 public void setRadioCapability(RadioAccessFamily[] rafs) {
6663 try {
6664 ProxyController.getInstance().setRadioCapability(rafs);
6665 } catch (RuntimeException e) {
6666 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6667 }
6668 }
6669
6670 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006671 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006672 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006673 try {
6674 TelephonyPermissions
6675 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6676 mApp, phone.getSubId(), "getRadioAccessFamily");
6677 } catch (SecurityException e) {
6678 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6679 throw e;
6680 }
chen xub97461a2018-10-26 14:17:57 -07006681 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006682 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006683 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 final long identity = Binder.clearCallingIdentity();
6686 try {
chen xub97461a2018-10-26 14:17:57 -07006687 TelephonyPermissions
6688 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6689 mApp, phone.getSubId(), "getRadioAccessFamily");
6690 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006691 } finally {
6692 Binder.restoreCallingIdentity(identity);
6693 }
chen xub97461a2018-10-26 14:17:57 -07006694 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006695 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006696
6697 @Override
6698 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006699 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006700 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701
6702 final long identity = Binder.clearCallingIdentity();
6703 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006704 ImsManager.getInstance(defaultPhone.getContext(),
6705 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 } finally {
6707 Binder.restoreCallingIdentity(identity);
6708 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006709 }
6710
6711 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006712 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006713 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6715 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006716 return false;
6717 }
Svet Ganovb320e182015-04-16 12:30:10 -07006718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006719 final long identity = Binder.clearCallingIdentity();
6720 try {
6721 // Check the user preference and the system-level IMS setting. Even if the user has
6722 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6723 // In the long run, we may instead need to check if there exists a connection service
6724 // which can support video calling.
6725 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006726 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727 return imsManager.isVtEnabledByPlatform()
6728 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6729 && imsManager.isVtEnabledByUser();
6730 } finally {
6731 Binder.restoreCallingIdentity(identity);
6732 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006733 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006734
Andrew Leea1239f22015-03-02 17:44:07 -08006735 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006736 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6737 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006739 mApp, subId, callingPackage, callingFeatureId,
6740 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741 return false;
6742 }
6743
6744 final long identity = Binder.clearCallingIdentity();
6745 try {
6746 CarrierConfigManager configManager =
6747 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006748 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
Andrew Leea1239f22015-03-02 17:44:07 -08006753 }
6754
6755 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006756 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006758 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 return false;
6760 }
6761
6762 final long identity = Binder.clearCallingIdentity();
6763 try {
6764 CarrierConfigManager configManager =
6765 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006766 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
6770 }
Andrew Leea1239f22015-03-02 17:44:07 -08006771 }
6772
Andrew Lee9431b832015-03-09 18:46:45 -07006773 @Override
6774 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006775 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006776 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006777 }
6778
6779 @Override
6780 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 final long identity = Binder.clearCallingIdentity();
6782 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006783 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
Andrew Lee9431b832015-03-09 18:46:45 -07006787 }
6788
Hall Liuf6668912018-10-31 17:05:23 -07006789 /**
6790 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6791 * support for the feature and device firmware support.
6792 *
6793 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6794 */
6795 @Override
6796 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006798 final Phone phone = getPhone(subscriptionId);
6799 if (phone == null) {
6800 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6801 return false;
6802 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006804 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6806 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006807 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006808 return isCarrierSupported && isDeviceSupported;
6809 } finally {
6810 Binder.restoreCallingIdentity(identity);
6811 }
Hall Liu98187582018-01-22 19:15:32 -08006812 }
6813
Hall Liuf6668912018-10-31 17:05:23 -07006814 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006815 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6816 * RTT setting, will return true if the device and carrier both support RTT.
6817 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006818 */
6819 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820 final long identity = Binder.clearCallingIdentity();
6821 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006822 boolean isRttSupported = isRttSupported(subscriptionId);
6823 boolean isUserRttSettingOn = Settings.Secure.getInt(
6824 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6825 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6826 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6827 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828 } finally {
6829 Binder.restoreCallingIdentity(identity);
6830 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006831 }
6832
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006833 @Deprecated
6834 @Override
6835 public String getDeviceId(String callingPackage) {
6836 return getDeviceIdWithFeature(callingPackage, null);
6837 }
6838
Sanket Padawe7310cc72015-01-14 09:53:20 -08006839 /**
6840 * Returns the unique device ID of phone, for example, the IMEI for
6841 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6842 *
6843 * <p>Requires Permission:
6844 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6845 */
6846 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006847 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006848 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006849 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006850 return null;
6851 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006852 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006853 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006854 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006855 return null;
6856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857
6858 final long identity = Binder.clearCallingIdentity();
6859 try {
6860 return phone.getDeviceId();
6861 } finally {
6862 Binder.restoreCallingIdentity(identity);
6863 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006864 }
6865
Ping Sunc67b7c22016-03-02 19:16:45 +08006866 /**
6867 * {@hide}
6868 * Returns the IMS Registration Status on a particular subid
6869 *
6870 * @param subId
6871 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006872 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006873 Phone phone = getPhone(subId);
6874 if (phone != null) {
6875 return phone.isImsRegistered();
6876 } else {
6877 return false;
6878 }
6879 }
6880
Santos Cordon7a1885b2015-02-03 11:15:19 -08006881 @Override
6882 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 final long identity = Binder.clearCallingIdentity();
6884 try {
6885 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6886 } finally {
6887 Binder.restoreCallingIdentity(identity);
6888 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006889 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006890
Tyler Gunnf70ed162019-04-03 15:28:53 -07006891 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006892 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006893 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006895 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006896 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6897 }
6898 final long identity = Binder.clearCallingIdentity();
6899 try {
6900 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6901 } finally {
6902 Binder.restoreCallingIdentity(identity);
6903 }
6904 }
6905
6906 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006907 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006908 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6909 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006910 final long identity = Binder.clearCallingIdentity();
6911 try {
6912 Phone phone = getPhone(subscriptionId);
6913 if (phone == null) {
6914 return null;
6915 }
6916 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6917 } finally {
6918 Binder.restoreCallingIdentity(identity);
6919 }
6920 }
6921
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006922 /**
6923 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006924 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006925 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 Phone phone = getPhone(subId);
6929 if (phone != null) {
6930 return phone.isWifiCallingEnabled();
6931 } else {
6932 return false;
6933 }
6934 } finally {
6935 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006936 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006937 }
6938
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006939 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006940 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006941 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006942 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943 final long identity = Binder.clearCallingIdentity();
6944 try {
6945 Phone phone = getPhone(subId);
6946 if (phone != null) {
6947 return phone.isVideoEnabled();
6948 } else {
6949 return false;
6950 }
6951 } finally {
6952 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006953 }
6954 }
6955
6956 /**
6957 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6958 * defined in {@link ImsRegistrationImplBase}.
6959 */
6960 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006961 final long identity = Binder.clearCallingIdentity();
6962 try {
6963 Phone phone = getPhone(subId);
6964 if (phone != null) {
6965 return phone.getImsRegistrationTech();
6966 } else {
6967 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6968 }
6969 } finally {
6970 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006971 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006972 }
6973
Stuart Scott8eef64f2015-04-08 15:13:54 -07006974 @Override
6975 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006976 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006977 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6978 return;
6979 }
6980
Svet Ganovcc087f82015-05-12 20:35:54 -07006981 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006982
Svet Ganovcc087f82015-05-12 20:35:54 -07006983 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006984 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6985 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006986 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006987 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006988 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006989 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006990 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6991 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006992 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006993 // There has been issues when Sms raw table somehow stores orphan
6994 // fragments. They lead to garbled message when new fragments come
6995 // in and combined with those stale ones. In case this happens again,
6996 // user can reset all network settings which will clean up this table.
6997 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006998 // Clean up IMS settings as well here.
6999 int slotId = getSlotIndex(subId);
7000 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7001 ImsManager.getInstance(mApp, slotId).factoryReset();
7002 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007003
7004 // Erase modem config if erase modem on network setting is enabled.
7005 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7006 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7007 if (configValue != null && Boolean.parseBoolean(configValue)) {
7008 sendEraseModemConfig(getDefaultPhone());
7009 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007010 } finally {
7011 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007012 }
7013 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007014
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007015 private void cleanUpSmsRawTable(Context context) {
7016 ContentResolver resolver = context.getContentResolver();
7017 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7018 resolver.delete(uri, null, null);
7019 }
7020
Narayan Kamath1c496c22015-04-16 14:40:19 +01007021 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007022 public String getSimLocaleForSubscriber(int subId) {
7023 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7024 final Phone phone = getPhone(subId);
7025 if (phone == null) {
7026 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007027 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 final long identity = Binder.clearCallingIdentity();
7030 try {
chen xu5d3637b2019-01-21 23:31:38 -08007031 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007032 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007033 if (info == null) {
7034 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7035 return null;
7036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037 // Try and fetch the locale from the carrier properties or from the SIM language
7038 // preferences (EF-PL and EF-LI)...
7039 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007041 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7042 if (localeFromDefaultSim != null) {
7043 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7044 if (DBG) log("Using locale from subId: " + subId + " locale: "
7045 + localeFromDefaultSim);
7046 return localeFromDefaultSim.toLanguageTag();
7047 } else {
7048 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 }
7050 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 // The SIM language preferences only store a language (e.g. fr = French), not an
7053 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7054 // the SIM and carrier preferences does not include a country we add the country
7055 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007056 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007058 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 return mccLocale.toLanguageTag();
7060 }
7061
7062 if (DBG) log("No locale found - returning null");
7063 return null;
7064 } finally {
7065 Binder.restoreCallingIdentity(identity);
7066 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007067 }
7068
7069 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007070 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007071 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007072 }
7073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 /**
7075 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7076 */
7077 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007078 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007079 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007080 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007081
Chenjie Yu1ba97252018-01-11 18:16:20 -08007082 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007083 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007084
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007085 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007086 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7087 * representing the state of the modem.
7088 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007089 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7090 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007091 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007092 */
7093 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007094 public void requestModemActivityInfo(ResultReceiver result) {
7095 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007096 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097
7098 final long identity = Binder.clearCallingIdentity();
7099 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007100 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101 } finally {
7102 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007103 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007104 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007105
Siddharth Rayb8114062018-06-17 15:02:38 -07007106 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7107 // less than total activity duration.
7108 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7109 if (info == null) {
7110 return false;
7111 }
7112 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007113 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7114 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7115
Siddharth Rayb8114062018-06-17 15:02:38 -07007116 return (info.isValid()
7117 && (info.getSleepTimeMillis() <= activityDurationMs)
7118 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007119 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007120 && (totalTxTimeMs <= activityDurationMs));
7121 }
7122
Jack Yu85bd38a2015-11-09 11:34:32 -08007123 /**
7124 * {@hide}
7125 * Returns the service state information on specified subscription.
7126 */
7127 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007128 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7129 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007131 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007132 return null;
7133 }
7134
Hall Liuf19c44f2018-11-27 14:38:17 -08007135 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7136 LocationAccessPolicy.checkLocationPermission(mApp,
7137 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7138 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007139 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007140 .setCallingPid(Binder.getCallingPid())
7141 .setCallingUid(Binder.getCallingUid())
7142 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007143 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007144 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007145 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7146 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007147 .build());
7148
7149 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7150 LocationAccessPolicy.checkLocationPermission(mApp,
7151 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7152 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007153 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007154 .setCallingPid(Binder.getCallingPid())
7155 .setCallingUid(Binder.getCallingUid())
7156 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007157 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007158 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007159 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7160 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007161 .build());
7162 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7163 boolean hasFinePermission =
7164 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7165 boolean hasCoarsePermission =
7166 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168 final long identity = Binder.clearCallingIdentity();
7169 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007170 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7171 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7172 Rlog.d(LOG_TAG,
7173 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7174 return null;
7175 }
7176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177 final Phone phone = getPhone(subId);
7178 if (phone == null) {
7179 return null;
7180 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007181
Hall Liuf19c44f2018-11-27 14:38:17 -08007182 ServiceState ss = phone.getServiceState();
7183
7184 // Scrub out the location info in ServiceState depending on what level of access
7185 // the caller has.
7186 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007187 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7188 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 } finally {
7190 Binder.restoreCallingIdentity(identity);
7191 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007192 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007193
7194 /**
7195 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7196 *
7197 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7198 * voicemail ringtone.
7199 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7200 * PhoneAccount.
7201 */
7202 @Override
7203 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 final long identity = Binder.clearCallingIdentity();
7205 try {
7206 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7207 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007208 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7212 } finally {
7213 Binder.restoreCallingIdentity(identity);
7214 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007215 }
7216
7217 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007218 * Sets the per-account voicemail ringtone.
7219 *
7220 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7221 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7222 *
7223 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7224 * voicemail ringtone.
7225 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7226 * PhoneAccount.
7227 */
7228 @Override
7229 public void setVoicemailRingtoneUri(String callingPackage,
7230 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007231 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007232 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007233 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7234 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7236 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7237 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239
7240 final long identity = Binder.clearCallingIdentity();
7241 try {
7242 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7243 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007244 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007245 }
7246 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7247 } finally {
7248 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007249 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007250 }
7251
7252 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007253 * Returns whether vibration is set for voicemail notification in Phone settings.
7254 *
7255 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7256 * voicemail vibration setting.
7257 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7258 */
7259 @Override
7260 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7264 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007265 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007268 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7269 } finally {
7270 Binder.restoreCallingIdentity(identity);
7271 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007272 }
7273
Youhan Wange64578a2016-05-02 15:32:42 -07007274 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007275 * Sets the per-account voicemail vibration.
7276 *
7277 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7278 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7279 *
7280 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7281 * voicemail vibration setting.
7282 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7283 * specific PhoneAccount.
7284 */
7285 @Override
7286 public void setVoicemailVibrationEnabled(String callingPackage,
7287 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007288 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007289 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007290 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7291 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7293 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7294 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007295 }
7296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297 final long identity = Binder.clearCallingIdentity();
7298 try {
7299 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7300 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007301 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 }
7303 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007306 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007307 }
7308
7309 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007310 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7311 *
7312 * @throws SecurityException if the caller does not have the required permission
7313 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007314 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007315 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007316 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007317 }
7318
7319 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007320 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7321 * permission.
7322 *
7323 * @throws SecurityException if the caller does not have the required permission
7324 */
7325 private void enforceSendSmsPermission() {
7326 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7327 }
7328
7329 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007330 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007331 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007332 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007333 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007334 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 final long identity = Binder.clearCallingIdentity();
7336 try {
7337 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007338 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007339 if (componentName == null) {
7340 throw new SecurityException(
7341 "Caller not current active visual voicemail package[null]");
7342 }
7343 String vvmPackage = componentName.getPackageName();
7344 if (!callingPackage.equals(vvmPackage)) {
7345 throw new SecurityException("Caller not current active visual voicemail package["
7346 + vvmPackage + "]");
7347 }
7348 } finally {
7349 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007350 }
7351 }
7352
7353 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007354 * Return the application ID for the app type.
7355 *
7356 * @param subId the subscription ID that this request applies to.
7357 * @param appType the uicc app type.
7358 * @return Application ID for specificied app type, or null if no uicc.
7359 */
7360 @Override
7361 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007362 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007363 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364
7365 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007366 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 if (phone == null) {
7368 return null;
7369 }
7370 String aid = null;
7371 try {
7372 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7373 .getApplicationByType(appType).getAid();
7374 } catch (Exception e) {
7375 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7376 }
7377 return aid;
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007380 }
Youhan Wange64578a2016-05-02 15:32:42 -07007381 }
7382
Youhan Wang4001d252016-05-11 10:29:41 -07007383 /**
7384 * Return the Electronic Serial Number.
7385 *
7386 * @param subId the subscription ID that this request applies to.
7387 * @return ESN or null if error.
7388 */
7389 @Override
7390 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007391 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007392 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393
7394 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007395 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 if (phone == null) {
7397 return null;
7398 }
7399 String esn = null;
7400 try {
7401 esn = phone.getEsn();
7402 } catch (Exception e) {
7403 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7404 }
7405 return esn;
7406 } finally {
7407 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007408 }
Youhan Wang4001d252016-05-11 10:29:41 -07007409 }
7410
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007411 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007412 * Return the Preferred Roaming List Version.
7413 *
7414 * @param subId the subscription ID that this request applies to.
7415 * @return PRLVersion or null if error.
7416 */
7417 @Override
7418 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007419 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007420 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421
7422 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007423 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 if (phone == null) {
7425 return null;
7426 }
7427 String cdmaPrlVersion = null;
7428 try {
7429 cdmaPrlVersion = phone.getCdmaPrlVersion();
7430 } catch (Exception e) {
7431 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7432 }
7433 return cdmaPrlVersion;
7434 } finally {
7435 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007436 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007437 }
7438
7439 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007440 * Get snapshot of Telephony histograms
7441 * @return List of Telephony histograms
7442 * @hide
7443 */
7444 @Override
7445 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7447 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448
7449 final long identity = Binder.clearCallingIdentity();
7450 try {
7451 return RIL.getTelephonyRILTimingHistograms();
7452 } finally {
7453 Binder.restoreCallingIdentity(identity);
7454 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007455 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007456
7457 /**
7458 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007459 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7460 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007461 * Require system privileges. In the future we may add this to carrier APIs.
7462 *
Michele Berionne482f8202018-11-27 18:57:59 -08007463 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007464 */
7465 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007466 @TelephonyManager.SetCarrierRestrictionResult
7467 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007468 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007469 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007470
Michele Berionne482f8202018-11-27 18:57:59 -08007471 if (carrierRestrictionRules == null) {
7472 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007473 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 final long identity = Binder.clearCallingIdentity();
7476 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007477 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007478 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 } finally {
7480 Binder.restoreCallingIdentity(identity);
7481 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007482 }
7483
7484 /**
7485 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007486 * Get the allowed carrier list and the excluded carrier list, including the priority between
7487 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007488 * Require system privileges. In the future we may add this to carrier APIs.
7489 *
Michele Berionne482f8202018-11-27 18:57:59 -08007490 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007491 */
7492 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007493 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007494 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007495 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496
7497 final long identity = Binder.clearCallingIdentity();
7498 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007499 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7500 if (response instanceof CarrierRestrictionRules) {
7501 return (CarrierRestrictionRules) response;
7502 }
7503 // Response is an Exception of some kind,
7504 // which is signalled to the user as a NULL retval
7505 return null;
7506 } catch (Exception e) {
7507 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7508 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007512 }
7513
fionaxu59545b42016-05-25 15:53:37 -07007514 /**
fionaxu59545b42016-05-25 15:53:37 -07007515 * Action set from carrier signalling broadcast receivers to enable/disable radio
7516 * @param subId the subscription ID that this action applies to.
7517 * @param enabled control enable or disable radio.
7518 * {@hide}
7519 */
7520 @Override
7521 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7522 enforceModifyPermission();
7523 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524
7525 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007526 if (phone == null) {
7527 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7528 return;
7529 }
7530 try {
7531 phone.carrierActionSetRadioEnabled(enabled);
7532 } catch (Exception e) {
7533 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 } finally {
7535 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007536 }
7537 }
7538
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007539 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007540 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7541 * network status based on which carrier apps could apply actions accordingly,
7542 * enable/disable default url handler for example.
7543 *
7544 * @param subId the subscription ID that this action applies to.
7545 * @param report control start/stop reporting the default network status.
7546 * {@hide}
7547 */
7548 @Override
7549 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7550 enforceModifyPermission();
7551 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552
7553 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007554 if (phone == null) {
7555 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7556 return;
7557 }
7558 try {
7559 phone.carrierActionReportDefaultNetworkStatus(report);
7560 } catch (Exception e) {
7561 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 } finally {
7563 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007564 }
7565 }
7566
7567 /**
fionaxud9622282017-07-17 17:51:30 -07007568 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7569 * @param subId the subscription ID that this action applies to.
7570 * {@hide}
7571 */
7572 @Override
7573 public void carrierActionResetAll(int subId) {
7574 enforceModifyPermission();
7575 final Phone phone = getPhone(subId);
7576 if (phone == null) {
7577 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7578 return;
7579 }
7580 try {
7581 phone.carrierActionResetAll();
7582 } catch (Exception e) {
7583 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7584 }
7585 }
7586
7587 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007588 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7589 * bug report is being generated.
7590 */
7591 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007592 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007593 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7594 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007595 writer.println("Permission Denial: can't dump Phone from pid="
7596 + Binder.getCallingPid()
7597 + ", uid=" + Binder.getCallingUid()
7598 + "without permission "
7599 + android.Manifest.permission.DUMP);
7600 return;
7601 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007602 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007603 }
Jack Yueb89b242016-06-22 13:27:47 -07007604
Brad Ebingerdac2f002018-04-03 15:17:52 -07007605 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007606 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7607 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7608 @NonNull String[] args) {
7609 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7610 this, in.getFileDescriptor(), out.getFileDescriptor(),
7611 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007612 }
7613
Jack Yueb89b242016-06-22 13:27:47 -07007614 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007615 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007616 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007617 * @param reason the reason the data enable change is taking place
7618 * @param enabled True if enabling the data, otherwise disabling.
7619 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007620 */
7621 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007622 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007623 boolean enabled) {
7624 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7625 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7626 try {
7627 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007628 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007629 } catch (SecurityException se) {
7630 enforceModifyPermission();
7631 }
7632 } else {
7633 enforceModifyPermission();
7634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007635
7636 final long identity = Binder.clearCallingIdentity();
7637 try {
7638 Phone phone = getPhone(subId);
7639 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007640 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7641 phone.carrierActionSetMeteredApnsEnabled(enabled);
7642 } else {
7643 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645 }
7646 } finally {
7647 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007648 }
7649 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007650
7651 /**
7652 * Get Client request stats
7653 * @return List of Client Request Stats
7654 * @hide
7655 */
7656 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007657 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7658 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007660 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007661 return null;
7662 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007663 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665 final long identity = Binder.clearCallingIdentity();
7666 try {
7667 if (phone != null) {
7668 return phone.getClientRequestStats();
7669 }
7670
7671 return null;
7672 } finally {
7673 Binder.restoreCallingIdentity(identity);
7674 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007675 }
7676
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007677 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007678 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007679 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007680 }
Jack Yueb4124c2017-02-16 15:32:43 -08007681
7682 /**
Grace Chen70990072017-03-24 17:21:30 -07007683 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007684 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007685 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007686 * @param state State of SIM (power down, power up, pass through)
7687 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7688 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7689 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007690 *
7691 **/
7692 @Override
Grace Chen70990072017-03-24 17:21:30 -07007693 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007694 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007695 Phone phone = PhoneFactory.getPhone(slotIndex);
7696
vagdeviaf9a5b92018-08-15 16:01:53 -07007697 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 final long identity = Binder.clearCallingIdentity();
7700 try {
7701 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007702 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703 }
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007706 }
7707 }
Shuo Qiandd210312017-04-12 22:11:33 +00007708
Tyler Gunn65d45c22017-06-05 11:22:26 -07007709 private boolean isUssdApiAllowed(int subId) {
7710 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007711 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007712 if (configManager == null) {
7713 return false;
7714 }
7715 PersistableBundle pb = configManager.getConfigForSubId(subId);
7716 if (pb == null) {
7717 return false;
7718 }
7719 return pb.getBoolean(
7720 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7721 }
7722
Shuo Qiandd210312017-04-12 22:11:33 +00007723 /**
7724 * Check if phone is in emergency callback mode
7725 * @return true if phone is in emergency callback mode
7726 * @param subId sub id
7727 */
goneil9c5f4872017-12-05 14:07:56 -08007728 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007729 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007730 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007731 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732
7733 final long identity = Binder.clearCallingIdentity();
7734 try {
7735 if (phone != null) {
7736 return phone.isInEcm();
7737 } else {
7738 return false;
7739 }
7740 } finally {
7741 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007742 }
7743 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007744
7745 /**
7746 * Get the current signal strength information for the given subscription.
7747 * Because this information is not updated when the device is in a low power state
7748 * it should not be relied-upon to be current.
7749 * @param subId Subscription index
7750 * @return the most recent cached signal strength info from the modem
7751 */
7752 @Override
7753 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754 final long identity = Binder.clearCallingIdentity();
7755 try {
7756 Phone p = getPhone(subId);
7757 if (p == null) {
7758 return null;
7759 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007760
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 return p.getSignalStrength();
7762 } finally {
7763 Binder.restoreCallingIdentity(identity);
7764 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007765 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007766
Pengquan Meng77b7f132018-08-22 14:49:57 -07007767 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007768 * Get the current modem radio state for the given slot.
7769 * @param slotIndex slot index.
7770 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007771 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007772 * @return the current radio power state from the modem
7773 */
7774 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007775 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007776 Phone phone = PhoneFactory.getPhone(slotIndex);
7777 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7779 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007780 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7781 }
7782
7783 final long identity = Binder.clearCallingIdentity();
7784 try {
7785 return phone.getRadioPowerState();
7786 } finally {
7787 Binder.restoreCallingIdentity(identity);
7788 }
7789 }
7790 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7791 }
7792
7793 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007794 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7795 *
7796 * <p>Requires one of the following permissions:
7797 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7798 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7799 * privileges.
7800 *
7801 * @param subId subscription id
7802 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7803 * {@code false}.
7804 */
7805 @Override
7806 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007807 try {
7808 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7809 null);
7810 } catch (Exception e) {
7811 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7812 mApp, subId, "isDataRoamingEnabled");
7813 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007814
Pengquan Menga1bb6272018-09-06 09:59:22 -07007815 boolean isEnabled = false;
7816 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007817 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007818 Phone phone = getPhone(subId);
7819 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007820 } finally {
7821 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007822 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007823 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007824 }
7825
7826
7827 /**
7828 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7829 *
7830 * <p> Requires permission:
7831 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7832 * privileges.
7833 *
7834 * @param subId subscription id
7835 * @param isEnabled {@code true} means enable, {@code false} means disable.
7836 */
7837 @Override
7838 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7840 mApp, subId, "setDataRoamingEnabled");
7841
Pengquan Menga1bb6272018-09-06 09:59:22 -07007842 final long identity = Binder.clearCallingIdentity();
7843 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007844 Phone phone = getPhone(subId);
7845 if (phone != null) {
7846 phone.setDataRoamingEnabled(isEnabled);
7847 }
7848 } finally {
7849 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007850 }
7851 }
7852
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007853 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007854 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007855 TelephonyPermissions
7856 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007857 mApp, subId, "isManualNetworkSelectionAllowed");
7858
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007859 boolean isAllowed = true;
7860 final long identity = Binder.clearCallingIdentity();
7861 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007862 Phone phone = getPhone(subId);
7863 if (phone != null) {
7864 isAllowed = phone.isCspPlmnEnabled();
7865 }
7866 } finally {
7867 Binder.restoreCallingIdentity(identity);
7868 }
7869 return isAllowed;
7870 }
7871
7872 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007873 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007874 // Verify that tha callingPackage belongs to the calling UID
7875 mApp.getSystemService(AppOpsManager.class)
7876 .checkPackage(Binder.getCallingUid(), callingPackage);
7877
Jordan Liu1e142fc2019-04-22 15:10:43 -07007878 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007879 try {
7880 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007881 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007882 } catch (SecurityException e) {
7883 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7884 // has carrier privileges on an active UICC
7885 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7886 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007887 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007888 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007889 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007890
7891 final long identity = Binder.clearCallingIdentity();
7892 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007893 UiccController uiccController = UiccController.getInstance();
7894 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007895 if (hasReadPermission) {
7896 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007897 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007898
7899 // Remove private info if the caller doesn't have access
7900 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7901 for (UiccCardInfo cardInfo : cardInfos) {
7902 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7903 // is available
7904 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7905 if (card == null || card.getUiccProfile() == null) {
7906 // assume no access if the card or profile is unavailable
7907 filteredInfos.add(cardInfo.getUnprivileged());
7908 continue;
7909 }
7910 UiccProfile profile = card.getUiccProfile();
7911 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7912 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7913 filteredInfos.add(cardInfo);
7914 } else {
7915 filteredInfos.add(cardInfo.getUnprivileged());
7916 }
7917 }
7918 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007919 } finally {
7920 Binder.restoreCallingIdentity(identity);
7921 }
7922 }
7923
7924 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007925 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007926 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007928 final long identity = Binder.clearCallingIdentity();
7929 try {
7930 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7931 if (slots == null) {
7932 Rlog.i(LOG_TAG, "slots is null.");
7933 return null;
7934 }
7935
7936 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7937 for (int i = 0; i < slots.length; i++) {
7938 UiccSlot slot = slots[i];
7939 if (slot == null) {
7940 continue;
7941 }
7942
Jordan Liu7be7e652019-05-06 18:55:02 +00007943 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007944 UiccCard card = slot.getUiccCard();
7945 if (card != null) {
7946 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007947 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007948 cardId = slot.getEid();
7949 if (TextUtils.isEmpty(cardId)) {
7950 cardId = slot.getIccId();
7951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 }
7953
Jordan Liu857451f2019-05-09 16:35:35 -07007954 if (cardId != null) {
7955 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7956 // if cardId is an EID, it's all digits so this is fine
7957 cardId = IccUtils.stripTrailingFs(cardId);
7958 }
7959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007960 int cardState = 0;
7961 switch (slot.getCardState()) {
7962 case CARDSTATE_ABSENT:
7963 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7964 break;
7965 case CARDSTATE_PRESENT:
7966 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7967 break;
7968 case CARDSTATE_ERROR:
7969 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7970 break;
7971 case CARDSTATE_RESTRICTED:
7972 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7973 break;
7974 default:
7975 break;
7976
7977 }
7978
7979 infos[i] = new UiccSlotInfo(
7980 slot.isActive(),
7981 slot.isEuicc(),
7982 cardId,
7983 cardState,
7984 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007985 slot.isExtendedApduSupported(),
7986 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987 }
7988 return infos;
7989 } finally {
7990 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007991 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007992 }
7993
7994 @Override
7995 public boolean switchSlots(int[] physicalSlots) {
7996 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997
7998 final long identity = Binder.clearCallingIdentity();
7999 try {
8000 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8001 } finally {
8002 Binder.restoreCallingIdentity(identity);
8003 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008004 }
Jack Yu4c988042018-02-27 15:30:01 -08008005
8006 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008007 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008008 final long identity = Binder.clearCallingIdentity();
8009 try {
8010 return UiccController.getInstance().getCardIdForDefaultEuicc();
8011 } finally {
8012 Binder.restoreCallingIdentity(identity);
8013 }
8014 }
8015
Pengquan Meng85728fb2018-03-12 16:31:21 -07008016 /**
goneil47ffb6e2018-04-06 15:40:58 -07008017 * A test API to reload the UICC profile.
8018 *
8019 * <p>Requires that the calling app has permission
8020 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8021 * @hide
8022 */
8023 @Override
8024 public void refreshUiccProfile(int subId) {
8025 enforceModifyPermission();
8026
8027 final long identity = Binder.clearCallingIdentity();
8028 try {
8029 Phone phone = getPhone(subId);
8030 if (phone == null) {
8031 return;
8032 }
8033 UiccCard uiccCard = phone.getUiccCard();
8034 if (uiccCard == null) {
8035 return;
8036 }
8037 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8038 if (uiccProfile == null) {
8039 return;
8040 }
8041 uiccProfile.refresh();
8042 } finally {
8043 Binder.restoreCallingIdentity(identity);
8044 }
8045 }
8046
8047 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008048 * Returns false if the mobile data is disabled by default, otherwise return true.
8049 */
8050 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008051 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008052 }
8053
8054 /**
8055 * Returns true if the data roaming is enabled by default, i.e the system property
8056 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8057 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8058 */
8059 private boolean getDefaultDataRoamingEnabled(int subId) {
8060 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008061 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008062 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008063 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8064 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8065 return isDataRoamingEnabled;
8066 }
8067
8068 /**
8069 * Returns the default network type for the given {@code subId}, if the default network type is
8070 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8071 */
8072 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008073 List<Integer> list = TelephonyProperties.default_network();
8074 int phoneId = mSubscriptionController.getPhoneId(subId);
8075 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8076 return list.get(phoneId);
8077 }
8078 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008079 }
fionaxua13278b2018-03-21 00:08:13 -07008080
8081 @Override
8082 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008083 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008084 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085
8086 final long identity = Binder.clearCallingIdentity();
8087 try {
8088 final Phone phone = getPhone(subId);
8089 if (phone == null) {
8090 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8091 return;
8092 }
chen xueaba88a2019-03-15 13:15:10 -07008093 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8094 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008095 if (carrierPrivilegeRules == null) {
8096 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8097 } else {
8098 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8099 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008100 } finally {
8101 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008102 }
fionaxua13278b2018-03-21 00:08:13 -07008103 }
8104
8105 @Override
8106 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008107 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108
8109 final long identity = Binder.clearCallingIdentity();
8110 try {
8111 final Phone phone = getPhone(subId);
8112 if (phone == null) {
8113 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8114 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8115 }
8116 return phone.getCarrierIdListVersion();
8117 } finally {
8118 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008119 }
fionaxua13278b2018-03-21 00:08:13 -07008120 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008121
8122 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008123 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8124 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008125 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008126 mApp, subId, callingPackage, callingFeatureId,
8127 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008128 return -1;
8129 }
8130
8131 final long identity = Binder.clearCallingIdentity();
8132 try {
8133 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8134 } finally {
8135 Binder.restoreCallingIdentity(identity);
8136 }
8137 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008138
8139 @Override
8140 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008141 TelephonyPermissions
8142 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008143 mApp, subId, "getCdmaRoamingMode");
8144
8145 final long identity = Binder.clearCallingIdentity();
8146 try {
8147 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
8150 }
8151 }
8152
8153 @Override
8154 public boolean setCdmaRoamingMode(int subId, int mode) {
8155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8156 mApp, subId, "setCdmaRoamingMode");
8157
8158 final long identity = Binder.clearCallingIdentity();
8159 try {
8160 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8161 } finally {
8162 Binder.restoreCallingIdentity(identity);
8163 }
8164 }
8165
8166 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008167 public int getCdmaSubscriptionMode(int subId) {
8168 TelephonyPermissions
8169 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8170 mApp, subId, "getCdmaSubscriptionMode");
8171
8172 final long identity = Binder.clearCallingIdentity();
8173 try {
8174 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8175 } finally {
8176 Binder.restoreCallingIdentity(identity);
8177 }
8178 }
8179
8180 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008181 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8183 mApp, subId, "setCdmaSubscriptionMode");
8184
8185 final long identity = Binder.clearCallingIdentity();
8186 try {
8187 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8188 } finally {
8189 Binder.restoreCallingIdentity(identity);
8190 }
8191 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008192
sqianc5eccab2018-10-19 18:46:41 -07008193 @Override
sqian8c685422019-02-22 15:55:18 -08008194 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008195 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008197 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8198 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008199 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8200 }
8201 final long identity = Binder.clearCallingIdentity();
8202 try {
sqian854d44b2018-12-12 16:48:18 -08008203 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8204 for (Phone phone: PhoneFactory.getPhones()) {
8205 if (phone.getEmergencyNumberTracker() != null
8206 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8207 emergencyNumberListInternal.put(
8208 phone.getSubId(),
8209 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8210 }
sqian11b7a0e2018-12-05 18:48:28 -08008211 }
sqian854d44b2018-12-12 16:48:18 -08008212 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008213 } finally {
8214 Binder.restoreCallingIdentity(identity);
8215 }
sqianc5eccab2018-10-19 18:46:41 -07008216 }
8217
8218 @Override
sqian8c685422019-02-22 15:55:18 -08008219 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008220 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008221 if (!exactMatch) {
8222 TelephonyPermissions
8223 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008224 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008225 }
8226 final long identity = Binder.clearCallingIdentity();
8227 try {
sqian854d44b2018-12-12 16:48:18 -08008228 for (Phone phone: PhoneFactory.getPhones()) {
8229 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008230 && phone.getEmergencyNumberTracker()
8231 .isEmergencyNumber(number, exactMatch)) {
8232 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008233 }
sqian11b7a0e2018-12-05 18:48:28 -08008234 }
8235 return false;
8236 } finally {
8237 Binder.restoreCallingIdentity(identity);
8238 }
8239 }
8240
sqianf4ca7ed2019-01-15 18:32:07 -08008241 /**
8242 * Update emergency number list for test mode.
8243 */
8244 @Override
8245 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8246 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8247 "updateEmergencyNumberListTestMode");
8248
8249 final long identity = Binder.clearCallingIdentity();
8250 try {
8251 for (Phone phone: PhoneFactory.getPhones()) {
8252 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8253 if (tracker != null) {
8254 tracker.executeEmergencyNumberTestModeCommand(action, num);
8255 }
8256 }
8257 } finally {
8258 Binder.restoreCallingIdentity(identity);
8259 }
8260 }
8261
8262 /**
8263 * Get the full emergency number list for test mode.
8264 */
8265 @Override
8266 public List<String> getEmergencyNumberListTestMode() {
8267 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8268 "getEmergencyNumberListTestMode");
8269
8270 final long identity = Binder.clearCallingIdentity();
8271 try {
8272 Set<String> emergencyNumbers = new HashSet<>();
8273 for (Phone phone: PhoneFactory.getPhones()) {
8274 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8275 if (tracker != null) {
8276 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8277 emergencyNumbers.add(num.getNumber());
8278 }
8279 }
8280 }
8281 return new ArrayList<>(emergencyNumbers);
8282 } finally {
8283 Binder.restoreCallingIdentity(identity);
8284 }
8285 }
8286
chen xud6b45bd2018-10-30 22:27:10 -07008287 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008288 public int getEmergencyNumberDbVersion(int subId) {
8289 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8290
8291 final long identity = Binder.clearCallingIdentity();
8292 try {
8293 final Phone phone = getPhone(subId);
8294 if (phone == null) {
8295 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8296 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8297 }
8298 return phone.getEmergencyNumberDbVersion();
8299 } finally {
8300 Binder.restoreCallingIdentity(identity);
8301 }
8302 }
8303
8304 @Override
8305 public void notifyOtaEmergencyNumberDbInstalled() {
8306 enforceModifyPermission();
8307
8308 final long identity = Binder.clearCallingIdentity();
8309 try {
8310 for (Phone phone: PhoneFactory.getPhones()) {
8311 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8312 if (tracker != null) {
8313 tracker.updateOtaEmergencyNumberDatabase();
8314 }
8315 }
8316 } finally {
8317 Binder.restoreCallingIdentity(identity);
8318 }
8319 }
8320
8321 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008322 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008323 enforceActiveEmergencySessionPermission();
8324
8325 final long identity = Binder.clearCallingIdentity();
8326 try {
8327 for (Phone phone: PhoneFactory.getPhones()) {
8328 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8329 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008330 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8331 }
8332 }
8333 } finally {
8334 Binder.restoreCallingIdentity(identity);
8335 }
8336 }
8337
8338 @Override
8339 public void resetOtaEmergencyNumberDbFilePath() {
8340 enforceActiveEmergencySessionPermission();
8341
8342 final long identity = Binder.clearCallingIdentity();
8343 try {
8344 for (Phone phone: PhoneFactory.getPhones()) {
8345 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8346 if (tracker != null) {
8347 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008348 }
8349 }
8350 } finally {
8351 Binder.restoreCallingIdentity(identity);
8352 }
8353 }
8354
8355 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008356 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8357 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8358 Phone phone = getPhone(subId);
8359 if (phone == null) {
8360 return null;
8361 }
8362 final long identity = Binder.clearCallingIdentity();
8363 try {
8364 UiccProfile profile = UiccController.getInstance()
8365 .getUiccProfileForPhone(phone.getPhoneId());
8366 if (profile != null) {
8367 return profile.getCertsFromCarrierPrivilegeAccessRules();
8368 }
8369 } finally {
8370 Binder.restoreCallingIdentity(identity);
8371 }
8372 return null;
8373 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008374
8375 /**
8376 * Enable or disable a modem stack.
8377 */
8378 @Override
8379 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8380 enforceModifyPermission();
8381
8382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 Phone phone = PhoneFactory.getPhone(slotIndex);
8385 if (phone == null) {
8386 return false;
8387 } else {
8388 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8389 }
8390 } finally {
8391 Binder.restoreCallingIdentity(identity);
8392 }
8393 }
Michelecea4cf22018-12-21 15:00:11 -08008394
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008395 /**
8396 * Whether a modem stack is enabled or not.
8397 */
8398 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008399 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8400 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008401 Phone phone = PhoneFactory.getPhone(slotIndex);
8402 if (phone == null) return false;
8403
8404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008405 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8406 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008407 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8408 }
8409
8410 final long identity = Binder.clearCallingIdentity();
8411 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008412 try {
8413 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8414 } catch (NoSuchElementException ex) {
8415 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8416 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008417 } finally {
8418 Binder.restoreCallingIdentity(identity);
8419 }
8420 }
8421
Michelecea4cf22018-12-21 15:00:11 -08008422 @Override
Michele0ea7d782019-03-19 14:58:42 -07008423 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008424 enforceModifyPermission();
8425
8426 final long identity = Binder.clearCallingIdentity();
8427 try {
8428 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008429 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008430 .commit();
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
8433 }
8434 }
8435
8436 @Override
Michele0ea7d782019-03-19 14:58:42 -07008437 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008438 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008440 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8441 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008442 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008443 }
Michelecea4cf22018-12-21 15:00:11 -08008444
8445 final long identity = Binder.clearCallingIdentity();
8446 try {
Michele0ea7d782019-03-19 14:58:42 -07008447 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008448 } finally {
8449 Binder.restoreCallingIdentity(identity);
8450 }
8451 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008452
Michele0ea7d782019-03-19 14:58:42 -07008453 @TelephonyManager.IsMultiSimSupportedResult
8454 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008455 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8456 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8457 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008458 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8459 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008460 }
8461 // Check if the hardware supports multisim functionality. If usage of multisim is not
8462 // supported by the modem, indicate that it is restricted.
8463 PhoneCapability staticCapability =
8464 mPhoneConfigurationManager.getStaticPhoneCapability();
8465 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008466 loge("isMultiSimSupportedInternal: no static configuration available");
8467 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008468 }
Sarah Chin7caee492020-02-18 20:49:02 +00008469 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008470 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8471 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008472 }
8473 // Check if support of multiple SIMs is restricted by carrier
8474 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008475 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008476 }
8477
Michele0ea7d782019-03-19 14:58:42 -07008478 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008479 }
8480
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008481 /**
8482 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008483 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8484 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8485 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008486 * @param numOfSims number of active sims we want to switch to
8487 */
8488 @Override
8489 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008490 if (numOfSims == 1) {
8491 enforceModifyPermission();
8492 } else {
8493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8494 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8495 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008496 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008497
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008498 try {
Michele30b57b22019-03-01 12:01:14 -08008499 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008500 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008501 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8502 return;
8503 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008504 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8505 } finally {
8506 Binder.restoreCallingIdentity(identity);
8507 }
8508 }
8509
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008510 @Override
8511 public boolean isApplicationOnUicc(int subId, int appType) {
8512 enforceReadPrivilegedPermission("isApplicationOnUicc");
8513 Phone phone = getPhone(subId);
8514 if (phone == null) {
8515 return false;
8516 }
8517 final long identity = Binder.clearCallingIdentity();
8518 try {
8519 UiccCard uiccCard = phone.getUiccCard();
8520 if (uiccCard == null) {
8521 return false;
8522 }
8523 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8524 if (uiccProfile == null) {
8525 return false;
8526 }
8527 if (TelephonyManager.APPTYPE_SIM <= appType
8528 && appType <= TelephonyManager.APPTYPE_ISIM) {
8529 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8530 }
8531 return false;
8532 } finally {
8533 Binder.restoreCallingIdentity(identity);
8534 }
8535 }
8536
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008537 /**
chen xub4baa772019-04-03 10:23:41 -07008538 * Get whether making changes to modem configurations will trigger reboot.
8539 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008540 */
8541 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008542 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8543 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008545 mApp, subId, callingPackage, callingFeatureId,
8546 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008547 return false;
8548 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008549 final long identity = Binder.clearCallingIdentity();
8550 try {
8551 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
8554 }
8555 }
8556
Nathan Harold29f5f052019-02-15 13:41:57 -08008557 private void updateModemStateMetrics() {
8558 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8559 // TODO: check the state for each modem if the api is ready.
8560 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8561 }
8562
Pengquan Meng3889a572019-01-23 11:16:29 -08008563 @Override
8564 public int[] getSlotsMapping() {
8565 enforceReadPrivilegedPermission("getSlotsMapping");
8566
8567 final long identity = Binder.clearCallingIdentity();
8568 try {
8569 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8570 // All logical slots should have a mapping to a physical slot.
8571 int[] logicalSlotsMapping = new int[phoneCount];
8572 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8573 for (int i = 0; i < slotInfos.length; i++) {
8574 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8575 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8576 }
8577 }
8578 return logicalSlotsMapping;
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
8581 }
8582 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008583
8584 /**
8585 * Get the IRadio HAL Version
8586 */
8587 @Override
8588 public int getRadioHalVersion() {
8589 Phone phone = getDefaultPhone();
8590 if (phone == null) return -1;
8591 HalVersion hv = phone.getHalVersion();
8592 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8593 return hv.major * 100 + hv.minor;
8594 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008595
8596 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008597 * Get the current calling package name.
8598 * @return the current calling package name
8599 */
8600 @Override
8601 public String getCurrentPackageName() {
8602 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8603 }
8604
8605 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008606 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8607 * corresponding network requests on a subId.
8608 *
8609 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008610 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008611 * 2) APN is un-metered for this subscription, or
8612 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008613 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008614 *
8615 * @return whether data is allowed for a apn type.
8616 *
8617 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008618 */
8619 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008620 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008621 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8622 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008623
8624 // Now that all security checks passes, perform the operation as ourselves.
8625 final long identity = Binder.clearCallingIdentity();
8626 try {
8627 Phone phone = getPhone(subId);
8628 if (phone == null) return false;
8629
Jack Yu41407ee2019-05-13 16:54:09 -07008630 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008631 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8632 } finally {
8633 Binder.restoreCallingIdentity(identity);
8634 }
8635 }
8636
8637 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008638 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008639 enforceReadPrivilegedPermission("isApnMetered");
8640
8641 // Now that all security checks passes, perform the operation as ourselves.
8642 final long identity = Binder.clearCallingIdentity();
8643 try {
8644 Phone phone = getPhone(subId);
8645 if (phone == null) return true; // By default return true.
8646
Jack Yu41407ee2019-05-13 16:54:09 -07008647 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008648 } finally {
8649 Binder.restoreCallingIdentity(identity);
8650 }
8651 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008652
8653 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008654 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8655 int subscriptionId, IBooleanConsumer resultCallback) {
8656 enforceModifyPermission();
8657 long token = Binder.clearCallingIdentity();
8658 try {
8659 Phone phone = getPhone(subscriptionId);
8660 if (phone == null) {
8661 try {
8662 if (resultCallback != null) {
8663 resultCallback.accept(false);
8664 }
8665 } catch (RemoteException e) {
8666 // ignore
8667 }
8668 return;
8669 }
8670 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8671 Pair.create(specifiers, (x) -> {
8672 try {
8673 if (resultCallback != null) {
8674 resultCallback.accept(x);
8675 }
8676 } catch (RemoteException e) {
8677 // ignore
8678 }
8679 });
8680 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8681 } finally {
8682 Binder.restoreCallingIdentity(token);
8683 }
8684 }
8685
8686 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008687 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008688 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008689 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8690 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8691 if (iccRecords == null) {
8692 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8693 return false;
8694 }
8695 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8696 }
8697
8698 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008699 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8700 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008701 if (callingPackage == null) {
8702 callingPackage = getCurrentPackageName();
8703 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008704 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8705 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008706 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8707 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008708 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8709 }
8710 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8711 Intent intent = new Intent();
8712 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8713 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8714 // Bring up choose default SMS subscription dialog right now
8715 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8716 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8717 mApp.startActivity(intent);
8718 }
chen xud5ca2d52019-05-28 15:20:57 -07008719
8720 @Override
8721 public String getMmsUAProfUrl(int subId) {
8722 //TODO investigate if this API should require proper permission check in R b/133791609
8723 final long identity = Binder.clearCallingIdentity();
8724 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008725 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8726 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8727 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8728 return carrierUAProfUrl;
8729 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008730 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8731 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008732 } finally {
8733 Binder.restoreCallingIdentity(identity);
8734 }
8735 }
8736
8737 @Override
8738 public String getMmsUserAgent(int subId) {
8739 //TODO investigate if this API should require proper permission check in R b/133791609
8740 final long identity = Binder.clearCallingIdentity();
8741 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008742 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8743 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8744 if (!TextUtils.isEmpty(carrierUserAgent)) {
8745 return carrierUserAgent;
8746 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008747 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8748 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008749 } finally {
8750 Binder.restoreCallingIdentity(identity);
8751 }
8752 }
Jack Yub07d4972019-05-28 16:12:25 -07008753
8754 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008755 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8756 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07008757
Jack Yub07d4972019-05-28 16:12:25 -07008758 final long identity = Binder.clearCallingIdentity();
8759 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008760 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07008761 if (phone == null) return false;
8762
Hall Liua62f5da2020-09-25 10:42:19 -07008763 switch (policy) {
8764 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8765 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8766 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8767 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8768 default:
8769 throw new IllegalArgumentException(policy + " is not a valid policy");
8770 }
Jack Yub07d4972019-05-28 16:12:25 -07008771 } finally {
8772 Binder.restoreCallingIdentity(identity);
8773 }
8774 }
8775
8776 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008777 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8778 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08008779 enforceModifyPermission();
8780
changbettyd5c246e2019-12-24 15:40:37 +08008781 final long identity = Binder.clearCallingIdentity();
8782 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008783 Phone phone = getPhone(subscriptionId);
8784 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08008785
Hall Liua62f5da2020-09-25 10:42:19 -07008786 switch (policy) {
8787 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8788 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8789 break;
8790 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8791 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8792 break;
8793 default:
8794 throw new IllegalArgumentException(policy + " is not a valid policy");
8795 }
changbettyd5c246e2019-12-24 15:40:37 +08008796 } finally {
8797 Binder.restoreCallingIdentity(identity);
8798 }
8799 }
8800
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008801 /**
Hall Liu746e03c2020-09-25 11:13:49 -07008802 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008803 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8804 * otherwise.
8805 */
8806 @Override
8807 public void setCepEnabled(boolean isCepEnabled) {
8808 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8809
8810 final long identity = Binder.clearCallingIdentity();
8811 try {
8812 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8813 for (Phone phone : PhoneFactory.getPhones()) {
8814 Phone defaultPhone = phone.getImsPhone();
8815 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8816 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8817 ImsPhoneCallTracker imsPhoneCallTracker =
8818 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8819 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8820 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8821 + imsPhone.getMsisdn());
8822 }
8823 }
8824 } finally {
8825 Binder.restoreCallingIdentity(identity);
8826 }
8827 }
allenwtsu46dcc572020-01-08 18:24:03 +08008828
8829 /**
8830 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8831 *
8832 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8833 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8834 * before being read.
8835 */
8836 @Override
8837 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8838 isCompressed) {
8839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8840 mApp, subId, "notifyRcsAutoConfigurationReceived");
8841 try {
8842 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8843 if (configBinder == null) {
8844 Rlog.e(LOG_TAG, "null result for getImsConfig");
8845 } else {
8846 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8847 }
8848 } catch (RemoteException e) {
8849 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8850 }
8851 }
zoey chene02881a2019-12-30 16:11:23 +08008852
8853 @Override
8854 public boolean isIccLockEnabled(int subId) {
8855 enforceReadPrivilegedPermission("isIccLockEnabled");
8856
8857 // Now that all security checks passes, perform the operation as ourselves.
8858 final long identity = Binder.clearCallingIdentity();
8859 try {
8860 Phone phone = getPhone(subId);
8861 if (phone != null && phone.getIccCard() != null) {
8862 return phone.getIccCard().getIccLockEnabled();
8863 } else {
8864 return false;
8865 }
8866 } finally {
8867 Binder.restoreCallingIdentity(identity);
8868 }
8869 }
8870
8871 /**
8872 * Set the ICC pin lock enabled or disabled.
8873 *
8874 * @return an integer representing the status of IccLock enabled or disabled in the following
8875 * three cases:
8876 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8877 * successfully.
8878 * - Positive number and zero for remaining password attempts.
8879 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8880 *
8881 */
8882 @Override
8883 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8884 enforceModifyPermission();
8885
8886 Phone phone = getPhone(subId);
8887 if (phone == null) {
8888 return 0;
8889 }
8890 // Now that all security checks passes, perform the operation as ourselves.
8891 final long identity = Binder.clearCallingIdentity();
8892 try {
8893 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8894 new Pair<Boolean, String>(enabled, password), phone, null);
8895 return attemptsRemaining;
8896
8897 } catch (Exception e) {
8898 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8899 } finally {
8900 Binder.restoreCallingIdentity(identity);
8901 }
8902 return 0;
8903 }
8904
8905 /**
8906 * Change the ICC password used in ICC pin lock.
8907 *
8908 * @return an integer representing the status of IccLock changed in the following three cases:
8909 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8910 * - Positive number and zero for remaining password attempts.
8911 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8912 *
8913 */
8914 @Override
8915 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8916 enforceModifyPermission();
8917
8918 Phone phone = getPhone(subId);
8919 if (phone == null) {
8920 return 0;
8921 }
8922 // Now that all security checks passes, perform the operation as ourselves.
8923 final long identity = Binder.clearCallingIdentity();
8924 try {
8925 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8926 new Pair<String, String>(oldPassword, newPassword), phone, null);
8927 return attemptsRemaining;
8928
8929 } catch (Exception e) {
8930 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8931 } finally {
8932 Binder.restoreCallingIdentity(identity);
8933 }
8934 return 0;
8935 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008936
8937 /**
8938 * Request for receiving user activity notification
8939 */
8940 @Override
8941 public void requestUserActivityNotification() {
8942 if (!mNotifyUserActivity.get()
8943 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8944 mNotifyUserActivity.set(true);
8945 }
8946 }
8947
8948 /**
8949 * Called when userActivity is signalled in the power manager.
8950 * This is safe to call from any thread, with any window manager locks held or not.
8951 */
8952 @Override
8953 public void userActivity() {
8954 // ***************************************
8955 // * Inherited from PhoneWindowManager *
8956 // ***************************************
8957 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8958 // WITH ITS LOCKS HELD.
8959 //
8960 // This code must be VERY careful about the locks
8961 // it acquires.
8962 // In fact, the current code acquires way too many,
8963 // and probably has lurking deadlocks.
8964
8965 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8966 throw new SecurityException("Only the OS may call notifyUserActivity()");
8967 }
8968
8969 if (mNotifyUserActivity.getAndSet(false)) {
8970 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8971 USER_ACTIVITY_NOTIFICATION_DELAY);
8972 }
8973 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008974
8975 @Override
8976 public boolean canConnectTo5GInDsdsMode() {
8977 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8978 }
Jack Yud10cdd42020-09-28 20:28:01 -07008979
8980 @Override
8981 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8982 String callingFeatureId) {
8983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8984 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8985 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8986 }
8987
8988 Phone phone = getPhone(subId);
8989 if (phone == null) {
8990 throw new RuntimeException("phone is not available");
8991 }
8992 // Now that all security checks passes, perform the operation as ourselves.
8993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 return phone.getEquivalentHomePlmns();
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009000}