blob: 1f002049d0ecac9ffe68c32791ca4004ea32c9a7 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800293 // Parameters of select command.
294 private static final int SELECT_COMMAND = 0xA4;
295 private static final int SELECT_P1 = 0x04;
296 private static final int SELECT_P2 = 0;
297 private static final int SELECT_P3 = 0x10;
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /** The singleton instance. */
300 private static PhoneInterfaceManager sInstance;
301
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800304 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700305 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private AppOpsManager mAppOps;
307 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800308 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700310 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 /** User Activity */
313 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
315
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700316 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
317
Derek Tan97ebb422014-09-05 16:55:38 -0700318 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
319 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800320 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800321 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700322
Michelecea4cf22018-12-21 15:00:11 -0800323 // String to store multi SIM allowed
324 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
325
Derek Tan740e1672017-06-27 14:56:27 -0700326 // The AID of ISD-R.
327 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
328
yinxub1bed742017-04-17 11:45:04 -0700329 private NetworkScanRequestTracker mNetworkScanRequestTracker;
330
David Kelly5e06a7f2018-03-12 14:10:59 +0000331 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
332 private static final int MANUFACTURER_CODE_LENGTH = 8;
333
Derek Tan89e89d42014-07-08 17:00:10 -0700334 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700335 * Experiment flag to enable erase modem config on reset network, default value is false
336 */
337 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
338 "reset_network_erase_modem_config_enabled";
339
340 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700341 * A request object to use for transmitting data to an ICC.
342 */
343 private static final class IccAPDUArgument {
344 public int channel, cla, command, p1, p2, p3;
345 public String data;
346
347 public IccAPDUArgument(int channel, int cla, int command,
348 int p1, int p2, int p3, String data) {
349 this.channel = channel;
350 this.cla = cla;
351 this.command = command;
352 this.p1 = p1;
353 this.p2 = p2;
354 this.p3 = p3;
355 this.data = data;
356 }
357 }
358
359 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700360 * A request object to use for transmitting data to an ICC.
361 */
362 private static final class ManualNetworkSelectionArgument {
363 public OperatorInfo operatorInfo;
364 public boolean persistSelection;
365
366 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
367 this.operatorInfo = operatorInfo;
368 this.persistSelection = persistSelection;
369 }
370 }
371
372 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
374 * request after sending. The main thread will notify the request when it is complete.
375 */
376 private static final class MainThreadRequest {
377 /** The argument to use for the request */
378 public Object argument;
379 /** The result of the request that is run on the main thread */
380 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800381 // The subscriber id that this request applies to. Defaults to
382 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
383 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Nathan Harold92bed182018-10-12 18:16:49 -0700385 // In cases where subId is unavailable, the caller needs to specify the phone.
386 public Phone phone;
387
vagdeviaf9a5b92018-08-15 16:01:53 -0700388 public WorkSource workSource;
389
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 public MainThreadRequest(Object argument) {
391 this.argument = argument;
392 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800393
Nathan Harold92bed182018-10-12 18:16:49 -0700394 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
395 this.argument = argument;
396 if (phone != null) {
397 this.phone = phone;
398 }
399 this.workSource = workSource;
400 }
401
vagdeviaf9a5b92018-08-15 16:01:53 -0700402 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800403 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800404 if (subId != null) {
405 this.subId = subId;
406 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700407 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 }
410
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800411 private static final class IncomingThirdPartyCallArgs {
412 public final ComponentName component;
413 public final String callId;
414 public final String callerDisplayName;
415
416 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
417 String callerDisplayName) {
418 this.component = component;
419 this.callId = callId;
420 this.callerDisplayName = callerDisplayName;
421 }
422 }
423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /**
425 * A handler that processes messages on the main thread in the phone process. Since many
426 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
427 * inbound binder threads to the main thread in the phone process. The Binder thread
428 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
429 * on, which will be notified when the operation completes and will contain the result of the
430 * request.
431 *
432 * <p>If a MainThreadRequest object is provided in the msg.obj field,
433 * note that request.result must be set to something non-null for the calling thread to
434 * unblock.
435 */
436 private final class MainThreadHandler extends Handler {
437 @Override
438 public void handleMessage(Message msg) {
439 MainThreadRequest request;
440 Message onCompleted;
441 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800442 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800444 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
446 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700447 case CMD_HANDLE_USSD_REQUEST: {
448 request = (MainThreadRequest) msg.obj;
449 final Phone phone = getPhoneFromRequest(request);
450 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
451 String ussdRequest = ussdObject.first;
452 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700453
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 if (!isUssdApiAllowed(request.subId)) {
455 // Carrier does not support use of this API, return failure.
456 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
457 UssdResponse response = new UssdResponse(ussdRequest, null);
458 Bundle returnData = new Bundle();
459 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
460 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700461
Pengquan Menga1bb6272018-09-06 09:59:22 -0700462 request.result = true;
463 notifyRequester(request);
464 return;
465 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700466
Pengquan Menga1bb6272018-09-06 09:59:22 -0700467 try {
468 request.result = phone != null
469 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
470 } catch (CallStateException cse) {
471 request.result = false;
472 }
473 // Wake up the requesting thread
474 notifyRequester(request);
475 break;
pkanwar32d516d2016-10-14 19:37:38 -0700476 }
477
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700480 final Phone phone = getPhoneFromRequest(request);
481 request.result = phone != null ?
482 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
483 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 if (uiccCard == null) {
494 loge("iccTransmitApduLogicalChannel: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
499 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700500 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 iccArgument.channel, iccArgument.cla, iccArgument.command,
502 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700504 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 break;
506
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 ar = (AsyncResult) msg.obj;
509 request = (MainThreadRequest) ar.userObj;
510 if (ar.exception == null && ar.result != null) {
511 request.result = ar.result;
512 } else {
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 if (ar.result == null) {
515 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800516 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800518 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700519 } else {
520 loge("iccTransmitApduLogicalChannel: Unknown exception");
521 }
522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 break;
525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
527 request = (MainThreadRequest) msg.obj;
528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 if (uiccCard == null) {
531 loge("iccTransmitApduBasicChannel: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 } else {
535 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
536 request);
537 uiccCard.iccTransmitApduBasicChannel(
538 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
539 iccArgument.p3, iccArgument.data, onCompleted);
540 }
541 break;
542
543 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 if (ar.result == null) {
551 loge("iccTransmitApduBasicChannel: Empty response");
552 } else if (ar.exception instanceof CommandException) {
553 loge("iccTransmitApduBasicChannel: CommandException: " +
554 ar.exception);
555 } else {
556 loge("iccTransmitApduBasicChannel: Unknown exception");
557 }
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 break;
561
562 case CMD_EXCHANGE_SIM_IO:
563 request = (MainThreadRequest) msg.obj;
564 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 if (uiccCard == null) {
567 loge("iccExchangeSimIO: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
572 request);
573 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
574 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
575 iccArgument.data, onCompleted);
576 }
577 break;
578
579 case EVENT_EXCHANGE_SIM_IO_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
582 if (ar.exception == null && ar.result != null) {
583 request.result = ar.result;
584 } else {
585 request.result = new IccIoResult(0x6f, 0, (byte[])null);
586 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 break;
589
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 case CMD_SEND_ENVELOPE:
591 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800592 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 if (uiccCard == null) {
594 loge("sendEnvelopeWithStatus: No UICC");
595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 } else {
598 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
599 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
600 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800601 break;
602
603 case EVENT_SEND_ENVELOPE_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800608 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
610 if (ar.result == null) {
611 loge("sendEnvelopeWithStatus: Empty response");
612 } else if (ar.exception instanceof CommandException) {
613 loge("sendEnvelopeWithStatus: CommandException: " +
614 ar.exception);
615 } else {
616 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
617 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800620 break;
621
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 case CMD_OPEN_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800625 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800628 request.result = new IccOpenLogicalChannelResponse(-1,
629 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800633 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
634 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case EVENT_OPEN_CHANNEL_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 int[] result = (int[]) ar.result;
644 int channelId = result[0];
645 byte[] selectResponse = null;
646 if (result.length > 1) {
647 selectResponse = new byte[result.length - 1];
648 for (int i = 1; i < result.length; ++i) {
649 selectResponse[i - 1] = (byte) result[i];
650 }
651 }
652 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 if (ar.result == null) {
656 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 if (ar.exception != null) {
659 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
660 }
661
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700662 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700663 if (ar.exception instanceof CommandException) {
664 CommandException.Error error =
665 ((CommandException) (ar.exception)).getCommandError();
666 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700668 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700669 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 }
671 }
672 openChannelResp = new IccOpenLogicalChannelResponse(
673 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700675 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
679 case CMD_CLOSE_CHANNEL:
680 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800681 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 if (uiccCard == null) {
683 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900684 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 } else {
687 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
688 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
692 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800693 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
694 break;
695
696 case CMD_NV_READ_ITEM:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800709 request.result = "";
710 if (ar.result == null) {
711 loge("nvReadItem: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("nvReadItem: CommandException: " +
714 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800716 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 }
718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 break;
721
Jake Hambye994d462014-02-03 13:10:13 -0800722 case CMD_NV_WRITE_ITEM:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
725 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800726 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700727 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800728 break;
729
730 case EVENT_NV_WRITE_ITEM_DONE:
731 handleNullReturnEvent(msg, "nvWriteItem");
732 break;
733
734 case CMD_NV_WRITE_CDMA_PRL:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800737 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
740 case EVENT_NV_WRITE_CDMA_PRL_DONE:
741 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
742 break;
743
chen xu6dac5ab2018-10-26 17:39:23 -0700744 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800745 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700746 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800747 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800748 break;
749
chen xu6dac5ab2018-10-26 17:39:23 -0700750 case EVENT_RESET_MODEM_CONFIG_DONE:
751 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800752 break;
753
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 case CMD_GET_PREFERRED_NETWORK_TYPE:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700757 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800758 break;
759
760 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
761 ar = (AsyncResult) msg.obj;
762 request = (MainThreadRequest) ar.userObj;
763 if (ar.exception == null && ar.result != null) {
764 request.result = ar.result; // Integer
765 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530766 // request.result must be set to something non-null
767 // for the calling thread to unblock
768 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800769 if (ar.result == null) {
770 loge("getPreferredNetworkType: Empty response");
771 } else if (ar.exception instanceof CommandException) {
772 loge("getPreferredNetworkType: CommandException: " +
773 ar.exception);
774 } else {
775 loge("getPreferredNetworkType: Unknown exception");
776 }
777 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700778 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800779 break;
780
781 case CMD_SET_PREFERRED_NETWORK_TYPE:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
784 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700785 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800786 break;
787
788 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
789 handleNullReturnEvent(msg, "setPreferredNetworkType");
790 break;
791
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000792 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
793 request = (MainThreadRequest)msg.obj;
794 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800795 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000796 break;
797
798 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
799 ar = (AsyncResult)msg.obj;
800 request = (MainThreadRequest)ar.userObj;
801 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700802 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000803 break;
804
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800805 case CMD_SET_VOICEMAIL_NUMBER:
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
808 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800809 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
810 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800811 break;
812
813 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
814 handleNullReturnEvent(msg, "setVoicemailNumber");
815 break;
816
Stuart Scott54788802015-03-30 13:18:01 -0700817 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
820 request);
821 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
822 break;
823
824 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
825 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
826 break;
827
Shishir Agrawal302c8692015-06-19 13:49:39 -0700828 case CMD_PERFORM_NETWORK_SCAN:
829 request = (MainThreadRequest) msg.obj;
830 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
831 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
832 break;
833
Hall Liu27d24262020-09-18 19:04:59 -0700834 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700837 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
838 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
839 request.argument;
840 int callForwardingReason = args.first;
841 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800842 break;
Hall Liu27d24262020-09-18 19:04:59 -0700843 }
844 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700847 TelephonyManager.CallForwardingInfoCallback callback =
848 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
849 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800850 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700851 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800852 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
853 for (CallForwardInfo callForwardInfo : callForwardInfos) {
854 // Service Class is a bit mask per 3gpp 27.007. Search for
855 // any service for voice call.
856 if ((callForwardInfo.serviceClass
857 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700858 callForwardingInfo = new CallForwardingInfo(true,
859 callForwardInfo.reason,
860 callForwardInfo.number,
861 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800862 break;
863 }
864 }
865 // Didn't find a call forward info for voice call.
866 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700867 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
868 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800869 }
Hall Liu27d24262020-09-18 19:04:59 -0700870 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800871 } else {
872 if (ar.result == null) {
873 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
874 }
875 if (ar.exception != null) {
876 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
877 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700878 int errorCode = TelephonyManager
879 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800880 if (ar.exception instanceof CommandException) {
881 CommandException.Error error =
882 ((CommandException) (ar.exception)).getCommandError();
883 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700884 errorCode = TelephonyManager
885 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800886 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700887 errorCode = TelephonyManager
888 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800889 }
890 }
Hall Liu27d24262020-09-18 19:04:59 -0700891 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -0800892 }
Shuo Qian4a594052020-01-23 11:59:30 -0800893 break;
Hall Liu27d24262020-09-18 19:04:59 -0700894 }
Shuo Qian4a594052020-01-23 11:59:30 -0800895
Hall Liu27d24262020-09-18 19:04:59 -0700896 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800897 request = (MainThreadRequest) msg.obj;
898 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700899 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -0800900 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -0700901 ((Pair<CallForwardingInfo, Consumer<Integer>>)
902 request.argument).first;
903 request.phone.setCallForwardingOption(
904 callForwardingInfoToSet.isEnabled()
905 ? CommandsInterface.CF_ACTION_ENABLE
906 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -0800907 callForwardingInfoToSet.getReason(),
908 callForwardingInfoToSet.getNumber(),
909 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
910 break;
Hall Liu27d24262020-09-18 19:04:59 -0700911 }
Shuo Qian4a594052020-01-23 11:59:30 -0800912
Hall Liu27d24262020-09-18 19:04:59 -0700913 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700916 Consumer<Integer> callback =
917 ((Pair<CallForwardingInfo, Consumer<Integer>>)
918 request.argument).second;
919 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -0800920 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -0700921 int errorCode = TelephonyManager.CallForwardingInfoCallback
922 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -0700923 if (ar.exception instanceof CommandException) {
924 CommandException.Error error =
925 ((CommandException) (ar.exception)).getCommandError();
926 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700927 errorCode = TelephonyManager.CallForwardingInfoCallback
928 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -0700929 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700930 errorCode = TelephonyManager.CallForwardingInfoCallback
931 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -0700932 }
933 }
934 callback.accept(errorCode);
935 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -0700936 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -0800937 }
Shuo Qian4a594052020-01-23 11:59:30 -0800938 break;
Hall Liu27d24262020-09-18 19:04:59 -0700939 }
Shuo Qian4a594052020-01-23 11:59:30 -0800940
Hall Liu27d24262020-09-18 19:04:59 -0700941 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
944 getPhoneFromRequest(request).getCallWaiting(onCompleted);
945 break;
Hall Liu27d24262020-09-18 19:04:59 -0700946 }
Shuo Qian4a594052020-01-23 11:59:30 -0800947
Hall Liu27d24262020-09-18 19:04:59 -0700948 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700951 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -0800952 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
953 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800954 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800955 // Service Class is a bit mask per 3gpp 27.007.
956 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800957 if (callForwardResults.length > 1
958 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -0700959 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800960 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -0700961 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
962 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -0800963 } else {
Hall Liu27d24262020-09-18 19:04:59 -0700964 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -0800965 }
966 } else {
967 if (ar.result == null) {
968 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
969 }
970 if (ar.exception != null) {
971 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
972 }
973 if (ar.exception instanceof CommandException) {
974 CommandException.Error error =
975 ((CommandException) (ar.exception)).getCommandError();
976 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
977 callForwardingStatus =
978 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
979 }
980 }
981 }
Hall Liu27d24262020-09-18 19:04:59 -0700982 callback.accept(callForwardingStatus);
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_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700989 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
990 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800991 break;
Hall Liu27d24262020-09-18 19:04:59 -0700992 }
Shuo Qian4a594052020-01-23 11:59:30 -0800993
Hall Liu27d24262020-09-18 19:04:59 -0700994 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700997 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
998 Consumer<Integer> callback =
999 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1000 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001001 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001002 if (ar.exception instanceof CommandException) {
1003 CommandException.Error error =
1004 ((CommandException) (ar.exception)).getCommandError();
1005 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1006 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1007 } else {
1008 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1009 }
1010 } else {
1011 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1012 }
1013 } else {
1014 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1015 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001016 }
Shuo Qian4a594052020-01-23 11:59:30 -08001017 break;
Hall Liu27d24262020-09-18 19:04:59 -07001018 }
Shuo Qian4a594052020-01-23 11:59:30 -08001019
Shishir Agrawal302c8692015-06-19 13:49:39 -07001020 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 CellNetworkScanResult cellScanResult;
1024 if (ar.exception == null && ar.result != null) {
1025 cellScanResult = new CellNetworkScanResult(
1026 CellNetworkScanResult.STATUS_SUCCESS,
1027 (List<OperatorInfo>) ar.result);
1028 } else {
1029 if (ar.result == null) {
1030 loge("getCellNetworkScanResults: Empty response");
1031 }
1032 if (ar.exception != null) {
1033 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1034 }
1035 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1036 if (ar.exception instanceof CommandException) {
1037 CommandException.Error error =
1038 ((CommandException) (ar.exception)).getCommandError();
1039 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1040 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1041 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1042 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1043 }
1044 }
1045 cellScanResult = new CellNetworkScanResult(errorCode, null);
1046 }
1047 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001048 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001049 break;
1050
1051 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1052 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001053 ManualNetworkSelectionArgument selArg =
1054 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001055 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1056 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001057 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1058 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001059 break;
1060
1061 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001062 ar = (AsyncResult) msg.obj;
1063 request = (MainThreadRequest) ar.userObj;
1064 if (ar.exception == null) {
1065 request.result = true;
1066 } else {
1067 request.result = false;
1068 loge("setNetworkSelectionModeManual " + ar.exception);
1069 }
1070 notifyRequester(request);
1071 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001072 break;
1073
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001074 case CMD_GET_MODEM_ACTIVITY_INFO:
1075 request = (MainThreadRequest) msg.obj;
1076 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001077 if (defaultPhone != null) {
1078 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001079 } else {
1080 ResultReceiver result = (ResultReceiver) request.argument;
1081 Bundle bundle = new Bundle();
1082 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001083 new ModemActivityInfo(0, 0, 0,
1084 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001085 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001086 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001087 break;
1088
1089 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1090 ar = (AsyncResult) msg.obj;
1091 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001092 ResultReceiver result = (ResultReceiver) request.argument;
1093
Hall Liu49656c02020-10-09 19:00:11 -07001094 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0,
1095 new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001096 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001097 // Update the last modem activity info and the result of the request.
1098 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1099 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001100 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001101 int[] txTimeMs = info.getTransmitTimeMillis();
1102 int[] lastModemTxTimeMs = mLastModemActivityInfo
1103 .getTransmitTimeMillis();
1104 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1105 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1106 }
Hall Liu49656c02020-10-09 19:00:11 -07001107 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001108 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1109 + mLastModemActivityInfo.getSleepTimeMillis());
1110 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1111 + mLastModemActivityInfo.getIdleTimeMillis());
1112 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1113 mLastModemActivityInfo.setReceiveTimeMillis(
1114 info.getReceiveTimeMillis()
1115 + mLastModemActivityInfo.getReceiveTimeMillis());
1116 }
Hall Liu49656c02020-10-09 19:00:11 -07001117 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001118 mLastModemActivityInfo.getSleepTimeMillis(),
1119 mLastModemActivityInfo.getIdleTimeMillis(),
1120 mLastModemActivityInfo.getTransmitTimeMillis(),
1121 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001122 } else {
1123 if (ar.result == null) {
1124 loge("queryModemActivityInfo: Empty response");
1125 } else if (ar.exception instanceof CommandException) {
1126 loge("queryModemActivityInfo: CommandException: " +
1127 ar.exception);
1128 } else {
1129 loge("queryModemActivityInfo: Unknown exception");
1130 }
1131 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001132 Bundle bundle = new Bundle();
1133 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1134 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001135 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001136 break;
1137
Meng Wang1a7c35a2016-05-05 20:56:15 -07001138 case CMD_SET_ALLOWED_CARRIERS:
1139 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001140 CarrierRestrictionRules argument =
1141 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001142 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001143 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001144 break;
1145
1146 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1147 ar = (AsyncResult) msg.obj;
1148 request = (MainThreadRequest) ar.userObj;
1149 if (ar.exception == null && ar.result != null) {
1150 request.result = ar.result;
1151 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001152 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1153 if (ar.exception instanceof CommandException) {
1154 loge("setAllowedCarriers: CommandException: " + ar.exception);
1155 CommandException.Error error =
1156 ((CommandException) (ar.exception)).getCommandError();
1157 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1158 request.result =
1159 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1160 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001161 } else {
1162 loge("setAllowedCarriers: Unknown exception");
1163 }
1164 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001165 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001166 break;
1167
1168 case CMD_GET_ALLOWED_CARRIERS:
1169 request = (MainThreadRequest) msg.obj;
1170 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001171 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001172 break;
1173
1174 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1175 ar = (AsyncResult) msg.obj;
1176 request = (MainThreadRequest) ar.userObj;
1177 if (ar.exception == null && ar.result != null) {
1178 request.result = ar.result;
1179 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001180 request.result = new IllegalStateException(
1181 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001182 if (ar.result == null) {
1183 loge("getAllowedCarriers: Empty response");
1184 } else if (ar.exception instanceof CommandException) {
1185 loge("getAllowedCarriers: CommandException: " +
1186 ar.exception);
1187 } else {
1188 loge("getAllowedCarriers: Unknown exception");
1189 }
1190 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001191 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001192 break;
1193
Nathan Haroldb3014052017-01-25 15:57:32 -08001194 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1195 ar = (AsyncResult) msg.obj;
1196 request = (MainThreadRequest) ar.userObj;
1197 if (ar.exception == null && ar.result != null) {
1198 request.result = ar.result;
1199 } else {
1200 request.result = new IllegalArgumentException(
1201 "Failed to retrieve Forbidden Plmns");
1202 if (ar.result == null) {
1203 loge("getForbiddenPlmns: Empty response");
1204 } else {
1205 loge("getForbiddenPlmns: Unknown exception");
1206 }
1207 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001208 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001209 break;
1210
1211 case CMD_GET_FORBIDDEN_PLMNS:
1212 request = (MainThreadRequest) msg.obj;
1213 uiccCard = getUiccCardFromRequest(request);
1214 if (uiccCard == null) {
1215 loge("getForbiddenPlmns() UiccCard is null");
1216 request.result = new IllegalArgumentException(
1217 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001218 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001219 break;
1220 }
1221 Integer appType = (Integer) request.argument;
1222 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1223 if (uiccApp == null) {
1224 loge("getForbiddenPlmns() no app with specified type -- "
1225 + appType);
1226 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001227 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001228 break;
1229 } else {
1230 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1231 + " specified type -- " + appType);
1232 }
1233 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1234 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1235 onCompleted);
1236 break;
1237
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001238 case CMD_SWITCH_SLOTS:
1239 request = (MainThreadRequest) msg.obj;
1240 int[] physicalSlots = (int[]) request.argument;
1241 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1242 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1243 break;
1244
1245 case EVENT_SWITCH_SLOTS_DONE:
1246 ar = (AsyncResult) msg.obj;
1247 request = (MainThreadRequest) ar.userObj;
1248 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001249 notifyRequester(request);
1250 break;
1251 case CMD_GET_NETWORK_SELECTION_MODE:
1252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1254 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1255 break;
1256
1257 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1258 ar = (AsyncResult) msg.obj;
1259 request = (MainThreadRequest) ar.userObj;
1260 if (ar.exception != null) {
1261 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1262 } else {
1263 int mode = ((int[]) ar.result)[0];
1264 if (mode == 0) {
1265 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1266 } else {
1267 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1268 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001269 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001270 notifyRequester(request);
1271 break;
1272 case CMD_GET_CDMA_ROAMING_MODE:
1273 request = (MainThreadRequest) msg.obj;
1274 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1275 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1276 break;
1277 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1278 ar = (AsyncResult) msg.obj;
1279 request = (MainThreadRequest) ar.userObj;
1280 if (ar.exception != null) {
1281 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1282 } else {
1283 request.result = ((int[]) ar.result)[0];
1284 }
1285 notifyRequester(request);
1286 break;
1287 case CMD_SET_CDMA_ROAMING_MODE:
1288 request = (MainThreadRequest) msg.obj;
1289 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1290 int mode = (int) request.argument;
1291 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1292 break;
1293 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1294 ar = (AsyncResult) msg.obj;
1295 request = (MainThreadRequest) ar.userObj;
1296 request.result = ar.exception == null;
1297 notifyRequester(request);
1298 break;
1299 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1300 request = (MainThreadRequest) msg.obj;
1301 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1302 int subscriptionMode = (int) request.argument;
1303 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1304 break;
1305 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1306 ar = (AsyncResult) msg.obj;
1307 request = (MainThreadRequest) ar.userObj;
1308 request.result = ar.exception == null;
1309 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001310 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001311 case CMD_GET_ALL_CELL_INFO:
1312 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001313 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001314 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001315 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001316 case EVENT_GET_ALL_CELL_INFO_DONE:
1317 ar = (AsyncResult) msg.obj;
1318 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001319 // If a timeout occurs, the response will be null
1320 request.result = (ar.exception == null && ar.result != null)
1321 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001322 synchronized (request) {
1323 request.notifyAll();
1324 }
1325 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001326 case CMD_REQUEST_CELL_INFO_UPDATE:
1327 request = (MainThreadRequest) msg.obj;
1328 request.phone.requestCellInfoUpdate(request.workSource,
1329 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1330 break;
1331 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
1334 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1335 try {
1336 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001337 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001338 cb.onError(
1339 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1340 ar.exception.getClass().getName(),
1341 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001342 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001343 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001344 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001345 } else {
1346 // use the result as returned
1347 cb.onCellInfo((List<CellInfo>) ar.result);
1348 }
1349 } catch (RemoteException re) {
1350 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1351 }
1352 break;
1353 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001354 request = (MainThreadRequest) msg.obj;
1355 WorkSource ws = (WorkSource) request.argument;
1356 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001357 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001358 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001360 ar = (AsyncResult) msg.obj;
1361 request = (MainThreadRequest) ar.userObj;
1362 if (ar.exception == null) {
1363 request.result = ar.result;
1364 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001365 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001366 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001367 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001368 }
1369
1370 synchronized (request) {
1371 request.notifyAll();
1372 }
1373 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001374 case CMD_MODEM_REBOOT:
1375 request = (MainThreadRequest) msg.obj;
1376 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001377 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001378 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001379 case EVENT_CMD_MODEM_REBOOT_DONE:
1380 handleNullReturnEvent(msg, "rebootModem");
1381 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001382 case CMD_REQUEST_ENABLE_MODEM:
1383 request = (MainThreadRequest) msg.obj;
1384 boolean enable = (boolean) request.argument;
1385 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001386 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001387 PhoneConfigurationManager.getInstance()
1388 .enablePhone(request.phone, enable, onCompleted);
1389 break;
1390 case EVENT_ENABLE_MODEM_DONE:
1391 ar = (AsyncResult) msg.obj;
1392 request = (MainThreadRequest) ar.userObj;
1393 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001394 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001395 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001396 if ((boolean) request.result) {
1397 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1398 updateModemStateMetrics();
1399 } else {
1400 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1401 + ar.exception);
1402 }
1403 notifyRequester(request);
1404 break;
1405 case CMD_GET_MODEM_STATUS:
1406 request = (MainThreadRequest) msg.obj;
1407 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1408 PhoneConfigurationManager.getInstance()
1409 .getPhoneStatusFromModem(request.phone, onCompleted);
1410 break;
1411 case EVENT_GET_MODEM_STATUS_DONE:
1412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 int id = request.phone.getPhoneId();
1415 if (ar.exception == null && ar.result != null) {
1416 request.result = ar.result;
1417 //update the cache as modem status has changed
1418 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1419 (boolean) request.result);
1420 } else {
1421 // Return true if modem status cannot be retrieved. For most cases,
1422 // modem status is on. And for older version modems, GET_MODEM_STATUS
1423 // and disable modem are not supported. Modem is always on.
1424 // TODO: this should be fixed in R to support a third
1425 // status UNKNOWN b/131631629
1426 request.result = true;
1427 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1428 + ar.exception);
1429 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001430 notifyRequester(request);
1431 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001432 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1433 request = (MainThreadRequest) msg.obj;
1434 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1435 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1436 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1437 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1438 break;
1439 }
1440 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1441 ar = (AsyncResult) msg.obj;
1442 request = (MainThreadRequest) ar.userObj;
1443 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1444 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1445 args.second.accept(ar.exception == null);
1446 notifyRequester(request);
1447 break;
1448 }
yincheng zhao2737e882019-09-06 17:06:54 -07001449 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
1452 if (ar.exception == null && ar.result != null) {
1453 request.result = ar.result;
1454 } else {
1455 request.result = -1;
1456 loge("Failed to set Forbidden Plmns");
1457 if (ar.result == null) {
1458 loge("setForbidenPlmns: Empty response");
1459 } else if (ar.exception != null) {
1460 loge("setForbiddenPlmns: Exception: " + ar.exception);
1461 request.result = -1;
1462 } else {
1463 loge("setForbiddenPlmns: Unknown exception");
1464 }
1465 }
1466 notifyRequester(request);
1467 break;
1468 case CMD_SET_FORBIDDEN_PLMNS:
1469 request = (MainThreadRequest) msg.obj;
1470 uiccCard = getUiccCardFromRequest(request);
1471 if (uiccCard == null) {
1472 loge("setForbiddenPlmns: UiccCard is null");
1473 request.result = -1;
1474 notifyRequester(request);
1475 break;
1476 }
1477 Pair<Integer, List<String>> setFplmnsArgs =
1478 (Pair<Integer, List<String>>) request.argument;
1479 appType = setFplmnsArgs.first;
1480 List<String> fplmns = setFplmnsArgs.second;
1481 uiccApp = uiccCard.getApplicationByType(appType);
1482 if (uiccApp == null) {
1483 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1484 request.result = -1;
1485 loge("Failed to get UICC App");
1486 notifyRequester(request);
1487 } else {
1488 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1489 ((SIMRecords) uiccApp.getIccRecords())
1490 .setForbiddenPlmns(onCompleted, fplmns);
1491 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001492 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001493 case CMD_ERASE_MODEM_CONFIG:
1494 request = (MainThreadRequest) msg.obj;
1495 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1496 defaultPhone.eraseModemConfig(onCompleted);
1497 break;
1498 case EVENT_ERASE_MODEM_CONFIG_DONE:
1499 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001500 break;
zoey chene02881a2019-12-30 16:11:23 +08001501
1502 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1503 request = (MainThreadRequest) msg.obj;
1504 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1505 Pair<String, String> changed = (Pair<String, String>) request.argument;
1506 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1507 changed.first, changed.second, onCompleted);
1508 break;
1509 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1510 ar = (AsyncResult) msg.obj;
1511 request = (MainThreadRequest) ar.userObj;
1512 if (ar.exception == null) {
1513 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1514 } else {
1515 request.result = msg.arg1;
1516 }
1517 notifyRequester(request);
1518 break;
1519
1520 case CMD_SET_ICC_LOCK_ENABLED:
1521 request = (MainThreadRequest) msg.obj;
1522 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1523 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1524 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1525 enabled.first, enabled.second, onCompleted);
1526 break;
1527 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 if (ar.exception == null) {
1531 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1532 } else {
1533 request.result = msg.arg1;
1534 }
1535 notifyRequester(request);
1536 break;
1537
Peter Wangdafb9ac2020-01-15 14:13:38 -08001538 case MSG_NOTIFY_USER_ACTIVITY:
1539 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001540 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001541 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1542 getDefaultPhone().getContext().sendBroadcastAsUser(
1543 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1544 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 default:
1546 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1547 break;
1548 }
1549 }
Jake Hambye994d462014-02-03 13:10:13 -08001550
Pengquan Menga1bb6272018-09-06 09:59:22 -07001551 private void notifyRequester(MainThreadRequest request) {
1552 synchronized (request) {
1553 request.notifyAll();
1554 }
1555 }
1556
Jake Hambye994d462014-02-03 13:10:13 -08001557 private void handleNullReturnEvent(Message msg, String command) {
1558 AsyncResult ar = (AsyncResult) msg.obj;
1559 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1560 if (ar.exception == null) {
1561 request.result = true;
1562 } else {
1563 request.result = false;
1564 if (ar.exception instanceof CommandException) {
1565 loge(command + ": CommandException: " + ar.exception);
1566 } else {
1567 loge(command + ": Unknown exception");
1568 }
1569 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001570 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 }
1573
1574 /**
1575 * Posts the specified command to be executed on the main thread,
1576 * waits for the request to complete, and returns the result.
1577 * @see #sendRequestAsync
1578 */
1579 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001580 return sendRequest(
1581 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001582 }
1583
1584 /**
1585 * Posts the specified command to be executed on the main thread,
1586 * waits for the request to complete, and returns the result.
1587 * @see #sendRequestAsync
1588 */
1589 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1590 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001591 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001592 }
1593
1594 /**
1595 * Posts the specified command to be executed on the main thread,
1596 * waits for the request to complete, and returns the result.
1597 * @see #sendRequestAsync
1598 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001599 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001600 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001601 }
1602
1603 /**
1604 * Posts the specified command to be executed on the main thread,
1605 * waits for the request to complete, and returns the result.
1606 * @see #sendRequestAsync
1607 */
Nathan Harold92bed182018-10-12 18:16:49 -07001608 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1609 return sendRequest(command, argument, subId, null, workSource);
1610 }
1611
1612 /**
1613 * Posts the specified command to be executed on the main thread,
1614 * waits for the request to complete, and returns the result.
1615 * @see #sendRequestAsync
1616 */
1617 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1618 return sendRequest(
1619 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1620 }
1621
1622 /**
1623 * Posts the specified command to be executed on the main thread,
1624 * waits for the request to complete, and returns the result.
1625 * @see #sendRequestAsync
1626 */
1627 private Object sendRequest(
1628 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1630 throw new RuntimeException("This method will deadlock if called from the main thread.");
1631 }
1632
Nathan Harold92bed182018-10-12 18:16:49 -07001633 MainThreadRequest request = null;
1634 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1635 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1636 } else if (phone != null) {
1637 request = new MainThreadRequest(argument, phone, workSource);
1638 } else {
1639 request = new MainThreadRequest(argument, subId, workSource);
1640 }
1641
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 Message msg = mMainThreadHandler.obtainMessage(command, request);
1643 msg.sendToTarget();
1644
1645 // Wait for the request to complete
1646 synchronized (request) {
1647 while (request.result == null) {
1648 try {
1649 request.wait();
1650 } catch (InterruptedException e) {
1651 // Do nothing, go back and wait until the request is complete
1652 }
1653 }
1654 }
1655 return request.result;
1656 }
1657
1658 /**
1659 * Asynchronous ("fire and forget") version of sendRequest():
1660 * Posts the specified command to be executed on the main thread, and
1661 * returns immediately.
1662 * @see #sendRequest
1663 */
1664 private void sendRequestAsync(int command) {
1665 mMainThreadHandler.sendEmptyMessage(command);
1666 }
1667
1668 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001669 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001670 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001671 */
1672 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001673 sendRequestAsync(command, argument, null, null);
1674 }
1675
1676 /**
1677 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1678 * @see {@link #sendRequest(int,Object)}
1679 */
1680 private void sendRequestAsync(
1681 int command, Object argument, Phone phone, WorkSource workSource) {
1682 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001683 Message msg = mMainThreadHandler.obtainMessage(command, request);
1684 msg.sendToTarget();
1685 }
1686
1687 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 * Initialize the singleton PhoneInterfaceManager instance.
1689 * This is only done once, at startup, from PhoneApp.onCreate().
1690 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001691 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 synchronized (PhoneInterfaceManager.class) {
1693 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001694 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 } else {
1696 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1697 }
1698 return sInstance;
1699 }
1700 }
1701
1702 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001703 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001706 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001707 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1709 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001710 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001711 mTelephonySharedPreferences =
1712 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001713 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001714 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001715 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 publish();
1718 }
1719
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001720 private Phone getDefaultPhone() {
1721 Phone thePhone = getPhone(getDefaultSubscription());
1722 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1723 }
1724
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 private void publish() {
1726 if (DBG) log("publish: " + this);
1727
Peter Wangc035ce42020-01-08 21:00:22 -08001728 TelephonyFrameworkInitializer
1729 .getTelephonyServiceManager()
1730 .getTelephonyServiceRegisterer()
1731 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 }
1733
Stuart Scott584921c2015-01-15 17:10:34 -08001734 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001735 if (request.phone != null) {
1736 return request.phone;
1737 } else {
1738 return getPhoneFromSubId(request.subId);
1739 }
1740 }
1741
1742 private Phone getPhoneFromSubId(int subId) {
1743 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1744 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001745 }
1746
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001747 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1748 Phone phone = getPhoneFromRequest(request);
1749 return phone == null ? null :
1750 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1751 }
1752
Wink Saville36469e72014-06-11 15:17:00 -07001753 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001755 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757
Naina Nallurid63128d2019-09-17 14:10:30 -07001758 private void sendEraseModemConfig(Phone phone) {
1759 if (phone != null) {
1760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1761 mApp, phone.getSubId(), "eraseModemConfig");
1762 final long identity = Binder.clearCallingIdentity();
1763 try {
1764 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1765 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
1768 }
1769 }
1770 }
1771
Peter Wang44b186e2020-01-13 23:33:09 -08001772 private boolean isImsAvailableOnDevice() {
1773 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1774 if (pm == null) {
1775 // For some reason package manger is not available.. This will fail internally anyway,
1776 // so do not throw error and allow.
1777 return true;
1778 }
1779 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1780 }
1781
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001783 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001784 }
1785
Wink Savilleb564aae2014-10-23 10:18:09 -07001786 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 if (DBG) log("dial: " + number);
1788 // No permission check needed here: This is just a wrapper around the
1789 // ACTION_DIAL intent, which is available to any app since it puts up
1790 // the UI before it does anything.
1791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 String url = createTelUrl(number);
1795 if (url == null) {
1796 return;
1797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 // PENDING: should we just silently fail if phone is offhook or ringing?
1800 PhoneConstants.State state = mCM.getState(subId);
1801 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1802 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1803 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1804 mApp.startActivity(intent);
1805 }
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809 }
1810
1811 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001812 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001813 }
1814
Wink Savilleb564aae2014-10-23 10:18:09 -07001815 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 if (DBG) log("call: " + number);
1817
1818 // This is just a wrapper around the ACTION_CALL intent, but we still
1819 // need to do a permission check since we're calling startActivity()
1820 // from the context of the phone app.
1821 enforceCallPermission();
1822
Jordan Liu1617b712019-07-10 15:06:26 -07001823 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 != AppOpsManager.MODE_ALLOWED) {
1825 return;
1826 }
1827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001828 final long identity = Binder.clearCallingIdentity();
1829 try {
1830 String url = createTelUrl(number);
1831 if (url == null) {
1832 return;
1833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835 boolean isValid = false;
1836 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1837 if (slist != null) {
1838 for (SubscriptionInfo subInfoRecord : slist) {
1839 if (subInfoRecord.getSubscriptionId() == subId) {
1840 isValid = true;
1841 break;
1842 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001843 }
Wink Saville08874612014-08-31 19:19:58 -07001844 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001845 if (!isValid) {
1846 return;
1847 }
Wink Saville08874612014-08-31 19:19:58 -07001848
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001849 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1850 intent.putExtra(SUBSCRIPTION_KEY, subId);
1851 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1852 mApp.startActivity(intent);
1853 } finally {
1854 Binder.restoreCallingIdentity(identity);
1855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 }
1857
Wink Savilleb564aae2014-10-23 10:18:09 -07001858 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001859 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001860 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1861 }
1862
Wink Savilleb564aae2014-10-23 10:18:09 -07001863 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001864 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001865 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1866 }
1867
Wink Savilleb564aae2014-10-23 10:18:09 -07001868 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001870
1871 final long identity = Binder.clearCallingIdentity();
1872 try {
1873 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1874 checkSimPin.start();
1875 return checkSimPin.unlockSim(null, pin);
1876 } finally {
1877 Binder.restoreCallingIdentity(identity);
1878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 }
1880
Wink Savilleb564aae2014-10-23 10:18:09 -07001881 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001883
1884 final long identity = Binder.clearCallingIdentity();
1885 try {
1886 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1887 checkSimPuk.start();
1888 return checkSimPuk.unlockSim(puk, pin);
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
1891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 }
1893
1894 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001895 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 * a synchronous one.
1897 */
1898 private static class UnlockSim extends Thread {
1899
1900 private final IccCard mSimCard;
1901
1902 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001903 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1904 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905
1906 // For replies from SimCard interface
1907 private Handler mHandler;
1908
1909 // For async handler to identify request type
1910 private static final int SUPPLY_PIN_COMPLETE = 100;
1911
1912 public UnlockSim(IccCard simCard) {
1913 mSimCard = simCard;
1914 }
1915
1916 @Override
1917 public void run() {
1918 Looper.prepare();
1919 synchronized (UnlockSim.this) {
1920 mHandler = new Handler() {
1921 @Override
1922 public void handleMessage(Message msg) {
1923 AsyncResult ar = (AsyncResult) msg.obj;
1924 switch (msg.what) {
1925 case SUPPLY_PIN_COMPLETE:
1926 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1927 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001928 mRetryCount = msg.arg1;
1929 if (ar.exception != null) {
1930 if (ar.exception instanceof CommandException &&
1931 ((CommandException)(ar.exception)).getCommandError()
1932 == CommandException.Error.PASSWORD_INCORRECT) {
1933 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001934 } //When UiccCardApp dispose,handle message and return exception
1935 else if (ar.exception instanceof CommandException &&
1936 ((CommandException) (ar.exception)).getCommandError()
1937 == CommandException.Error.ABORTED) {
1938 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001939 } else {
1940 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1941 }
1942 } else {
1943 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 mDone = true;
1946 UnlockSim.this.notifyAll();
1947 }
1948 break;
1949 }
1950 }
1951 };
1952 UnlockSim.this.notifyAll();
1953 }
1954 Looper.loop();
1955 }
1956
1957 /*
1958 * Use PIN or PUK to unlock SIM card
1959 *
1960 * If PUK is null, unlock SIM card with PIN
1961 *
1962 * If PUK is not null, unlock SIM card with PUK and set PIN code
1963 */
Wink Saville9de0f752013-10-22 19:04:03 -07001964 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965
1966 while (mHandler == null) {
1967 try {
1968 wait();
1969 } catch (InterruptedException e) {
1970 Thread.currentThread().interrupt();
1971 }
1972 }
1973 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1974
1975 if (puk == null) {
1976 mSimCard.supplyPin(pin, callback);
1977 } else {
1978 mSimCard.supplyPuk(puk, pin, callback);
1979 }
1980
1981 while (!mDone) {
1982 try {
1983 Log.d(LOG_TAG, "wait for done");
1984 wait();
1985 } catch (InterruptedException e) {
1986 // Restore the interrupted status
1987 Thread.currentThread().interrupt();
1988 }
1989 }
1990 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001991 int[] resultArray = new int[2];
1992 resultArray[0] = mResult;
1993 resultArray[1] = mRetryCount;
1994 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
1996 }
1997
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001998 /**
1999 * This method has been removed due to privacy and stability concerns.
2000 */
2001 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002003 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2004 return;
Wink Saville36469e72014-06-11 15:17:00 -07002005 }
2006
Nathan Harold1f889d82020-06-04 17:05:26 -07002007 @Override
2008 public void updateServiceLocationWithPackageName(String callingPackage) {
2009 mApp.getSystemService(AppOpsManager.class)
2010 .checkPackage(Binder.getCallingUid(), callingPackage);
2011
2012 final int targetSdk = getTargetSdk(callingPackage);
2013 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2014 // Callers targeting S have no business invoking this method.
2015 return;
2016 }
2017
2018 LocationAccessPolicy.LocationPermissionResult locationResult =
2019 LocationAccessPolicy.checkLocationPermission(mApp,
2020 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2021 .setCallingPackage(callingPackage)
2022 .setCallingFeatureId(null)
2023 .setCallingPid(Binder.getCallingPid())
2024 .setCallingUid(Binder.getCallingUid())
2025 .setMethod("updateServiceLocation")
2026 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2027 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2028 .build());
2029 // Apps that lack location permission have no business calling this method;
2030 // however, because no permission was declared in the public API, denials must
2031 // all be "soft".
2032 switch (locationResult) {
2033 case DENIED_HARD: /* fall through */
2034 case DENIED_SOFT:
2035 return;
2036 }
2037
2038 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039 final long identity = Binder.clearCallingIdentity();
2040 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002041 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002043 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002044 }
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002047 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 }
2049
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002050 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002051 @Override
2052 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002053 return isRadioOnWithFeature(callingPackage, null);
2054 }
2055
2056
2057 @Override
2058 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2059 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2060 callingFeatureId);
2061 }
2062
2063 @Deprecated
2064 @Override
2065 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2066 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002067 }
2068
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002069 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002070 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2071 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002073 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002074 return false;
2075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 return isRadioOnForSubscriber(subId);
2080 } finally {
2081 Binder.restoreCallingIdentity(identity);
2082 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002083 }
2084
2085 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002086 final long identity = Binder.clearCallingIdentity();
2087 try {
2088 final Phone phone = getPhone(subId);
2089 if (phone != null) {
2090 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2091 } else {
2092 return false;
2093 }
2094 } finally {
2095 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 }
2098
2099 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002100 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 }
Wink Saville36469e72014-06-11 15:17:00 -07002102
Wink Savilleb564aae2014-10-23 10:18:09 -07002103 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002105
2106 final long identity = Binder.clearCallingIdentity();
2107 try {
2108 final Phone phone = getPhone(subId);
2109 if (phone != null) {
2110 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2111 }
2112 } finally {
2113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002114 }
Wink Saville36469e72014-06-11 15:17:00 -07002115 }
2116
2117 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002118 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002119 }
2120
Wink Savilleb564aae2014-10-23 10:18:09 -07002121 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002122 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002123
2124 final long identity = Binder.clearCallingIdentity();
2125 try {
2126 final Phone phone = getPhone(subId);
2127 if (phone == null) {
2128 return false;
2129 }
2130 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2131 toggleRadioOnOffForSubscriber(subId);
2132 }
2133 return true;
2134 } finally {
2135 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 }
Wink Saville36469e72014-06-11 15:17:00 -07002138
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002139 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002140 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002141 /*
2142 * If any of the Radios are available, it will need to be
2143 * shutdown. So return true if any Radio is available.
2144 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002145 final long identity = Binder.clearCallingIdentity();
2146 try {
2147 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2148 Phone phone = PhoneFactory.getPhone(i);
2149 if (phone != null && phone.isRadioAvailable()) return true;
2150 }
2151 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2152 return false;
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002155 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002156 }
2157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002158 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002159 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002160 enforceModifyPermission();
2161
2162 final long identity = Binder.clearCallingIdentity();
2163 try {
2164 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2165 logv("Shutting down Phone " + i);
2166 shutdownRadioUsingPhoneId(i);
2167 }
2168 } finally {
2169 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002170 }
2171 }
2172
2173 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002174 Phone phone = PhoneFactory.getPhone(phoneId);
2175 if (phone != null && phone.isRadioAvailable()) {
2176 phone.shutdownRadio();
2177 }
2178 }
2179
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002181 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002182
2183 final long identity = Binder.clearCallingIdentity();
2184 try {
2185 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2186 if (defaultPhone != null) {
2187 defaultPhone.setRadioPower(turnOn);
2188 return true;
2189 } else {
2190 loge("There's no default phone.");
2191 return false;
2192 }
2193 } finally {
2194 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002195 }
Wink Saville36469e72014-06-11 15:17:00 -07002196 }
2197
Wink Savilleb564aae2014-10-23 10:18:09 -07002198 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002200
2201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 final Phone phone = getPhone(subId);
2204 if (phone != null) {
2205 phone.setRadioPower(turnOn);
2206 return true;
2207 } else {
2208 return false;
2209 }
2210 } finally {
2211 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 }
2214
Wink Saville36469e72014-06-11 15:17:00 -07002215 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 public boolean enableDataConnectivity() {
2218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002219
2220 final long identity = Binder.clearCallingIdentity();
2221 try {
2222 int subId = mSubscriptionController.getDefaultDataSubId();
2223 final Phone phone = getPhone(subId);
2224 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002225 phone.getDataEnabledSettings().setDataEnabled(
2226 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227 return true;
2228 } else {
2229 return false;
2230 }
2231 } finally {
2232 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235
Wink Saville36469e72014-06-11 15:17:00 -07002236 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002237 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 public boolean disableDataConnectivity() {
2239 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240
2241 final long identity = Binder.clearCallingIdentity();
2242 try {
2243 int subId = mSubscriptionController.getDefaultDataSubId();
2244 final Phone phone = getPhone(subId);
2245 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002246 phone.getDataEnabledSettings().setDataEnabled(
2247 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002248 return true;
2249 } else {
2250 return false;
2251 }
2252 } finally {
2253 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 }
2256
Sanket Padawe356d7632015-06-22 14:03:32 -07002257 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002258 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259 final long identity = Binder.clearCallingIdentity();
2260 try {
2261 final Phone phone = getPhone(subId);
2262 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002263 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 } else {
2265 return false;
2266 }
2267 } finally {
2268 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 }
2271
2272 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002273 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002274 }
2275
pkanwarae03a6b2016-11-06 20:37:09 -08002276 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277 enforceCallPermission();
2278
2279 final long identity = Binder.clearCallingIdentity();
2280 try {
2281 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2282 return;
2283 }
2284 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2285 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2286 } finally {
2287 Binder.restoreCallingIdentity(identity);
2288 }
pkanwar32d516d2016-10-14 19:37:38 -07002289 };
2290
Wink Savilleb564aae2014-10-23 10:18:09 -07002291 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293
2294 final long identity = Binder.clearCallingIdentity();
2295 try {
2296 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2297 return false;
2298 }
2299 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2300 } finally {
2301 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 }
2304
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002306 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002307 }
2308
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002309 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 Phone phone = PhoneFactory.getPhone(slotIndex);
2313 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2314 PhoneConstantConversions.convertCallState(phone.getState());
2315 } finally {
2316 Binder.restoreCallingIdentity(identity);
2317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 }
2319
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002321 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002322 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2323 }
2324
2325 @Override
2326 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327 final long identity = Binder.clearCallingIdentity();
2328 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002329 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330 if (phone != null) {
2331 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2332 } else {
2333 return PhoneConstantConversions.convertDataState(
2334 PhoneConstants.DataState.DISCONNECTED);
2335 }
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
2340
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002342 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002343 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2344 }
2345
2346 @Override
2347 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348 final long identity = Binder.clearCallingIdentity();
2349 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002350 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351 if (phone != null) {
2352 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2353 } else {
2354 return TelephonyManager.DATA_ACTIVITY_NONE;
2355 }
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360
2361 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002362 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002363 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002364 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002365
2366 LocationAccessPolicy.LocationPermissionResult locationResult =
2367 LocationAccessPolicy.checkLocationPermission(mApp,
2368 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2369 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002370 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002371 .setCallingPid(Binder.getCallingPid())
2372 .setCallingUid(Binder.getCallingUid())
2373 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002374 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002375 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2376 .build());
2377 switch (locationResult) {
2378 case DENIED_HARD:
2379 throw new SecurityException("Not allowed to access cell location");
2380 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002381 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2382 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 }
2384
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002385 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002386 final long identity = Binder.clearCallingIdentity();
2387 try {
2388 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002389 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002390 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
Svetoslav64fad262015-04-14 14:35:21 -07002394 }
2395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002397 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002398 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2399 // registered cell info, so return a NULL country instead.
2400 final long identity = Binder.clearCallingIdentity();
2401 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002402 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2403 // Get default phone in this case.
2404 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2405 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002406 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002407 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002408 if (phone == null) return "";
2409 ServiceStateTracker sst = phone.getServiceStateTracker();
2410 if (sst == null) return "";
2411 LocaleTracker lt = sst.getLocaleTracker();
2412 if (lt == null) return "";
2413 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2414 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2415 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002416 } finally {
2417 Binder.restoreCallingIdentity(identity);
2418 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002419 }
2420
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002421 /**
2422 * This method was removed due to potential issues caused by performing partial
2423 * updates of service state, and lack of a credible use case.
2424 *
2425 * This has the ability to break the telephony implementation by disabling notification of
2426 * changes in device connectivity. DO NOT USE THIS!
2427 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002428 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 public void enableLocationUpdates() {
2430 mApp.enforceCallingOrSelfPermission(
2431 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 }
2433
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002434 /**
2435 * This method was removed due to potential issues caused by performing partial
2436 * updates of service state, and lack of a credible use case.
2437 *
2438 * This has the ability to break the telephony implementation by disabling notification of
2439 * changes in device connectivity. DO NOT USE THIS!
2440 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 @Override
2442 public void disableLocationUpdates() {
2443 mApp.enforceCallingOrSelfPermission(
2444 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
Nathan Harold31d7ff32018-10-15 20:20:30 -07002447 /**
2448 * Returns the target SDK version number for a given package name.
2449 *
Nathan Haroldec184742019-07-10 17:04:16 -07002450 * This call MUST be invoked before clearing the calling UID.
2451 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002452 * @return target SDK if the package is found or INT_MAX.
2453 */
2454 private int getTargetSdk(String packageName) {
2455 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002456 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002457 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002458 if (ai != null) return ai.targetSdkVersion;
2459 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002460 loge("Failed to get package info for pkg="
2461 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002462 }
2463 return Integer.MAX_VALUE;
2464 }
2465
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 @Override
2467 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002468 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2469 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002470 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002471 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2472 throw new SecurityException(
2473 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2474 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002475
Jordan Liu1617b712019-07-10 15:06:26 -07002476 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2478 return null;
2479 }
Svetoslav64fad262015-04-14 14:35:21 -07002480
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002481 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002483 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002484 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485
Nathan Haroldf180aac2018-06-01 18:43:55 -07002486 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2487 for (CellInfo ci : info) {
2488 if (ci instanceof CellInfoGsm) {
2489 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2490 } else if (ci instanceof CellInfoWcdma) {
2491 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002494 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 }
2496
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002497 private List<CellInfo> getCachedCellInfo() {
2498 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2499 for (Phone phone : PhoneFactory.getPhones()) {
2500 List<CellInfo> info = phone.getAllCellInfo();
2501 if (info != null) cellInfos.addAll(info);
2502 }
2503 return cellInfos;
2504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505
2506 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002507 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002508 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002509 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002510
2511 LocationAccessPolicy.LocationPermissionResult locationResult =
2512 LocationAccessPolicy.checkLocationPermission(mApp,
2513 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2514 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002515 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002516 .setCallingPid(Binder.getCallingPid())
2517 .setCallingUid(Binder.getCallingUid())
2518 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002519 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002520 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2521 .build());
2522 switch (locationResult) {
2523 case DENIED_HARD:
2524 throw new SecurityException("Not allowed to access cell info");
2525 case DENIED_SOFT:
2526 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002527 }
2528
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002529 final int targetSdk = getTargetSdk(callingPackage);
2530 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2531 return getCachedCellInfo();
2532 }
2533
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002534 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002535 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536 final long identity = Binder.clearCallingIdentity();
2537 try {
2538 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2539 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002540 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002541 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 if (info != null) cellInfos.addAll(info);
2543 }
2544 return cellInfos;
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 }
2548 }
2549
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002550 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002551 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2552 String callingFeatureId) {
2553 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2554 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002555 }
2556
2557 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002558 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2559 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002560 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002561 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002562 }
2563
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002564 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2565 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002566 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002567 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002568
2569 LocationAccessPolicy.LocationPermissionResult locationResult =
2570 LocationAccessPolicy.checkLocationPermission(mApp,
2571 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2572 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002573 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002574 .setCallingPid(Binder.getCallingPid())
2575 .setCallingUid(Binder.getCallingUid())
2576 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002577 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2578 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002579 .build());
2580 switch (locationResult) {
2581 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002582 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2583 // Safetynet logging for b/154934934
2584 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2585 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002586 throw new SecurityException("Not allowed to access cell info");
2587 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002588 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2589 // Safetynet logging for b/154934934
2590 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2591 }
Nathan Harold5320c422019-05-09 10:26:08 -07002592 try {
2593 cb.onCellInfo(new ArrayList<CellInfo>());
2594 } catch (RemoteException re) {
2595 // Drop without consequences
2596 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002597 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002598 }
2599
Nathan Harolda939a962019-05-09 10:13:47 -07002600
2601 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002602 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2603
2604 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2605 }
2606
2607 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002609 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002610 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611
2612 final long identity = Binder.clearCallingIdentity();
2613 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002614 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 } finally {
2616 Binder.restoreCallingIdentity(identity);
2617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619
Shishir Agrawala9f32182016-04-12 12:00:16 -07002620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002621 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002622 Phone phone = PhoneFactory.getPhone(slotIndex);
2623 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 return null;
2625 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002626 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002627 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002628 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002629 return null;
2630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631
2632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 return phone.getImei();
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
2637 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002638 }
2639
2640 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002641 public String getTypeAllocationCodeForSlot(int slotIndex) {
2642 Phone phone = PhoneFactory.getPhone(slotIndex);
2643 String tac = null;
2644 if (phone != null) {
2645 String imei = phone.getImei();
2646 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2647 }
2648 return tac;
2649 }
2650
2651 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002652 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002653 Phone phone = PhoneFactory.getPhone(slotIndex);
2654 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002655 return null;
2656 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002657
Jeff Davidson913390f2018-02-23 17:11:49 -08002658 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002659 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002660 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002661 return null;
2662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663
2664 final long identity = Binder.clearCallingIdentity();
2665 try {
2666 return phone.getMeid();
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
Jack Yu2af8d712017-03-15 17:14:14 -07002670 }
2671
2672 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002673 public String getManufacturerCodeForSlot(int slotIndex) {
2674 Phone phone = PhoneFactory.getPhone(slotIndex);
2675 String manufacturerCode = null;
2676 if (phone != null) {
2677 String meid = phone.getMeid();
2678 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2679 }
2680 return manufacturerCode;
2681 }
2682
2683 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002684 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2685 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002686 Phone phone = PhoneFactory.getPhone(slotIndex);
2687 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002688 return null;
2689 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002690 int subId = phone.getSubId();
2691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002692 mApp, subId, callingPackage, callingFeatureId,
2693 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002694 return null;
2695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 return phone.getDeviceSvn();
2700 } finally {
2701 Binder.restoreCallingIdentity(identity);
2702 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002703 }
2704
fionaxu43304da2017-11-27 22:51:16 -08002705 @Override
2706 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707 final long identity = Binder.clearCallingIdentity();
2708 try {
2709 final Phone phone = getPhone(subId);
2710 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
fionaxu43304da2017-11-27 22:51:16 -08002714 }
2715
2716 @Override
2717 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 final Phone phone = getPhone(subId);
2721 return phone == null ? null : phone.getCarrierName();
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
2724 }
fionaxu43304da2017-11-27 22:51:16 -08002725 }
2726
calvinpanffe225e2018-11-01 19:43:06 +08002727 @Override
chen xu0026ca62019-03-06 15:28:50 -08002728 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002729 final long identity = Binder.clearCallingIdentity();
2730 try {
2731 final Phone phone = getPhone(subId);
2732 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002733 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002734 } finally {
2735 Binder.restoreCallingIdentity(identity);
2736 }
2737 }
2738
2739 @Override
chen xu0026ca62019-03-06 15:28:50 -08002740 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002744 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002745 } finally {
2746 Binder.restoreCallingIdentity(identity);
2747 }
2748 }
2749
chen xu651eec72018-11-11 19:03:44 -08002750 @Override
chen xu864e11c2018-12-06 22:10:03 -08002751 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2752 if (!isSubscriptionMccMnc) {
2753 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2754 }
chen xu651eec72018-11-11 19:03:44 -08002755 final Phone phone = PhoneFactory.getPhone(slotIndex);
2756 if (phone == null) {
2757 return TelephonyManager.UNKNOWN_CARRIER_ID;
2758 }
2759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
2764 }
2765 }
2766
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002767 //
2768 // Internal helper methods.
2769 //
2770
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002771 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2773 *
2774 * @throws SecurityException if the caller does not have the required permission
2775 */
2776 private void enforceModifyPermission() {
2777 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2778 }
2779
Shuo Qiancd19c462020-01-16 20:51:11 -08002780 /**
2781 * Make sure the caller is system.
2782 *
2783 * @throws SecurityException if the caller is not system.
2784 */
2785 private void enforceSystemCaller() {
2786 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2787 throw new SecurityException("Caller must be system");
2788 }
2789 }
2790
Shuo Qian3b6ee772019-11-13 17:43:31 -08002791 private void enforceActiveEmergencySessionPermission() {
2792 mApp.enforceCallingOrSelfPermission(
2793 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2794 }
2795
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 /**
2797 * Make sure the caller has the CALL_PHONE permission.
2798 *
2799 * @throws SecurityException if the caller does not have the required permission
2800 */
2801 private void enforceCallPermission() {
2802 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2803 }
2804
paulhu5a773602019-08-23 19:17:33 +08002805 private void enforceSettingsPermission() {
2806 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002807 }
2808
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809 private String createTelUrl(String number) {
2810 if (TextUtils.isEmpty(number)) {
2811 return null;
2812 }
2813
Jake Hambye994d462014-02-03 13:10:13 -08002814 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816
Ihab Awadf9e92732013-12-05 18:02:52 -08002817 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2819 }
2820
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002821 private static void logv(String msg) {
2822 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2823 }
2824
Ihab Awadf9e92732013-12-05 18:02:52 -08002825 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2827 }
2828
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002829 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002831 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002832 }
2833
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002835 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 final Phone phone = PhoneFactory.getPhone(slotIndex);
2839 if (phone == null) {
2840 return PhoneConstants.PHONE_TYPE_NONE;
2841 } else {
2842 return phone.getPhoneType();
2843 }
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
2849 /**
2850 * Returns the CDMA ERI icon index to display
2851 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002853 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2854 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2855 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002856 }
2857
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002859 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2860 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002862 mApp, subId, callingPackage, callingFeatureId,
2863 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002864 return -1;
2865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866
2867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 final Phone phone = getPhone(subId);
2870 if (phone != null) {
2871 return phone.getCdmaEriIconIndex();
2872 } else {
2873 return -1;
2874 }
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878 }
2879
2880 /**
2881 * Returns the CDMA ERI icon mode,
2882 * 0 - ON
2883 * 1 - FLASHING
2884 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002885 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002886 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2887 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2888 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002889 }
2890
Sanket Padawe356d7632015-06-22 14:03:32 -07002891 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002892 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2893 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002895 mApp, subId, callingPackage, callingFeatureId,
2896 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002897 return -1;
2898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 final Phone phone = getPhone(subId);
2903 if (phone != null) {
2904 return phone.getCdmaEriIconMode();
2905 } else {
2906 return -1;
2907 }
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 }
2912
2913 /**
2914 * Returns the CDMA ERI text,
2915 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002916 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002917 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2918 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2919 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002920 }
2921
Sanket Padawe356d7632015-06-22 14:03:32 -07002922 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002923 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2924 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002926 mApp, subId, callingPackage, callingFeatureId,
2927 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002928 return null;
2929 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002930
2931 final long identity = Binder.clearCallingIdentity();
2932 try {
2933 final Phone phone = getPhone(subId);
2934 if (phone != null) {
2935 return phone.getCdmaEriText();
2936 } else {
2937 return null;
2938 }
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002942 }
2943
2944 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002945 * Returns the CDMA MDN.
2946 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002947 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002948 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2950 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002955 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 return phone.getLine1Number();
2957 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002958 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002959 return null;
2960 }
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002963 }
2964 }
2965
2966 /**
2967 * Returns the CDMA MIN.
2968 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002969 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002970 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2972 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002973
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 final Phone phone = getPhone(subId);
2977 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2978 return phone.getCdmaMin();
2979 } else {
2980 return null;
2981 }
2982 } finally {
2983 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002984 }
2985 }
2986
Hall Liud892bec2018-11-30 14:51:45 -08002987 @Override
2988 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2989 INumberVerificationCallback callback, String callingPackage) {
2990 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2991 != PERMISSION_GRANTED) {
2992 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2993 }
2994 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2995
2996 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2997 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2998 throw new SecurityException("Calling package must be configured in the device config");
2999 }
3000
3001 if (range == null) {
3002 throw new NullPointerException("Range must be non-null");
3003 }
3004
3005 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003006 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003007
3008 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3009 }
3010
Junda Liuca05d5d2014-08-14 22:36:34 -07003011 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003012 * Returns true if CDMA provisioning needs to run.
3013 */
3014 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 final long identity = Binder.clearCallingIdentity();
3016 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003017 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 }
3022
3023 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003024 * Sets the voice mail number of a given subId.
3025 */
3026 @Override
3027 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003028 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3029 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3034 new Pair<String, String>(alphaTag, number), new Integer(subId));
3035 return success;
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003039 }
3040
Ta-wei Yen87c49842016-05-13 21:19:52 -07003041 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003042 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003044 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3045 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003046 if (!TextUtils.equals(callingPackage, systemDialer)) {
3047 throw new SecurityException("caller must be system dialer");
3048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049
3050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3053 if (phoneAccountHandle == null) {
3054 return null;
3055 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003056 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003059 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003060 }
3061
3062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003063 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3064 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003067 mApp, subId, callingPackage, callingFeatureId,
3068 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003069 return null;
3070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003072 final long identity = Binder.clearCallingIdentity();
3073 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003074 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003078 }
3079
3080 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003081 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3082 VisualVoicemailSmsFilterSettings settings) {
3083 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003088 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003092 }
3093
3094 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003095 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3096 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097
3098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003101 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003105 }
3106
3107 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003108 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3109 String callingPackage, int subId) {
3110 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111
3112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003115 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003119 }
3120
3121 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003122 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003123 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124
3125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003128 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003132 }
3133
3134 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003135 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3136 String callingAttributionTag, int subId, String number, int port, String text,
3137 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003138 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003139 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003140 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003141 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003142 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3143 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003144 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003145
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003146 /**
fionaxu0152e512016-11-14 13:36:14 -08003147 * Sets the voice activation state of a given subId.
3148 */
3149 @Override
3150 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3152 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 final Phone phone = getPhone(subId);
3157 if (phone != null) {
3158 phone.setVoiceActivationState(activationState);
3159 } else {
3160 loge("setVoiceActivationState fails with invalid subId: " + subId);
3161 }
3162 } finally {
3163 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003164 }
3165 }
3166
3167 /**
3168 * Sets the data activation state of a given subId.
3169 */
3170 @Override
3171 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3173 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174
3175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 final Phone phone = getPhone(subId);
3178 if (phone != null) {
3179 phone.setDataActivationState(activationState);
3180 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003181 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003182 }
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003185 }
3186 }
3187
3188 /**
3189 * Returns the voice activation state of a given subId.
3190 */
3191 @Override
3192 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003193 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194
fionaxu0152e512016-11-14 13:36:14 -08003195 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 if (phone != null) {
3199 return phone.getVoiceActivationState();
3200 } else {
3201 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3202 }
3203 } finally {
3204 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003205 }
3206 }
3207
3208 /**
3209 * Returns the data activation state of a given subId.
3210 */
3211 @Override
3212 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214
fionaxu0152e512016-11-14 13:36:14 -08003215 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 if (phone != null) {
3219 return phone.getDataActivationState();
3220 } else {
3221 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3222 }
3223 } finally {
3224 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003225 }
3226 }
3227
3228 /**
Wink Saville36469e72014-06-11 15:17:00 -07003229 * Returns the unread count of voicemails for a subId
3230 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003231 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003232 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3233 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003235 mApp, subId, callingPackage, callingFeatureId,
3236 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003237 return 0;
3238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003239 final long identity = Binder.clearCallingIdentity();
3240 try {
3241 final Phone phone = getPhone(subId);
3242 if (phone != null) {
3243 return phone.getVoiceMessageCount();
3244 } else {
3245 return 0;
3246 }
3247 } finally {
3248 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 }
3251
3252 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003253 * returns true, if the device is in a state where both voice and data
3254 * are supported simultaneously. This can change based on location or network condition.
3255 */
3256 @Override
3257 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003258 final long identity = Binder.clearCallingIdentity();
3259 try {
3260 final Phone phone = getPhone(subId);
3261 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3262 } finally {
3263 Binder.restoreCallingIdentity(identity);
3264 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003265 }
3266
3267 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003268 * Send the dialer code if called from the current default dialer or the caller has
3269 * carrier privilege.
3270 * @param inputCode The dialer code to send
3271 */
3272 @Override
3273 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003275 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003276 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3277 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003278 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003279 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003280 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282
3283 final long identity = Binder.clearCallingIdentity();
3284 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
fionaxu235cc5e2017-03-06 22:25:57 -08003289 }
3290
Pengquan Menga1bb6272018-09-06 09:59:22 -07003291 @Override
3292 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003293 TelephonyPermissions
3294 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3295 mApp, subId, "getNetworkSelectionMode");
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 if (!isActiveSubscription(subId)) {
3299 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3300 }
3301 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3302 } finally {
3303 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003304 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003305 }
3306
Brad Ebinger35c841c2018-10-01 10:40:55 -07003307 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003308 public boolean isInEmergencySmsMode() {
3309 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 for (Phone phone : PhoneFactory.getPhones()) {
3313 if (phone.isInEmergencySmsMode()) {
3314 return true;
3315 }
3316 }
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
3320 return false;
3321 }
3322
shilu366312e2019-12-17 09:28:10 -08003323 /**
3324 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3325 * @param subId The subscription to use to check the configuration.
3326 * @param c The callback that will be used to send the result.
3327 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003328 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003329 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3330 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003331 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3332 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003333
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003334 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3336 "IMS not available on device.");
3337 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003338 final long token = Binder.clearCallingIdentity();
3339 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003340 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003341 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003342 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003343 } catch (ImsException e) {
3344 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 } finally {
3346 Binder.restoreCallingIdentity(token);
3347 }
3348 }
3349
shilu366312e2019-12-17 09:28:10 -08003350 /**
3351 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3352 * @param subId The subscription to use to check the configuration.
3353 * @param c The callback that will be used to send the result.
3354 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003355 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003356 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003357 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3358 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003359 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3360 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3361 }
Meng Wangafbc5852019-09-19 17:37:13 -07003362 final long token = Binder.clearCallingIdentity();
3363 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003364 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003365 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3366 .removeRegistrationCallbackForSubscription(c, subId);
3367 } catch (ImsException e) {
3368 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3369 + "is inactive, ignoring unregister.");
3370 // If the subscription is no longer active, just return, since the callback
3371 // will already have been removed internally.
3372 } finally {
3373 Binder.restoreCallingIdentity(token);
3374 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003375 }
3376
Brad Ebingera34a6c22019-10-22 17:36:18 -07003377 /**
3378 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3379 */
3380 @Override
3381 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3382 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3383 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3384 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3385 "IMS not available on device.");
3386 }
3387 final long token = Binder.clearCallingIdentity();
3388 try {
3389 Phone phone = getPhone(subId);
3390 if (phone == null) {
3391 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3392 + subId + "'");
3393 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3394 }
3395 phone.getImsRegistrationState(regState -> {
3396 try {
3397 consumer.accept((regState == null)
3398 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3399 } catch (RemoteException e) {
3400 // Ignore if the remote process is no longer available to call back.
3401 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3402 }
3403 });
3404 } finally {
3405 Binder.restoreCallingIdentity(token);
3406 }
3407 }
3408
3409 /**
3410 * Get the transport type for the IMS service registration state.
3411 */
3412 @Override
3413 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003414 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3415 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003416 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3417 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3418 "IMS not available on device.");
3419 }
3420 final long token = Binder.clearCallingIdentity();
3421 try {
3422 Phone phone = getPhone(subId);
3423 if (phone == null) {
3424 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3425 + subId + "'");
3426 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3427 }
3428 phone.getImsRegistrationTech(regTech -> {
3429 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3430 int regTechConverted = (regTech == null)
3431 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3432 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3433 regTechConverted);
3434 try {
3435 consumer.accept(regTechConverted);
3436 } catch (RemoteException e) {
3437 // Ignore if the remote process is no longer available to call back.
3438 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3439 }
3440 });
3441 } finally {
3442 Binder.restoreCallingIdentity(token);
3443 }
3444 }
3445
shilu366312e2019-12-17 09:28:10 -08003446 /**
3447 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3448 * @param subId The subscription to use to check the configuration.
3449 * @param c The callback that will be used to send the result.
3450 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003451 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003452 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3453 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003454 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3455 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003456 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3457 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3458 "IMS not available on device.");
3459 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003460 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3461 final long token = Binder.clearCallingIdentity();
3462 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003463 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003464 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003465 } catch (ImsException e) {
3466 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003467 } finally {
3468 Binder.restoreCallingIdentity(token);
3469 }
3470 }
3471
shilu366312e2019-12-17 09:28:10 -08003472 /**
3473 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3474 * @param subId The subscription to use to check the configuration.
3475 * @param c The callback that will be used to send the result.
3476 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003477 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003478 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003479 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3480 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003481 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3482 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3483 }
Meng Wangafbc5852019-09-19 17:37:13 -07003484
3485 final long token = Binder.clearCallingIdentity();
3486 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003487 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003488 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003489 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003490 } catch (ImsException e) {
3491 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3492 + "is inactive, ignoring unregister.");
3493 // If the subscription is no longer active, just return, since the callback
3494 // will already have been removed internally.
3495 } finally {
3496 Binder.restoreCallingIdentity(token);
3497 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003498 }
3499
3500 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003501 public boolean isCapable(int subId, int capability, int regTech) {
3502 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003503 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3504 final long token = Binder.clearCallingIdentity();
3505 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003506 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003507 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003508 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3510 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003511 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003512 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3513 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 } finally {
3515 Binder.restoreCallingIdentity(token);
3516 }
3517 }
3518
3519 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003520 public boolean isAvailable(int subId, int capability, int regTech) {
3521 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 final long token = Binder.clearCallingIdentity();
3523 try {
3524 Phone phone = getPhone(subId);
3525 if (phone == null) return false;
3526 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003527 } catch (com.android.ims.ImsException e) {
3528 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3529 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 } finally {
3531 Binder.restoreCallingIdentity(token);
3532 }
3533 }
3534
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003535 /**
3536 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3537 * subscription.
3538 * @param subId The subscription to use to check the configuration.
3539 * @param callback The callback that will be used to send the result.
3540 * @param capability The MmTelFeature capability that will be used to send the result.
3541 * @param transportType The transport type of the MmTelFeature capability.
3542 */
3543 @Override
3544 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3545 int transportType) {
3546 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3547 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3548 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3549 "IMS not available on device.");
3550 }
3551 final long token = Binder.clearCallingIdentity();
3552 try {
3553 int slotId = getSlotIndex(subId);
3554 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3555 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3556 + subId + "'");
3557 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3558 }
3559 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3560 transportType, aBoolean -> {
3561 try {
3562 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3563 } catch (RemoteException e) {
3564 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3565 + "running. Ignore");
3566 }
3567 });
3568 } finally {
3569 Binder.restoreCallingIdentity(token);
3570 }
3571 }
3572
shilu366312e2019-12-17 09:28:10 -08003573 /**
3574 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3575 * @param subId The subscription to use to check the configuration.
3576 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003577 @Override
3578 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003579 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3580 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003581
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3583 final long token = Binder.clearCallingIdentity();
3584 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003585 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003587 } catch (ImsException e) {
3588 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 } finally {
3590 Binder.restoreCallingIdentity(token);
3591 }
3592 }
3593
3594 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003595 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003597 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003601 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003603 } catch (ImsException e) {
3604 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 } finally {
3606 Binder.restoreCallingIdentity(identity);
3607 }
3608 }
3609
shilu366312e2019-12-17 09:28:10 -08003610 /**
3611 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3612 * @param subId The subscription to use to check the configuration.
3613 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003615 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003616 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3617 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 final long identity = Binder.clearCallingIdentity();
3619 try {
3620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003621 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3622 } catch (ImsException e) {
3623 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003624 } finally {
3625 Binder.restoreCallingIdentity(identity);
3626 }
3627 }
3628
3629 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003630 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003632 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003636 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003637 } catch (ImsException e) {
3638 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 } finally {
3640 Binder.restoreCallingIdentity(identity);
3641 }
3642 }
3643
shilu366312e2019-12-17 09:28:10 -08003644 /**
3645 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3646 * @param subId The subscription to use to check the configuration.
3647 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003648 @Override
3649 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003650 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3651 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003652 final long identity = Binder.clearCallingIdentity();
3653 try {
3654 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003655 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003656 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003657 } catch (ImsException e) {
3658 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
3662 }
3663
3664 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003665 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003667 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003671 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003672 } catch (ImsException e) {
3673 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
3677 }
3678
shilu366312e2019-12-17 09:28:10 -08003679 /**
3680 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3681 * @param subId The subscription to use to check the configuration.
3682 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003683 @Override
3684 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003685 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3686 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003690 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003692 } catch (ImsException e) {
3693 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
3697 }
3698
3699 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003700 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003702 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 } catch (ImsException e) {
3709 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
3713 }
3714
3715 @Override
3716 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3718 "setVoWiFiNonPersistent");
3719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003722 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003723 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 } catch (ImsException e) {
3725 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
3729 }
3730
shilu366312e2019-12-17 09:28:10 -08003731 /**
3732 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3733 * @param subId The subscription to use to check the configuration.
3734 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003735 @Override
3736 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003737 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3738 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003743 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003744 } catch (ImsException e) {
3745 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
3749 }
3750
3751 @Override
3752 public void setVoWiFiModeSetting(int subId, int mode) {
3753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3754 "setVoWiFiModeSetting");
3755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003758 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003759 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003760 } catch (ImsException e) {
3761 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
3765 }
3766
3767 @Override
3768 public int getVoWiFiRoamingModeSetting(int subId) {
3769 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3770 final long identity = Binder.clearCallingIdentity();
3771 try {
3772 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003773 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003774 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003775 } catch (ImsException e) {
3776 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003777 } finally {
3778 Binder.restoreCallingIdentity(identity);
3779 }
3780 }
3781
3782 @Override
3783 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3785 "setVoWiFiRoamingModeSetting");
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003789 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003790 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003791 } catch (ImsException e) {
3792 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 } finally {
3794 Binder.restoreCallingIdentity(identity);
3795 }
3796 }
3797
3798 @Override
3799 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3801 "setRttCapabilityEnabled");
3802 final long identity = Binder.clearCallingIdentity();
3803 try {
3804 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003805 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3806 } catch (ImsException e) {
3807 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003808 } finally {
3809 Binder.restoreCallingIdentity(identity);
3810 }
3811 }
3812
shilu366312e2019-12-17 09:28:10 -08003813 /**
3814 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3815 * @param subId The subscription to use to check the configuration.
3816 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003817 @Override
3818 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003819 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3820 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 final long identity = Binder.clearCallingIdentity();
3822 try {
3823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003824 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003826 } catch (ImsException e) {
3827 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 } finally {
3829 Binder.restoreCallingIdentity(identity);
3830 }
3831 }
3832
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003833 @Override
3834 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3835 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3836 final long identity = Binder.clearCallingIdentity();
3837 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003838 if (!isImsAvailableOnDevice()) {
3839 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3840 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003841 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003842 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003843 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003844 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003845 } catch (ImsException e) {
3846 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003847 } finally {
3848 Binder.restoreCallingIdentity(identity);
3849 }
3850 }
3851
3852 @Override
3853 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3854 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3855 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3857 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3858 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003859 try {
3860 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003861 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003862 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003863 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003864 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3865 + "is inactive, ignoring unregister.");
3866 // If the subscription is no longer active, just return, since the callback will already
3867 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003868 } finally {
3869 Binder.restoreCallingIdentity(identity);
3870 }
3871 }
3872
allenwtsu99c623b2020-01-03 18:24:23 +08003873
3874 private void checkModifyPhoneStatePermission(int subId, String message) {
3875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3876 message);
3877 }
3878
3879 private boolean isImsProvisioningRequired(int subId, int capability,
3880 boolean isMmtelCapability) {
3881 Phone phone = getPhone(subId);
3882 if (phone == null) {
3883 loge("phone instance null for subid " + subId);
3884 return false;
3885 }
3886 if (isMmtelCapability) {
3887 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3888 return false;
3889 }
3890 } else {
3891 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3892 return false;
3893 }
3894 }
3895 return true;
3896 }
3897
3898 @Override
3899 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3900 boolean isProvisioned) {
3901 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3902
3903 final long identity = Binder.clearCallingIdentity();
3904 try {
3905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3906 if (!isImsProvisioningRequired(subId, capability, false)) {
3907 return;
3908 }
3909
3910 // this capability requires provisioning, route to the correct API.
3911 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3912 switch (capability) {
3913 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3914 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3915 ims.setEabProvisioned(isProvisioned);
3916 break;
3917 default: {
3918 throw new IllegalArgumentException("Tried to set provisioning for "
3919 + "rcs capability '" + capability + "', which does not require "
3920 + "provisioning.");
3921 }
3922 }
3923 } finally {
3924 Binder.restoreCallingIdentity(identity);
3925 }
3926
3927 }
3928
3929
3930 @Override
3931 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3932 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3936 if (!isImsProvisioningRequired(subId, capability, false)) {
3937 return true;
3938 }
3939
3940 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3941 switch (capability) {
3942 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3943 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3944 return ims.isEabProvisionedOnDevice();
3945
3946 default: {
3947 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3948 + "capability '" + capability + "', which does not require "
3949 + "provisioning.");
3950 }
3951 }
3952
3953 } finally {
3954 Binder.restoreCallingIdentity(identity);
3955 }
3956 }
3957
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003958 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003959 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3960 boolean isProvisioned) {
3961 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3962 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3963 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3964 }
allenwtsu99c623b2020-01-03 18:24:23 +08003965 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003969 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003970 return;
3971 }
3972
3973 // this capability requires provisioning, route to the correct API.
3974 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3975 switch (capability) {
3976 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3977 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3978 ims.setVolteProvisioned(isProvisioned);
3979 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3980 ims.setWfcProvisioned(isProvisioned);
3981 }
3982 break;
3983 }
3984 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3985 // There is currently no difference in VT provisioning type.
3986 ims.setVtProvisioned(isProvisioned);
3987 break;
3988 }
3989 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3990 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3991 // change the capability of the feature instead if needed.
3992 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3993 == isProvisioned) {
3994 // No change in provisioning.
3995 return;
3996 }
3997 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3998 try {
3999 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004000 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004001 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4002 + ", Exception" + e.getMessage());
4003 }
4004 break;
4005 }
4006 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004007 throw new IllegalArgumentException("Tried to set provisioning for "
4008 + "MmTel capability '" + capability + "', which does not require "
4009 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004010 }
4011 }
4012
4013 } finally {
4014 Binder.restoreCallingIdentity(identity);
4015 }
4016 }
4017
4018 @Override
4019 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4020 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4021 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4022 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4023 }
4024 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4025 final long identity = Binder.clearCallingIdentity();
4026 try {
4027 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004028 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004029 return true;
4030 }
4031
4032 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4033 switch (capability) {
4034 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4035 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4036 return ims.isVolteProvisionedOnDevice();
4037 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4038 return ims.isWfcProvisionedOnDevice();
4039 }
4040 // This should never happen, since we are checking tech above to make sure it
4041 // is either LTE or IWLAN.
4042 throw new IllegalArgumentException("Invalid radio technology for voice "
4043 + "capability.");
4044 }
4045 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4046 // There is currently no difference in VT provisioning type.
4047 return ims.isVtProvisionedOnDevice();
4048 }
4049 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4050 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4051 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4052 }
4053 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004054 throw new IllegalArgumentException(
4055 "Tried to get provisioning for MmTel capability '" + capability
4056 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004057 }
4058 }
4059
4060 } finally {
4061 Binder.restoreCallingIdentity(identity);
4062 }
4063 }
4064
4065 @Override
4066 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4067 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4068 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4069 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4070 }
4071 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4072 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4073 return (provisionedBits & capability) > 0;
4074 }
4075
4076 @Override
4077 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4078 boolean isProvisioned) {
4079 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4080 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4081 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4082 }
4083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4084 "setProvisioningStatusForCapability");
4085 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4086 // If the current provisioning status for capability already matches isProvisioned,
4087 // do nothing.
4088 if (((provisionedBits & capability) > 0) == isProvisioned) {
4089 return;
4090 }
4091 if (isProvisioned) {
4092 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4093 } else {
4094 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4095 }
4096 }
4097
4098 /**
4099 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4100 * technology. The bitfield should mirror the bitfield defined by
4101 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4102 */
4103 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4104 String key = getMmTelProvisioningKey(subId, tech);
4105 // Default is no capabilities are provisioned.
4106 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4107 }
4108
4109 /**
4110 * Sets the MmTel capability provisioning bitfield (defined by
4111 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4112 * technology specified.
4113 *
4114 * Note: This is a synchronous command and should not be called on UI thread.
4115 */
4116 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4117 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4118 String key = getMmTelProvisioningKey(subId, tech);
4119 editor.putInt(key, newField);
4120 editor.commit();
4121 }
4122
4123 private static String getMmTelProvisioningKey(int subId, int tech) {
4124 // resulting key is provision_ims_mmtel_{subId}_{tech}
4125 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4126 }
4127
4128 /**
4129 * Query CarrierConfig to see if the specified capability requires provisioning for the
4130 * carrier associated with the subscription id.
4131 */
4132 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4133 int capability) {
4134 CarrierConfigManager configManager = new CarrierConfigManager(context);
4135 PersistableBundle c = configManager.getConfigForSubId(subId);
4136 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004137 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004138 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4139 false);
4140 boolean requireVoiceVtProvisioning = c.getBoolean(
4141 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4142
4143 // First check to make sure that the capability requires provisioning.
4144 switch (capability) {
4145 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4146 // intentional fallthrough
4147 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4148 if (requireVoiceVtProvisioning) {
4149 // Voice and Video requires provisioning
4150 return true;
4151 }
4152 break;
4153 }
4154 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4155 if (requireUtProvisioning) {
4156 // UT requires provisioning
4157 return true;
4158 }
4159 break;
4160 }
4161 }
4162 return false;
4163 }
4164
allenwtsu99c623b2020-01-03 18:24:23 +08004165 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4166 int capability) {
4167 CarrierConfigManager configManager = new CarrierConfigManager(context);
4168 PersistableBundle c = configManager.getConfigForSubId(subId);
4169
4170 boolean requireRcsProvisioning = c.getBoolean(
4171 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4172
4173 // First check to make sure that the capability requires provisioning.
4174 switch (capability) {
4175 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4176 // intentional fallthrough
4177 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4178 if (requireRcsProvisioning) {
4179 // OPTION or PRESENCE requires provisioning
4180 return true;
4181 }
4182 break;
4183 }
4184 }
4185 return false;
4186 }
4187
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004188 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004189 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004190 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4191 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4192 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004193 enforceReadPrivilegedPermission("getImsProvisioningInt");
4194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004197 int slotId = getSlotIndex(subId);
4198 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4199 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4200 + subId + "' for key:" + key);
4201 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4202 }
4203 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004204 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004205 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4206 + subId + "' for key:" + key);
4207 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004208 } finally {
4209 Binder.restoreCallingIdentity(identity);
4210 }
4211 }
4212
4213 @Override
4214 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004215 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4216 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4217 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004218 enforceReadPrivilegedPermission("getImsProvisioningString");
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
4221 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004222 int slotId = getSlotIndex(subId);
4223 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4224 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4225 + subId + "' for key:" + key);
4226 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4227 }
4228 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004229 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004230 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4231 + subId + "' for key:" + key);
4232 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004233 } finally {
4234 Binder.restoreCallingIdentity(identity);
4235 }
4236 }
4237
4238 @Override
4239 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004240 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4241 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4242 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4244 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004245 final long identity = Binder.clearCallingIdentity();
4246 try {
4247 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004248 int slotId = getSlotIndex(subId);
4249 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4250 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4251 + subId + "' for key:" + key);
4252 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4253 }
4254 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004255 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004256 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4257 + "' for key:" + key);
4258 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
4262 }
4263
4264 @Override
4265 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004266 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4267 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4268 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4270 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004271 final long identity = Binder.clearCallingIdentity();
4272 try {
4273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004274 int slotId = getSlotIndex(subId);
4275 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4276 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4277 + subId + "' for key:" + key);
4278 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4279 }
4280 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004281 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004282 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4283 + "' for key:" + key);
4284 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004285 } finally {
4286 Binder.restoreCallingIdentity(identity);
4287 }
4288 }
4289
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004290 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 int slotId = SubscriptionManager.getSlotIndex(subId);
4292 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004293 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4294 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 }
4296 return slotId;
4297 }
4298
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004299 private int getSlotIndex(int subId) {
4300 int slotId = SubscriptionManager.getSlotIndex(subId);
4301 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4302 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4303 }
4304 return slotId;
4305 }
4306
Wink Saville36469e72014-06-11 15:17:00 -07004307 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004308 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004309 */
4310 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004311 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4312 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004313 final int targetSdk = getTargetSdk(callingPackage);
4314 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004315 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004316 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004317 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004318 mApp, subId, callingPackage, callingFeatureId,
4319 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004320 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4321 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 final Phone phone = getPhone(subId);
4326 if (phone != null) {
4327 return phone.getServiceState().getDataNetworkType();
4328 } else {
4329 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4330 }
4331 } finally {
4332 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004334 }
4335
4336 /**
4337 * Returns the data network type
4338 */
4339 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004340 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4341 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4342 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004343 }
4344
4345 /**
4346 * Returns the data network type for a subId
4347 */
4348 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004349 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4350 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004352 mApp, subId, callingPackage, callingFeatureId,
4353 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004354 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4355 }
4356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 final Phone phone = getPhone(subId);
4360 if (phone != null) {
4361 return phone.getServiceState().getDataNetworkType();
4362 } else {
4363 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4364 }
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004368 }
4369
4370 /**
Wink Saville36469e72014-06-11 15:17:00 -07004371 * Returns the Voice network type for a subId
4372 */
4373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004374 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4375 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004377 mApp, subId, callingPackage, callingFeatureId,
4378 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004379 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4380 }
4381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382 final long identity = Binder.clearCallingIdentity();
4383 try {
4384 final Phone phone = getPhone(subId);
4385 if (phone != null) {
4386 return phone.getServiceState().getVoiceNetworkType();
4387 } else {
4388 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4389 }
4390 } finally {
4391 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004393 }
4394
4395 /**
4396 * @return true if a ICC card is present
4397 */
4398 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004399 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004400 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4401 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004402 }
4403
4404 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004405 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004406 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004407 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004408 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 final long identity = Binder.clearCallingIdentity();
4410 try {
4411 final Phone phone = PhoneFactory.getPhone(slotIndex);
4412 if (phone != null) {
4413 return phone.getIccCard().hasIccCard();
4414 } else {
4415 return false;
4416 }
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004420 }
4421
4422 /**
4423 * Return if the current radio is LTE on CDMA. This
4424 * is a tri-state return value as for a period of time
4425 * the mode may be unknown.
4426 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004427 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004428 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004429 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004430 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004431 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004432 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4433 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4434 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004435 }
4436
Sanket Padawe356d7632015-06-22 14:03:32 -07004437 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004438 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4439 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004440 try {
4441 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4442 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004443 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4444 }
4445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 final long identity = Binder.clearCallingIdentity();
4447 try {
4448 final Phone phone = getPhone(subId);
4449 if (phone == null) {
4450 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4451 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004452 return TelephonyProperties.lte_on_cdma_device()
4453 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004454 }
4455 } finally {
4456 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004457 }
Wink Saville36469e72014-06-11 15:17:00 -07004458 }
4459
Wink Saville36469e72014-06-11 15:17:00 -07004460 /**
4461 * {@hide}
4462 * Returns Default subId, 0 in the case of single standby.
4463 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004464 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004465 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004466 }
4467
Shishir Agrawala9f32182016-04-12 12:00:16 -07004468 private int getSlotForDefaultSubscription() {
4469 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4470 }
4471
Wink Savilleb564aae2014-10-23 10:18:09 -07004472 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004473 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004474 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004475
Pengquan Menge92a50d2018-09-21 15:54:48 -07004476 private boolean isActiveSubscription(int subId) {
4477 return mSubscriptionController.isActiveSubId(subId);
4478 }
4479
Ihab Awadf2177b72013-11-25 13:33:23 -08004480 /**
4481 * @see android.telephony.TelephonyManager.WifiCallingChoices
4482 */
4483 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004484 final long identity = Binder.clearCallingIdentity();
4485 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004486 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4488 getWhenToMakeWifiCallsDefaultPreference());
4489 } finally {
4490 Binder.restoreCallingIdentity(identity);
4491 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004492 }
4493
4494 /**
4495 * @see android.telephony.TelephonyManager.WifiCallingChoices
4496 */
4497 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 final long identity = Binder.clearCallingIdentity();
4499 try {
4500 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004501 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004506 }
4507
Sailesh Nepald1e68152013-12-12 19:08:02 -08004508 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004509 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004510 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004511 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004512
Jordan Liu4c733742019-02-28 12:03:40 -08004513 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4514 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4515 if (phoneId == -1) {
4516 throw new IllegalArgumentException("Given slot index: " + slotIndex
4517 + " does not correspond to an active phone");
4518 }
4519 return PhoneFactory.getPhone(phoneId);
4520 }
4521
Shishir Agrawal566b7612013-10-28 14:41:00 -07004522 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004523 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4524 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4526 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004527 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004528 if (DBG) {
4529 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4530 }
4531 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4532 p2);
4533 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004534
Jordan Liu4c733742019-02-28 12:03:40 -08004535
4536 @Override
4537 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4538 int slotIndex, String callingPackage, String aid, int p2) {
4539 enforceModifyPermission();
4540 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4541 if (DBG) {
4542 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4543 }
4544 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4545 callingPackage, aid, p2);
4546 }
4547
4548 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4549 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550 final long identity = Binder.clearCallingIdentity();
4551 try {
4552 if (TextUtils.equals(ISDR_AID, aid)) {
4553 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004554 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4555 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 if (bestComponent == null
4557 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4558 loge("The calling package is not allowed to access ISD-R.");
4559 throw new SecurityException(
4560 "The calling package is not allowed to access ISD-R.");
4561 }
Derek Tan740e1672017-06-27 14:56:27 -07004562 }
Derek Tan740e1672017-06-27 14:56:27 -07004563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004565 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4566 null /* workSource */);
4567 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 return response;
4569 } finally {
4570 Binder.restoreCallingIdentity(identity);
4571 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004572 }
4573
4574 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004575 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4577 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004578 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4579 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4580 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004581
Jordan Liu4c733742019-02-28 12:03:40 -08004582 @Override
4583 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4584 enforceModifyPermission();
4585 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4586 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4587 channel);
4588 }
4589
4590 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 final long identity = Binder.clearCallingIdentity();
4592 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593 if (channel < 0) {
4594 return false;
4595 }
Jordan Liu4c733742019-02-28 12:03:40 -08004596 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4597 null /* workSource */);
4598 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599 return success;
4600 } finally {
4601 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004602 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004603 }
4604
4605 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004606 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004607 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4609 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004610 if (DBG) {
4611 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4612 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4613 + p3 + " data=" + data);
4614 }
4615 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4616 command, p1, p2, p3, data);
4617 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004618
Jordan Liu4c733742019-02-28 12:03:40 -08004619 @Override
4620 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4621 int command, int p1, int p2, int p3, String data) {
4622 enforceModifyPermission();
4623 if (DBG) {
4624 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4625 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4626 + p3 + " data=" + data);
4627 }
4628 return iccTransmitApduLogicalChannelWithPermission(
4629 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4630 data);
4631 }
4632
4633 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4634 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 final long identity = Binder.clearCallingIdentity();
4636 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004637 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004638 return "";
4639 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004642 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4643 null /* workSource */);
4644 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 // Append the returned status code to the end of the response payload.
4647 String s = Integer.toHexString(
4648 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4649 if (response.payload != null) {
4650 s = IccUtils.bytesToHexString(response.payload) + s;
4651 }
4652 return s;
4653 } finally {
4654 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004655 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004656 }
Jake Hambye994d462014-02-03 13:10:13 -08004657
Evan Charltonc66da362014-05-16 14:06:40 -07004658 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004659 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4660 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4662 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004664 if (DBG) {
4665 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4666 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4667 }
4668 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4669 cla, command, p1, p2, p3, data);
4670 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004671
Jordan Liu4c733742019-02-28 12:03:40 -08004672 @Override
4673 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4674 int command, int p1, int p2, int p3, String data) {
4675 enforceModifyPermission();
4676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4677 if (DBG) {
4678 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4679 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4680 + " data=" + data);
4681 }
4682
4683 return iccTransmitApduBasicChannelWithPermission(
4684 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4685 p2, p3, data);
4686 }
4687
4688 // open APDU basic channel assuming the caller has sufficient permissions
4689 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4690 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4694 && TextUtils.equals(ISDR_AID, data)) {
4695 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004696 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4697 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 if (bestComponent == null
4699 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4700 loge("The calling package is not allowed to select ISD-R.");
4701 throw new SecurityException(
4702 "The calling package is not allowed to select ISD-R.");
4703 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004704 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004707 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4708 null /* workSource */);
4709 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 // Append the returned status code to the end of the response payload.
4712 String s = Integer.toHexString(
4713 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4714 if (response.payload != null) {
4715 s = IccUtils.bytesToHexString(response.payload) + s;
4716 }
4717 return s;
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004720 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004721 }
4722
4723 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004724 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004725 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4727 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729 final long identity = Binder.clearCallingIdentity();
4730 try {
4731 if (DBG) {
4732 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4733 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4734 }
4735
4736 IccIoResult response =
4737 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4738 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4739 subId);
4740
4741 if (DBG) {
4742 log("Exchange SIM_IO [R]" + response);
4743 }
4744
4745 byte[] result = null;
4746 int length = 2;
4747 if (response.payload != null) {
4748 length = 2 + response.payload.length;
4749 result = new byte[length];
4750 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4751 } else {
4752 result = new byte[length];
4753 }
4754
4755 result[length - 1] = (byte) response.sw2;
4756 result[length - 2] = (byte) response.sw1;
4757 return result;
4758 } finally {
4759 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004760 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004761 }
4762
Nathan Haroldb3014052017-01-25 15:57:32 -08004763 /**
4764 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4765 * on a particular subscription
4766 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004767 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4768 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004770 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004771 return null;
4772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773
4774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 if (appType != TelephonyManager.APPTYPE_USIM
4777 && appType != TelephonyManager.APPTYPE_SIM) {
4778 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4779 return null;
4780 }
4781 Object response = sendRequest(
4782 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4783 if (response instanceof String[]) {
4784 return (String[]) response;
4785 }
yincheng zhao2737e882019-09-06 17:06:54 -07004786 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004787 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004788 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 } finally {
4790 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004791 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004792 }
4793
yincheng zhao2737e882019-09-06 17:06:54 -07004794 /**
4795 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4796 * subscription.
4797 *
4798 * @param subId the id of the subscription.
4799 * @param appType the uicc app type, must be USIM or SIM.
4800 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4801 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004802 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004803 * @return number of fplmns that is successfully written to the SIM.
4804 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004805 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4806 String callingFeatureId) {
4807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4808 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004809 if (DBG) logv("no permissions for setForbiddenplmns");
4810 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4811 }
4812 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4813 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4814 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4815 }
4816 if (fplmns == null) {
4817 throw new IllegalArgumentException("Fplmn List provided is null");
4818 }
4819 for (String fplmn : fplmns) {
4820 if (!CellIdentity.isValidPlmn(fplmn)) {
4821 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4822 }
4823 }
4824 final long identity = Binder.clearCallingIdentity();
4825 try {
4826 Object response = sendRequest(
4827 CMD_SET_FORBIDDEN_PLMNS,
4828 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4829 subId);
4830 return (int) response;
4831 } finally {
4832 Binder.restoreCallingIdentity(identity);
4833 }
4834 }
4835
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004836 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004837 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4839 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841 final long identity = Binder.clearCallingIdentity();
4842 try {
4843 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4844 if (response.payload == null) {
4845 return "";
4846 }
Evan Charltonc66da362014-05-16 14:06:40 -07004847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848 // Append the returned status code to the end of the response payload.
4849 String s = Integer.toHexString(
4850 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4851 s = IccUtils.bytesToHexString(response.payload) + s;
4852 return s;
4853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
Evan Charltonc66da362014-05-16 14:06:40 -07004856 }
4857
Jake Hambye994d462014-02-03 13:10:13 -08004858 /**
4859 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4860 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4861 *
4862 * @param itemID the ID of the item to read
4863 * @return the NV item as a String, or null on error.
4864 */
4865 @Override
4866 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004867 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4869 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870
4871 final long identity = Binder.clearCallingIdentity();
4872 try {
4873 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004874 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4876 return value;
4877 } finally {
4878 Binder.restoreCallingIdentity(identity);
4879 }
Jake Hambye994d462014-02-03 13:10:13 -08004880 }
4881
4882 /**
4883 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4884 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4885 *
4886 * @param itemID the ID of the item to read
4887 * @param itemValue the value to write, as a String
4888 * @return true on success; false on any failure
4889 */
4890 @Override
4891 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004892 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4894 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895
4896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4899 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004900 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004901 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4902 return success;
4903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
Jake Hambye994d462014-02-03 13:10:13 -08004906 }
4907
4908 /**
4909 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4910 * Used for device configuration by some CDMA operators.
4911 *
4912 * @param preferredRoamingList byte array containing the new PRL
4913 * @return true on success; false on any failure
4914 */
4915 @Override
4916 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4918 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004919
4920 final long identity = Binder.clearCallingIdentity();
4921 try {
4922 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4923 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4924 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4925 return success;
4926 } finally {
4927 Binder.restoreCallingIdentity(identity);
4928 }
Jake Hambye994d462014-02-03 13:10:13 -08004929 }
4930
4931 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004932 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004933 * Used for device configuration by some CDMA operators.
4934 *
chen xu6dac5ab2018-10-26 17:39:23 -07004935 * @param slotIndex - device slot.
4936 *
Jake Hambye994d462014-02-03 13:10:13 -08004937 * @return true on success; false on any failure
4938 */
4939 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004940 public boolean resetModemConfig(int slotIndex) {
4941 Phone phone = PhoneFactory.getPhone(slotIndex);
4942 if (phone != null) {
4943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4944 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945
chen xu6dac5ab2018-10-26 17:39:23 -07004946 final long identity = Binder.clearCallingIdentity();
4947 try {
4948 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4949 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4950 return success;
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 }
chen xu6dac5ab2018-10-26 17:39:23 -07004955 return false;
4956 }
4957
4958 /**
4959 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4960 *
4961 * @param slotIndex - device slot.
4962 *
4963 * @return true on success; false on any failure
4964 */
4965 @Override
4966 public boolean rebootModem(int slotIndex) {
4967 Phone phone = PhoneFactory.getPhone(slotIndex);
4968 if (phone != null) {
4969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4970 mApp, phone.getSubId(), "rebootModem");
4971
4972 final long identity = Binder.clearCallingIdentity();
4973 try {
4974 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4975 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4976 return success;
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
4980 }
4981 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004982 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004983
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004984 public String[] getPcscfAddress(String apnType, String callingPackage,
4985 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004986 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4988 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004989 return new String[0];
4990 }
4991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 final long identity = Binder.clearCallingIdentity();
4993 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004994 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 } finally {
4996 Binder.restoreCallingIdentity(identity);
4997 }
Wink Saville36469e72014-06-11 15:17:00 -07004998 }
4999
Brad Ebinger51f743a2017-01-23 13:50:20 -08005000 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005001 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5002 * {@link #disableIms(int)}.
5003 * @param slotIndex device slot.
5004 */
5005 public void resetIms(int slotIndex) {
5006 enforceModifyPermission();
5007
5008 final long identity = Binder.clearCallingIdentity();
5009 try {
5010 if (mImsResolver == null) {
5011 // may happen if the does not support IMS.
5012 return;
5013 }
5014 mImsResolver.disableIms(slotIndex);
5015 mImsResolver.enableIms(slotIndex);
5016 } finally {
5017 Binder.restoreCallingIdentity(identity);
5018 }
5019 }
5020
5021 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005022 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5023 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005024 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005025 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005026 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027
5028 final long identity = Binder.clearCallingIdentity();
5029 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005030 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005031 // may happen if the device does not support IMS.
5032 return;
5033 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005034 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005038 }
5039
5040 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005041 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5042 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005043 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005044 public void disableIms(int slotId) {
5045 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046
5047 final long identity = Binder.clearCallingIdentity();
5048 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005049 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005050 // may happen if the device does not support IMS.
5051 return;
5052 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005053 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 } finally {
5055 Binder.restoreCallingIdentity(identity);
5056 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005057 }
5058
5059 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005060 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5061 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005062 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005063 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005064 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005065 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066
5067 final long identity = Binder.clearCallingIdentity();
5068 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005069 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005070 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5071 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005072 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005073 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 } finally {
5075 Binder.restoreCallingIdentity(identity);
5076 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005077 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005078 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005079 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5080 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005081 @Override
5082 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005083 enforceModifyPermission();
5084
5085 final long identity = Binder.clearCallingIdentity();
5086 try {
5087 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005088 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
5092 }
5093
5094 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005095 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005096 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005097 */
5098 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5099 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100
5101 final long identity = Binder.clearCallingIdentity();
5102 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005103 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005104 // may happen if the device does not support IMS.
5105 return null;
5106 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005107 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 } finally {
5109 Binder.restoreCallingIdentity(identity);
5110 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005111 }
5112
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005113 /**
5114 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005115 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005116 */
5117 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5118 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119
5120 final long identity = Binder.clearCallingIdentity();
5121 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005122 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005123 // may happen if the device does not support IMS.
5124 return null;
5125 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005126 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005127 } finally {
5128 Binder.restoreCallingIdentity(identity);
5129 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005130 }
5131
Brad Ebinger884c07b2018-02-15 16:17:40 -08005132 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005133 * Sets the ImsService Package Name that Telephony will bind to.
5134 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005135 * @param slotIndex the slot ID that the ImsService should bind for.
5136 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005137 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005138 * @param featureTypes An integer array of feature types associated with a packageName.
5139 * @param packageName The name of the package that the current configuration will be replaced
5140 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005141 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005142 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005143 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5144 int[] featureTypes, String packageName) {
5145 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5146 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5148 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005149 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005150
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151 final long identity = Binder.clearCallingIdentity();
5152 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005153 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005154 // may happen if the device does not support IMS.
5155 return false;
5156 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005157 Map<Integer, String> featureConfig = new HashMap<>();
5158 for (int featureType : featureTypes) {
5159 featureConfig.put(featureType, packageName);
5160 }
5161 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5162 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 } finally {
5164 Binder.restoreCallingIdentity(identity);
5165 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005166 }
5167
5168 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005169 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005170 *
5171 * @param slotId The slot that the ImsService is associated with.
5172 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5173 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005174 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005175 * @return the package name of the ImsService configuration.
5176 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005177 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5178 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005179 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005180 TelephonyPermissions
5181 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5182 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5183 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005187 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005188 // may happen if the device does not support IMS.
5189 return "";
5190 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005191 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005192 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5193 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005194 } finally {
5195 Binder.restoreCallingIdentity(identity);
5196 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005197 }
5198
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005199 /**
5200 * Get the MmTelFeature state associated with the requested subscription id.
5201 * @param subId The subscription that the MmTelFeature is associated with.
5202 * @param callback A callback with an integer containing the
5203 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5204 */
5205 @Override
5206 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5207 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5208 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5209 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5210 "IMS not available on device.");
5211 }
5212 final long token = Binder.clearCallingIdentity();
5213 try {
5214 int slotId = getSlotIndex(subId);
5215 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5216 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5217 + subId + "'");
5218 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5219 }
5220 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5221 try {
5222 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5223 } catch (RemoteException e) {
5224 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5225 + "Ignore");
5226 }
5227 });
5228 } finally {
5229 Binder.restoreCallingIdentity(token);
5230 }
5231 }
5232
Wink Saville36469e72014-06-11 15:17:00 -07005233 public void setImsRegistrationState(boolean registered) {
5234 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235
5236 final long identity = Binder.clearCallingIdentity();
5237 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005238 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 } finally {
5240 Binder.restoreCallingIdentity(identity);
5241 }
Wink Saville36469e72014-06-11 15:17:00 -07005242 }
5243
5244 /**
Stuart Scott54788802015-03-30 13:18:01 -07005245 * Set the network selection mode to automatic.
5246 *
5247 */
5248 @Override
5249 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5251 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252
5253 final long identity = Binder.clearCallingIdentity();
5254 try {
shilufc958392020-01-20 11:36:01 -08005255 if (!isActiveSubscription(subId)) {
5256 return;
5257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5259 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
Stuart Scott54788802015-03-30 13:18:01 -07005263 }
5264
Jack Yud10cdd42020-09-28 20:28:01 -07005265 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005266 * Ask the radio to connect to the input network and change selection mode to manual.
5267 *
5268 * @param subId the id of the subscription.
5269 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5270 * the operator to attach to.
5271 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5272 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5273 * normal network selection next time.
5274 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005275 */
5276 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005277 public boolean setNetworkSelectionModeManual(
5278 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5280 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005281
5282 if (!isActiveSubscription(subId)) {
5283 return false;
5284 }
5285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 final long identity = Binder.clearCallingIdentity();
5287 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005288 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005290 if (DBG) {
5291 log("setNetworkSelectionModeManual: subId: " + subId
5292 + " operator: " + operatorInfo);
5293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5295 } finally {
5296 Binder.restoreCallingIdentity(identity);
5297 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005298 }
shilu84f6e8b2019-12-19 13:58:01 -08005299 /**
5300 * Get the manual network selection
5301 *
5302 * @param subId the id of the subscription.
5303 *
5304 * @return the previously saved user selected PLMN
5305 */
5306 @Override
5307 public String getManualNetworkSelectionPlmn(int subId) {
5308 TelephonyPermissions
5309 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5310 mApp, subId, "getManualNetworkSelectionPlmn");
5311
5312 final long identity = Binder.clearCallingIdentity();
5313 try {
5314 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005315 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005316 }
5317
5318 final Phone phone = getPhone(subId);
5319 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005320 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005321 }
5322 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5323 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5324 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
5328 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005329
5330 /**
5331 * Scans for available networks.
5332 */
5333 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005334 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5335 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5337 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005338 LocationAccessPolicy.LocationPermissionResult locationResult =
5339 LocationAccessPolicy.checkLocationPermission(mApp,
5340 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5341 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005342 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005343 .setCallingPid(Binder.getCallingPid())
5344 .setCallingUid(Binder.getCallingUid())
5345 .setMethod("getCellNetworkScanResults")
5346 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005347 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5348 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005349 .build());
5350 switch (locationResult) {
5351 case DENIED_HARD:
5352 throw new SecurityException("Not allowed to access scan results -- location");
5353 case DENIED_SOFT:
5354 return null;
5355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356
Pengquan Menga1bb6272018-09-06 09:59:22 -07005357 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 try {
5359 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005360 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005365 }
5366
5367 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005368 * Get the call forwarding info, given the call forwarding reason.
5369 */
5370 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005371 public void getCallForwarding(int subId, int callForwardingReason,
5372 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005373 enforceReadPrivilegedPermission("getCallForwarding");
5374 long identity = Binder.clearCallingIdentity();
5375 try {
5376 if (DBG) {
5377 log("getCallForwarding: subId " + subId
5378 + " callForwardingReason" + callForwardingReason);
5379 }
Hall Liu27d24262020-09-18 19:04:59 -07005380
5381 Phone phone = getPhone(subId);
5382 if (phone == null) {
5383 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005384 callback.onError(
5385 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005386 } catch (RemoteException e) {
5387 // ignore
5388 }
5389 return;
5390 }
5391
5392 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5393 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5394 @Override
5395 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5396 try {
5397 callback.onCallForwardingInfoAvailable(info);
5398 } catch (RemoteException e) {
5399 // ignore
5400 }
5401 }
5402
5403 @Override
5404 public void onError(int error) {
5405 try {
5406 callback.onError(error);
5407 } catch (RemoteException e) {
5408 // ignore
5409 }
5410 }
5411 });
5412 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005413 } finally {
5414 Binder.restoreCallingIdentity(identity);
5415 }
5416 }
5417
5418 /**
5419 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5420 * reason, the number to forward, and the timeout before the forwarding is attempted.
5421 */
5422 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005423 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5424 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005425 enforceModifyPermission();
5426 long identity = Binder.clearCallingIdentity();
5427 try {
5428 if (DBG) {
5429 log("setCallForwarding: subId " + subId
5430 + " callForwardingInfo" + callForwardingInfo);
5431 }
Hall Liu27d24262020-09-18 19:04:59 -07005432
5433 Phone phone = getPhone(subId);
5434 if (phone == null) {
5435 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005436 callback.accept(
5437 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005438 } catch (RemoteException e) {
5439 // ignore
5440 }
5441 return;
5442 }
5443
5444 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5445 FunctionalUtils.ignoreRemoteException(callback::accept));
5446
5447 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005448 } finally {
5449 Binder.restoreCallingIdentity(identity);
5450 }
5451 }
5452
5453 /**
Hall Liu27d24262020-09-18 19:04:59 -07005454 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005455 */
5456 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005457 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005458 enforceReadPrivilegedPermission("getCallForwarding");
5459 long identity = Binder.clearCallingIdentity();
5460 try {
Hall Liu27d24262020-09-18 19:04:59 -07005461
5462 Phone phone = getPhone(subId);
5463 if (phone == null) {
5464 try {
5465 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5466 } catch (RemoteException e) {
5467 // ignore
5468 }
5469 return;
5470 }
5471
5472 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5473
Shuo Qian4a594052020-01-23 11:59:30 -08005474 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005475 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005476 } finally {
5477 Binder.restoreCallingIdentity(identity);
5478 }
5479 }
5480
5481 /**
Hall Liu27d24262020-09-18 19:04:59 -07005482 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005483 */
5484 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005485 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005486 enforceModifyPermission();
5487 long identity = Binder.clearCallingIdentity();
5488 try {
Hall Liu27d24262020-09-18 19:04:59 -07005489 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5490
5491 Phone phone = getPhone(subId);
5492 if (phone == null) {
5493 try {
5494 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5495 } catch (RemoteException e) {
5496 // ignore
5497 }
5498 return;
5499 }
5500
5501 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5502 FunctionalUtils.ignoreRemoteException(callback::accept));
5503
5504 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
5508 }
5509
5510 /**
yinxub1bed742017-04-17 11:45:04 -07005511 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005512 *
yinxub1bed742017-04-17 11:45:04 -07005513 * @param subId id of the subscription
5514 * @param request contains the radio access networks with bands/channels to scan
5515 * @param messenger callback messenger for scan results or errors
5516 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005517 * @return the id of the requested scan which can be used to stop the scan.
5518 */
5519 @Override
5520 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005521 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5523 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005524 LocationAccessPolicy.LocationPermissionResult locationResult =
5525 LocationAccessPolicy.checkLocationPermission(mApp,
5526 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5527 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005528 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005529 .setCallingPid(Binder.getCallingPid())
5530 .setCallingUid(Binder.getCallingUid())
5531 .setMethod("requestNetworkScan")
5532 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005533 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5534 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005535 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005536 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005537 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5538 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005539 if (e != null) {
5540 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5541 throw e;
5542 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005543 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005544 return TelephonyScanManager.INVALID_SCAN_ID;
5545 }
5546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 }
Hall Liu912dfd32019-04-25 14:02:26 -07005548 int callingUid = Binder.getCallingUid();
5549 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005550 final long identity = Binder.clearCallingIdentity();
5551 try {
5552 return mNetworkScanRequestTracker.startNetworkScan(
5553 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005554 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005555 } finally {
5556 Binder.restoreCallingIdentity(identity);
5557 }
yinxu504e1392017-04-12 16:03:22 -07005558 }
5559
Hall Liub2ac8ef2019-02-28 15:56:23 -08005560 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005561 NetworkScanRequest request, int subId, String callingPackage) {
5562 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005563 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5564 boolean hasNetworkScanPermission =
5565 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5566 == PERMISSION_GRANTED;
5567
5568 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5569 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5570 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005571 }
5572
5573 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5574 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005575 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5576 return new SecurityException("Specific channels must not be"
5577 + " scanned without location access.");
5578 }
5579 }
5580 }
5581
Hall Liub2ac8ef2019-02-28 15:56:23 -08005582 return null;
5583 }
5584
yinxu504e1392017-04-12 16:03:22 -07005585 /**
5586 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005587 *
5588 * @param subId id of the subscription
5589 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005590 */
5591 @Override
5592 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5594 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595
Hall Liu912dfd32019-04-25 14:02:26 -07005596 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597 final long identity = Binder.clearCallingIdentity();
5598 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005599 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
yinxu504e1392017-04-12 16:03:22 -07005603 }
5604
5605 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005606 * Get the calculated preferred network type.
5607 * Used for debugging incorrect network type.
5608 *
5609 * @return the preferred network type, defined in RILConstants.java.
5610 */
5611 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005612 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005613 final Phone defaultPhone = getDefaultPhone();
5614 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005615 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005616 return RILConstants.PREFERRED_NETWORK_MODE;
5617 }
5618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005622 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Junda Liu84d15a22014-07-02 11:21:04 -07005626 }
5627
5628 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005629 * Get the preferred network type.
5630 * Used for device configuration by some CDMA operators.
5631 *
5632 * @return the preferred network type, defined in RILConstants.java.
5633 */
5634 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005635 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005636 TelephonyPermissions
5637 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5638 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639
5640 final long identity = Binder.clearCallingIdentity();
5641 try {
5642 if (DBG) log("getPreferredNetworkType");
5643 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5644 int networkType = (result != null ? result[0] : -1);
5645 if (DBG) log("getPreferredNetworkType: " + networkType);
5646 return networkType;
5647 } finally {
5648 Binder.restoreCallingIdentity(identity);
5649 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005650 }
5651
5652 /**
5653 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005654 *
5655 * @param networkType the preferred network type, defined in RILConstants.java.
5656 * @return true on success; false on any failure.
5657 */
5658 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005659 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5661 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662
5663 final long identity = Binder.clearCallingIdentity();
5664 try {
calvinpan8ed33732020-03-12 14:17:55 +08005665 Boolean success = (Boolean) sendRequest(
5666 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005667
5668 if (success) {
5669 Settings.Global.putInt(mApp.getContentResolver(),
5670 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5671 }
calvinpan8ed33732020-03-12 14:17:55 +08005672 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5673 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005676 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005677 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005678
5679 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005680 * Get the allowed network types that store in the telephony provider.
5681 *
5682 * @param subId the id of the subscription.
5683 * @return allowedNetworkTypes the allowed network types.
5684 */
5685 @Override
5686 public long getAllowedNetworkTypes(int subId) {
5687 TelephonyPermissions
5688 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5689 mApp, subId, "getAllowedNetworkTypes");
5690
5691 final long identity = Binder.clearCallingIdentity();
5692 try {
5693 return SubscriptionManager.getLongSubscriptionProperty(
5694 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
5697 }
5698 }
5699
5700 /**
5701 * Set the allowed network types.
5702 *
5703 * @param subId the id of the subscription.
5704 * @param allowedNetworkTypes the allowed network types.
5705 * @return true on success; false on any failure.
5706 */
5707 @Override
5708 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5710 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005711
calvinpan8ed33732020-03-12 14:17:55 +08005712 SubscriptionManager.setSubscriptionProperty(subId,
5713 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5714 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005715
calvinpan8ed33732020-03-12 14:17:55 +08005716 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5717 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5718 RILConstants.PREFERRED_NETWORK_MODE);
5719 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005720 }
5721
5722 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005723 * Get the allowed network types for certain reason.
5724 *
5725 * @param subId the id of the subscription.
5726 * @param reason the reason the allowed network type change is taking place
5727 * @return the allowed network types.
5728 */
5729 @Override
5730 public long getAllowedNetworkTypesForReason(int subId,
5731 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5732 TelephonyPermissions
5733 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5734 mApp, subId, "getAllowedNetworkTypesForReason");
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
5737 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
5741 }
5742
5743 /**
5744 * Get the effective allowed network types on the device.
5745 * This API will return an intersection of allowed network types for all reasons,
5746 * including the configuration done through setAllowedNetworkTypes
5747 *
5748 * @param subId the id of the subscription.
5749 * @return the allowed network types
5750 */
5751 @Override
5752 public long getEffectiveAllowedNetworkTypes(int subId) {
5753 TelephonyPermissions
5754 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5755 mApp, subId, "getEffectiveAllowedNetworkTypes");
5756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5759 } finally {
5760 Binder.restoreCallingIdentity(identity);
5761 }
5762 }
5763
5764 /**
5765 * Set the allowed network types of the device and
5766 * provide the reason triggering the allowed network change.
5767 *
5768 * @param subId the id of the subscription.
5769 * @param reason the reason the allowed network type change is taking place
5770 * @param allowedNetworkTypes the allowed network types.
5771 * @return true on success; false on any failure.
5772 */
5773 @Override
5774 public boolean setAllowedNetworkTypesForReason(int subId,
5775 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5777 mApp, subId, "setAllowedNetworkTypesForReason");
5778 final long identity = Binder.clearCallingIdentity();
5779 try {
5780 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5781 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5782 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5783 RILConstants.PREFERRED_NETWORK_MODE);
5784 return setPreferredNetworkType(subId, preferredNetworkMode);
5785 } finally {
5786 Binder.restoreCallingIdentity(identity);
5787 }
5788 }
5789
5790 /**
Miaoa84611c2019-03-15 09:21:10 +08005791 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005792 *
Miaoa84611c2019-03-15 09:21:10 +08005793 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005794 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005795 * @hide
5796 */
5797 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005798 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005801 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802 try {
Miaoa84611c2019-03-15 09:21:10 +08005803 if (phone != null) {
5804 return phone.hasMatchedTetherApnSetting();
5805 } else {
5806 return false;
5807 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 } finally {
5809 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005810 }
Junda Liu475951f2014-11-07 16:45:03 -08005811 }
5812
5813 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005814 * Enable or disable always reporting signal strength changes from radio.
5815 *
5816 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5817 */
5818 @Override
5819 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5820 enforceModifyPermission();
5821 enforceSystemCaller();
5822
5823 final long identity = Binder.clearCallingIdentity();
5824 final Phone phone = getPhone(subId);
5825 try {
5826 if (phone != null) {
5827 if (DBG) {
5828 log("setAlwaysReportSignalStrength: subId=" + subId
5829 + " isEnable=" + isEnable);
5830 }
5831 phone.setAlwaysReportSignalStrength(isEnable);
5832 } else {
5833 loge("setAlwaysReportSignalStrength: no phone found for subId="
5834 + subId);
5835 }
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
5839 }
5840
5841 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005842 * Get the user enabled state of Mobile Data.
5843 *
5844 * TODO: remove and use isUserDataEnabled.
5845 * This can't be removed now because some vendor codes
5846 * calls through ITelephony directly while they should
5847 * use TelephonyManager.
5848 *
5849 * @return true on enabled
5850 */
5851 @Override
5852 public boolean getDataEnabled(int subId) {
5853 return isUserDataEnabled(subId);
5854 }
5855
5856 /**
5857 * Get whether mobile data is enabled per user setting.
5858 *
5859 * There are other factors deciding whether mobile data is actually enabled, but they are
5860 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005861 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005862 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005863 *
5864 * @return {@code true} if data is enabled else {@code false}
5865 */
5866 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005867 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005868 try {
5869 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5870 null);
5871 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5873 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005874 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875
5876 final long identity = Binder.clearCallingIdentity();
5877 try {
5878 int phoneId = mSubscriptionController.getPhoneId(subId);
5879 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5880 Phone phone = PhoneFactory.getPhone(phoneId);
5881 if (phone != null) {
5882 boolean retVal = phone.isUserDataEnabled();
5883 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5884 return retVal;
5885 } else {
5886 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5887 return false;
5888 }
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005891 }
5892 }
5893
5894 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005895 * Checks if the device is capable of mobile data by considering whether whether the
5896 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5897 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005898 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005899 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005900 */
5901 @Override
5902 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005903 try {
5904 try {
5905 mApp.enforceCallingOrSelfPermission(
5906 android.Manifest.permission.ACCESS_NETWORK_STATE,
5907 null);
5908 } catch (Exception e) {
5909 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
5910 "isDataEnabled");
5911 }
5912 } catch (Exception e) {
5913 enforceReadPrivilegedPermission("isDataEnabled");
5914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915
5916 final long identity = Binder.clearCallingIdentity();
5917 try {
5918 int phoneId = mSubscriptionController.getPhoneId(subId);
5919 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5920 Phone phone = PhoneFactory.getPhone(phoneId);
5921 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005922 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5924 return retVal;
5925 } else {
5926 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5927 return false;
5928 }
5929 } finally {
5930 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005931 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005932 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005933
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005934 /**
5935 * Check if data is enabled for a specific reason
5936 * @param subId Subscription index
5937 * @param reason the reason the data enable change is taking place
5938 * @return {@code true} if the overall data is enabled; {@code false} if not.
5939 */
5940 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005941 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005942 @TelephonyManager.DataEnabledReason int reason) {
5943 try {
5944 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5945 null);
5946 } catch (Exception e) {
5947 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005948 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005949 }
5950
5951
5952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 int phoneId = mSubscriptionController.getPhoneId(subId);
5955 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005956 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005957 + " reason=" + reason);
5958 }
5959 Phone phone = PhoneFactory.getPhone(phoneId);
5960 if (phone != null) {
5961 boolean retVal;
5962 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
5963 retVal = phone.isUserDataEnabled();
5964 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005965 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005966 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005967 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005968 return retVal;
5969 } else {
5970 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005971 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005972 + subId + " retVal=false");
5973 }
5974 return false;
5975 }
5976 } finally {
5977 Binder.restoreCallingIdentity(identity);
5978 }
5979 }
5980
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005981 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005982 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07005983 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5984 // Skip the check if it's one of these special uids
5985 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5986 }
5987
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005988 //load access rules from carrier configs, and check those as well: b/139133814
5989 SubscriptionController subController = SubscriptionController.getInstance();
5990 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5991 || subController == null) return privilegeFromSim;
5992
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005993 PackageManager pkgMgr = phone.getContext().getPackageManager();
5994 String[] packages = pkgMgr.getPackagesForUid(uid);
5995
5996 final long identity = Binder.clearCallingIdentity();
5997 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005998 int subId = phone.getSubId();
5999 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6000 // A test override is in place for the privileges for this subId, so don't try to
6001 // read the subscription privileges.
6002 return privilegeFromSim;
6003 }
6004 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006005 SubscriptionManager subManager = (SubscriptionManager)
6006 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6007 for (String pkg : packages) {
6008 if (subManager.canManageSubscription(subInfo, pkg)) {
6009 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6010 }
6011 }
6012 return privilegeFromSim;
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
6016 }
6017
6018 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6019 String pkgName) {
6020 //load access rules from carrier configs, and check those as well: b/139133814
6021 SubscriptionController subController = SubscriptionController.getInstance();
6022 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6023 || subController == null) return privilegeFromSim;
6024
6025 final long identity = Binder.clearCallingIdentity();
6026 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006027 int subId = phone.getSubId();
6028 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6029 // A test override is in place for the privileges for this subId, so don't try to
6030 // read the subscription privileges.
6031 return privilegeFromSim;
6032 }
6033 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006034 SubscriptionManager subManager = (SubscriptionManager)
6035 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6036 return subManager.canManageSubscription(subInfo, pkgName)
6037 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6038 } finally {
6039 Binder.restoreCallingIdentity(identity);
6040 }
6041 }
6042
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006043 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006044 public int getCarrierPrivilegeStatus(int subId) {
6045 final Phone phone = getPhone(subId);
6046 if (phone == null) {
6047 loge("getCarrierPrivilegeStatus: Invalid subId");
6048 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6049 }
6050 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006051 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006052 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006053 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6054 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006055
6056 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6057 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006058 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006059 }
Junda Liu29340342014-07-10 15:23:27 -07006060
6061 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006062 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006063 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006064 final Phone phone = getPhone(subId);
6065 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006066 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006067 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6068 }
6069 UiccProfile profile =
6070 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6071 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006072 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006073 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6074 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006075 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006076 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006077 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006078 }
6079
6080 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006081 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6082 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006083 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006084 }
6085
6086 int phoneId = SubscriptionManager.getPhoneId(subId);
6087 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006088 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006089 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006090 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6091 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006092 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6093 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6094 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006095 }
6096
6097 @Override
6098 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006099 if (TextUtils.isEmpty(pkgName))
6100 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006101 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6102 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6103 UiccCard card = UiccController.getInstance().getUiccCard(i);
6104 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006105 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006106 continue;
6107 }
6108
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006109 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6110 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6111 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006112 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6113 break;
6114 }
6115 }
6116
6117 return result;
Junda Liu29340342014-07-10 15:23:27 -07006118 }
Derek Tan89e89d42014-07-08 17:00:10 -07006119
6120 @Override
Junda Liue64de782015-04-16 17:19:16 -07006121 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6122 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6123 loge("phoneId " + phoneId + " is not valid.");
6124 return null;
6125 }
6126 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006127 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006128 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006129 return null ;
6130 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006131 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006132 }
6133
Amith Yamasani6e118872016-02-19 12:53:51 -08006134 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006135 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006136 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006137 List<String> privilegedPackages = new ArrayList<>();
6138 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006139 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6140 // has UICC in that slot.
6141 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006142 if (card.hasCarrierPrivilegeRules()) {
6143 if (packages == null) {
6144 // Only check packages in user 0 for now
6145 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006146 PackageManager.MATCH_DISABLED_COMPONENTS
6147 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006148 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006149 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006150 }
6151 for (int p = packages.size() - 1; p >= 0; p--) {
6152 PackageInfo pkgInfo = packages.get(p);
6153 if (pkgInfo != null && pkgInfo.packageName != null
6154 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006155 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006156 privilegedPackages.add(pkgInfo.packageName);
6157 }
6158 }
6159 }
6160 }
6161 return privilegedPackages;
6162 }
6163
chen xuf7e9fe82019-05-09 19:31:02 -07006164 @Override
6165 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006166 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6167
6168 final long identity = Binder.clearCallingIdentity();
6169
chen xuf7e9fe82019-05-09 19:31:02 -07006170 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006171 try {
6172 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6173 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6174 }
6175 } finally {
6176 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006177 }
6178 return privilegedPackages;
6179 }
6180
Wink Savilleb564aae2014-10-23 10:18:09 -07006181 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006182 final Phone phone = getPhone(subId);
6183 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006184 if (card == null) {
6185 loge("getIccId: No UICC");
6186 return null;
6187 }
6188 String iccId = card.getIccId();
6189 if (TextUtils.isEmpty(iccId)) {
6190 loge("getIccId: ICC ID is null or empty.");
6191 return null;
6192 }
6193 return iccId;
6194 }
6195
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006196 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006197 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6198 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006199 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006200 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202 final long identity = Binder.clearCallingIdentity();
6203 try {
6204 final String iccId = getIccId(subId);
6205 final Phone phone = getPhone(subId);
6206 if (phone == null) {
6207 return false;
6208 }
6209 final String subscriberId = phone.getSubscriberId();
6210
6211 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006212 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 + subscriberId + " to " + number);
6214 }
6215
6216 if (TextUtils.isEmpty(iccId)) {
6217 return false;
6218 }
6219
6220 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6221
6222 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6223 if (alphaTag == null) {
6224 editor.remove(alphaTagPrefKey);
6225 } else {
6226 editor.putString(alphaTagPrefKey, alphaTag);
6227 }
6228
6229 // Record both the line number and IMSI for this ICCID, since we need to
6230 // track all merged IMSIs based on line number
6231 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6232 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6233 if (number == null) {
6234 editor.remove(numberPrefKey);
6235 editor.remove(subscriberPrefKey);
6236 } else {
6237 editor.putString(numberPrefKey, number);
6238 editor.putString(subscriberPrefKey, subscriberId);
6239 }
6240
6241 editor.commit();
6242 return true;
6243 } finally {
6244 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006245 }
Derek Tan7226c842014-07-02 17:42:23 -07006246 }
6247
6248 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006249 public String getLine1NumberForDisplay(int subId, String callingPackage,
6250 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006251 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006252 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006253 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006254 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006255 return null;
6256 }
Derek Tan97ebb422014-09-05 16:55:38 -07006257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 final long identity = Binder.clearCallingIdentity();
6259 try {
6260 String iccId = getIccId(subId);
6261 if (iccId != null) {
6262 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6263 if (DBG_MERGE) {
6264 log("getLine1NumberForDisplay returning "
6265 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6266 }
6267 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006268 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6270 return null;
6271 } finally {
6272 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006273 }
Derek Tan7226c842014-07-02 17:42:23 -07006274 }
6275
6276 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006277 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6278 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006280 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006281 return null;
6282 }
Derek Tan97ebb422014-09-05 16:55:38 -07006283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 final long identity = Binder.clearCallingIdentity();
6285 try {
6286 String iccId = getIccId(subId);
6287 if (iccId != null) {
6288 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6289 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6290 }
6291 return null;
6292 } finally {
6293 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006294 }
Derek Tan7226c842014-07-02 17:42:23 -07006295 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006296
6297 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006298 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6299 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006300 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6301 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006303 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006304 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006305 return null;
6306 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006307
Jordan Liub49b04b2019-05-06 14:45:15 -07006308 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6309 // the process, where TelephonyManager was instantiated.
6310 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006311 final long identity = Binder.clearCallingIdentity();
6312 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006313 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 final TelephonyManager tele = TelephonyManager.from(context);
6315 final SubscriptionManager sub = SubscriptionManager.from(context);
6316
6317 // Figure out what subscribers are currently active
6318 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319
Jordan Liub49b04b2019-05-06 14:45:15 -07006320 // Only consider subs which match the current subId
6321 // This logic can be simplified. See b/131189269 for progress.
6322 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006323 activeSubscriberIds.add(tele.getSubscriberId(subId));
6324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325
6326 // First pass, find a number override for an active subscriber
6327 String mergeNumber = null;
6328 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6329 for (String key : prefs.keySet()) {
6330 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6331 final String subscriberId = (String) prefs.get(key);
6332 if (activeSubscriberIds.contains(subscriberId)) {
6333 final String iccId = key.substring(
6334 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6335 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6336 mergeNumber = (String) prefs.get(numberKey);
6337 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006338 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 + " for active subscriber " + subscriberId);
6340 }
6341 if (!TextUtils.isEmpty(mergeNumber)) {
6342 break;
6343 }
6344 }
6345 }
6346 }
6347
6348 // Shortcut when no active merged subscribers
6349 if (TextUtils.isEmpty(mergeNumber)) {
6350 return null;
6351 }
6352
6353 // Second pass, find all subscribers under that line override
6354 final ArraySet<String> result = new ArraySet<>();
6355 for (String key : prefs.keySet()) {
6356 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6357 final String number = (String) prefs.get(key);
6358 if (mergeNumber.equals(number)) {
6359 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6360 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6361 final String subscriberId = (String) prefs.get(subscriberKey);
6362 if (!TextUtils.isEmpty(subscriberId)) {
6363 result.add(subscriberId);
6364 }
6365 }
6366 }
6367 }
6368
6369 final String[] resultArray = result.toArray(new String[result.size()]);
6370 Arrays.sort(resultArray);
6371 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006372 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6374 }
6375 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006376 } finally {
6377 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006378 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006379 }
6380
6381 @Override
zoey chen38003472019-12-13 17:16:31 +08006382 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6383 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006384
6385 final long identity = Binder.clearCallingIdentity();
6386 try {
6387 final TelephonyManager telephonyManager = mApp.getSystemService(
6388 TelephonyManager.class);
6389 String subscriberId = telephonyManager.getSubscriberId(subId);
6390 if (subscriberId == null) {
6391 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006392 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006393 + subId);
6394 }
6395 return null;
6396 }
6397
6398 final SubscriptionInfo info = SubscriptionController.getInstance()
6399 .getSubscriptionInfo(subId);
6400 final ParcelUuid groupUuid = info.getGroupUuid();
6401 // If it doesn't belong to any group, return just subscriberId of itself.
6402 if (groupUuid == null) {
6403 return new String[]{subscriberId};
6404 }
6405
6406 // Get all subscriberIds from the group.
6407 final List<String> mergedSubscriberIds = new ArrayList<>();
6408 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006409 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006410 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006411 for (SubscriptionInfo subInfo : groupInfos) {
6412 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6413 if (subscriberId != null) {
6414 mergedSubscriberIds.add(subscriberId);
6415 }
6416 }
6417
6418 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6419 } finally {
6420 Binder.restoreCallingIdentity(identity);
6421
6422 }
6423 }
6424
6425 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006426 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006427 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006428 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429
6430 final long identity = Binder.clearCallingIdentity();
6431 try {
6432 final Phone phone = getPhone(subId);
6433 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6434 } finally {
6435 Binder.restoreCallingIdentity(identity);
6436 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006437 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006438
6439 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006440 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006441 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6442 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006443 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6444 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445
6446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 final Phone phone = getPhone(subId);
6449 if (phone == null) {
6450 return false;
6451 }
6452 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6453 cdmaNonRoamingList);
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006456 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006457 }
6458
6459 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006460 @Deprecated
6461 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6462 enforceModifyPermission();
6463
6464 int returnValue = 0;
6465 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006466 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006467 if(result.exception == null) {
6468 if (result.result != null) {
6469 byte[] responseData = (byte[])(result.result);
6470 if(responseData.length > oemResp.length) {
6471 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6472 responseData.length + "bytes. Buffer Size is " +
6473 oemResp.length + "bytes.");
6474 }
6475 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6476 returnValue = responseData.length;
6477 }
6478 } else {
6479 CommandException ex = (CommandException) result.exception;
6480 returnValue = ex.getCommandError().ordinal();
6481 if(returnValue > 0) returnValue *= -1;
6482 }
6483 } catch (RuntimeException e) {
6484 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6485 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6486 if(returnValue > 0) returnValue *= -1;
6487 }
6488
6489 return returnValue;
6490 }
6491
6492 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006493 public void setRadioCapability(RadioAccessFamily[] rafs) {
6494 try {
6495 ProxyController.getInstance().setRadioCapability(rafs);
6496 } catch (RuntimeException e) {
6497 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6498 }
6499 }
6500
6501 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006502 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006503 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006504 try {
6505 TelephonyPermissions
6506 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6507 mApp, phone.getSubId(), "getRadioAccessFamily");
6508 } catch (SecurityException e) {
6509 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6510 throw e;
6511 }
chen xub97461a2018-10-26 14:17:57 -07006512 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006513 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006514 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006515 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516 final long identity = Binder.clearCallingIdentity();
6517 try {
chen xub97461a2018-10-26 14:17:57 -07006518 TelephonyPermissions
6519 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6520 mApp, phone.getSubId(), "getRadioAccessFamily");
6521 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
chen xub97461a2018-10-26 14:17:57 -07006525 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006526 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006527
6528 @Override
6529 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006530 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006531 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532
6533 final long identity = Binder.clearCallingIdentity();
6534 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006535 ImsManager.getInstance(defaultPhone.getContext(),
6536 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006537 } finally {
6538 Binder.restoreCallingIdentity(identity);
6539 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006540 }
6541
6542 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006543 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006544 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6546 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006547 return false;
6548 }
Svet Ganovb320e182015-04-16 12:30:10 -07006549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 final long identity = Binder.clearCallingIdentity();
6551 try {
6552 // Check the user preference and the system-level IMS setting. Even if the user has
6553 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6554 // In the long run, we may instead need to check if there exists a connection service
6555 // which can support video calling.
6556 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006557 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 return imsManager.isVtEnabledByPlatform()
6559 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6560 && imsManager.isVtEnabledByUser();
6561 } finally {
6562 Binder.restoreCallingIdentity(identity);
6563 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006564 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006565
Andrew Leea1239f22015-03-02 17:44:07 -08006566 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006567 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6568 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006570 mApp, subId, callingPackage, callingFeatureId,
6571 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 return false;
6573 }
6574
6575 final long identity = Binder.clearCallingIdentity();
6576 try {
6577 CarrierConfigManager configManager =
6578 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006579 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6581 } finally {
6582 Binder.restoreCallingIdentity(identity);
6583 }
Andrew Leea1239f22015-03-02 17:44:07 -08006584 }
6585
6586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006587 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006589 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 return false;
6591 }
6592
6593 final long identity = Binder.clearCallingIdentity();
6594 try {
6595 CarrierConfigManager configManager =
6596 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006597 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6599 } finally {
6600 Binder.restoreCallingIdentity(identity);
6601 }
Andrew Leea1239f22015-03-02 17:44:07 -08006602 }
6603
Andrew Lee9431b832015-03-09 18:46:45 -07006604 @Override
6605 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006606 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006607 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006608 }
6609
6610 @Override
6611 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 final long identity = Binder.clearCallingIdentity();
6613 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006614 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615 } finally {
6616 Binder.restoreCallingIdentity(identity);
6617 }
Andrew Lee9431b832015-03-09 18:46:45 -07006618 }
6619
Hall Liuf6668912018-10-31 17:05:23 -07006620 /**
6621 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6622 * support for the feature and device firmware support.
6623 *
6624 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6625 */
6626 @Override
6627 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006629 final Phone phone = getPhone(subscriptionId);
6630 if (phone == null) {
6631 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6632 return false;
6633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006635 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6637 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006638 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 return isCarrierSupported && isDeviceSupported;
6640 } finally {
6641 Binder.restoreCallingIdentity(identity);
6642 }
Hall Liu98187582018-01-22 19:15:32 -08006643 }
6644
Hall Liuf6668912018-10-31 17:05:23 -07006645 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006646 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6647 * RTT setting, will return true if the device and carrier both support RTT.
6648 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006649 */
6650 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651 final long identity = Binder.clearCallingIdentity();
6652 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006653 boolean isRttSupported = isRttSupported(subscriptionId);
6654 boolean isUserRttSettingOn = Settings.Secure.getInt(
6655 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6656 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6657 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6658 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 } finally {
6660 Binder.restoreCallingIdentity(identity);
6661 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006662 }
6663
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006664 @Deprecated
6665 @Override
6666 public String getDeviceId(String callingPackage) {
6667 return getDeviceIdWithFeature(callingPackage, null);
6668 }
6669
Sanket Padawe7310cc72015-01-14 09:53:20 -08006670 /**
6671 * Returns the unique device ID of phone, for example, the IMEI for
6672 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6673 *
6674 * <p>Requires Permission:
6675 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6676 */
6677 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006678 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006679 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006680 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006681 return null;
6682 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006683 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006684 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006685 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006686 return null;
6687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688
6689 final long identity = Binder.clearCallingIdentity();
6690 try {
6691 return phone.getDeviceId();
6692 } finally {
6693 Binder.restoreCallingIdentity(identity);
6694 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006695 }
6696
Ping Sunc67b7c22016-03-02 19:16:45 +08006697 /**
6698 * {@hide}
6699 * Returns the IMS Registration Status on a particular subid
6700 *
6701 * @param subId
6702 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006703 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006704 Phone phone = getPhone(subId);
6705 if (phone != null) {
6706 return phone.isImsRegistered();
6707 } else {
6708 return false;
6709 }
6710 }
6711
Santos Cordon7a1885b2015-02-03 11:15:19 -08006712 @Override
6713 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 final long identity = Binder.clearCallingIdentity();
6715 try {
6716 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6717 } finally {
6718 Binder.restoreCallingIdentity(identity);
6719 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006720 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006721
Tyler Gunnf70ed162019-04-03 15:28:53 -07006722 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006723 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006724 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006726 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006727 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6728 }
6729 final long identity = Binder.clearCallingIdentity();
6730 try {
6731 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734 }
6735 }
6736
6737 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006738 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006739 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6740 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006741 final long identity = Binder.clearCallingIdentity();
6742 try {
6743 Phone phone = getPhone(subscriptionId);
6744 if (phone == null) {
6745 return null;
6746 }
6747 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6748 } finally {
6749 Binder.restoreCallingIdentity(identity);
6750 }
6751 }
6752
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006753 /**
6754 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006755 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006756 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 final long identity = Binder.clearCallingIdentity();
6758 try {
6759 Phone phone = getPhone(subId);
6760 if (phone != null) {
6761 return phone.isWifiCallingEnabled();
6762 } else {
6763 return false;
6764 }
6765 } finally {
6766 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006767 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006768 }
6769
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006770 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006771 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006772 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006773 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774 final long identity = Binder.clearCallingIdentity();
6775 try {
6776 Phone phone = getPhone(subId);
6777 if (phone != null) {
6778 return phone.isVideoEnabled();
6779 } else {
6780 return false;
6781 }
6782 } finally {
6783 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006784 }
6785 }
6786
6787 /**
6788 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6789 * defined in {@link ImsRegistrationImplBase}.
6790 */
6791 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792 final long identity = Binder.clearCallingIdentity();
6793 try {
6794 Phone phone = getPhone(subId);
6795 if (phone != null) {
6796 return phone.getImsRegistrationTech();
6797 } else {
6798 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6799 }
6800 } finally {
6801 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006802 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006803 }
6804
Stuart Scott8eef64f2015-04-08 15:13:54 -07006805 @Override
6806 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006807 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006808 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6809 return;
6810 }
6811
Svet Ganovcc087f82015-05-12 20:35:54 -07006812 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006813
Svet Ganovcc087f82015-05-12 20:35:54 -07006814 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006815 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6816 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006817 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006818 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006819 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006820 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006821 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6822 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006823 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006824 // There has been issues when Sms raw table somehow stores orphan
6825 // fragments. They lead to garbled message when new fragments come
6826 // in and combined with those stale ones. In case this happens again,
6827 // user can reset all network settings which will clean up this table.
6828 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006829 // Clean up IMS settings as well here.
6830 int slotId = getSlotIndex(subId);
6831 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6832 ImsManager.getInstance(mApp, slotId).factoryReset();
6833 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006834
6835 // Erase modem config if erase modem on network setting is enabled.
6836 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6837 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6838 if (configValue != null && Boolean.parseBoolean(configValue)) {
6839 sendEraseModemConfig(getDefaultPhone());
6840 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006841 } finally {
6842 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006843 }
6844 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006845
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006846 private void cleanUpSmsRawTable(Context context) {
6847 ContentResolver resolver = context.getContentResolver();
6848 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6849 resolver.delete(uri, null, null);
6850 }
6851
Narayan Kamath1c496c22015-04-16 14:40:19 +01006852 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006853 public String getSimLocaleForSubscriber(int subId) {
6854 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6855 final Phone phone = getPhone(subId);
6856 if (phone == null) {
6857 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006858 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860 final long identity = Binder.clearCallingIdentity();
6861 try {
chen xu5d3637b2019-01-21 23:31:38 -08006862 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006863 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006864 if (info == null) {
6865 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6866 return null;
6867 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 // Try and fetch the locale from the carrier properties or from the SIM language
6869 // preferences (EF-PL and EF-LI)...
6870 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006872 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6873 if (localeFromDefaultSim != null) {
6874 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6875 if (DBG) log("Using locale from subId: " + subId + " locale: "
6876 + localeFromDefaultSim);
6877 return localeFromDefaultSim.toLanguageTag();
6878 } else {
6879 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006880 }
6881 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 // The SIM language preferences only store a language (e.g. fr = French), not an
6884 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6885 // the SIM and carrier preferences does not include a country we add the country
6886 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006887 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006889 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890 return mccLocale.toLanguageTag();
6891 }
6892
6893 if (DBG) log("No locale found - returning null");
6894 return null;
6895 } finally {
6896 Binder.restoreCallingIdentity(identity);
6897 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006898 }
6899
6900 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006901 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006902 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006903 }
6904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006905 /**
6906 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6907 */
6908 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006909 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006910 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006911 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006912
Chenjie Yu1ba97252018-01-11 18:16:20 -08006913 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07006914 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006915
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006916 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006917 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6918 * representing the state of the modem.
6919 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006920 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6921 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006922 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006923 */
6924 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006925 public void requestModemActivityInfo(ResultReceiver result) {
6926 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006927 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928
6929 final long identity = Binder.clearCallingIdentity();
6930 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006931 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006932 } finally {
6933 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006934 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006935 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006936
Siddharth Rayb8114062018-06-17 15:02:38 -07006937 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6938 // less than total activity duration.
6939 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6940 if (info == null) {
6941 return false;
6942 }
6943 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07006944 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
6945 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
6946
Siddharth Rayb8114062018-06-17 15:02:38 -07006947 return (info.isValid()
6948 && (info.getSleepTimeMillis() <= activityDurationMs)
6949 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006950 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006951 && (totalTxTimeMs <= activityDurationMs));
6952 }
6953
Jack Yu85bd38a2015-11-09 11:34:32 -08006954 /**
6955 * {@hide}
6956 * Returns the service state information on specified subscription.
6957 */
6958 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006959 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6960 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006961 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006962 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006963 return null;
6964 }
6965
Hall Liuf19c44f2018-11-27 14:38:17 -08006966 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6967 LocationAccessPolicy.checkLocationPermission(mApp,
6968 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6969 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006970 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006971 .setCallingPid(Binder.getCallingPid())
6972 .setCallingUid(Binder.getCallingUid())
6973 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006974 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006975 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006976 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6977 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006978 .build());
6979
6980 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6981 LocationAccessPolicy.checkLocationPermission(mApp,
6982 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6983 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006984 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006985 .setCallingPid(Binder.getCallingPid())
6986 .setCallingUid(Binder.getCallingUid())
6987 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006988 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006989 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006990 .setMinSdkVersionForFine(Integer.MAX_VALUE)
6991 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006992 .build());
6993 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6994 boolean hasFinePermission =
6995 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6996 boolean hasCoarsePermission =
6997 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 final long identity = Binder.clearCallingIdentity();
7000 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007001 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7002 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7003 Rlog.d(LOG_TAG,
7004 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7005 return null;
7006 }
7007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 final Phone phone = getPhone(subId);
7009 if (phone == null) {
7010 return null;
7011 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007012
Hall Liuf19c44f2018-11-27 14:38:17 -08007013 ServiceState ss = phone.getServiceState();
7014
7015 // Scrub out the location info in ServiceState depending on what level of access
7016 // the caller has.
7017 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007018 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7019 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007020 } finally {
7021 Binder.restoreCallingIdentity(identity);
7022 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007023 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007024
7025 /**
7026 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7027 *
7028 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7029 * voicemail ringtone.
7030 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7031 * PhoneAccount.
7032 */
7033 @Override
7034 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 final long identity = Binder.clearCallingIdentity();
7036 try {
7037 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7038 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007039 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7043 } finally {
7044 Binder.restoreCallingIdentity(identity);
7045 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007046 }
7047
7048 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007049 * Sets the per-account voicemail ringtone.
7050 *
7051 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7052 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7053 *
7054 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7055 * voicemail ringtone.
7056 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7057 * PhoneAccount.
7058 */
7059 @Override
7060 public void setVoicemailRingtoneUri(String callingPackage,
7061 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007062 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007064 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7065 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7067 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7068 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070
7071 final long identity = Binder.clearCallingIdentity();
7072 try {
7073 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7074 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007075 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007076 }
7077 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7078 } finally {
7079 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007080 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007081 }
7082
7083 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007084 * Returns whether vibration is set for voicemail notification in Phone settings.
7085 *
7086 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7087 * voicemail vibration setting.
7088 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7089 */
7090 @Override
7091 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7095 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007096 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7100 } finally {
7101 Binder.restoreCallingIdentity(identity);
7102 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007103 }
7104
Youhan Wange64578a2016-05-02 15:32:42 -07007105 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007106 * Sets the per-account voicemail vibration.
7107 *
7108 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7109 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7110 *
7111 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7112 * voicemail vibration setting.
7113 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7114 * specific PhoneAccount.
7115 */
7116 @Override
7117 public void setVoicemailVibrationEnabled(String callingPackage,
7118 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007119 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007120 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007121 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7122 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7124 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7125 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007126 }
7127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 final long identity = Binder.clearCallingIdentity();
7129 try {
7130 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7131 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007132 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133 }
7134 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7135 } finally {
7136 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007137 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007138 }
7139
7140 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007141 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7142 *
7143 * @throws SecurityException if the caller does not have the required permission
7144 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007145 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007146 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007147 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007148 }
7149
7150 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007151 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7152 * permission.
7153 *
7154 * @throws SecurityException if the caller does not have the required permission
7155 */
7156 private void enforceSendSmsPermission() {
7157 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7158 }
7159
7160 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007161 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007162 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007163 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007164 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007165 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166 final long identity = Binder.clearCallingIdentity();
7167 try {
7168 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007169 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170 if (componentName == null) {
7171 throw new SecurityException(
7172 "Caller not current active visual voicemail package[null]");
7173 }
7174 String vvmPackage = componentName.getPackageName();
7175 if (!callingPackage.equals(vvmPackage)) {
7176 throw new SecurityException("Caller not current active visual voicemail package["
7177 + vvmPackage + "]");
7178 }
7179 } finally {
7180 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007181 }
7182 }
7183
7184 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007185 * Return the application ID for the app type.
7186 *
7187 * @param subId the subscription ID that this request applies to.
7188 * @param appType the uicc app type.
7189 * @return Application ID for specificied app type, or null if no uicc.
7190 */
7191 @Override
7192 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007193 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007194 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195
7196 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007197 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198 if (phone == null) {
7199 return null;
7200 }
7201 String aid = null;
7202 try {
7203 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7204 .getApplicationByType(appType).getAid();
7205 } catch (Exception e) {
7206 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7207 }
7208 return aid;
7209 } finally {
7210 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007211 }
Youhan Wange64578a2016-05-02 15:32:42 -07007212 }
7213
Youhan Wang4001d252016-05-11 10:29:41 -07007214 /**
7215 * Return the Electronic Serial Number.
7216 *
7217 * @param subId the subscription ID that this request applies to.
7218 * @return ESN or null if error.
7219 */
7220 @Override
7221 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007222 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007223 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224
7225 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007226 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 if (phone == null) {
7228 return null;
7229 }
7230 String esn = null;
7231 try {
7232 esn = phone.getEsn();
7233 } catch (Exception e) {
7234 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7235 }
7236 return esn;
7237 } finally {
7238 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007239 }
Youhan Wang4001d252016-05-11 10:29:41 -07007240 }
7241
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007242 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007243 * Return the Preferred Roaming List Version.
7244 *
7245 * @param subId the subscription ID that this request applies to.
7246 * @return PRLVersion or null if error.
7247 */
7248 @Override
7249 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007250 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007251 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252
7253 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007254 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255 if (phone == null) {
7256 return null;
7257 }
7258 String cdmaPrlVersion = null;
7259 try {
7260 cdmaPrlVersion = phone.getCdmaPrlVersion();
7261 } catch (Exception e) {
7262 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7263 }
7264 return cdmaPrlVersion;
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007267 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007268 }
7269
7270 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007271 * Get snapshot of Telephony histograms
7272 * @return List of Telephony histograms
7273 * @hide
7274 */
7275 @Override
7276 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7278 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279
7280 final long identity = Binder.clearCallingIdentity();
7281 try {
7282 return RIL.getTelephonyRILTimingHistograms();
7283 } finally {
7284 Binder.restoreCallingIdentity(identity);
7285 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007286 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007287
7288 /**
7289 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007290 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7291 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007292 * Require system privileges. In the future we may add this to carrier APIs.
7293 *
Michele Berionne482f8202018-11-27 18:57:59 -08007294 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007295 */
7296 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007297 @TelephonyManager.SetCarrierRestrictionResult
7298 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007299 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007300 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007301
Michele Berionne482f8202018-11-27 18:57:59 -08007302 if (carrierRestrictionRules == null) {
7303 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007304 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306 final long identity = Binder.clearCallingIdentity();
7307 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007308 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007309 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 } finally {
7311 Binder.restoreCallingIdentity(identity);
7312 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007313 }
7314
7315 /**
7316 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007317 * Get the allowed carrier list and the excluded carrier list, including the priority between
7318 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007319 * Require system privileges. In the future we may add this to carrier APIs.
7320 *
Michele Berionne482f8202018-11-27 18:57:59 -08007321 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007322 */
7323 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007324 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007325 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007326 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327
7328 final long identity = Binder.clearCallingIdentity();
7329 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007330 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7331 if (response instanceof CarrierRestrictionRules) {
7332 return (CarrierRestrictionRules) response;
7333 }
7334 // Response is an Exception of some kind,
7335 // which is signalled to the user as a NULL retval
7336 return null;
7337 } catch (Exception e) {
7338 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7339 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340 } finally {
7341 Binder.restoreCallingIdentity(identity);
7342 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007343 }
7344
fionaxu59545b42016-05-25 15:53:37 -07007345 /**
fionaxu59545b42016-05-25 15:53:37 -07007346 * Action set from carrier signalling broadcast receivers to enable/disable radio
7347 * @param subId the subscription ID that this action applies to.
7348 * @param enabled control enable or disable radio.
7349 * {@hide}
7350 */
7351 @Override
7352 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7353 enforceModifyPermission();
7354 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007355
7356 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007357 if (phone == null) {
7358 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7359 return;
7360 }
7361 try {
7362 phone.carrierActionSetRadioEnabled(enabled);
7363 } catch (Exception e) {
7364 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 } finally {
7366 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007367 }
7368 }
7369
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007370 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007371 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7372 * network status based on which carrier apps could apply actions accordingly,
7373 * enable/disable default url handler for example.
7374 *
7375 * @param subId the subscription ID that this action applies to.
7376 * @param report control start/stop reporting the default network status.
7377 * {@hide}
7378 */
7379 @Override
7380 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7381 enforceModifyPermission();
7382 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383
7384 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007385 if (phone == null) {
7386 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7387 return;
7388 }
7389 try {
7390 phone.carrierActionReportDefaultNetworkStatus(report);
7391 } catch (Exception e) {
7392 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 } finally {
7394 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007395 }
7396 }
7397
7398 /**
fionaxud9622282017-07-17 17:51:30 -07007399 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7400 * @param subId the subscription ID that this action applies to.
7401 * {@hide}
7402 */
7403 @Override
7404 public void carrierActionResetAll(int subId) {
7405 enforceModifyPermission();
7406 final Phone phone = getPhone(subId);
7407 if (phone == null) {
7408 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7409 return;
7410 }
7411 try {
7412 phone.carrierActionResetAll();
7413 } catch (Exception e) {
7414 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7415 }
7416 }
7417
7418 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007419 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7420 * bug report is being generated.
7421 */
7422 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007423 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007424 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7425 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007426 writer.println("Permission Denial: can't dump Phone from pid="
7427 + Binder.getCallingPid()
7428 + ", uid=" + Binder.getCallingUid()
7429 + "without permission "
7430 + android.Manifest.permission.DUMP);
7431 return;
7432 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007433 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007434 }
Jack Yueb89b242016-06-22 13:27:47 -07007435
Brad Ebingerdac2f002018-04-03 15:17:52 -07007436 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007437 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7438 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7439 @NonNull String[] args) {
7440 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7441 this, in.getFileDescriptor(), out.getFileDescriptor(),
7442 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007443 }
7444
Jack Yueb89b242016-06-22 13:27:47 -07007445 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007446 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007447 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007448 * @param reason the reason the data enable change is taking place
7449 * @param enabled True if enabling the data, otherwise disabling.
7450 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007451 */
7452 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007453 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007454 boolean enabled) {
7455 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7456 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7457 try {
7458 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007459 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007460 } catch (SecurityException se) {
7461 enforceModifyPermission();
7462 }
7463 } else {
7464 enforceModifyPermission();
7465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466
7467 final long identity = Binder.clearCallingIdentity();
7468 try {
7469 Phone phone = getPhone(subId);
7470 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007471 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7472 phone.carrierActionSetMeteredApnsEnabled(enabled);
7473 } else {
7474 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 }
7477 } finally {
7478 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007479 }
7480 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007481
7482 /**
7483 * Get Client request stats
7484 * @return List of Client Request Stats
7485 * @hide
7486 */
7487 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007488 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7489 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007490 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007491 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007492 return null;
7493 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007494 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 final long identity = Binder.clearCallingIdentity();
7497 try {
7498 if (phone != null) {
7499 return phone.getClientRequestStats();
7500 }
7501
7502 return null;
7503 } finally {
7504 Binder.restoreCallingIdentity(identity);
7505 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007506 }
7507
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007508 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007509 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007510 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007511 }
Jack Yueb4124c2017-02-16 15:32:43 -08007512
7513 /**
Grace Chen70990072017-03-24 17:21:30 -07007514 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007515 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007516 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007517 * @param state State of SIM (power down, power up, pass through)
7518 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7519 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7520 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007521 *
7522 **/
7523 @Override
Grace Chen70990072017-03-24 17:21:30 -07007524 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007525 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007526 Phone phone = PhoneFactory.getPhone(slotIndex);
7527
vagdeviaf9a5b92018-08-15 16:01:53 -07007528 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7529
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 final long identity = Binder.clearCallingIdentity();
7531 try {
7532 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007533 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 }
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007537 }
7538 }
Shuo Qiandd210312017-04-12 22:11:33 +00007539
Tyler Gunn65d45c22017-06-05 11:22:26 -07007540 private boolean isUssdApiAllowed(int subId) {
7541 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007542 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007543 if (configManager == null) {
7544 return false;
7545 }
7546 PersistableBundle pb = configManager.getConfigForSubId(subId);
7547 if (pb == null) {
7548 return false;
7549 }
7550 return pb.getBoolean(
7551 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7552 }
7553
Shuo Qiandd210312017-04-12 22:11:33 +00007554 /**
7555 * Check if phone is in emergency callback mode
7556 * @return true if phone is in emergency callback mode
7557 * @param subId sub id
7558 */
goneil9c5f4872017-12-05 14:07:56 -08007559 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007560 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007561 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007562 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563
7564 final long identity = Binder.clearCallingIdentity();
7565 try {
7566 if (phone != null) {
7567 return phone.isInEcm();
7568 } else {
7569 return false;
7570 }
7571 } finally {
7572 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007573 }
7574 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007575
7576 /**
7577 * Get the current signal strength information for the given subscription.
7578 * Because this information is not updated when the device is in a low power state
7579 * it should not be relied-upon to be current.
7580 * @param subId Subscription index
7581 * @return the most recent cached signal strength info from the modem
7582 */
7583 @Override
7584 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 final long identity = Binder.clearCallingIdentity();
7586 try {
7587 Phone p = getPhone(subId);
7588 if (p == null) {
7589 return null;
7590 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007592 return p.getSignalStrength();
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
7595 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007596 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007597
Pengquan Meng77b7f132018-08-22 14:49:57 -07007598 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007599 * Get the current modem radio state for the given slot.
7600 * @param slotIndex slot index.
7601 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007602 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007603 * @return the current radio power state from the modem
7604 */
7605 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007606 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007607 Phone phone = PhoneFactory.getPhone(slotIndex);
7608 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7610 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007611 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7612 }
7613
7614 final long identity = Binder.clearCallingIdentity();
7615 try {
7616 return phone.getRadioPowerState();
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
7619 }
7620 }
7621 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7622 }
7623
7624 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007625 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7626 *
7627 * <p>Requires one of the following permissions:
7628 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7629 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7630 * privileges.
7631 *
7632 * @param subId subscription id
7633 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7634 * {@code false}.
7635 */
7636 @Override
7637 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007638 try {
7639 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7640 null);
7641 } catch (Exception e) {
7642 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7643 mApp, subId, "isDataRoamingEnabled");
7644 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007645
Pengquan Menga1bb6272018-09-06 09:59:22 -07007646 boolean isEnabled = false;
7647 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007648 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007649 Phone phone = getPhone(subId);
7650 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007651 } finally {
7652 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007653 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007654 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007655 }
7656
7657
7658 /**
7659 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7660 *
7661 * <p> Requires permission:
7662 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7663 * privileges.
7664 *
7665 * @param subId subscription id
7666 * @param isEnabled {@code true} means enable, {@code false} means disable.
7667 */
7668 @Override
7669 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7671 mApp, subId, "setDataRoamingEnabled");
7672
Pengquan Menga1bb6272018-09-06 09:59:22 -07007673 final long identity = Binder.clearCallingIdentity();
7674 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007675 Phone phone = getPhone(subId);
7676 if (phone != null) {
7677 phone.setDataRoamingEnabled(isEnabled);
7678 }
7679 } finally {
7680 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007681 }
7682 }
7683
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007684 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007685 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007686 TelephonyPermissions
7687 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007688 mApp, subId, "isManualNetworkSelectionAllowed");
7689
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007690 boolean isAllowed = true;
7691 final long identity = Binder.clearCallingIdentity();
7692 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007693 Phone phone = getPhone(subId);
7694 if (phone != null) {
7695 isAllowed = phone.isCspPlmnEnabled();
7696 }
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
7699 }
7700 return isAllowed;
7701 }
7702
7703 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007704 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007705 // Verify that tha callingPackage belongs to the calling UID
7706 mApp.getSystemService(AppOpsManager.class)
7707 .checkPackage(Binder.getCallingUid(), callingPackage);
7708
Jordan Liu1e142fc2019-04-22 15:10:43 -07007709 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007710 try {
7711 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007712 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007713 } catch (SecurityException e) {
7714 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7715 // has carrier privileges on an active UICC
7716 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7717 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007718 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007719 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007720 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007721
7722 final long identity = Binder.clearCallingIdentity();
7723 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007724 UiccController uiccController = UiccController.getInstance();
7725 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007726 if (hasReadPermission) {
7727 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007728 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007729
7730 // Remove private info if the caller doesn't have access
7731 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7732 for (UiccCardInfo cardInfo : cardInfos) {
7733 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7734 // is available
7735 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7736 if (card == null || card.getUiccProfile() == null) {
7737 // assume no access if the card or profile is unavailable
7738 filteredInfos.add(cardInfo.getUnprivileged());
7739 continue;
7740 }
7741 UiccProfile profile = card.getUiccProfile();
7742 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7743 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7744 filteredInfos.add(cardInfo);
7745 } else {
7746 filteredInfos.add(cardInfo.getUnprivileged());
7747 }
7748 }
7749 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007750 } finally {
7751 Binder.restoreCallingIdentity(identity);
7752 }
7753 }
7754
7755 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007756 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007757 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 final long identity = Binder.clearCallingIdentity();
7760 try {
7761 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7762 if (slots == null) {
7763 Rlog.i(LOG_TAG, "slots is null.");
7764 return null;
7765 }
7766
7767 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7768 for (int i = 0; i < slots.length; i++) {
7769 UiccSlot slot = slots[i];
7770 if (slot == null) {
7771 continue;
7772 }
7773
Jordan Liu7be7e652019-05-06 18:55:02 +00007774 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775 UiccCard card = slot.getUiccCard();
7776 if (card != null) {
7777 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007778 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007779 cardId = slot.getEid();
7780 if (TextUtils.isEmpty(cardId)) {
7781 cardId = slot.getIccId();
7782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007783 }
7784
Jordan Liu857451f2019-05-09 16:35:35 -07007785 if (cardId != null) {
7786 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7787 // if cardId is an EID, it's all digits so this is fine
7788 cardId = IccUtils.stripTrailingFs(cardId);
7789 }
7790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791 int cardState = 0;
7792 switch (slot.getCardState()) {
7793 case CARDSTATE_ABSENT:
7794 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7795 break;
7796 case CARDSTATE_PRESENT:
7797 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7798 break;
7799 case CARDSTATE_ERROR:
7800 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7801 break;
7802 case CARDSTATE_RESTRICTED:
7803 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7804 break;
7805 default:
7806 break;
7807
7808 }
7809
7810 infos[i] = new UiccSlotInfo(
7811 slot.isActive(),
7812 slot.isEuicc(),
7813 cardId,
7814 cardState,
7815 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007816 slot.isExtendedApduSupported(),
7817 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 }
7819 return infos;
7820 } finally {
7821 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007822 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007823 }
7824
7825 @Override
7826 public boolean switchSlots(int[] physicalSlots) {
7827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828
7829 final long identity = Binder.clearCallingIdentity();
7830 try {
7831 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7832 } finally {
7833 Binder.restoreCallingIdentity(identity);
7834 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007835 }
Jack Yu4c988042018-02-27 15:30:01 -08007836
7837 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007838 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007839 final long identity = Binder.clearCallingIdentity();
7840 try {
7841 return UiccController.getInstance().getCardIdForDefaultEuicc();
7842 } finally {
7843 Binder.restoreCallingIdentity(identity);
7844 }
7845 }
7846
Pengquan Meng85728fb2018-03-12 16:31:21 -07007847 /**
goneil47ffb6e2018-04-06 15:40:58 -07007848 * A test API to reload the UICC profile.
7849 *
7850 * <p>Requires that the calling app has permission
7851 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7852 * @hide
7853 */
7854 @Override
7855 public void refreshUiccProfile(int subId) {
7856 enforceModifyPermission();
7857
7858 final long identity = Binder.clearCallingIdentity();
7859 try {
7860 Phone phone = getPhone(subId);
7861 if (phone == null) {
7862 return;
7863 }
7864 UiccCard uiccCard = phone.getUiccCard();
7865 if (uiccCard == null) {
7866 return;
7867 }
7868 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7869 if (uiccProfile == null) {
7870 return;
7871 }
7872 uiccProfile.refresh();
7873 } finally {
7874 Binder.restoreCallingIdentity(identity);
7875 }
7876 }
7877
7878 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007879 * Returns false if the mobile data is disabled by default, otherwise return true.
7880 */
7881 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007882 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007883 }
7884
7885 /**
7886 * Returns true if the data roaming is enabled by default, i.e the system property
7887 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7888 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7889 */
7890 private boolean getDefaultDataRoamingEnabled(int subId) {
7891 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007892 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07007893 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007894 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7895 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7896 return isDataRoamingEnabled;
7897 }
7898
7899 /**
7900 * Returns the default network type for the given {@code subId}, if the default network type is
7901 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7902 */
7903 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007904 List<Integer> list = TelephonyProperties.default_network();
7905 int phoneId = mSubscriptionController.getPhoneId(subId);
7906 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7907 return list.get(phoneId);
7908 }
7909 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007910 }
fionaxua13278b2018-03-21 00:08:13 -07007911
7912 @Override
7913 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007914 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007915 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007916
7917 final long identity = Binder.clearCallingIdentity();
7918 try {
7919 final Phone phone = getPhone(subId);
7920 if (phone == null) {
7921 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7922 return;
7923 }
chen xueaba88a2019-03-15 13:15:10 -07007924 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7925 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07007926 if (carrierPrivilegeRules == null) {
7927 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7928 } else {
7929 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 } finally {
7932 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007933 }
fionaxua13278b2018-03-21 00:08:13 -07007934 }
7935
7936 @Override
7937 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007938 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939
7940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 final Phone phone = getPhone(subId);
7943 if (phone == null) {
7944 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7945 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7946 }
7947 return phone.getCarrierIdListVersion();
7948 } finally {
7949 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007950 }
fionaxua13278b2018-03-21 00:08:13 -07007951 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007952
7953 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007954 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7955 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007957 mApp, subId, callingPackage, callingFeatureId,
7958 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007959 return -1;
7960 }
7961
7962 final long identity = Binder.clearCallingIdentity();
7963 try {
7964 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7965 } finally {
7966 Binder.restoreCallingIdentity(identity);
7967 }
7968 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007969
7970 @Override
7971 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007972 TelephonyPermissions
7973 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007974 mApp, subId, "getCdmaRoamingMode");
7975
7976 final long identity = Binder.clearCallingIdentity();
7977 try {
7978 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7979 } finally {
7980 Binder.restoreCallingIdentity(identity);
7981 }
7982 }
7983
7984 @Override
7985 public boolean setCdmaRoamingMode(int subId, int mode) {
7986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7987 mApp, subId, "setCdmaRoamingMode");
7988
7989 final long identity = Binder.clearCallingIdentity();
7990 try {
7991 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7992 } finally {
7993 Binder.restoreCallingIdentity(identity);
7994 }
7995 }
7996
7997 @Override
7998 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8000 mApp, subId, "setCdmaSubscriptionMode");
8001
8002 final long identity = Binder.clearCallingIdentity();
8003 try {
8004 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8005 } finally {
8006 Binder.restoreCallingIdentity(identity);
8007 }
8008 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008009
sqianc5eccab2018-10-19 18:46:41 -07008010 @Override
sqian8c685422019-02-22 15:55:18 -08008011 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008012 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008014 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8015 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008016 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8017 }
8018 final long identity = Binder.clearCallingIdentity();
8019 try {
sqian854d44b2018-12-12 16:48:18 -08008020 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8021 for (Phone phone: PhoneFactory.getPhones()) {
8022 if (phone.getEmergencyNumberTracker() != null
8023 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8024 emergencyNumberListInternal.put(
8025 phone.getSubId(),
8026 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8027 }
sqian11b7a0e2018-12-05 18:48:28 -08008028 }
sqian854d44b2018-12-12 16:48:18 -08008029 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008030 } finally {
8031 Binder.restoreCallingIdentity(identity);
8032 }
sqianc5eccab2018-10-19 18:46:41 -07008033 }
8034
8035 @Override
sqian8c685422019-02-22 15:55:18 -08008036 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008037 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008038 if (!exactMatch) {
8039 TelephonyPermissions
8040 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008041 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008042 }
8043 final long identity = Binder.clearCallingIdentity();
8044 try {
sqian854d44b2018-12-12 16:48:18 -08008045 for (Phone phone: PhoneFactory.getPhones()) {
8046 if (phone.getEmergencyNumberTracker() != null
8047 && phone.getEmergencyNumberTracker() != null) {
8048 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
8049 number, exactMatch)) {
8050 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008051 }
8052 }
sqian11b7a0e2018-12-05 18:48:28 -08008053 }
8054 return false;
8055 } finally {
8056 Binder.restoreCallingIdentity(identity);
8057 }
8058 }
8059
sqianf4ca7ed2019-01-15 18:32:07 -08008060 /**
8061 * Update emergency number list for test mode.
8062 */
8063 @Override
8064 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8065 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8066 "updateEmergencyNumberListTestMode");
8067
8068 final long identity = Binder.clearCallingIdentity();
8069 try {
8070 for (Phone phone: PhoneFactory.getPhones()) {
8071 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8072 if (tracker != null) {
8073 tracker.executeEmergencyNumberTestModeCommand(action, num);
8074 }
8075 }
8076 } finally {
8077 Binder.restoreCallingIdentity(identity);
8078 }
8079 }
8080
8081 /**
8082 * Get the full emergency number list for test mode.
8083 */
8084 @Override
8085 public List<String> getEmergencyNumberListTestMode() {
8086 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8087 "getEmergencyNumberListTestMode");
8088
8089 final long identity = Binder.clearCallingIdentity();
8090 try {
8091 Set<String> emergencyNumbers = new HashSet<>();
8092 for (Phone phone: PhoneFactory.getPhones()) {
8093 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8094 if (tracker != null) {
8095 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8096 emergencyNumbers.add(num.getNumber());
8097 }
8098 }
8099 }
8100 return new ArrayList<>(emergencyNumbers);
8101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103 }
8104 }
8105
chen xud6b45bd2018-10-30 22:27:10 -07008106 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008107 public int getEmergencyNumberDbVersion(int subId) {
8108 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8109
8110 final long identity = Binder.clearCallingIdentity();
8111 try {
8112 final Phone phone = getPhone(subId);
8113 if (phone == null) {
8114 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8115 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8116 }
8117 return phone.getEmergencyNumberDbVersion();
8118 } finally {
8119 Binder.restoreCallingIdentity(identity);
8120 }
8121 }
8122
8123 @Override
8124 public void notifyOtaEmergencyNumberDbInstalled() {
8125 enforceModifyPermission();
8126
8127 final long identity = Binder.clearCallingIdentity();
8128 try {
8129 for (Phone phone: PhoneFactory.getPhones()) {
8130 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8131 if (tracker != null) {
8132 tracker.updateOtaEmergencyNumberDatabase();
8133 }
8134 }
8135 } finally {
8136 Binder.restoreCallingIdentity(identity);
8137 }
8138 }
8139
8140 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008141 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008142 enforceActiveEmergencySessionPermission();
8143
8144 final long identity = Binder.clearCallingIdentity();
8145 try {
8146 for (Phone phone: PhoneFactory.getPhones()) {
8147 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8148 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008149 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8150 }
8151 }
8152 } finally {
8153 Binder.restoreCallingIdentity(identity);
8154 }
8155 }
8156
8157 @Override
8158 public void resetOtaEmergencyNumberDbFilePath() {
8159 enforceActiveEmergencySessionPermission();
8160
8161 final long identity = Binder.clearCallingIdentity();
8162 try {
8163 for (Phone phone: PhoneFactory.getPhones()) {
8164 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8165 if (tracker != null) {
8166 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008167 }
8168 }
8169 } finally {
8170 Binder.restoreCallingIdentity(identity);
8171 }
8172 }
8173
8174 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008175 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8176 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8177 Phone phone = getPhone(subId);
8178 if (phone == null) {
8179 return null;
8180 }
8181 final long identity = Binder.clearCallingIdentity();
8182 try {
8183 UiccProfile profile = UiccController.getInstance()
8184 .getUiccProfileForPhone(phone.getPhoneId());
8185 if (profile != null) {
8186 return profile.getCertsFromCarrierPrivilegeAccessRules();
8187 }
8188 } finally {
8189 Binder.restoreCallingIdentity(identity);
8190 }
8191 return null;
8192 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008193
8194 /**
8195 * Enable or disable a modem stack.
8196 */
8197 @Override
8198 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8199 enforceModifyPermission();
8200
8201 final long identity = Binder.clearCallingIdentity();
8202 try {
8203 Phone phone = PhoneFactory.getPhone(slotIndex);
8204 if (phone == null) {
8205 return false;
8206 } else {
8207 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8208 }
8209 } finally {
8210 Binder.restoreCallingIdentity(identity);
8211 }
8212 }
Michelecea4cf22018-12-21 15:00:11 -08008213
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008214 /**
8215 * Whether a modem stack is enabled or not.
8216 */
8217 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008218 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8219 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008220 Phone phone = PhoneFactory.getPhone(slotIndex);
8221 if (phone == null) return false;
8222
8223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008224 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8225 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008226 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8227 }
8228
8229 final long identity = Binder.clearCallingIdentity();
8230 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008231 try {
8232 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8233 } catch (NoSuchElementException ex) {
8234 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8235 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008236 } finally {
8237 Binder.restoreCallingIdentity(identity);
8238 }
8239 }
8240
Michelecea4cf22018-12-21 15:00:11 -08008241 @Override
Michele0ea7d782019-03-19 14:58:42 -07008242 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008243 enforceModifyPermission();
8244
8245 final long identity = Binder.clearCallingIdentity();
8246 try {
8247 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008248 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008249 .commit();
8250 } finally {
8251 Binder.restoreCallingIdentity(identity);
8252 }
8253 }
8254
8255 @Override
Michele0ea7d782019-03-19 14:58:42 -07008256 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008257 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008259 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8260 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008261 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008262 }
Michelecea4cf22018-12-21 15:00:11 -08008263
8264 final long identity = Binder.clearCallingIdentity();
8265 try {
Michele0ea7d782019-03-19 14:58:42 -07008266 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008267 } finally {
8268 Binder.restoreCallingIdentity(identity);
8269 }
8270 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008271
Michele0ea7d782019-03-19 14:58:42 -07008272 @TelephonyManager.IsMultiSimSupportedResult
8273 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008274 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8275 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8276 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008277 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8278 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008279 }
8280 // Check if the hardware supports multisim functionality. If usage of multisim is not
8281 // supported by the modem, indicate that it is restricted.
8282 PhoneCapability staticCapability =
8283 mPhoneConfigurationManager.getStaticPhoneCapability();
8284 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008285 loge("isMultiSimSupportedInternal: no static configuration available");
8286 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008287 }
Sarah Chin7caee492020-02-18 20:49:02 +00008288 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008289 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8290 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008291 }
8292 // Check if support of multiple SIMs is restricted by carrier
8293 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008294 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008295 }
8296
Michele0ea7d782019-03-19 14:58:42 -07008297 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008298 }
8299
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008300 /**
8301 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008302 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8303 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8304 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008305 * @param numOfSims number of active sims we want to switch to
8306 */
8307 @Override
8308 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008309 if (numOfSims == 1) {
8310 enforceModifyPermission();
8311 } else {
8312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8313 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8314 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008315 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008316
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008317 try {
Michele30b57b22019-03-01 12:01:14 -08008318 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008319 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008320 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8321 return;
8322 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008323 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
8327 }
8328
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008329 @Override
8330 public boolean isApplicationOnUicc(int subId, int appType) {
8331 enforceReadPrivilegedPermission("isApplicationOnUicc");
8332 Phone phone = getPhone(subId);
8333 if (phone == null) {
8334 return false;
8335 }
8336 final long identity = Binder.clearCallingIdentity();
8337 try {
8338 UiccCard uiccCard = phone.getUiccCard();
8339 if (uiccCard == null) {
8340 return false;
8341 }
8342 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8343 if (uiccProfile == null) {
8344 return false;
8345 }
8346 if (TelephonyManager.APPTYPE_SIM <= appType
8347 && appType <= TelephonyManager.APPTYPE_ISIM) {
8348 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8349 }
8350 return false;
8351 } finally {
8352 Binder.restoreCallingIdentity(identity);
8353 }
8354 }
8355
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008356 /**
chen xub4baa772019-04-03 10:23:41 -07008357 * Get whether making changes to modem configurations will trigger reboot.
8358 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008359 */
8360 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008361 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8362 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008363 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008364 mApp, subId, callingPackage, callingFeatureId,
8365 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008366 return false;
8367 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008368 final long identity = Binder.clearCallingIdentity();
8369 try {
8370 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8371 } finally {
8372 Binder.restoreCallingIdentity(identity);
8373 }
8374 }
8375
Nathan Harold29f5f052019-02-15 13:41:57 -08008376 private void updateModemStateMetrics() {
8377 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8378 // TODO: check the state for each modem if the api is ready.
8379 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8380 }
8381
Pengquan Meng3889a572019-01-23 11:16:29 -08008382 @Override
8383 public int[] getSlotsMapping() {
8384 enforceReadPrivilegedPermission("getSlotsMapping");
8385
8386 final long identity = Binder.clearCallingIdentity();
8387 try {
8388 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8389 // All logical slots should have a mapping to a physical slot.
8390 int[] logicalSlotsMapping = new int[phoneCount];
8391 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8392 for (int i = 0; i < slotInfos.length; i++) {
8393 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8394 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8395 }
8396 }
8397 return logicalSlotsMapping;
8398 } finally {
8399 Binder.restoreCallingIdentity(identity);
8400 }
8401 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008402
8403 /**
8404 * Get the IRadio HAL Version
8405 */
8406 @Override
8407 public int getRadioHalVersion() {
8408 Phone phone = getDefaultPhone();
8409 if (phone == null) return -1;
8410 HalVersion hv = phone.getHalVersion();
8411 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8412 return hv.major * 100 + hv.minor;
8413 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008414
8415 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008416 * Get the current calling package name.
8417 * @return the current calling package name
8418 */
8419 @Override
8420 public String getCurrentPackageName() {
8421 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8422 }
8423
8424 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008425 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8426 * corresponding network requests on a subId.
8427 *
8428 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008429 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008430 * 2) APN is un-metered for this subscription, or
8431 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008432 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008433 *
8434 * @return whether data is allowed for a apn type.
8435 *
8436 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008437 */
8438 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008439 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008440 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8441 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008442
8443 // Now that all security checks passes, perform the operation as ourselves.
8444 final long identity = Binder.clearCallingIdentity();
8445 try {
8446 Phone phone = getPhone(subId);
8447 if (phone == null) return false;
8448
Jack Yu41407ee2019-05-13 16:54:09 -07008449 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008450 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8451 } finally {
8452 Binder.restoreCallingIdentity(identity);
8453 }
8454 }
8455
8456 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008457 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008458 enforceReadPrivilegedPermission("isApnMetered");
8459
8460 // Now that all security checks passes, perform the operation as ourselves.
8461 final long identity = Binder.clearCallingIdentity();
8462 try {
8463 Phone phone = getPhone(subId);
8464 if (phone == null) return true; // By default return true.
8465
Jack Yu41407ee2019-05-13 16:54:09 -07008466 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008467 } finally {
8468 Binder.restoreCallingIdentity(identity);
8469 }
8470 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008471
8472 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008473 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8474 int subscriptionId, IBooleanConsumer resultCallback) {
8475 enforceModifyPermission();
8476 long token = Binder.clearCallingIdentity();
8477 try {
8478 Phone phone = getPhone(subscriptionId);
8479 if (phone == null) {
8480 try {
8481 if (resultCallback != null) {
8482 resultCallback.accept(false);
8483 }
8484 } catch (RemoteException e) {
8485 // ignore
8486 }
8487 return;
8488 }
8489 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8490 Pair.create(specifiers, (x) -> {
8491 try {
8492 if (resultCallback != null) {
8493 resultCallback.accept(x);
8494 }
8495 } catch (RemoteException e) {
8496 // ignore
8497 }
8498 });
8499 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8500 } finally {
8501 Binder.restoreCallingIdentity(token);
8502 }
8503 }
8504
8505 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008506 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008507 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008508 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8509 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8510 if (iccRecords == null) {
8511 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8512 return false;
8513 }
8514 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8515 }
8516
8517 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008518 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8519 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008520 if (callingPackage == null) {
8521 callingPackage = getCurrentPackageName();
8522 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008523 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8524 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008525 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8526 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008527 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8528 }
8529 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8530 Intent intent = new Intent();
8531 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8532 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8533 // Bring up choose default SMS subscription dialog right now
8534 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8535 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8536 mApp.startActivity(intent);
8537 }
chen xud5ca2d52019-05-28 15:20:57 -07008538
8539 @Override
8540 public String getMmsUAProfUrl(int subId) {
8541 //TODO investigate if this API should require proper permission check in R b/133791609
8542 final long identity = Binder.clearCallingIdentity();
8543 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008544 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8545 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8546 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8547 return carrierUAProfUrl;
8548 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008549 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8550 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008551 } finally {
8552 Binder.restoreCallingIdentity(identity);
8553 }
8554 }
8555
8556 @Override
8557 public String getMmsUserAgent(int subId) {
8558 //TODO investigate if this API should require proper permission check in R b/133791609
8559 final long identity = Binder.clearCallingIdentity();
8560 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008561 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8562 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8563 if (!TextUtils.isEmpty(carrierUserAgent)) {
8564 return carrierUserAgent;
8565 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008566 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8567 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008568 } finally {
8569 Binder.restoreCallingIdentity(identity);
8570 }
8571 }
Jack Yub07d4972019-05-28 16:12:25 -07008572
8573 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008574 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8575 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07008576
Jack Yub07d4972019-05-28 16:12:25 -07008577 final long identity = Binder.clearCallingIdentity();
8578 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008579 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07008580 if (phone == null) return false;
8581
Hall Liua62f5da2020-09-25 10:42:19 -07008582 switch (policy) {
8583 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8584 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8585 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8586 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8587 default:
8588 throw new IllegalArgumentException(policy + " is not a valid policy");
8589 }
Jack Yub07d4972019-05-28 16:12:25 -07008590 } finally {
8591 Binder.restoreCallingIdentity(identity);
8592 }
8593 }
8594
8595 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008596 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8597 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08008598 enforceModifyPermission();
8599
changbettyd5c246e2019-12-24 15:40:37 +08008600 final long identity = Binder.clearCallingIdentity();
8601 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008602 Phone phone = getPhone(subscriptionId);
8603 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08008604
Hall Liua62f5da2020-09-25 10:42:19 -07008605 switch (policy) {
8606 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8607 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8608 break;
8609 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8610 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8611 break;
8612 default:
8613 throw new IllegalArgumentException(policy + " is not a valid policy");
8614 }
changbettyd5c246e2019-12-24 15:40:37 +08008615 } finally {
8616 Binder.restoreCallingIdentity(identity);
8617 }
8618 }
8619
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008620 /**
Hall Liu746e03c2020-09-25 11:13:49 -07008621 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008622 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8623 * otherwise.
8624 */
8625 @Override
8626 public void setCepEnabled(boolean isCepEnabled) {
8627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8628
8629 final long identity = Binder.clearCallingIdentity();
8630 try {
8631 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8632 for (Phone phone : PhoneFactory.getPhones()) {
8633 Phone defaultPhone = phone.getImsPhone();
8634 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8635 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8636 ImsPhoneCallTracker imsPhoneCallTracker =
8637 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8638 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8639 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8640 + imsPhone.getMsisdn());
8641 }
8642 }
8643 } finally {
8644 Binder.restoreCallingIdentity(identity);
8645 }
8646 }
allenwtsu46dcc572020-01-08 18:24:03 +08008647
8648 /**
8649 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8650 *
8651 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8652 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8653 * before being read.
8654 */
8655 @Override
8656 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8657 isCompressed) {
8658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8659 mApp, subId, "notifyRcsAutoConfigurationReceived");
8660 try {
8661 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8662 if (configBinder == null) {
8663 Rlog.e(LOG_TAG, "null result for getImsConfig");
8664 } else {
8665 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8666 }
8667 } catch (RemoteException e) {
8668 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8669 }
8670 }
zoey chene02881a2019-12-30 16:11:23 +08008671
8672 @Override
8673 public boolean isIccLockEnabled(int subId) {
8674 enforceReadPrivilegedPermission("isIccLockEnabled");
8675
8676 // Now that all security checks passes, perform the operation as ourselves.
8677 final long identity = Binder.clearCallingIdentity();
8678 try {
8679 Phone phone = getPhone(subId);
8680 if (phone != null && phone.getIccCard() != null) {
8681 return phone.getIccCard().getIccLockEnabled();
8682 } else {
8683 return false;
8684 }
8685 } finally {
8686 Binder.restoreCallingIdentity(identity);
8687 }
8688 }
8689
8690 /**
8691 * Set the ICC pin lock enabled or disabled.
8692 *
8693 * @return an integer representing the status of IccLock enabled or disabled in the following
8694 * three cases:
8695 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8696 * successfully.
8697 * - Positive number and zero for remaining password attempts.
8698 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8699 *
8700 */
8701 @Override
8702 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8703 enforceModifyPermission();
8704
8705 Phone phone = getPhone(subId);
8706 if (phone == null) {
8707 return 0;
8708 }
8709 // Now that all security checks passes, perform the operation as ourselves.
8710 final long identity = Binder.clearCallingIdentity();
8711 try {
8712 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8713 new Pair<Boolean, String>(enabled, password), phone, null);
8714 return attemptsRemaining;
8715
8716 } catch (Exception e) {
8717 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8718 } finally {
8719 Binder.restoreCallingIdentity(identity);
8720 }
8721 return 0;
8722 }
8723
8724 /**
8725 * Change the ICC password used in ICC pin lock.
8726 *
8727 * @return an integer representing the status of IccLock changed in the following three cases:
8728 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8729 * - Positive number and zero for remaining password attempts.
8730 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8731 *
8732 */
8733 @Override
8734 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8735 enforceModifyPermission();
8736
8737 Phone phone = getPhone(subId);
8738 if (phone == null) {
8739 return 0;
8740 }
8741 // Now that all security checks passes, perform the operation as ourselves.
8742 final long identity = Binder.clearCallingIdentity();
8743 try {
8744 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8745 new Pair<String, String>(oldPassword, newPassword), phone, null);
8746 return attemptsRemaining;
8747
8748 } catch (Exception e) {
8749 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8750 } finally {
8751 Binder.restoreCallingIdentity(identity);
8752 }
8753 return 0;
8754 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008755
8756 /**
8757 * Request for receiving user activity notification
8758 */
8759 @Override
8760 public void requestUserActivityNotification() {
8761 if (!mNotifyUserActivity.get()
8762 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8763 mNotifyUserActivity.set(true);
8764 }
8765 }
8766
8767 /**
8768 * Called when userActivity is signalled in the power manager.
8769 * This is safe to call from any thread, with any window manager locks held or not.
8770 */
8771 @Override
8772 public void userActivity() {
8773 // ***************************************
8774 // * Inherited from PhoneWindowManager *
8775 // ***************************************
8776 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8777 // WITH ITS LOCKS HELD.
8778 //
8779 // This code must be VERY careful about the locks
8780 // it acquires.
8781 // In fact, the current code acquires way too many,
8782 // and probably has lurking deadlocks.
8783
8784 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8785 throw new SecurityException("Only the OS may call notifyUserActivity()");
8786 }
8787
8788 if (mNotifyUserActivity.getAndSet(false)) {
8789 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8790 USER_ACTIVITY_NOTIFICATION_DELAY);
8791 }
8792 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008793
8794 @Override
8795 public boolean canConnectTo5GInDsdsMode() {
8796 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8797 }
Jack Yud10cdd42020-09-28 20:28:01 -07008798
8799 @Override
8800 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8801 String callingFeatureId) {
8802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8803 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8804 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8805 }
8806
8807 Phone phone = getPhone(subId);
8808 if (phone == null) {
8809 throw new RuntimeException("phone is not available");
8810 }
8811 // Now that all security checks passes, perform the operation as ourselves.
8812 final long identity = Binder.clearCallingIdentity();
8813 try {
8814 return phone.getEquivalentHomePlmns();
8815 } finally {
8816 Binder.restoreCallingIdentity(identity);
8817 }
8818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008819}