blob: 7793059660fd5e89673a1ad34411a0696f58cff5 [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,
1083 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1084 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001085 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001086 break;
1087
1088 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1089 ar = (AsyncResult) msg.obj;
1090 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001091 ResultReceiver result = (ResultReceiver) request.argument;
1092
1093 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001094 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001095 // Update the last modem activity info and the result of the request.
1096 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1097 if (isModemActivityInfoValid(info)) {
1098 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1099 int[] txTimeMs = info.getTransmitTimeMillis();
1100 int[] lastModemTxTimeMs = mLastModemActivityInfo
1101 .getTransmitTimeMillis();
1102 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1103 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1104 }
1105 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1106 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1107 + mLastModemActivityInfo.getSleepTimeMillis());
1108 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1109 + mLastModemActivityInfo.getIdleTimeMillis());
1110 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1111 mLastModemActivityInfo.setReceiveTimeMillis(
1112 info.getReceiveTimeMillis()
1113 + mLastModemActivityInfo.getReceiveTimeMillis());
1114 }
1115 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1116 mLastModemActivityInfo.getSleepTimeMillis(),
1117 mLastModemActivityInfo.getIdleTimeMillis(),
1118 mLastModemActivityInfo.getTransmitTimeMillis(),
1119 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001120 } else {
1121 if (ar.result == null) {
1122 loge("queryModemActivityInfo: Empty response");
1123 } else if (ar.exception instanceof CommandException) {
1124 loge("queryModemActivityInfo: CommandException: " +
1125 ar.exception);
1126 } else {
1127 loge("queryModemActivityInfo: Unknown exception");
1128 }
1129 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001130 Bundle bundle = new Bundle();
1131 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1132 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001133 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001134 break;
1135
Meng Wang1a7c35a2016-05-05 20:56:15 -07001136 case CMD_SET_ALLOWED_CARRIERS:
1137 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001138 CarrierRestrictionRules argument =
1139 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001140 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001141 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001142 break;
1143
1144 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 if (ar.exception == null && ar.result != null) {
1148 request.result = ar.result;
1149 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001150 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1151 if (ar.exception instanceof CommandException) {
1152 loge("setAllowedCarriers: CommandException: " + ar.exception);
1153 CommandException.Error error =
1154 ((CommandException) (ar.exception)).getCommandError();
1155 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1156 request.result =
1157 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1158 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001159 } else {
1160 loge("setAllowedCarriers: Unknown exception");
1161 }
1162 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001163 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001164 break;
1165
1166 case CMD_GET_ALLOWED_CARRIERS:
1167 request = (MainThreadRequest) msg.obj;
1168 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001169 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001170 break;
1171
1172 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1173 ar = (AsyncResult) msg.obj;
1174 request = (MainThreadRequest) ar.userObj;
1175 if (ar.exception == null && ar.result != null) {
1176 request.result = ar.result;
1177 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001178 request.result = new IllegalStateException(
1179 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001180 if (ar.result == null) {
1181 loge("getAllowedCarriers: Empty response");
1182 } else if (ar.exception instanceof CommandException) {
1183 loge("getAllowedCarriers: CommandException: " +
1184 ar.exception);
1185 } else {
1186 loge("getAllowedCarriers: Unknown exception");
1187 }
1188 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001189 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001190 break;
1191
Nathan Haroldb3014052017-01-25 15:57:32 -08001192 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1193 ar = (AsyncResult) msg.obj;
1194 request = (MainThreadRequest) ar.userObj;
1195 if (ar.exception == null && ar.result != null) {
1196 request.result = ar.result;
1197 } else {
1198 request.result = new IllegalArgumentException(
1199 "Failed to retrieve Forbidden Plmns");
1200 if (ar.result == null) {
1201 loge("getForbiddenPlmns: Empty response");
1202 } else {
1203 loge("getForbiddenPlmns: Unknown exception");
1204 }
1205 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001206 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001207 break;
1208
1209 case CMD_GET_FORBIDDEN_PLMNS:
1210 request = (MainThreadRequest) msg.obj;
1211 uiccCard = getUiccCardFromRequest(request);
1212 if (uiccCard == null) {
1213 loge("getForbiddenPlmns() UiccCard is null");
1214 request.result = new IllegalArgumentException(
1215 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001216 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001217 break;
1218 }
1219 Integer appType = (Integer) request.argument;
1220 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1221 if (uiccApp == null) {
1222 loge("getForbiddenPlmns() no app with specified type -- "
1223 + appType);
1224 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001225 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001226 break;
1227 } else {
1228 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1229 + " specified type -- " + appType);
1230 }
1231 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1232 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1233 onCompleted);
1234 break;
1235
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001236 case CMD_SWITCH_SLOTS:
1237 request = (MainThreadRequest) msg.obj;
1238 int[] physicalSlots = (int[]) request.argument;
1239 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1240 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1241 break;
1242
1243 case EVENT_SWITCH_SLOTS_DONE:
1244 ar = (AsyncResult) msg.obj;
1245 request = (MainThreadRequest) ar.userObj;
1246 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001247 notifyRequester(request);
1248 break;
1249 case CMD_GET_NETWORK_SELECTION_MODE:
1250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1252 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1253 break;
1254
1255 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1256 ar = (AsyncResult) msg.obj;
1257 request = (MainThreadRequest) ar.userObj;
1258 if (ar.exception != null) {
1259 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1260 } else {
1261 int mode = ((int[]) ar.result)[0];
1262 if (mode == 0) {
1263 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1264 } else {
1265 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1266 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001267 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001268 notifyRequester(request);
1269 break;
1270 case CMD_GET_CDMA_ROAMING_MODE:
1271 request = (MainThreadRequest) msg.obj;
1272 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1273 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1274 break;
1275 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1276 ar = (AsyncResult) msg.obj;
1277 request = (MainThreadRequest) ar.userObj;
1278 if (ar.exception != null) {
1279 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1280 } else {
1281 request.result = ((int[]) ar.result)[0];
1282 }
1283 notifyRequester(request);
1284 break;
1285 case CMD_SET_CDMA_ROAMING_MODE:
1286 request = (MainThreadRequest) msg.obj;
1287 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1288 int mode = (int) request.argument;
1289 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1290 break;
1291 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1292 ar = (AsyncResult) msg.obj;
1293 request = (MainThreadRequest) ar.userObj;
1294 request.result = ar.exception == null;
1295 notifyRequester(request);
1296 break;
1297 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1298 request = (MainThreadRequest) msg.obj;
1299 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1300 int subscriptionMode = (int) request.argument;
1301 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1302 break;
1303 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
1306 request.result = ar.exception == null;
1307 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001308 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001309 case CMD_GET_ALL_CELL_INFO:
1310 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001311 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001312 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001313 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001314 case EVENT_GET_ALL_CELL_INFO_DONE:
1315 ar = (AsyncResult) msg.obj;
1316 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001317 // If a timeout occurs, the response will be null
1318 request.result = (ar.exception == null && ar.result != null)
1319 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001320 synchronized (request) {
1321 request.notifyAll();
1322 }
1323 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001324 case CMD_REQUEST_CELL_INFO_UPDATE:
1325 request = (MainThreadRequest) msg.obj;
1326 request.phone.requestCellInfoUpdate(request.workSource,
1327 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1328 break;
1329 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
1332 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1333 try {
1334 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001335 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001336 cb.onError(
1337 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1338 ar.exception.getClass().getName(),
1339 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001340 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001341 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001342 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001343 } else {
1344 // use the result as returned
1345 cb.onCellInfo((List<CellInfo>) ar.result);
1346 }
1347 } catch (RemoteException re) {
1348 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1349 }
1350 break;
1351 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001352 request = (MainThreadRequest) msg.obj;
1353 WorkSource ws = (WorkSource) request.argument;
1354 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001355 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001356 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001357 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001358 ar = (AsyncResult) msg.obj;
1359 request = (MainThreadRequest) ar.userObj;
1360 if (ar.exception == null) {
1361 request.result = ar.result;
1362 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001363 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001364 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001365 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001366 }
1367
1368 synchronized (request) {
1369 request.notifyAll();
1370 }
1371 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001372 case CMD_MODEM_REBOOT:
1373 request = (MainThreadRequest) msg.obj;
1374 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001375 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001376 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001377 case EVENT_CMD_MODEM_REBOOT_DONE:
1378 handleNullReturnEvent(msg, "rebootModem");
1379 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001380 case CMD_REQUEST_ENABLE_MODEM:
1381 request = (MainThreadRequest) msg.obj;
1382 boolean enable = (boolean) request.argument;
1383 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001384 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001385 PhoneConfigurationManager.getInstance()
1386 .enablePhone(request.phone, enable, onCompleted);
1387 break;
1388 case EVENT_ENABLE_MODEM_DONE:
1389 ar = (AsyncResult) msg.obj;
1390 request = (MainThreadRequest) ar.userObj;
1391 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001392 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001393 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001394 if ((boolean) request.result) {
1395 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1396 updateModemStateMetrics();
1397 } else {
1398 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1399 + ar.exception);
1400 }
1401 notifyRequester(request);
1402 break;
1403 case CMD_GET_MODEM_STATUS:
1404 request = (MainThreadRequest) msg.obj;
1405 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1406 PhoneConfigurationManager.getInstance()
1407 .getPhoneStatusFromModem(request.phone, onCompleted);
1408 break;
1409 case EVENT_GET_MODEM_STATUS_DONE:
1410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
1412 int id = request.phone.getPhoneId();
1413 if (ar.exception == null && ar.result != null) {
1414 request.result = ar.result;
1415 //update the cache as modem status has changed
1416 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1417 (boolean) request.result);
1418 } else {
1419 // Return true if modem status cannot be retrieved. For most cases,
1420 // modem status is on. And for older version modems, GET_MODEM_STATUS
1421 // and disable modem are not supported. Modem is always on.
1422 // TODO: this should be fixed in R to support a third
1423 // status UNKNOWN b/131631629
1424 request.result = true;
1425 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1426 + ar.exception);
1427 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001428 notifyRequester(request);
1429 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001430 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1431 request = (MainThreadRequest) msg.obj;
1432 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1433 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1434 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1435 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1436 break;
1437 }
1438 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
1441 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1442 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1443 args.second.accept(ar.exception == null);
1444 notifyRequester(request);
1445 break;
1446 }
yincheng zhao2737e882019-09-06 17:06:54 -07001447 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null && ar.result != null) {
1451 request.result = ar.result;
1452 } else {
1453 request.result = -1;
1454 loge("Failed to set Forbidden Plmns");
1455 if (ar.result == null) {
1456 loge("setForbidenPlmns: Empty response");
1457 } else if (ar.exception != null) {
1458 loge("setForbiddenPlmns: Exception: " + ar.exception);
1459 request.result = -1;
1460 } else {
1461 loge("setForbiddenPlmns: Unknown exception");
1462 }
1463 }
1464 notifyRequester(request);
1465 break;
1466 case CMD_SET_FORBIDDEN_PLMNS:
1467 request = (MainThreadRequest) msg.obj;
1468 uiccCard = getUiccCardFromRequest(request);
1469 if (uiccCard == null) {
1470 loge("setForbiddenPlmns: UiccCard is null");
1471 request.result = -1;
1472 notifyRequester(request);
1473 break;
1474 }
1475 Pair<Integer, List<String>> setFplmnsArgs =
1476 (Pair<Integer, List<String>>) request.argument;
1477 appType = setFplmnsArgs.first;
1478 List<String> fplmns = setFplmnsArgs.second;
1479 uiccApp = uiccCard.getApplicationByType(appType);
1480 if (uiccApp == null) {
1481 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1482 request.result = -1;
1483 loge("Failed to get UICC App");
1484 notifyRequester(request);
1485 } else {
1486 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1487 ((SIMRecords) uiccApp.getIccRecords())
1488 .setForbiddenPlmns(onCompleted, fplmns);
1489 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001490 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001491 case CMD_ERASE_MODEM_CONFIG:
1492 request = (MainThreadRequest) msg.obj;
1493 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1494 defaultPhone.eraseModemConfig(onCompleted);
1495 break;
1496 case EVENT_ERASE_MODEM_CONFIG_DONE:
1497 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001498 break;
zoey chene02881a2019-12-30 16:11:23 +08001499
1500 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1501 request = (MainThreadRequest) msg.obj;
1502 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1503 Pair<String, String> changed = (Pair<String, String>) request.argument;
1504 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1505 changed.first, changed.second, onCompleted);
1506 break;
1507 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1508 ar = (AsyncResult) msg.obj;
1509 request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null) {
1511 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1512 } else {
1513 request.result = msg.arg1;
1514 }
1515 notifyRequester(request);
1516 break;
1517
1518 case CMD_SET_ICC_LOCK_ENABLED:
1519 request = (MainThreadRequest) msg.obj;
1520 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1521 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1522 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1523 enabled.first, enabled.second, onCompleted);
1524 break;
1525 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1526 ar = (AsyncResult) msg.obj;
1527 request = (MainThreadRequest) ar.userObj;
1528 if (ar.exception == null) {
1529 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1530 } else {
1531 request.result = msg.arg1;
1532 }
1533 notifyRequester(request);
1534 break;
1535
Peter Wangdafb9ac2020-01-15 14:13:38 -08001536 case MSG_NOTIFY_USER_ACTIVITY:
1537 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001538 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001539 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1540 getDefaultPhone().getContext().sendBroadcastAsUser(
1541 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1542 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 default:
1544 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1545 break;
1546 }
1547 }
Jake Hambye994d462014-02-03 13:10:13 -08001548
Pengquan Menga1bb6272018-09-06 09:59:22 -07001549 private void notifyRequester(MainThreadRequest request) {
1550 synchronized (request) {
1551 request.notifyAll();
1552 }
1553 }
1554
Jake Hambye994d462014-02-03 13:10:13 -08001555 private void handleNullReturnEvent(Message msg, String command) {
1556 AsyncResult ar = (AsyncResult) msg.obj;
1557 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1558 if (ar.exception == null) {
1559 request.result = true;
1560 } else {
1561 request.result = false;
1562 if (ar.exception instanceof CommandException) {
1563 loge(command + ": CommandException: " + ar.exception);
1564 } else {
1565 loge(command + ": Unknown exception");
1566 }
1567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001568 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
1571
1572 /**
1573 * Posts the specified command to be executed on the main thread,
1574 * waits for the request to complete, and returns the result.
1575 * @see #sendRequestAsync
1576 */
1577 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001578 return sendRequest(
1579 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001580 }
1581
1582 /**
1583 * Posts the specified command to be executed on the main thread,
1584 * waits for the request to complete, and returns the result.
1585 * @see #sendRequestAsync
1586 */
1587 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1588 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001589 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001590 }
1591
1592 /**
1593 * Posts the specified command to be executed on the main thread,
1594 * waits for the request to complete, and returns the result.
1595 * @see #sendRequestAsync
1596 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001597 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001598 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001599 }
1600
1601 /**
1602 * Posts the specified command to be executed on the main thread,
1603 * waits for the request to complete, and returns the result.
1604 * @see #sendRequestAsync
1605 */
Nathan Harold92bed182018-10-12 18:16:49 -07001606 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1607 return sendRequest(command, argument, subId, null, workSource);
1608 }
1609
1610 /**
1611 * Posts the specified command to be executed on the main thread,
1612 * waits for the request to complete, and returns the result.
1613 * @see #sendRequestAsync
1614 */
1615 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1616 return sendRequest(
1617 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1618 }
1619
1620 /**
1621 * Posts the specified command to be executed on the main thread,
1622 * waits for the request to complete, and returns the result.
1623 * @see #sendRequestAsync
1624 */
1625 private Object sendRequest(
1626 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1628 throw new RuntimeException("This method will deadlock if called from the main thread.");
1629 }
1630
Nathan Harold92bed182018-10-12 18:16:49 -07001631 MainThreadRequest request = null;
1632 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1633 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1634 } else if (phone != null) {
1635 request = new MainThreadRequest(argument, phone, workSource);
1636 } else {
1637 request = new MainThreadRequest(argument, subId, workSource);
1638 }
1639
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 Message msg = mMainThreadHandler.obtainMessage(command, request);
1641 msg.sendToTarget();
1642
1643 // Wait for the request to complete
1644 synchronized (request) {
1645 while (request.result == null) {
1646 try {
1647 request.wait();
1648 } catch (InterruptedException e) {
1649 // Do nothing, go back and wait until the request is complete
1650 }
1651 }
1652 }
1653 return request.result;
1654 }
1655
1656 /**
1657 * Asynchronous ("fire and forget") version of sendRequest():
1658 * Posts the specified command to be executed on the main thread, and
1659 * returns immediately.
1660 * @see #sendRequest
1661 */
1662 private void sendRequestAsync(int command) {
1663 mMainThreadHandler.sendEmptyMessage(command);
1664 }
1665
1666 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001667 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001668 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001669 */
1670 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001671 sendRequestAsync(command, argument, null, null);
1672 }
1673
1674 /**
1675 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1676 * @see {@link #sendRequest(int,Object)}
1677 */
1678 private void sendRequestAsync(
1679 int command, Object argument, Phone phone, WorkSource workSource) {
1680 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001681 Message msg = mMainThreadHandler.obtainMessage(command, request);
1682 msg.sendToTarget();
1683 }
1684
1685 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 * Initialize the singleton PhoneInterfaceManager instance.
1687 * This is only done once, at startup, from PhoneApp.onCreate().
1688 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001689 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 synchronized (PhoneInterfaceManager.class) {
1691 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001692 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 } else {
1694 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1695 }
1696 return sInstance;
1697 }
1698 }
1699
1700 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001701 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001704 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001705 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1707 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001708 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001709 mTelephonySharedPreferences =
1710 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001711 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001712 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001713 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001714
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 publish();
1716 }
1717
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001718 private Phone getDefaultPhone() {
1719 Phone thePhone = getPhone(getDefaultSubscription());
1720 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1721 }
1722
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 private void publish() {
1724 if (DBG) log("publish: " + this);
1725
Peter Wangc035ce42020-01-08 21:00:22 -08001726 TelephonyFrameworkInitializer
1727 .getTelephonyServiceManager()
1728 .getTelephonyServiceRegisterer()
1729 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 }
1731
Stuart Scott584921c2015-01-15 17:10:34 -08001732 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001733 if (request.phone != null) {
1734 return request.phone;
1735 } else {
1736 return getPhoneFromSubId(request.subId);
1737 }
1738 }
1739
1740 private Phone getPhoneFromSubId(int subId) {
1741 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1742 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001743 }
1744
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001745 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1746 Phone phone = getPhoneFromRequest(request);
1747 return phone == null ? null :
1748 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1749 }
1750
Wink Saville36469e72014-06-11 15:17:00 -07001751 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001752 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001753 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755
Naina Nallurid63128d2019-09-17 14:10:30 -07001756 private void sendEraseModemConfig(Phone phone) {
1757 if (phone != null) {
1758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1759 mApp, phone.getSubId(), "eraseModemConfig");
1760 final long identity = Binder.clearCallingIdentity();
1761 try {
1762 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1763 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1764 } finally {
1765 Binder.restoreCallingIdentity(identity);
1766 }
1767 }
1768 }
1769
Peter Wang44b186e2020-01-13 23:33:09 -08001770 private boolean isImsAvailableOnDevice() {
1771 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1772 if (pm == null) {
1773 // For some reason package manger is not available.. This will fail internally anyway,
1774 // so do not throw error and allow.
1775 return true;
1776 }
1777 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1778 }
1779
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001781 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001782 }
1783
Wink Savilleb564aae2014-10-23 10:18:09 -07001784 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 if (DBG) log("dial: " + number);
1786 // No permission check needed here: This is just a wrapper around the
1787 // ACTION_DIAL intent, which is available to any app since it puts up
1788 // the UI before it does anything.
1789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001790 final long identity = Binder.clearCallingIdentity();
1791 try {
1792 String url = createTelUrl(number);
1793 if (url == null) {
1794 return;
1795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 // PENDING: should we just silently fail if phone is offhook or ringing?
1798 PhoneConstants.State state = mCM.getState(subId);
1799 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1800 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1801 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1802 mApp.startActivity(intent);
1803 }
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 }
1807 }
1808
1809 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001810 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001811 }
1812
Wink Savilleb564aae2014-10-23 10:18:09 -07001813 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 if (DBG) log("call: " + number);
1815
1816 // This is just a wrapper around the ACTION_CALL intent, but we still
1817 // need to do a permission check since we're calling startActivity()
1818 // from the context of the phone app.
1819 enforceCallPermission();
1820
Jordan Liu1617b712019-07-10 15:06:26 -07001821 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 != AppOpsManager.MODE_ALLOWED) {
1823 return;
1824 }
1825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001826 final long identity = Binder.clearCallingIdentity();
1827 try {
1828 String url = createTelUrl(number);
1829 if (url == null) {
1830 return;
1831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833 boolean isValid = false;
1834 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1835 if (slist != null) {
1836 for (SubscriptionInfo subInfoRecord : slist) {
1837 if (subInfoRecord.getSubscriptionId() == subId) {
1838 isValid = true;
1839 break;
1840 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001841 }
Wink Saville08874612014-08-31 19:19:58 -07001842 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001843 if (!isValid) {
1844 return;
1845 }
Wink Saville08874612014-08-31 19:19:58 -07001846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1848 intent.putExtra(SUBSCRIPTION_KEY, subId);
1849 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1850 mApp.startActivity(intent);
1851 } finally {
1852 Binder.restoreCallingIdentity(identity);
1853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 }
1855
Wink Savilleb564aae2014-10-23 10:18:09 -07001856 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001857 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001858 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1859 }
1860
Wink Savilleb564aae2014-10-23 10:18:09 -07001861 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001862 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001863 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1864 }
1865
Wink Savilleb564aae2014-10-23 10:18:09 -07001866 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001868
1869 final long identity = Binder.clearCallingIdentity();
1870 try {
1871 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1872 checkSimPin.start();
1873 return checkSimPin.unlockSim(null, pin);
1874 } finally {
1875 Binder.restoreCallingIdentity(identity);
1876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 }
1878
Wink Savilleb564aae2014-10-23 10:18:09 -07001879 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001881
1882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1885 checkSimPuk.start();
1886 return checkSimPuk.unlockSim(puk, pin);
1887 } finally {
1888 Binder.restoreCallingIdentity(identity);
1889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
1892 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001893 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 * a synchronous one.
1895 */
1896 private static class UnlockSim extends Thread {
1897
1898 private final IccCard mSimCard;
1899
1900 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001901 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1902 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903
1904 // For replies from SimCard interface
1905 private Handler mHandler;
1906
1907 // For async handler to identify request type
1908 private static final int SUPPLY_PIN_COMPLETE = 100;
1909
1910 public UnlockSim(IccCard simCard) {
1911 mSimCard = simCard;
1912 }
1913
1914 @Override
1915 public void run() {
1916 Looper.prepare();
1917 synchronized (UnlockSim.this) {
1918 mHandler = new Handler() {
1919 @Override
1920 public void handleMessage(Message msg) {
1921 AsyncResult ar = (AsyncResult) msg.obj;
1922 switch (msg.what) {
1923 case SUPPLY_PIN_COMPLETE:
1924 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1925 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001926 mRetryCount = msg.arg1;
1927 if (ar.exception != null) {
1928 if (ar.exception instanceof CommandException &&
1929 ((CommandException)(ar.exception)).getCommandError()
1930 == CommandException.Error.PASSWORD_INCORRECT) {
1931 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001932 } //When UiccCardApp dispose,handle message and return exception
1933 else if (ar.exception instanceof CommandException &&
1934 ((CommandException) (ar.exception)).getCommandError()
1935 == CommandException.Error.ABORTED) {
1936 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001937 } else {
1938 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1939 }
1940 } else {
1941 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 mDone = true;
1944 UnlockSim.this.notifyAll();
1945 }
1946 break;
1947 }
1948 }
1949 };
1950 UnlockSim.this.notifyAll();
1951 }
1952 Looper.loop();
1953 }
1954
1955 /*
1956 * Use PIN or PUK to unlock SIM card
1957 *
1958 * If PUK is null, unlock SIM card with PIN
1959 *
1960 * If PUK is not null, unlock SIM card with PUK and set PIN code
1961 */
Wink Saville9de0f752013-10-22 19:04:03 -07001962 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963
1964 while (mHandler == null) {
1965 try {
1966 wait();
1967 } catch (InterruptedException e) {
1968 Thread.currentThread().interrupt();
1969 }
1970 }
1971 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1972
1973 if (puk == null) {
1974 mSimCard.supplyPin(pin, callback);
1975 } else {
1976 mSimCard.supplyPuk(puk, pin, callback);
1977 }
1978
1979 while (!mDone) {
1980 try {
1981 Log.d(LOG_TAG, "wait for done");
1982 wait();
1983 } catch (InterruptedException e) {
1984 // Restore the interrupted status
1985 Thread.currentThread().interrupt();
1986 }
1987 }
1988 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001989 int[] resultArray = new int[2];
1990 resultArray[0] = mResult;
1991 resultArray[1] = mRetryCount;
1992 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 }
1994 }
1995
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001996 /**
1997 * This method has been removed due to privacy and stability concerns.
1998 */
1999 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002001 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2002 return;
Wink Saville36469e72014-06-11 15:17:00 -07002003 }
2004
Nathan Harold1f889d82020-06-04 17:05:26 -07002005 @Override
2006 public void updateServiceLocationWithPackageName(String callingPackage) {
2007 mApp.getSystemService(AppOpsManager.class)
2008 .checkPackage(Binder.getCallingUid(), callingPackage);
2009
2010 final int targetSdk = getTargetSdk(callingPackage);
2011 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2012 // Callers targeting S have no business invoking this method.
2013 return;
2014 }
2015
2016 LocationAccessPolicy.LocationPermissionResult locationResult =
2017 LocationAccessPolicy.checkLocationPermission(mApp,
2018 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2019 .setCallingPackage(callingPackage)
2020 .setCallingFeatureId(null)
2021 .setCallingPid(Binder.getCallingPid())
2022 .setCallingUid(Binder.getCallingUid())
2023 .setMethod("updateServiceLocation")
2024 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2025 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2026 .build());
2027 // Apps that lack location permission have no business calling this method;
2028 // however, because no permission was declared in the public API, denials must
2029 // all be "soft".
2030 switch (locationResult) {
2031 case DENIED_HARD: /* fall through */
2032 case DENIED_SOFT:
2033 return;
2034 }
2035
2036 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002037 final long identity = Binder.clearCallingIdentity();
2038 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002039 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002041 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 }
2043 } finally {
2044 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002045 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 }
2047
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002048 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002049 @Override
2050 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002051 return isRadioOnWithFeature(callingPackage, null);
2052 }
2053
2054
2055 @Override
2056 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2057 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2058 callingFeatureId);
2059 }
2060
2061 @Deprecated
2062 @Override
2063 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2064 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002065 }
2066
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002067 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002068 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2069 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002071 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002072 return false;
2073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074
2075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 return isRadioOnForSubscriber(subId);
2078 } finally {
2079 Binder.restoreCallingIdentity(identity);
2080 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002081 }
2082
2083 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002084 final long identity = Binder.clearCallingIdentity();
2085 try {
2086 final Phone phone = getPhone(subId);
2087 if (phone != null) {
2088 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2089 } else {
2090 return false;
2091 }
2092 } finally {
2093 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 }
2096
2097 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002098 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 }
Wink Saville36469e72014-06-11 15:17:00 -07002100
Wink Savilleb564aae2014-10-23 10:18:09 -07002101 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103
2104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 final Phone phone = getPhone(subId);
2107 if (phone != null) {
2108 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2109 }
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002112 }
Wink Saville36469e72014-06-11 15:17:00 -07002113 }
2114
2115 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002116 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002117 }
2118
Wink Savilleb564aae2014-10-23 10:18:09 -07002119 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002120 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002121
2122 final long identity = Binder.clearCallingIdentity();
2123 try {
2124 final Phone phone = getPhone(subId);
2125 if (phone == null) {
2126 return false;
2127 }
2128 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2129 toggleRadioOnOffForSubscriber(subId);
2130 }
2131 return true;
2132 } finally {
2133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 }
Wink Saville36469e72014-06-11 15:17:00 -07002136
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002137 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002138 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002139 /*
2140 * If any of the Radios are available, it will need to be
2141 * shutdown. So return true if any Radio is available.
2142 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002143 final long identity = Binder.clearCallingIdentity();
2144 try {
2145 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2146 Phone phone = PhoneFactory.getPhone(i);
2147 if (phone != null && phone.isRadioAvailable()) return true;
2148 }
2149 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2150 return false;
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002153 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002154 }
2155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002157 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002158 enforceModifyPermission();
2159
2160 final long identity = Binder.clearCallingIdentity();
2161 try {
2162 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2163 logv("Shutting down Phone " + i);
2164 shutdownRadioUsingPhoneId(i);
2165 }
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002168 }
2169 }
2170
2171 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002172 Phone phone = PhoneFactory.getPhone(phoneId);
2173 if (phone != null && phone.isRadioAvailable()) {
2174 phone.shutdownRadio();
2175 }
2176 }
2177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002179 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002180
2181 final long identity = Binder.clearCallingIdentity();
2182 try {
2183 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2184 if (defaultPhone != null) {
2185 defaultPhone.setRadioPower(turnOn);
2186 return true;
2187 } else {
2188 loge("There's no default phone.");
2189 return false;
2190 }
2191 } finally {
2192 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002193 }
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
Wink Savilleb564aae2014-10-23 10:18:09 -07002196 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002198
2199 final long identity = Binder.clearCallingIdentity();
2200 try {
2201 final Phone phone = getPhone(subId);
2202 if (phone != null) {
2203 phone.setRadioPower(turnOn);
2204 return true;
2205 } else {
2206 return false;
2207 }
2208 } finally {
2209 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 }
2212
Wink Saville36469e72014-06-11 15:17:00 -07002213 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 public boolean enableDataConnectivity() {
2216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002217
2218 final long identity = Binder.clearCallingIdentity();
2219 try {
2220 int subId = mSubscriptionController.getDefaultDataSubId();
2221 final Phone phone = getPhone(subId);
2222 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002223 phone.getDataEnabledSettings().setDataEnabled(
2224 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002225 return true;
2226 } else {
2227 return false;
2228 }
2229 } finally {
2230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 }
2233
Wink Saville36469e72014-06-11 15:17:00 -07002234 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002235 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 public boolean disableDataConnectivity() {
2237 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238
2239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 int subId = mSubscriptionController.getDefaultDataSubId();
2242 final Phone phone = getPhone(subId);
2243 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002244 phone.getDataEnabledSettings().setDataEnabled(
2245 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002246 return true;
2247 } else {
2248 return false;
2249 }
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
Sanket Padawe356d7632015-06-22 14:03:32 -07002255 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002256 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 final Phone phone = getPhone(subId);
2260 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002261 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262 } else {
2263 return false;
2264 }
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269
2270 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002271 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002272 }
2273
pkanwarae03a6b2016-11-06 20:37:09 -08002274 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275 enforceCallPermission();
2276
2277 final long identity = Binder.clearCallingIdentity();
2278 try {
2279 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2280 return;
2281 }
2282 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2283 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2284 } finally {
2285 Binder.restoreCallingIdentity(identity);
2286 }
pkanwar32d516d2016-10-14 19:37:38 -07002287 };
2288
Wink Savilleb564aae2014-10-23 10:18:09 -07002289 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002291
2292 final long identity = Binder.clearCallingIdentity();
2293 try {
2294 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2295 return false;
2296 }
2297 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002304 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002305 }
2306
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002307 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002308 final long identity = Binder.clearCallingIdentity();
2309 try {
2310 Phone phone = PhoneFactory.getPhone(slotIndex);
2311 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2312 PhoneConstantConversions.convertCallState(phone.getState());
2313 } finally {
2314 Binder.restoreCallingIdentity(identity);
2315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 }
2317
Sanket Padawe356d7632015-06-22 14:03:32 -07002318 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002319 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002320 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2321 }
2322
2323 @Override
2324 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325 final long identity = Binder.clearCallingIdentity();
2326 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002327 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002328 if (phone != null) {
2329 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2330 } else {
2331 return PhoneConstantConversions.convertDataState(
2332 PhoneConstants.DataState.DISCONNECTED);
2333 }
2334 } finally {
2335 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 }
2338
Sanket Padawe356d7632015-06-22 14:03:32 -07002339 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002340 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002341 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2342 }
2343
2344 @Override
2345 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346 final long identity = Binder.clearCallingIdentity();
2347 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002348 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002349 if (phone != null) {
2350 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2351 } else {
2352 return TelephonyManager.DATA_ACTIVITY_NONE;
2353 }
2354 } finally {
2355 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 }
2358
2359 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002360 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002361 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002362 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002363
2364 LocationAccessPolicy.LocationPermissionResult locationResult =
2365 LocationAccessPolicy.checkLocationPermission(mApp,
2366 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2367 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002368 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002369 .setCallingPid(Binder.getCallingPid())
2370 .setCallingUid(Binder.getCallingUid())
2371 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002372 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002373 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2374 .build());
2375 switch (locationResult) {
2376 case DENIED_HARD:
2377 throw new SecurityException("Not allowed to access cell location");
2378 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002379 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2380 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 }
2382
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002383 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002387 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002388 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002389 } finally {
2390 Binder.restoreCallingIdentity(identity);
2391 }
Svetoslav64fad262015-04-14 14:35:21 -07002392 }
2393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002395 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002396 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2397 // registered cell info, so return a NULL country instead.
2398 final long identity = Binder.clearCallingIdentity();
2399 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002400 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2401 // Get default phone in this case.
2402 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2403 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002404 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002405 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002406 if (phone == null) return "";
2407 ServiceStateTracker sst = phone.getServiceStateTracker();
2408 if (sst == null) return "";
2409 LocaleTracker lt = sst.getLocaleTracker();
2410 if (lt == null) return "";
2411 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2412 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2413 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002414 } finally {
2415 Binder.restoreCallingIdentity(identity);
2416 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002417 }
2418
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002419 /**
2420 * This method was removed due to potential issues caused by performing partial
2421 * updates of service state, and lack of a credible use case.
2422 *
2423 * This has the ability to break the telephony implementation by disabling notification of
2424 * changes in device connectivity. DO NOT USE THIS!
2425 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002426 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 public void enableLocationUpdates() {
2428 mApp.enforceCallingOrSelfPermission(
2429 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 }
2431
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002432 /**
2433 * This method was removed due to potential issues caused by performing partial
2434 * updates of service state, and lack of a credible use case.
2435 *
2436 * This has the ability to break the telephony implementation by disabling notification of
2437 * changes in device connectivity. DO NOT USE THIS!
2438 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 @Override
2440 public void disableLocationUpdates() {
2441 mApp.enforceCallingOrSelfPermission(
2442 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444
Nathan Harold31d7ff32018-10-15 20:20:30 -07002445 /**
2446 * Returns the target SDK version number for a given package name.
2447 *
Nathan Haroldec184742019-07-10 17:04:16 -07002448 * This call MUST be invoked before clearing the calling UID.
2449 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002450 * @return target SDK if the package is found or INT_MAX.
2451 */
2452 private int getTargetSdk(String packageName) {
2453 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002454 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002455 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002456 if (ai != null) return ai.targetSdkVersion;
2457 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002458 loge("Failed to get package info for pkg="
2459 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002460 }
2461 return Integer.MAX_VALUE;
2462 }
2463
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 @Override
2465 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002466 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2467 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002468 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002469 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2470 throw new SecurityException(
2471 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2472 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002473
Jordan Liu1617b712019-07-10 15:06:26 -07002474 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2476 return null;
2477 }
Svetoslav64fad262015-04-14 14:35:21 -07002478
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002479 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002481 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002482 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483
Nathan Haroldf180aac2018-06-01 18:43:55 -07002484 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2485 for (CellInfo ci : info) {
2486 if (ci instanceof CellInfoGsm) {
2487 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2488 } else if (ci instanceof CellInfoWcdma) {
2489 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002492 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 }
2494
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002495 private List<CellInfo> getCachedCellInfo() {
2496 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2497 for (Phone phone : PhoneFactory.getPhones()) {
2498 List<CellInfo> info = phone.getAllCellInfo();
2499 if (info != null) cellInfos.addAll(info);
2500 }
2501 return cellInfos;
2502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503
2504 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002505 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002506 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002507 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002508
2509 LocationAccessPolicy.LocationPermissionResult locationResult =
2510 LocationAccessPolicy.checkLocationPermission(mApp,
2511 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2512 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002513 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002514 .setCallingPid(Binder.getCallingPid())
2515 .setCallingUid(Binder.getCallingUid())
2516 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002517 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002518 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2519 .build());
2520 switch (locationResult) {
2521 case DENIED_HARD:
2522 throw new SecurityException("Not allowed to access cell info");
2523 case DENIED_SOFT:
2524 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 }
2526
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002527 final int targetSdk = getTargetSdk(callingPackage);
2528 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2529 return getCachedCellInfo();
2530 }
2531
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002532 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002533 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534 final long identity = Binder.clearCallingIdentity();
2535 try {
2536 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2537 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002538 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002539 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540 if (info != null) cellInfos.addAll(info);
2541 }
2542 return cellInfos;
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002545 }
2546 }
2547
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002548 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002549 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2550 String callingFeatureId) {
2551 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2552 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002553 }
2554
2555 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002556 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2557 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002558 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002559 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002560 }
2561
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002562 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2563 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002564 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002565 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002566
2567 LocationAccessPolicy.LocationPermissionResult locationResult =
2568 LocationAccessPolicy.checkLocationPermission(mApp,
2569 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2570 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002571 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002572 .setCallingPid(Binder.getCallingPid())
2573 .setCallingUid(Binder.getCallingUid())
2574 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002575 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2576 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002577 .build());
2578 switch (locationResult) {
2579 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002580 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2581 // Safetynet logging for b/154934934
2582 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2583 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002584 throw new SecurityException("Not allowed to access cell info");
2585 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002586 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2587 // Safetynet logging for b/154934934
2588 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2589 }
Nathan Harold5320c422019-05-09 10:26:08 -07002590 try {
2591 cb.onCellInfo(new ArrayList<CellInfo>());
2592 } catch (RemoteException re) {
2593 // Drop without consequences
2594 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002595 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002596 }
2597
Nathan Harolda939a962019-05-09 10:13:47 -07002598
2599 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002600 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2601
2602 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2603 }
2604
2605 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002607 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002608 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609
2610 final long identity = Binder.clearCallingIdentity();
2611 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002612 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 } finally {
2614 Binder.restoreCallingIdentity(identity);
2615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 }
2617
Shishir Agrawala9f32182016-04-12 12:00:16 -07002618 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002619 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002620 Phone phone = PhoneFactory.getPhone(slotIndex);
2621 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002622 return null;
2623 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002624 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002625 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002626 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002627 return null;
2628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629
2630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 return phone.getImei();
2633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002636 }
2637
2638 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002639 public String getTypeAllocationCodeForSlot(int slotIndex) {
2640 Phone phone = PhoneFactory.getPhone(slotIndex);
2641 String tac = null;
2642 if (phone != null) {
2643 String imei = phone.getImei();
2644 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2645 }
2646 return tac;
2647 }
2648
2649 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002650 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002651 Phone phone = PhoneFactory.getPhone(slotIndex);
2652 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002653 return null;
2654 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002655
Jeff Davidson913390f2018-02-23 17:11:49 -08002656 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002657 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002658 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002659 return null;
2660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661
2662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 return phone.getMeid();
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
2667 }
Jack Yu2af8d712017-03-15 17:14:14 -07002668 }
2669
2670 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002671 public String getManufacturerCodeForSlot(int slotIndex) {
2672 Phone phone = PhoneFactory.getPhone(slotIndex);
2673 String manufacturerCode = null;
2674 if (phone != null) {
2675 String meid = phone.getMeid();
2676 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2677 }
2678 return manufacturerCode;
2679 }
2680
2681 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002682 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2683 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002684 Phone phone = PhoneFactory.getPhone(slotIndex);
2685 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002686 return null;
2687 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002688 int subId = phone.getSubId();
2689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002690 mApp, subId, callingPackage, callingFeatureId,
2691 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002692 return null;
2693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694
2695 final long identity = Binder.clearCallingIdentity();
2696 try {
2697 return phone.getDeviceSvn();
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
2700 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002701 }
2702
fionaxu43304da2017-11-27 22:51:16 -08002703 @Override
2704 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 final Phone phone = getPhone(subId);
2708 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2709 } finally {
2710 Binder.restoreCallingIdentity(identity);
2711 }
fionaxu43304da2017-11-27 22:51:16 -08002712 }
2713
2714 @Override
2715 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 final Phone phone = getPhone(subId);
2719 return phone == null ? null : phone.getCarrierName();
2720 } finally {
2721 Binder.restoreCallingIdentity(identity);
2722 }
fionaxu43304da2017-11-27 22:51:16 -08002723 }
2724
calvinpanffe225e2018-11-01 19:43:06 +08002725 @Override
chen xu0026ca62019-03-06 15:28:50 -08002726 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 final Phone phone = getPhone(subId);
2730 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002731 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002732 } finally {
2733 Binder.restoreCallingIdentity(identity);
2734 }
2735 }
2736
2737 @Override
chen xu0026ca62019-03-06 15:28:50 -08002738 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002742 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002743 } finally {
2744 Binder.restoreCallingIdentity(identity);
2745 }
2746 }
2747
chen xu651eec72018-11-11 19:03:44 -08002748 @Override
chen xu864e11c2018-12-06 22:10:03 -08002749 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2750 if (!isSubscriptionMccMnc) {
2751 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2752 }
chen xu651eec72018-11-11 19:03:44 -08002753 final Phone phone = PhoneFactory.getPhone(slotIndex);
2754 if (phone == null) {
2755 return TelephonyManager.UNKNOWN_CARRIER_ID;
2756 }
2757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2760 } finally {
2761 Binder.restoreCallingIdentity(identity);
2762 }
2763 }
2764
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 //
2766 // Internal helper methods.
2767 //
2768
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002769 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2771 *
2772 * @throws SecurityException if the caller does not have the required permission
2773 */
2774 private void enforceModifyPermission() {
2775 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2776 }
2777
Shuo Qiancd19c462020-01-16 20:51:11 -08002778 /**
2779 * Make sure the caller is system.
2780 *
2781 * @throws SecurityException if the caller is not system.
2782 */
2783 private void enforceSystemCaller() {
2784 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2785 throw new SecurityException("Caller must be system");
2786 }
2787 }
2788
Shuo Qian3b6ee772019-11-13 17:43:31 -08002789 private void enforceActiveEmergencySessionPermission() {
2790 mApp.enforceCallingOrSelfPermission(
2791 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2792 }
2793
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 /**
2795 * Make sure the caller has the CALL_PHONE permission.
2796 *
2797 * @throws SecurityException if the caller does not have the required permission
2798 */
2799 private void enforceCallPermission() {
2800 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2801 }
2802
paulhu5a773602019-08-23 19:17:33 +08002803 private void enforceSettingsPermission() {
2804 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002805 }
2806
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002807 private String createTelUrl(String number) {
2808 if (TextUtils.isEmpty(number)) {
2809 return null;
2810 }
2811
Jake Hambye994d462014-02-03 13:10:13 -08002812 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 }
2814
Ihab Awadf9e92732013-12-05 18:02:52 -08002815 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2817 }
2818
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002819 private static void logv(String msg) {
2820 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2821 }
2822
Ihab Awadf9e92732013-12-05 18:02:52 -08002823 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2825 }
2826
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002827 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002829 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002830 }
2831
Sanket Padawe356d7632015-06-22 14:03:32 -07002832 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002833 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002834 final long identity = Binder.clearCallingIdentity();
2835 try {
2836 final Phone phone = PhoneFactory.getPhone(slotIndex);
2837 if (phone == null) {
2838 return PhoneConstants.PHONE_TYPE_NONE;
2839 } else {
2840 return phone.getPhoneType();
2841 }
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 }
2846
2847 /**
2848 * Returns the CDMA ERI icon index to display
2849 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002850 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002851 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2852 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2853 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002854 }
2855
Sanket Padawe356d7632015-06-22 14:03:32 -07002856 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002857 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2858 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002859 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002860 mApp, subId, callingPackage, callingFeatureId,
2861 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002862 return -1;
2863 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864
2865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 final Phone phone = getPhone(subId);
2868 if (phone != null) {
2869 return phone.getCdmaEriIconIndex();
2870 } else {
2871 return -1;
2872 }
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 }
2877
2878 /**
2879 * Returns the CDMA ERI icon mode,
2880 * 0 - ON
2881 * 1 - FLASHING
2882 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002883 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002884 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2885 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2886 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002887 }
2888
Sanket Padawe356d7632015-06-22 14:03:32 -07002889 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002890 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2891 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002893 mApp, subId, callingPackage, callingFeatureId,
2894 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002895 return -1;
2896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897
2898 final long identity = Binder.clearCallingIdentity();
2899 try {
2900 final Phone phone = getPhone(subId);
2901 if (phone != null) {
2902 return phone.getCdmaEriIconMode();
2903 } else {
2904 return -1;
2905 }
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002909 }
2910
2911 /**
2912 * Returns the CDMA ERI text,
2913 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002914 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002915 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2916 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2917 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002918 }
2919
Sanket Padawe356d7632015-06-22 14:03:32 -07002920 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002921 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2922 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002924 mApp, subId, callingPackage, callingFeatureId,
2925 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002926 return null;
2927 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002928
2929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 final Phone phone = getPhone(subId);
2932 if (phone != null) {
2933 return phone.getCdmaEriText();
2934 } else {
2935 return null;
2936 }
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 }
2941
2942 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002943 * Returns the CDMA MDN.
2944 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002945 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002946 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2948 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949
2950 final long identity = Binder.clearCallingIdentity();
2951 try {
2952 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002953 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 return phone.getLine1Number();
2955 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002956 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957 return null;
2958 }
2959 } finally {
2960 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002961 }
2962 }
2963
2964 /**
2965 * Returns the CDMA MIN.
2966 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002968 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2970 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 final Phone phone = getPhone(subId);
2975 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2976 return phone.getCdmaMin();
2977 } else {
2978 return null;
2979 }
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002982 }
2983 }
2984
Hall Liud892bec2018-11-30 14:51:45 -08002985 @Override
2986 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2987 INumberVerificationCallback callback, String callingPackage) {
2988 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2989 != PERMISSION_GRANTED) {
2990 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2991 }
2992 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2993
2994 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2995 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2996 throw new SecurityException("Calling package must be configured in the device config");
2997 }
2998
2999 if (range == null) {
3000 throw new NullPointerException("Range must be non-null");
3001 }
3002
3003 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003004 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003005
3006 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3007 }
3008
Junda Liuca05d5d2014-08-14 22:36:34 -07003009 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 * Returns true if CDMA provisioning needs to run.
3011 */
3012 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 final long identity = Binder.clearCallingIdentity();
3014 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003015 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 }
3020
3021 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003022 * Sets the voice mail number of a given subId.
3023 */
3024 @Override
3025 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003026 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3027 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003028
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3032 new Pair<String, String>(alphaTag, number), new Integer(subId));
3033 return success;
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003037 }
3038
Ta-wei Yen87c49842016-05-13 21:19:52 -07003039 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003040 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003042 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3043 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003044 if (!TextUtils.equals(callingPackage, systemDialer)) {
3045 throw new SecurityException("caller must be system dialer");
3046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047
3048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3051 if (phoneAccountHandle == null) {
3052 return null;
3053 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003054 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055 } finally {
3056 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003057 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003058 }
3059
3060 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003061 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3062 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003065 mApp, subId, callingPackage, callingFeatureId,
3066 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003067 return null;
3068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003070 final long identity = Binder.clearCallingIdentity();
3071 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003072 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003076 }
3077
3078 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003079 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3080 VisualVoicemailSmsFilterSettings settings) {
3081 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003086 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003090 }
3091
3092 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003093 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3094 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003095
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003099 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003100 } finally {
3101 Binder.restoreCallingIdentity(identity);
3102 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003103 }
3104
3105 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003106 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3107 String callingPackage, int subId) {
3108 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003113 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003117 }
3118
3119 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003120 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003121 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003122
3123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003126 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003130 }
3131
3132 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003133 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3134 String callingAttributionTag, int subId, String number, int port, String text,
3135 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003136 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003137 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003138 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003139 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003140 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3141 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003142 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003143
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003144 /**
fionaxu0152e512016-11-14 13:36:14 -08003145 * Sets the voice activation state of a given subId.
3146 */
3147 @Override
3148 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3150 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151
3152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 final Phone phone = getPhone(subId);
3155 if (phone != null) {
3156 phone.setVoiceActivationState(activationState);
3157 } else {
3158 loge("setVoiceActivationState fails with invalid subId: " + subId);
3159 }
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003162 }
3163 }
3164
3165 /**
3166 * Sets the data activation state of a given subId.
3167 */
3168 @Override
3169 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3171 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172
3173 final long identity = Binder.clearCallingIdentity();
3174 try {
3175 final Phone phone = getPhone(subId);
3176 if (phone != null) {
3177 phone.setDataActivationState(activationState);
3178 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003179 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003180 }
3181 } finally {
3182 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003183 }
3184 }
3185
3186 /**
3187 * Returns the voice activation state of a given subId.
3188 */
3189 @Override
3190 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003191 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192
fionaxu0152e512016-11-14 13:36:14 -08003193 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 if (phone != null) {
3197 return phone.getVoiceActivationState();
3198 } else {
3199 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3200 }
3201 } finally {
3202 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003203 }
3204 }
3205
3206 /**
3207 * Returns the data activation state of a given subId.
3208 */
3209 @Override
3210 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003211 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212
fionaxu0152e512016-11-14 13:36:14 -08003213 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 if (phone != null) {
3217 return phone.getDataActivationState();
3218 } else {
3219 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3220 }
3221 } finally {
3222 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003223 }
3224 }
3225
3226 /**
Wink Saville36469e72014-06-11 15:17:00 -07003227 * Returns the unread count of voicemails for a subId
3228 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003230 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3231 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003232 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003233 mApp, subId, callingPackage, callingFeatureId,
3234 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003235 return 0;
3236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 final Phone phone = getPhone(subId);
3240 if (phone != null) {
3241 return phone.getVoiceMessageCount();
3242 } else {
3243 return 0;
3244 }
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 }
3249
3250 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003251 * returns true, if the device is in a state where both voice and data
3252 * are supported simultaneously. This can change based on location or network condition.
3253 */
3254 @Override
3255 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 final Phone phone = getPhone(subId);
3259 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3260 } finally {
3261 Binder.restoreCallingIdentity(identity);
3262 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003263 }
3264
3265 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003266 * Send the dialer code if called from the current default dialer or the caller has
3267 * carrier privilege.
3268 * @param inputCode The dialer code to send
3269 */
3270 @Override
3271 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003272 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003273 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003274 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3275 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003276 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003277 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003278 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
3281 final long identity = Binder.clearCallingIdentity();
3282 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003283 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284 } finally {
3285 Binder.restoreCallingIdentity(identity);
3286 }
fionaxu235cc5e2017-03-06 22:25:57 -08003287 }
3288
Pengquan Menga1bb6272018-09-06 09:59:22 -07003289 @Override
3290 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003291 TelephonyPermissions
3292 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3293 mApp, subId, "getNetworkSelectionMode");
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 if (!isActiveSubscription(subId)) {
3297 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3298 }
3299 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3300 } finally {
3301 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003302 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003303 }
3304
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003306 public boolean isInEmergencySmsMode() {
3307 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3308 final long identity = Binder.clearCallingIdentity();
3309 try {
3310 for (Phone phone : PhoneFactory.getPhones()) {
3311 if (phone.isInEmergencySmsMode()) {
3312 return true;
3313 }
3314 }
3315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
3318 return false;
3319 }
3320
shilu366312e2019-12-17 09:28:10 -08003321 /**
3322 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3323 * @param subId The subscription to use to check the configuration.
3324 * @param c The callback that will be used to send the result.
3325 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003326 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003327 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3328 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003329 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3330 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003331
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003332 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3333 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3334 "IMS not available on device.");
3335 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003336 final long token = Binder.clearCallingIdentity();
3337 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003338 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003339 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003340 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003341 } catch (ImsException e) {
3342 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003343 } finally {
3344 Binder.restoreCallingIdentity(token);
3345 }
3346 }
3347
shilu366312e2019-12-17 09:28:10 -08003348 /**
3349 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3350 * @param subId The subscription to use to check the configuration.
3351 * @param c The callback that will be used to send the result.
3352 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003354 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003355 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3356 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003357 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3358 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3359 }
Meng Wangafbc5852019-09-19 17:37:13 -07003360 final long token = Binder.clearCallingIdentity();
3361 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003362 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003363 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3364 .removeRegistrationCallbackForSubscription(c, subId);
3365 } catch (ImsException e) {
3366 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3367 + "is inactive, ignoring unregister.");
3368 // If the subscription is no longer active, just return, since the callback
3369 // will already have been removed internally.
3370 } finally {
3371 Binder.restoreCallingIdentity(token);
3372 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003373 }
3374
Brad Ebingera34a6c22019-10-22 17:36:18 -07003375 /**
3376 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3377 */
3378 @Override
3379 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3380 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3381 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3382 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3383 "IMS not available on device.");
3384 }
3385 final long token = Binder.clearCallingIdentity();
3386 try {
3387 Phone phone = getPhone(subId);
3388 if (phone == null) {
3389 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3390 + subId + "'");
3391 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3392 }
3393 phone.getImsRegistrationState(regState -> {
3394 try {
3395 consumer.accept((regState == null)
3396 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3397 } catch (RemoteException e) {
3398 // Ignore if the remote process is no longer available to call back.
3399 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3400 }
3401 });
3402 } finally {
3403 Binder.restoreCallingIdentity(token);
3404 }
3405 }
3406
3407 /**
3408 * Get the transport type for the IMS service registration state.
3409 */
3410 @Override
3411 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003412 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3413 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003414 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3415 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3416 "IMS not available on device.");
3417 }
3418 final long token = Binder.clearCallingIdentity();
3419 try {
3420 Phone phone = getPhone(subId);
3421 if (phone == null) {
3422 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3423 + subId + "'");
3424 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3425 }
3426 phone.getImsRegistrationTech(regTech -> {
3427 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3428 int regTechConverted = (regTech == null)
3429 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3430 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3431 regTechConverted);
3432 try {
3433 consumer.accept(regTechConverted);
3434 } catch (RemoteException e) {
3435 // Ignore if the remote process is no longer available to call back.
3436 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3437 }
3438 });
3439 } finally {
3440 Binder.restoreCallingIdentity(token);
3441 }
3442 }
3443
shilu366312e2019-12-17 09:28:10 -08003444 /**
3445 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3446 * @param subId The subscription to use to check the configuration.
3447 * @param c The callback that will be used to send the result.
3448 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003449 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003450 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3451 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003452 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3453 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003454 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3455 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3456 "IMS not available on device.");
3457 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003458 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3459 final long token = Binder.clearCallingIdentity();
3460 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003461 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003463 } catch (ImsException e) {
3464 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003465 } finally {
3466 Binder.restoreCallingIdentity(token);
3467 }
3468 }
3469
shilu366312e2019-12-17 09:28:10 -08003470 /**
3471 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3472 * @param subId The subscription to use to check the configuration.
3473 * @param c The callback that will be used to send the result.
3474 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003475 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003476 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003477 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3478 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003479 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3480 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3481 }
Meng Wangafbc5852019-09-19 17:37:13 -07003482
3483 final long token = Binder.clearCallingIdentity();
3484 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003485 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003486 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003487 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003488 } catch (ImsException e) {
3489 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3490 + "is inactive, ignoring unregister.");
3491 // If the subscription is no longer active, just return, since the callback
3492 // will already have been removed internally.
3493 } finally {
3494 Binder.restoreCallingIdentity(token);
3495 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003496 }
3497
3498 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003499 public boolean isCapable(int subId, int capability, int regTech) {
3500 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003501 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3502 final long token = Binder.clearCallingIdentity();
3503 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003504 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003506 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003507 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3508 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003509 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003510 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3511 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003512 } finally {
3513 Binder.restoreCallingIdentity(token);
3514 }
3515 }
3516
3517 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003518 public boolean isAvailable(int subId, int capability, int regTech) {
3519 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003520 final long token = Binder.clearCallingIdentity();
3521 try {
3522 Phone phone = getPhone(subId);
3523 if (phone == null) return false;
3524 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003525 } catch (com.android.ims.ImsException e) {
3526 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3527 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003528 } finally {
3529 Binder.restoreCallingIdentity(token);
3530 }
3531 }
3532
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003533 /**
3534 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3535 * subscription.
3536 * @param subId The subscription to use to check the configuration.
3537 * @param callback The callback that will be used to send the result.
3538 * @param capability The MmTelFeature capability that will be used to send the result.
3539 * @param transportType The transport type of the MmTelFeature capability.
3540 */
3541 @Override
3542 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3543 int transportType) {
3544 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3545 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3546 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3547 "IMS not available on device.");
3548 }
3549 final long token = Binder.clearCallingIdentity();
3550 try {
3551 int slotId = getSlotIndex(subId);
3552 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3553 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3554 + subId + "'");
3555 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3556 }
3557 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3558 transportType, aBoolean -> {
3559 try {
3560 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3561 } catch (RemoteException e) {
3562 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3563 + "running. Ignore");
3564 }
3565 });
3566 } finally {
3567 Binder.restoreCallingIdentity(token);
3568 }
3569 }
3570
shilu366312e2019-12-17 09:28:10 -08003571 /**
3572 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3573 * @param subId The subscription to use to check the configuration.
3574 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 @Override
3576 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003577 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3578 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003579
Brad Ebinger35c841c2018-10-01 10:40:55 -07003580 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3581 final long token = Binder.clearCallingIdentity();
3582 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003583 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003585 } catch (ImsException e) {
3586 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 } finally {
3588 Binder.restoreCallingIdentity(token);
3589 }
3590 }
3591
3592 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003593 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003595 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003599 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003601 } catch (ImsException e) {
3602 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
3606 }
3607
shilu366312e2019-12-17 09:28:10 -08003608 /**
3609 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3610 * @param subId The subscription to use to check the configuration.
3611 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003612 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003613 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003614 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3615 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 final long identity = Binder.clearCallingIdentity();
3617 try {
3618 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003619 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3620 } catch (ImsException e) {
3621 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 } finally {
3623 Binder.restoreCallingIdentity(identity);
3624 }
3625 }
3626
3627 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003628 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003630 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003631 final long identity = Binder.clearCallingIdentity();
3632 try {
3633 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003634 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003635 } catch (ImsException e) {
3636 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
3640 }
3641
shilu366312e2019-12-17 09:28:10 -08003642 /**
3643 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3644 * @param subId The subscription to use to check the configuration.
3645 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003646 @Override
3647 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003648 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3649 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003653 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003654 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003655 } catch (ImsException e) {
3656 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
3660 }
3661
3662 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003663 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003665 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003669 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003670 } catch (ImsException e) {
3671 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003672 } finally {
3673 Binder.restoreCallingIdentity(identity);
3674 }
3675 }
3676
shilu366312e2019-12-17 09:28:10 -08003677 /**
3678 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3679 * @param subId The subscription to use to check the configuration.
3680 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003681 @Override
3682 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003683 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3684 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003688 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003689 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003690 } catch (ImsException e) {
3691 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
3695 }
3696
3697 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003698 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003700 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003704 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003705 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003706 } catch (ImsException e) {
3707 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
3711 }
3712
3713 @Override
3714 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3716 "setVoWiFiNonPersistent");
3717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003720 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003721 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003722 } catch (ImsException e) {
3723 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
3727 }
3728
shilu366312e2019-12-17 09:28:10 -08003729 /**
3730 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3731 * @param subId The subscription to use to check the configuration.
3732 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 @Override
3734 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003735 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3736 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 final long identity = Binder.clearCallingIdentity();
3738 try {
3739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003740 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003741 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003742 } catch (ImsException e) {
3743 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
3747 }
3748
3749 @Override
3750 public void setVoWiFiModeSetting(int subId, int mode) {
3751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3752 "setVoWiFiModeSetting");
3753 final long identity = Binder.clearCallingIdentity();
3754 try {
3755 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003756 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 } catch (ImsException e) {
3759 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003760 } finally {
3761 Binder.restoreCallingIdentity(identity);
3762 }
3763 }
3764
3765 @Override
3766 public int getVoWiFiRoamingModeSetting(int subId) {
3767 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003771 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003772 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003773 } catch (ImsException e) {
3774 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003775 } finally {
3776 Binder.restoreCallingIdentity(identity);
3777 }
3778 }
3779
3780 @Override
3781 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3783 "setVoWiFiRoamingModeSetting");
3784 final long identity = Binder.clearCallingIdentity();
3785 try {
3786 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003787 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003789 } catch (ImsException e) {
3790 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003791 } finally {
3792 Binder.restoreCallingIdentity(identity);
3793 }
3794 }
3795
3796 @Override
3797 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3799 "setRttCapabilityEnabled");
3800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003803 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3804 } catch (ImsException e) {
3805 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003806 } finally {
3807 Binder.restoreCallingIdentity(identity);
3808 }
3809 }
3810
shilu366312e2019-12-17 09:28:10 -08003811 /**
3812 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3813 * @param subId The subscription to use to check the configuration.
3814 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003815 @Override
3816 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003817 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3818 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003822 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003823 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003824 } catch (ImsException e) {
3825 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 } finally {
3827 Binder.restoreCallingIdentity(identity);
3828 }
3829 }
3830
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003831 @Override
3832 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3833 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3834 final long identity = Binder.clearCallingIdentity();
3835 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003836 if (!isImsAvailableOnDevice()) {
3837 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3838 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003839 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003841 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003842 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003843 } catch (ImsException e) {
3844 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003845 } finally {
3846 Binder.restoreCallingIdentity(identity);
3847 }
3848 }
3849
3850 @Override
3851 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3852 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3853 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003854 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3855 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3856 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003857 try {
3858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003859 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003860 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003861 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003862 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3863 + "is inactive, ignoring unregister.");
3864 // If the subscription is no longer active, just return, since the callback will already
3865 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003866 } finally {
3867 Binder.restoreCallingIdentity(identity);
3868 }
3869 }
3870
allenwtsu99c623b2020-01-03 18:24:23 +08003871
3872 private void checkModifyPhoneStatePermission(int subId, String message) {
3873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3874 message);
3875 }
3876
3877 private boolean isImsProvisioningRequired(int subId, int capability,
3878 boolean isMmtelCapability) {
3879 Phone phone = getPhone(subId);
3880 if (phone == null) {
3881 loge("phone instance null for subid " + subId);
3882 return false;
3883 }
3884 if (isMmtelCapability) {
3885 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3886 return false;
3887 }
3888 } else {
3889 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3890 return false;
3891 }
3892 }
3893 return true;
3894 }
3895
3896 @Override
3897 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3898 boolean isProvisioned) {
3899 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3900
3901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3904 if (!isImsProvisioningRequired(subId, capability, false)) {
3905 return;
3906 }
3907
3908 // this capability requires provisioning, route to the correct API.
3909 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3910 switch (capability) {
3911 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3912 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3913 ims.setEabProvisioned(isProvisioned);
3914 break;
3915 default: {
3916 throw new IllegalArgumentException("Tried to set provisioning for "
3917 + "rcs capability '" + capability + "', which does not require "
3918 + "provisioning.");
3919 }
3920 }
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
3924
3925 }
3926
3927
3928 @Override
3929 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3930 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3934 if (!isImsProvisioningRequired(subId, capability, false)) {
3935 return true;
3936 }
3937
3938 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3939 switch (capability) {
3940 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3941 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3942 return ims.isEabProvisionedOnDevice();
3943
3944 default: {
3945 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3946 + "capability '" + capability + "', which does not require "
3947 + "provisioning.");
3948 }
3949 }
3950
3951 } finally {
3952 Binder.restoreCallingIdentity(identity);
3953 }
3954 }
3955
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003956 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003957 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3958 boolean isProvisioned) {
3959 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3960 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3961 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3962 }
allenwtsu99c623b2020-01-03 18:24:23 +08003963 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003964 final long identity = Binder.clearCallingIdentity();
3965 try {
3966 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003967 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003968 return;
3969 }
3970
3971 // this capability requires provisioning, route to the correct API.
3972 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3973 switch (capability) {
3974 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3975 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3976 ims.setVolteProvisioned(isProvisioned);
3977 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3978 ims.setWfcProvisioned(isProvisioned);
3979 }
3980 break;
3981 }
3982 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3983 // There is currently no difference in VT provisioning type.
3984 ims.setVtProvisioned(isProvisioned);
3985 break;
3986 }
3987 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3988 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3989 // change the capability of the feature instead if needed.
3990 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3991 == isProvisioned) {
3992 // No change in provisioning.
3993 return;
3994 }
3995 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3996 try {
3997 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003998 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003999 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4000 + ", Exception" + e.getMessage());
4001 }
4002 break;
4003 }
4004 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004005 throw new IllegalArgumentException("Tried to set provisioning for "
4006 + "MmTel capability '" + capability + "', which does not require "
4007 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004008 }
4009 }
4010
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
4014 }
4015
4016 @Override
4017 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4018 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4019 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4020 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4021 }
4022 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004026 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004027 return true;
4028 }
4029
4030 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4031 switch (capability) {
4032 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4033 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4034 return ims.isVolteProvisionedOnDevice();
4035 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4036 return ims.isWfcProvisionedOnDevice();
4037 }
4038 // This should never happen, since we are checking tech above to make sure it
4039 // is either LTE or IWLAN.
4040 throw new IllegalArgumentException("Invalid radio technology for voice "
4041 + "capability.");
4042 }
4043 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4044 // There is currently no difference in VT provisioning type.
4045 return ims.isVtProvisionedOnDevice();
4046 }
4047 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4048 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4049 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4050 }
4051 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004052 throw new IllegalArgumentException(
4053 "Tried to get provisioning for MmTel capability '" + capability
4054 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004055 }
4056 }
4057
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
4061 }
4062
4063 @Override
4064 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4065 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4066 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4067 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4068 }
4069 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4070 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4071 return (provisionedBits & capability) > 0;
4072 }
4073
4074 @Override
4075 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4076 boolean isProvisioned) {
4077 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4078 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4079 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4080 }
4081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4082 "setProvisioningStatusForCapability");
4083 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4084 // If the current provisioning status for capability already matches isProvisioned,
4085 // do nothing.
4086 if (((provisionedBits & capability) > 0) == isProvisioned) {
4087 return;
4088 }
4089 if (isProvisioned) {
4090 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4091 } else {
4092 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4093 }
4094 }
4095
4096 /**
4097 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4098 * technology. The bitfield should mirror the bitfield defined by
4099 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4100 */
4101 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4102 String key = getMmTelProvisioningKey(subId, tech);
4103 // Default is no capabilities are provisioned.
4104 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4105 }
4106
4107 /**
4108 * Sets the MmTel capability provisioning bitfield (defined by
4109 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4110 * technology specified.
4111 *
4112 * Note: This is a synchronous command and should not be called on UI thread.
4113 */
4114 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4115 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4116 String key = getMmTelProvisioningKey(subId, tech);
4117 editor.putInt(key, newField);
4118 editor.commit();
4119 }
4120
4121 private static String getMmTelProvisioningKey(int subId, int tech) {
4122 // resulting key is provision_ims_mmtel_{subId}_{tech}
4123 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4124 }
4125
4126 /**
4127 * Query CarrierConfig to see if the specified capability requires provisioning for the
4128 * carrier associated with the subscription id.
4129 */
4130 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4131 int capability) {
4132 CarrierConfigManager configManager = new CarrierConfigManager(context);
4133 PersistableBundle c = configManager.getConfigForSubId(subId);
4134 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004135 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004136 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4137 false);
4138 boolean requireVoiceVtProvisioning = c.getBoolean(
4139 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4140
4141 // First check to make sure that the capability requires provisioning.
4142 switch (capability) {
4143 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4144 // intentional fallthrough
4145 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4146 if (requireVoiceVtProvisioning) {
4147 // Voice and Video requires provisioning
4148 return true;
4149 }
4150 break;
4151 }
4152 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4153 if (requireUtProvisioning) {
4154 // UT requires provisioning
4155 return true;
4156 }
4157 break;
4158 }
4159 }
4160 return false;
4161 }
4162
allenwtsu99c623b2020-01-03 18:24:23 +08004163 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4164 int capability) {
4165 CarrierConfigManager configManager = new CarrierConfigManager(context);
4166 PersistableBundle c = configManager.getConfigForSubId(subId);
4167
4168 boolean requireRcsProvisioning = c.getBoolean(
4169 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4170
4171 // First check to make sure that the capability requires provisioning.
4172 switch (capability) {
4173 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4174 // intentional fallthrough
4175 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4176 if (requireRcsProvisioning) {
4177 // OPTION or PRESENCE requires provisioning
4178 return true;
4179 }
4180 break;
4181 }
4182 }
4183 return false;
4184 }
4185
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004186 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004187 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004188 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4189 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4190 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004191 enforceReadPrivilegedPermission("getImsProvisioningInt");
4192 final long identity = Binder.clearCallingIdentity();
4193 try {
4194 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004195 int slotId = getSlotIndex(subId);
4196 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4197 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4198 + subId + "' for key:" + key);
4199 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4200 }
4201 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004202 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004203 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4204 + subId + "' for key:" + key);
4205 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004206 } finally {
4207 Binder.restoreCallingIdentity(identity);
4208 }
4209 }
4210
4211 @Override
4212 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004213 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4214 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4215 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004216 enforceReadPrivilegedPermission("getImsProvisioningString");
4217 final long identity = Binder.clearCallingIdentity();
4218 try {
4219 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004220 int slotId = getSlotIndex(subId);
4221 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4222 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4223 + subId + "' for key:" + key);
4224 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4225 }
4226 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004227 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004228 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4229 + subId + "' for key:" + key);
4230 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004231 } finally {
4232 Binder.restoreCallingIdentity(identity);
4233 }
4234 }
4235
4236 @Override
4237 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004238 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4239 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4240 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4242 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004243 final long identity = Binder.clearCallingIdentity();
4244 try {
4245 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004246 int slotId = getSlotIndex(subId);
4247 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4248 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4249 + subId + "' for key:" + key);
4250 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4251 }
4252 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004253 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004254 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4255 + "' for key:" + key);
4256 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004257 } finally {
4258 Binder.restoreCallingIdentity(identity);
4259 }
4260 }
4261
4262 @Override
4263 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004264 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4265 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4266 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4268 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004269 final long identity = Binder.clearCallingIdentity();
4270 try {
4271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004272 int slotId = getSlotIndex(subId);
4273 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4274 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4275 + subId + "' for key:" + key);
4276 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4277 }
4278 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004279 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004280 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4281 + "' for key:" + key);
4282 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
4286 }
4287
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004288 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 int slotId = SubscriptionManager.getSlotIndex(subId);
4290 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004291 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4292 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 }
4294 return slotId;
4295 }
4296
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004297 private int getSlotIndex(int subId) {
4298 int slotId = SubscriptionManager.getSlotIndex(subId);
4299 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4300 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4301 }
4302 return slotId;
4303 }
4304
Wink Saville36469e72014-06-11 15:17:00 -07004305 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004306 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004307 */
4308 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004309 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4310 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004311 final int targetSdk = getTargetSdk(callingPackage);
4312 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004313 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004314 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004315 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004316 mApp, subId, callingPackage, callingFeatureId,
4317 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004318 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4319 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321 final long identity = Binder.clearCallingIdentity();
4322 try {
4323 final Phone phone = getPhone(subId);
4324 if (phone != null) {
4325 return phone.getServiceState().getDataNetworkType();
4326 } else {
4327 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4328 }
4329 } finally {
4330 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004332 }
4333
4334 /**
4335 * Returns the data network type
4336 */
4337 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004338 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4339 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4340 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004341 }
4342
4343 /**
4344 * Returns the data network type for a subId
4345 */
4346 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004347 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4348 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004349 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004350 mApp, subId, callingPackage, callingFeatureId,
4351 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004352 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4353 }
4354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 final Phone phone = getPhone(subId);
4358 if (phone != null) {
4359 return phone.getServiceState().getDataNetworkType();
4360 } else {
4361 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4362 }
4363 } finally {
4364 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004366 }
4367
4368 /**
Wink Saville36469e72014-06-11 15:17:00 -07004369 * Returns the Voice network type for a subId
4370 */
4371 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004372 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4373 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004375 mApp, subId, callingPackage, callingFeatureId,
4376 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004377 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4378 }
4379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380 final long identity = Binder.clearCallingIdentity();
4381 try {
4382 final Phone phone = getPhone(subId);
4383 if (phone != null) {
4384 return phone.getServiceState().getVoiceNetworkType();
4385 } else {
4386 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4387 }
4388 } finally {
4389 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004391 }
4392
4393 /**
4394 * @return true if a ICC card is present
4395 */
4396 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004397 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004398 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4399 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004400 }
4401
4402 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004403 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004404 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004405 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004406 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 final long identity = Binder.clearCallingIdentity();
4408 try {
4409 final Phone phone = PhoneFactory.getPhone(slotIndex);
4410 if (phone != null) {
4411 return phone.getIccCard().hasIccCard();
4412 } else {
4413 return false;
4414 }
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004418 }
4419
4420 /**
4421 * Return if the current radio is LTE on CDMA. This
4422 * is a tri-state return value as for a period of time
4423 * the mode may be unknown.
4424 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004425 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004426 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004427 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004428 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004429 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004430 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4431 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4432 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004433 }
4434
Sanket Padawe356d7632015-06-22 14:03:32 -07004435 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004436 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4437 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004438 try {
4439 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4440 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004441 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4442 }
4443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 final long identity = Binder.clearCallingIdentity();
4445 try {
4446 final Phone phone = getPhone(subId);
4447 if (phone == null) {
4448 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4449 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004450 return TelephonyProperties.lte_on_cdma_device()
4451 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 }
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004455 }
Wink Saville36469e72014-06-11 15:17:00 -07004456 }
4457
Wink Saville36469e72014-06-11 15:17:00 -07004458 /**
4459 * {@hide}
4460 * Returns Default subId, 0 in the case of single standby.
4461 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004462 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004463 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004464 }
4465
Shishir Agrawala9f32182016-04-12 12:00:16 -07004466 private int getSlotForDefaultSubscription() {
4467 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4468 }
4469
Wink Savilleb564aae2014-10-23 10:18:09 -07004470 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004471 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004472 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004473
Pengquan Menge92a50d2018-09-21 15:54:48 -07004474 private boolean isActiveSubscription(int subId) {
4475 return mSubscriptionController.isActiveSubId(subId);
4476 }
4477
Ihab Awadf2177b72013-11-25 13:33:23 -08004478 /**
4479 * @see android.telephony.TelephonyManager.WifiCallingChoices
4480 */
4481 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 final long identity = Binder.clearCallingIdentity();
4483 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004484 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4486 getWhenToMakeWifiCallsDefaultPreference());
4487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004490 }
4491
4492 /**
4493 * @see android.telephony.TelephonyManager.WifiCallingChoices
4494 */
4495 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004499 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004504 }
4505
Sailesh Nepald1e68152013-12-12 19:08:02 -08004506 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004507 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004508 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004509 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004510
Jordan Liu4c733742019-02-28 12:03:40 -08004511 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4512 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4513 if (phoneId == -1) {
4514 throw new IllegalArgumentException("Given slot index: " + slotIndex
4515 + " does not correspond to an active phone");
4516 }
4517 return PhoneFactory.getPhone(phoneId);
4518 }
4519
Shishir Agrawal566b7612013-10-28 14:41:00 -07004520 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004521 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4522 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4524 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004526 if (DBG) {
4527 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4528 }
4529 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4530 p2);
4531 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004532
Jordan Liu4c733742019-02-28 12:03:40 -08004533
4534 @Override
4535 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4536 int slotIndex, String callingPackage, String aid, int p2) {
4537 enforceModifyPermission();
4538 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4539 if (DBG) {
4540 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4541 }
4542 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4543 callingPackage, aid, p2);
4544 }
4545
4546 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4547 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004548 final long identity = Binder.clearCallingIdentity();
4549 try {
4550 if (TextUtils.equals(ISDR_AID, aid)) {
4551 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004552 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4553 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 if (bestComponent == null
4555 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4556 loge("The calling package is not allowed to access ISD-R.");
4557 throw new SecurityException(
4558 "The calling package is not allowed to access ISD-R.");
4559 }
Derek Tan740e1672017-06-27 14:56:27 -07004560 }
Derek Tan740e1672017-06-27 14:56:27 -07004561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004562 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004563 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4564 null /* workSource */);
4565 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566 return response;
4567 } finally {
4568 Binder.restoreCallingIdentity(identity);
4569 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004570 }
4571
4572 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004573 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4575 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004576 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4577 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4578 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004579
Jordan Liu4c733742019-02-28 12:03:40 -08004580 @Override
4581 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4582 enforceModifyPermission();
4583 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4584 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4585 channel);
4586 }
4587
4588 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 final long identity = Binder.clearCallingIdentity();
4590 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 if (channel < 0) {
4592 return false;
4593 }
Jordan Liu4c733742019-02-28 12:03:40 -08004594 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4595 null /* workSource */);
4596 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 return success;
4598 } finally {
4599 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004600 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004601 }
4602
4603 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004604 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004605 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4607 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004608 if (DBG) {
4609 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4610 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4611 + p3 + " data=" + data);
4612 }
4613 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4614 command, p1, p2, p3, data);
4615 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004616
Jordan Liu4c733742019-02-28 12:03:40 -08004617 @Override
4618 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4619 int command, int p1, int p2, int p3, String data) {
4620 enforceModifyPermission();
4621 if (DBG) {
4622 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4623 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4624 + p3 + " data=" + data);
4625 }
4626 return iccTransmitApduLogicalChannelWithPermission(
4627 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4628 data);
4629 }
4630
4631 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4632 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633 final long identity = Binder.clearCallingIdentity();
4634 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004635 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636 return "";
4637 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004639 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004640 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4641 null /* workSource */);
4642 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644 // Append the returned status code to the end of the response payload.
4645 String s = Integer.toHexString(
4646 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4647 if (response.payload != null) {
4648 s = IccUtils.bytesToHexString(response.payload) + s;
4649 }
4650 return s;
4651 } finally {
4652 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004654 }
Jake Hambye994d462014-02-03 13:10:13 -08004655
Evan Charltonc66da362014-05-16 14:06:40 -07004656 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004657 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4658 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4660 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004662 if (DBG) {
4663 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4664 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4665 }
4666 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4667 cla, command, p1, p2, p3, data);
4668 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004669
Jordan Liu4c733742019-02-28 12:03:40 -08004670 @Override
4671 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4672 int command, int p1, int p2, int p3, String data) {
4673 enforceModifyPermission();
4674 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4675 if (DBG) {
4676 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4677 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4678 + " data=" + data);
4679 }
4680
4681 return iccTransmitApduBasicChannelWithPermission(
4682 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4683 p2, p3, data);
4684 }
4685
4686 // open APDU basic channel assuming the caller has sufficient permissions
4687 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4688 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 final long identity = Binder.clearCallingIdentity();
4690 try {
4691 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4692 && TextUtils.equals(ISDR_AID, data)) {
4693 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004694 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4695 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696 if (bestComponent == null
4697 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4698 loge("The calling package is not allowed to select ISD-R.");
4699 throw new SecurityException(
4700 "The calling package is not allowed to select ISD-R.");
4701 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004702 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004705 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4706 null /* workSource */);
4707 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004709 // Append the returned status code to the end of the response payload.
4710 String s = Integer.toHexString(
4711 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4712 if (response.payload != null) {
4713 s = IccUtils.bytesToHexString(response.payload) + s;
4714 }
4715 return s;
4716 } finally {
4717 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004718 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004719 }
4720
4721 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004722 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004723 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4725 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 if (DBG) {
4730 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4731 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4732 }
4733
4734 IccIoResult response =
4735 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4736 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4737 subId);
4738
4739 if (DBG) {
4740 log("Exchange SIM_IO [R]" + response);
4741 }
4742
4743 byte[] result = null;
4744 int length = 2;
4745 if (response.payload != null) {
4746 length = 2 + response.payload.length;
4747 result = new byte[length];
4748 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4749 } else {
4750 result = new byte[length];
4751 }
4752
4753 result[length - 1] = (byte) response.sw2;
4754 result[length - 2] = (byte) response.sw1;
4755 return result;
4756 } finally {
4757 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004758 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004759 }
4760
Nathan Haroldb3014052017-01-25 15:57:32 -08004761 /**
4762 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4763 * on a particular subscription
4764 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004765 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4766 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004768 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004769 return null;
4770 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004771
4772 final long identity = Binder.clearCallingIdentity();
4773 try {
4774 if (appType != TelephonyManager.APPTYPE_USIM
4775 && appType != TelephonyManager.APPTYPE_SIM) {
4776 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4777 return null;
4778 }
4779 Object response = sendRequest(
4780 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4781 if (response instanceof String[]) {
4782 return (String[]) response;
4783 }
yincheng zhao2737e882019-09-06 17:06:54 -07004784 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004786 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004787 } finally {
4788 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004789 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004790 }
4791
yincheng zhao2737e882019-09-06 17:06:54 -07004792 /**
4793 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4794 * subscription.
4795 *
4796 * @param subId the id of the subscription.
4797 * @param appType the uicc app type, must be USIM or SIM.
4798 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4799 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004800 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004801 * @return number of fplmns that is successfully written to the SIM.
4802 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004803 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4804 String callingFeatureId) {
4805 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4806 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004807 if (DBG) logv("no permissions for setForbiddenplmns");
4808 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4809 }
4810 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4811 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4812 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4813 }
4814 if (fplmns == null) {
4815 throw new IllegalArgumentException("Fplmn List provided is null");
4816 }
4817 for (String fplmn : fplmns) {
4818 if (!CellIdentity.isValidPlmn(fplmn)) {
4819 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4820 }
4821 }
4822 final long identity = Binder.clearCallingIdentity();
4823 try {
4824 Object response = sendRequest(
4825 CMD_SET_FORBIDDEN_PLMNS,
4826 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4827 subId);
4828 return (int) response;
4829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
4832 }
4833
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004834 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004835 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4837 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004839 final long identity = Binder.clearCallingIdentity();
4840 try {
4841 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4842 if (response.payload == null) {
4843 return "";
4844 }
Evan Charltonc66da362014-05-16 14:06:40 -07004845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004846 // Append the returned status code to the end of the response payload.
4847 String s = Integer.toHexString(
4848 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4849 s = IccUtils.bytesToHexString(response.payload) + s;
4850 return s;
4851 } finally {
4852 Binder.restoreCallingIdentity(identity);
4853 }
Evan Charltonc66da362014-05-16 14:06:40 -07004854 }
4855
Jake Hambye994d462014-02-03 13:10:13 -08004856 /**
4857 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4858 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4859 *
4860 * @param itemID the ID of the item to read
4861 * @return the NV item as a String, or null on error.
4862 */
4863 @Override
4864 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004865 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4867 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004868
4869 final long identity = Binder.clearCallingIdentity();
4870 try {
4871 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004872 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4874 return value;
4875 } finally {
4876 Binder.restoreCallingIdentity(identity);
4877 }
Jake Hambye994d462014-02-03 13:10:13 -08004878 }
4879
4880 /**
4881 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4882 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4883 *
4884 * @param itemID the ID of the item to read
4885 * @param itemValue the value to write, as a String
4886 * @return true on success; false on any failure
4887 */
4888 @Override
4889 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004890 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4892 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893
4894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4897 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004898 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4900 return success;
4901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
Jake Hambye994d462014-02-03 13:10:13 -08004904 }
4905
4906 /**
4907 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4908 * Used for device configuration by some CDMA operators.
4909 *
4910 * @param preferredRoamingList byte array containing the new PRL
4911 * @return true on success; false on any failure
4912 */
4913 @Override
4914 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4916 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917
4918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4921 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4922 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4923 return success;
4924 } finally {
4925 Binder.restoreCallingIdentity(identity);
4926 }
Jake Hambye994d462014-02-03 13:10:13 -08004927 }
4928
4929 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004930 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004931 * Used for device configuration by some CDMA operators.
4932 *
chen xu6dac5ab2018-10-26 17:39:23 -07004933 * @param slotIndex - device slot.
4934 *
Jake Hambye994d462014-02-03 13:10:13 -08004935 * @return true on success; false on any failure
4936 */
4937 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004938 public boolean resetModemConfig(int slotIndex) {
4939 Phone phone = PhoneFactory.getPhone(slotIndex);
4940 if (phone != null) {
4941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4942 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943
chen xu6dac5ab2018-10-26 17:39:23 -07004944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4947 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4948 return success;
4949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 }
chen xu6dac5ab2018-10-26 17:39:23 -07004953 return false;
4954 }
4955
4956 /**
4957 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4958 *
4959 * @param slotIndex - device slot.
4960 *
4961 * @return true on success; false on any failure
4962 */
4963 @Override
4964 public boolean rebootModem(int slotIndex) {
4965 Phone phone = PhoneFactory.getPhone(slotIndex);
4966 if (phone != null) {
4967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4968 mApp, phone.getSubId(), "rebootModem");
4969
4970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4973 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4974 return success;
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
4977 }
4978 }
4979 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004980 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004981
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004982 public String[] getPcscfAddress(String apnType, String callingPackage,
4983 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004984 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4986 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004987 return new String[0];
4988 }
4989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990 final long identity = Binder.clearCallingIdentity();
4991 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004992 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
Wink Saville36469e72014-06-11 15:17:00 -07004996 }
4997
Brad Ebinger51f743a2017-01-23 13:50:20 -08004998 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004999 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5000 * {@link #disableIms(int)}.
5001 * @param slotIndex device slot.
5002 */
5003 public void resetIms(int slotIndex) {
5004 enforceModifyPermission();
5005
5006 final long identity = Binder.clearCallingIdentity();
5007 try {
5008 if (mImsResolver == null) {
5009 // may happen if the does not support IMS.
5010 return;
5011 }
5012 mImsResolver.disableIms(slotIndex);
5013 mImsResolver.enableIms(slotIndex);
5014 } finally {
5015 Binder.restoreCallingIdentity(identity);
5016 }
5017 }
5018
5019 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005020 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5021 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005022 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005023 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005024 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025
5026 final long identity = Binder.clearCallingIdentity();
5027 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005028 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005029 // may happen if the device does not support IMS.
5030 return;
5031 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005032 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005036 }
5037
5038 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005039 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5040 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005041 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005042 public void disableIms(int slotId) {
5043 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044
5045 final long identity = Binder.clearCallingIdentity();
5046 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005047 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005048 // may happen if the device does not support IMS.
5049 return;
5050 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005051 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 } finally {
5053 Binder.restoreCallingIdentity(identity);
5054 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005055 }
5056
5057 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005058 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5059 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005060 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005061 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005062 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005063 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064
5065 final long identity = Binder.clearCallingIdentity();
5066 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005067 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005068 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5069 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005070 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005071 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005075 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005076 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005077 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5078 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005079 @Override
5080 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005081 enforceModifyPermission();
5082
5083 final long identity = Binder.clearCallingIdentity();
5084 try {
5085 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005086 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005087 } finally {
5088 Binder.restoreCallingIdentity(identity);
5089 }
5090 }
5091
5092 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005093 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005094 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005095 */
5096 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5097 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098
5099 final long identity = Binder.clearCallingIdentity();
5100 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005101 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005102 // may happen if the device does not support IMS.
5103 return null;
5104 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005105 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 } finally {
5107 Binder.restoreCallingIdentity(identity);
5108 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005109 }
5110
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005111 /**
5112 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005113 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005114 */
5115 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5116 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117
5118 final long identity = Binder.clearCallingIdentity();
5119 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005120 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005121 // may happen if the device does not support IMS.
5122 return null;
5123 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005124 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005125 } finally {
5126 Binder.restoreCallingIdentity(identity);
5127 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005128 }
5129
Brad Ebinger884c07b2018-02-15 16:17:40 -08005130 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005131 * Sets the ImsService Package Name that Telephony will bind to.
5132 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005133 * @param slotIndex the slot ID that the ImsService should bind for.
5134 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005135 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005136 * @param featureTypes An integer array of feature types associated with a packageName.
5137 * @param packageName The name of the package that the current configuration will be replaced
5138 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005139 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005140 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005141 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5142 int[] featureTypes, String packageName) {
5143 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5144 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5146 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005147 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 final long identity = Binder.clearCallingIdentity();
5150 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005151 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005152 // may happen if the device does not support IMS.
5153 return false;
5154 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005155 Map<Integer, String> featureConfig = new HashMap<>();
5156 for (int featureType : featureTypes) {
5157 featureConfig.put(featureType, packageName);
5158 }
5159 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5160 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 } finally {
5162 Binder.restoreCallingIdentity(identity);
5163 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005164 }
5165
5166 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005167 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005168 *
5169 * @param slotId The slot that the ImsService is associated with.
5170 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5171 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005172 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005173 * @return the package name of the ImsService configuration.
5174 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005175 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5176 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005177 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005178 TelephonyPermissions
5179 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5180 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5181 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183 final long identity = Binder.clearCallingIdentity();
5184 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005185 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005186 // may happen if the device does not support IMS.
5187 return "";
5188 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005189 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005190 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5191 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005195 }
5196
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005197 /**
5198 * Get the MmTelFeature state associated with the requested subscription id.
5199 * @param subId The subscription that the MmTelFeature is associated with.
5200 * @param callback A callback with an integer containing the
5201 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5202 */
5203 @Override
5204 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5205 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5206 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5207 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5208 "IMS not available on device.");
5209 }
5210 final long token = Binder.clearCallingIdentity();
5211 try {
5212 int slotId = getSlotIndex(subId);
5213 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5214 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5215 + subId + "'");
5216 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5217 }
5218 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5219 try {
5220 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5221 } catch (RemoteException e) {
5222 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5223 + "Ignore");
5224 }
5225 });
5226 } finally {
5227 Binder.restoreCallingIdentity(token);
5228 }
5229 }
5230
Wink Saville36469e72014-06-11 15:17:00 -07005231 public void setImsRegistrationState(boolean registered) {
5232 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233
5234 final long identity = Binder.clearCallingIdentity();
5235 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005236 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
Wink Saville36469e72014-06-11 15:17:00 -07005240 }
5241
5242 /**
Stuart Scott54788802015-03-30 13:18:01 -07005243 * Set the network selection mode to automatic.
5244 *
5245 */
5246 @Override
5247 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5249 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250
5251 final long identity = Binder.clearCallingIdentity();
5252 try {
shilufc958392020-01-20 11:36:01 -08005253 if (!isActiveSubscription(subId)) {
5254 return;
5255 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5257 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Stuart Scott54788802015-03-30 13:18:01 -07005261 }
5262
Jack Yud10cdd42020-09-28 20:28:01 -07005263 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005264 * Ask the radio to connect to the input network and change selection mode to manual.
5265 *
5266 * @param subId the id of the subscription.
5267 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5268 * the operator to attach to.
5269 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5270 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5271 * normal network selection next time.
5272 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005273 */
5274 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005275 public boolean setNetworkSelectionModeManual(
5276 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5278 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005279
5280 if (!isActiveSubscription(subId)) {
5281 return false;
5282 }
5283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 final long identity = Binder.clearCallingIdentity();
5285 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005286 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005288 if (DBG) {
5289 log("setNetworkSelectionModeManual: subId: " + subId
5290 + " operator: " + operatorInfo);
5291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5293 } finally {
5294 Binder.restoreCallingIdentity(identity);
5295 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005296 }
shilu84f6e8b2019-12-19 13:58:01 -08005297 /**
5298 * Get the manual network selection
5299 *
5300 * @param subId the id of the subscription.
5301 *
5302 * @return the previously saved user selected PLMN
5303 */
5304 @Override
5305 public String getManualNetworkSelectionPlmn(int subId) {
5306 TelephonyPermissions
5307 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5308 mApp, subId, "getManualNetworkSelectionPlmn");
5309
5310 final long identity = Binder.clearCallingIdentity();
5311 try {
5312 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005313 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005314 }
5315
5316 final Phone phone = getPhone(subId);
5317 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005318 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005319 }
5320 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5321 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5322 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
5325 }
5326 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005327
5328 /**
5329 * Scans for available networks.
5330 */
5331 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005332 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5333 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5335 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005336 LocationAccessPolicy.LocationPermissionResult locationResult =
5337 LocationAccessPolicy.checkLocationPermission(mApp,
5338 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5339 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005340 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005341 .setCallingPid(Binder.getCallingPid())
5342 .setCallingUid(Binder.getCallingUid())
5343 .setMethod("getCellNetworkScanResults")
5344 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005345 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5346 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005347 .build());
5348 switch (locationResult) {
5349 case DENIED_HARD:
5350 throw new SecurityException("Not allowed to access scan results -- location");
5351 case DENIED_SOFT:
5352 return null;
5353 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354
Pengquan Menga1bb6272018-09-06 09:59:22 -07005355 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 try {
5357 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005358 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005363 }
5364
5365 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005366 * Get the call forwarding info, given the call forwarding reason.
5367 */
5368 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005369 public void getCallForwarding(int subId, int callForwardingReason,
5370 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005371 enforceReadPrivilegedPermission("getCallForwarding");
5372 long identity = Binder.clearCallingIdentity();
5373 try {
5374 if (DBG) {
5375 log("getCallForwarding: subId " + subId
5376 + " callForwardingReason" + callForwardingReason);
5377 }
Hall Liu27d24262020-09-18 19:04:59 -07005378
5379 Phone phone = getPhone(subId);
5380 if (phone == null) {
5381 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005382 callback.onError(
5383 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005384 } catch (RemoteException e) {
5385 // ignore
5386 }
5387 return;
5388 }
5389
5390 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5391 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5392 @Override
5393 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5394 try {
5395 callback.onCallForwardingInfoAvailable(info);
5396 } catch (RemoteException e) {
5397 // ignore
5398 }
5399 }
5400
5401 @Override
5402 public void onError(int error) {
5403 try {
5404 callback.onError(error);
5405 } catch (RemoteException e) {
5406 // ignore
5407 }
5408 }
5409 });
5410 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
5414 }
5415
5416 /**
5417 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5418 * reason, the number to forward, and the timeout before the forwarding is attempted.
5419 */
5420 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005421 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5422 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005423 enforceModifyPermission();
5424 long identity = Binder.clearCallingIdentity();
5425 try {
5426 if (DBG) {
5427 log("setCallForwarding: subId " + subId
5428 + " callForwardingInfo" + callForwardingInfo);
5429 }
Hall Liu27d24262020-09-18 19:04:59 -07005430
5431 Phone phone = getPhone(subId);
5432 if (phone == null) {
5433 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005434 callback.accept(
5435 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005436 } catch (RemoteException e) {
5437 // ignore
5438 }
5439 return;
5440 }
5441
5442 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5443 FunctionalUtils.ignoreRemoteException(callback::accept));
5444
5445 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005446 } finally {
5447 Binder.restoreCallingIdentity(identity);
5448 }
5449 }
5450
5451 /**
Hall Liu27d24262020-09-18 19:04:59 -07005452 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005453 */
5454 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005455 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005456 enforceReadPrivilegedPermission("getCallForwarding");
5457 long identity = Binder.clearCallingIdentity();
5458 try {
Hall Liu27d24262020-09-18 19:04:59 -07005459
5460 Phone phone = getPhone(subId);
5461 if (phone == null) {
5462 try {
5463 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5464 } catch (RemoteException e) {
5465 // ignore
5466 }
5467 return;
5468 }
5469
5470 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5471
Shuo Qian4a594052020-01-23 11:59:30 -08005472 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005473 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005474 } finally {
5475 Binder.restoreCallingIdentity(identity);
5476 }
5477 }
5478
5479 /**
Hall Liu27d24262020-09-18 19:04:59 -07005480 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005481 */
5482 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005483 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005484 enforceModifyPermission();
5485 long identity = Binder.clearCallingIdentity();
5486 try {
Hall Liu27d24262020-09-18 19:04:59 -07005487 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5488
5489 Phone phone = getPhone(subId);
5490 if (phone == null) {
5491 try {
5492 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5493 } catch (RemoteException e) {
5494 // ignore
5495 }
5496 return;
5497 }
5498
5499 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5500 FunctionalUtils.ignoreRemoteException(callback::accept));
5501
5502 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005503 } finally {
5504 Binder.restoreCallingIdentity(identity);
5505 }
5506 }
5507
5508 /**
yinxub1bed742017-04-17 11:45:04 -07005509 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005510 *
yinxub1bed742017-04-17 11:45:04 -07005511 * @param subId id of the subscription
5512 * @param request contains the radio access networks with bands/channels to scan
5513 * @param messenger callback messenger for scan results or errors
5514 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005515 * @return the id of the requested scan which can be used to stop the scan.
5516 */
5517 @Override
5518 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005519 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5521 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005522 LocationAccessPolicy.LocationPermissionResult locationResult =
5523 LocationAccessPolicy.checkLocationPermission(mApp,
5524 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5525 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005526 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005527 .setCallingPid(Binder.getCallingPid())
5528 .setCallingUid(Binder.getCallingUid())
5529 .setMethod("requestNetworkScan")
5530 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005531 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5532 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005533 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005534 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005535 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5536 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005537 if (e != null) {
5538 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5539 throw e;
5540 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005541 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005542 return TelephonyScanManager.INVALID_SCAN_ID;
5543 }
5544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 }
Hall Liu912dfd32019-04-25 14:02:26 -07005546 int callingUid = Binder.getCallingUid();
5547 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005548 final long identity = Binder.clearCallingIdentity();
5549 try {
5550 return mNetworkScanRequestTracker.startNetworkScan(
5551 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005552 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555 }
yinxu504e1392017-04-12 16:03:22 -07005556 }
5557
Hall Liub2ac8ef2019-02-28 15:56:23 -08005558 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005559 NetworkScanRequest request, int subId, String callingPackage) {
5560 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005561 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5562 boolean hasNetworkScanPermission =
5563 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5564 == PERMISSION_GRANTED;
5565
5566 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5567 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5568 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005569 }
5570
5571 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5572 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005573 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5574 return new SecurityException("Specific channels must not be"
5575 + " scanned without location access.");
5576 }
5577 }
5578 }
5579
Hall Liub2ac8ef2019-02-28 15:56:23 -08005580 return null;
5581 }
5582
yinxu504e1392017-04-12 16:03:22 -07005583 /**
5584 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005585 *
5586 * @param subId id of the subscription
5587 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005588 */
5589 @Override
5590 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5592 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593
Hall Liu912dfd32019-04-25 14:02:26 -07005594 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 final long identity = Binder.clearCallingIdentity();
5596 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005597 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
yinxu504e1392017-04-12 16:03:22 -07005601 }
5602
5603 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005604 * Get the calculated preferred network type.
5605 * Used for debugging incorrect network type.
5606 *
5607 * @return the preferred network type, defined in RILConstants.java.
5608 */
5609 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005610 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005611 final Phone defaultPhone = getDefaultPhone();
5612 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005613 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005614 return RILConstants.PREFERRED_NETWORK_MODE;
5615 }
5616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 final long identity = Binder.clearCallingIdentity();
5618 try {
5619 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005620 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
Junda Liu84d15a22014-07-02 11:21:04 -07005624 }
5625
5626 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005627 * Get the preferred network type.
5628 * Used for device configuration by some CDMA operators.
5629 *
5630 * @return the preferred network type, defined in RILConstants.java.
5631 */
5632 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005633 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005634 TelephonyPermissions
5635 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5636 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637
5638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 if (DBG) log("getPreferredNetworkType");
5641 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5642 int networkType = (result != null ? result[0] : -1);
5643 if (DBG) log("getPreferredNetworkType: " + networkType);
5644 return networkType;
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005648 }
5649
5650 /**
5651 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005652 *
5653 * @param networkType the preferred network type, defined in RILConstants.java.
5654 * @return true on success; false on any failure.
5655 */
5656 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005657 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5659 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660
5661 final long identity = Binder.clearCallingIdentity();
5662 try {
calvinpan8ed33732020-03-12 14:17:55 +08005663 Boolean success = (Boolean) sendRequest(
5664 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005665
5666 if (success) {
5667 Settings.Global.putInt(mApp.getContentResolver(),
5668 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5669 }
calvinpan8ed33732020-03-12 14:17:55 +08005670 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5671 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 } finally {
5673 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005674 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005675 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005676
5677 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005678 * Get the allowed network types that store in the telephony provider.
5679 *
5680 * @param subId the id of the subscription.
5681 * @return allowedNetworkTypes the allowed network types.
5682 */
5683 @Override
5684 public long getAllowedNetworkTypes(int subId) {
5685 TelephonyPermissions
5686 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5687 mApp, subId, "getAllowedNetworkTypes");
5688
5689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 return SubscriptionManager.getLongSubscriptionProperty(
5692 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5693 } finally {
5694 Binder.restoreCallingIdentity(identity);
5695 }
5696 }
5697
5698 /**
5699 * Set the allowed network types.
5700 *
5701 * @param subId the id of the subscription.
5702 * @param allowedNetworkTypes the allowed network types.
5703 * @return true on success; false on any failure.
5704 */
5705 @Override
5706 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5708 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005709
calvinpan8ed33732020-03-12 14:17:55 +08005710 SubscriptionManager.setSubscriptionProperty(subId,
5711 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5712 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005713
calvinpan8ed33732020-03-12 14:17:55 +08005714 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5715 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5716 RILConstants.PREFERRED_NETWORK_MODE);
5717 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005718 }
5719
5720 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005721 * Get the allowed network types for certain reason.
5722 *
5723 * @param subId the id of the subscription.
5724 * @param reason the reason the allowed network type change is taking place
5725 * @return the allowed network types.
5726 */
5727 @Override
5728 public long getAllowedNetworkTypesForReason(int subId,
5729 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5730 TelephonyPermissions
5731 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5732 mApp, subId, "getAllowedNetworkTypesForReason");
5733 final long identity = Binder.clearCallingIdentity();
5734 try {
5735 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
5739 }
5740
5741 /**
5742 * Get the effective allowed network types on the device.
5743 * This API will return an intersection of allowed network types for all reasons,
5744 * including the configuration done through setAllowedNetworkTypes
5745 *
5746 * @param subId the id of the subscription.
5747 * @return the allowed network types
5748 */
5749 @Override
5750 public long getEffectiveAllowedNetworkTypes(int subId) {
5751 TelephonyPermissions
5752 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5753 mApp, subId, "getEffectiveAllowedNetworkTypes");
5754 final long identity = Binder.clearCallingIdentity();
5755 try {
5756 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
5760 }
5761
5762 /**
5763 * Set the allowed network types of the device and
5764 * provide the reason triggering the allowed network change.
5765 *
5766 * @param subId the id of the subscription.
5767 * @param reason the reason the allowed network type change is taking place
5768 * @param allowedNetworkTypes the allowed network types.
5769 * @return true on success; false on any failure.
5770 */
5771 @Override
5772 public boolean setAllowedNetworkTypesForReason(int subId,
5773 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5775 mApp, subId, "setAllowedNetworkTypesForReason");
5776 final long identity = Binder.clearCallingIdentity();
5777 try {
5778 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5779 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5780 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5781 RILConstants.PREFERRED_NETWORK_MODE);
5782 return setPreferredNetworkType(subId, preferredNetworkMode);
5783 } finally {
5784 Binder.restoreCallingIdentity(identity);
5785 }
5786 }
5787
5788 /**
Miaoa84611c2019-03-15 09:21:10 +08005789 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005790 *
Miaoa84611c2019-03-15 09:21:10 +08005791 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005792 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005793 * @hide
5794 */
5795 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005796 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005799 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 try {
Miaoa84611c2019-03-15 09:21:10 +08005801 if (phone != null) {
5802 return phone.hasMatchedTetherApnSetting();
5803 } else {
5804 return false;
5805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 } finally {
5807 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005808 }
Junda Liu475951f2014-11-07 16:45:03 -08005809 }
5810
5811 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005812 * Enable or disable always reporting signal strength changes from radio.
5813 *
5814 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5815 */
5816 @Override
5817 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5818 enforceModifyPermission();
5819 enforceSystemCaller();
5820
5821 final long identity = Binder.clearCallingIdentity();
5822 final Phone phone = getPhone(subId);
5823 try {
5824 if (phone != null) {
5825 if (DBG) {
5826 log("setAlwaysReportSignalStrength: subId=" + subId
5827 + " isEnable=" + isEnable);
5828 }
5829 phone.setAlwaysReportSignalStrength(isEnable);
5830 } else {
5831 loge("setAlwaysReportSignalStrength: no phone found for subId="
5832 + subId);
5833 }
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
5836 }
5837 }
5838
5839 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005840 * Get the user enabled state of Mobile Data.
5841 *
5842 * TODO: remove and use isUserDataEnabled.
5843 * This can't be removed now because some vendor codes
5844 * calls through ITelephony directly while they should
5845 * use TelephonyManager.
5846 *
5847 * @return true on enabled
5848 */
5849 @Override
5850 public boolean getDataEnabled(int subId) {
5851 return isUserDataEnabled(subId);
5852 }
5853
5854 /**
5855 * Get whether mobile data is enabled per user setting.
5856 *
5857 * There are other factors deciding whether mobile data is actually enabled, but they are
5858 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005859 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005860 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005861 *
5862 * @return {@code true} if data is enabled else {@code false}
5863 */
5864 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005865 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005866 try {
5867 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5868 null);
5869 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5871 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873
5874 final long identity = Binder.clearCallingIdentity();
5875 try {
5876 int phoneId = mSubscriptionController.getPhoneId(subId);
5877 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5878 Phone phone = PhoneFactory.getPhone(phoneId);
5879 if (phone != null) {
5880 boolean retVal = phone.isUserDataEnabled();
5881 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5882 return retVal;
5883 } else {
5884 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5885 return false;
5886 }
5887 } finally {
5888 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005889 }
5890 }
5891
5892 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005893 * Checks if the device is capable of mobile data by considering whether whether the
5894 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5895 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005896 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005897 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005898 */
5899 @Override
5900 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005901 try {
5902 try {
5903 mApp.enforceCallingOrSelfPermission(
5904 android.Manifest.permission.ACCESS_NETWORK_STATE,
5905 null);
5906 } catch (Exception e) {
5907 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
5908 "isDataEnabled");
5909 }
5910 } catch (Exception e) {
5911 enforceReadPrivilegedPermission("isDataEnabled");
5912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 int phoneId = mSubscriptionController.getPhoneId(subId);
5917 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5918 Phone phone = PhoneFactory.getPhone(phoneId);
5919 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005920 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5922 return retVal;
5923 } else {
5924 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5925 return false;
5926 }
5927 } finally {
5928 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005929 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005930 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005931
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005932 /**
5933 * Check if data is enabled for a specific reason
5934 * @param subId Subscription index
5935 * @param reason the reason the data enable change is taking place
5936 * @return {@code true} if the overall data is enabled; {@code false} if not.
5937 */
5938 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005939 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005940 @TelephonyManager.DataEnabledReason int reason) {
5941 try {
5942 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5943 null);
5944 } catch (Exception e) {
5945 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005946 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005947 }
5948
5949
5950 final long identity = Binder.clearCallingIdentity();
5951 try {
5952 int phoneId = mSubscriptionController.getPhoneId(subId);
5953 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005954 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005955 + " reason=" + reason);
5956 }
5957 Phone phone = PhoneFactory.getPhone(phoneId);
5958 if (phone != null) {
5959 boolean retVal;
5960 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
5961 retVal = phone.isUserDataEnabled();
5962 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005963 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005964 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005965 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005966 return retVal;
5967 } else {
5968 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07005969 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005970 + subId + " retVal=false");
5971 }
5972 return false;
5973 }
5974 } finally {
5975 Binder.restoreCallingIdentity(identity);
5976 }
5977 }
5978
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005979 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005980 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07005981 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5982 // Skip the check if it's one of these special uids
5983 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5984 }
5985
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005986 //load access rules from carrier configs, and check those as well: b/139133814
5987 SubscriptionController subController = SubscriptionController.getInstance();
5988 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5989 || subController == null) return privilegeFromSim;
5990
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005991 PackageManager pkgMgr = phone.getContext().getPackageManager();
5992 String[] packages = pkgMgr.getPackagesForUid(uid);
5993
5994 final long identity = Binder.clearCallingIdentity();
5995 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005996 int subId = phone.getSubId();
5997 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5998 // A test override is in place for the privileges for this subId, so don't try to
5999 // read the subscription privileges.
6000 return privilegeFromSim;
6001 }
6002 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006003 SubscriptionManager subManager = (SubscriptionManager)
6004 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6005 for (String pkg : packages) {
6006 if (subManager.canManageSubscription(subInfo, pkg)) {
6007 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6008 }
6009 }
6010 return privilegeFromSim;
6011 } finally {
6012 Binder.restoreCallingIdentity(identity);
6013 }
6014 }
6015
6016 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6017 String pkgName) {
6018 //load access rules from carrier configs, and check those as well: b/139133814
6019 SubscriptionController subController = SubscriptionController.getInstance();
6020 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6021 || subController == null) return privilegeFromSim;
6022
6023 final long identity = Binder.clearCallingIdentity();
6024 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006025 int subId = phone.getSubId();
6026 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6027 // A test override is in place for the privileges for this subId, so don't try to
6028 // read the subscription privileges.
6029 return privilegeFromSim;
6030 }
6031 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006032 SubscriptionManager subManager = (SubscriptionManager)
6033 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6034 return subManager.canManageSubscription(subInfo, pkgName)
6035 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6036 } finally {
6037 Binder.restoreCallingIdentity(identity);
6038 }
6039 }
6040
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006041 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006042 public int getCarrierPrivilegeStatus(int subId) {
6043 final Phone phone = getPhone(subId);
6044 if (phone == null) {
6045 loge("getCarrierPrivilegeStatus: Invalid subId");
6046 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6047 }
6048 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006049 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006050 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006051 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6052 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006053
6054 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6055 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006056 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006057 }
Junda Liu29340342014-07-10 15:23:27 -07006058
6059 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006060 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006061 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006062 final Phone phone = getPhone(subId);
6063 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006064 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006065 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6066 }
6067 UiccProfile profile =
6068 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6069 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006070 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006071 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6072 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006073 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006074 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006075 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006076 }
6077
6078 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006079 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6080 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006081 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006082 }
6083
6084 int phoneId = SubscriptionManager.getPhoneId(subId);
6085 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006086 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006087 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006088 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6089 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006090 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6091 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6092 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006093 }
6094
6095 @Override
6096 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006097 if (TextUtils.isEmpty(pkgName))
6098 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006099 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6100 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6101 UiccCard card = UiccController.getInstance().getUiccCard(i);
6102 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006103 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006104 continue;
6105 }
6106
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006107 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6108 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6109 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006110 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6111 break;
6112 }
6113 }
6114
6115 return result;
Junda Liu29340342014-07-10 15:23:27 -07006116 }
Derek Tan89e89d42014-07-08 17:00:10 -07006117
6118 @Override
Junda Liue64de782015-04-16 17:19:16 -07006119 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6120 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6121 loge("phoneId " + phoneId + " is not valid.");
6122 return null;
6123 }
6124 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006125 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006126 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006127 return null ;
6128 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006129 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006130 }
6131
Amith Yamasani6e118872016-02-19 12:53:51 -08006132 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006133 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006134 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006135 List<String> privilegedPackages = new ArrayList<>();
6136 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006137 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6138 // has UICC in that slot.
6139 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006140 if (card.hasCarrierPrivilegeRules()) {
6141 if (packages == null) {
6142 // Only check packages in user 0 for now
6143 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006144 PackageManager.MATCH_DISABLED_COMPONENTS
6145 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006146 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006147 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006148 }
6149 for (int p = packages.size() - 1; p >= 0; p--) {
6150 PackageInfo pkgInfo = packages.get(p);
6151 if (pkgInfo != null && pkgInfo.packageName != null
6152 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006153 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006154 privilegedPackages.add(pkgInfo.packageName);
6155 }
6156 }
6157 }
6158 }
6159 return privilegedPackages;
6160 }
6161
chen xuf7e9fe82019-05-09 19:31:02 -07006162 @Override
6163 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006164 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6165
6166 final long identity = Binder.clearCallingIdentity();
6167
chen xuf7e9fe82019-05-09 19:31:02 -07006168 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006169 try {
6170 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6171 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6172 }
6173 } finally {
6174 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006175 }
6176 return privilegedPackages;
6177 }
6178
Wink Savilleb564aae2014-10-23 10:18:09 -07006179 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006180 final Phone phone = getPhone(subId);
6181 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006182 if (card == null) {
6183 loge("getIccId: No UICC");
6184 return null;
6185 }
6186 String iccId = card.getIccId();
6187 if (TextUtils.isEmpty(iccId)) {
6188 loge("getIccId: ICC ID is null or empty.");
6189 return null;
6190 }
6191 return iccId;
6192 }
6193
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006194 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006195 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6196 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006197 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006198 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006200 final long identity = Binder.clearCallingIdentity();
6201 try {
6202 final String iccId = getIccId(subId);
6203 final Phone phone = getPhone(subId);
6204 if (phone == null) {
6205 return false;
6206 }
6207 final String subscriberId = phone.getSubscriberId();
6208
6209 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006210 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211 + subscriberId + " to " + number);
6212 }
6213
6214 if (TextUtils.isEmpty(iccId)) {
6215 return false;
6216 }
6217
6218 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6219
6220 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6221 if (alphaTag == null) {
6222 editor.remove(alphaTagPrefKey);
6223 } else {
6224 editor.putString(alphaTagPrefKey, alphaTag);
6225 }
6226
6227 // Record both the line number and IMSI for this ICCID, since we need to
6228 // track all merged IMSIs based on line number
6229 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6230 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6231 if (number == null) {
6232 editor.remove(numberPrefKey);
6233 editor.remove(subscriberPrefKey);
6234 } else {
6235 editor.putString(numberPrefKey, number);
6236 editor.putString(subscriberPrefKey, subscriberId);
6237 }
6238
6239 editor.commit();
6240 return true;
6241 } finally {
6242 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006243 }
Derek Tan7226c842014-07-02 17:42:23 -07006244 }
6245
6246 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006247 public String getLine1NumberForDisplay(int subId, String callingPackage,
6248 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006249 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006251 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006252 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006253 return null;
6254 }
Derek Tan97ebb422014-09-05 16:55:38 -07006255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 final long identity = Binder.clearCallingIdentity();
6257 try {
6258 String iccId = getIccId(subId);
6259 if (iccId != null) {
6260 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6261 if (DBG_MERGE) {
6262 log("getLine1NumberForDisplay returning "
6263 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6264 }
6265 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006266 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6268 return null;
6269 } finally {
6270 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006271 }
Derek Tan7226c842014-07-02 17:42:23 -07006272 }
6273
6274 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006275 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6276 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006277 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006278 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006279 return null;
6280 }
Derek Tan97ebb422014-09-05 16:55:38 -07006281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 final long identity = Binder.clearCallingIdentity();
6283 try {
6284 String iccId = getIccId(subId);
6285 if (iccId != null) {
6286 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6287 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6288 }
6289 return null;
6290 } finally {
6291 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006292 }
Derek Tan7226c842014-07-02 17:42:23 -07006293 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006294
6295 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006296 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6297 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006298 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6299 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006301 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006302 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006303 return null;
6304 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006305
Jordan Liub49b04b2019-05-06 14:45:15 -07006306 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6307 // the process, where TelephonyManager was instantiated.
6308 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006309 final long identity = Binder.clearCallingIdentity();
6310 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006311 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006312 final TelephonyManager tele = TelephonyManager.from(context);
6313 final SubscriptionManager sub = SubscriptionManager.from(context);
6314
6315 // Figure out what subscribers are currently active
6316 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317
Jordan Liub49b04b2019-05-06 14:45:15 -07006318 // Only consider subs which match the current subId
6319 // This logic can be simplified. See b/131189269 for progress.
6320 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006321 activeSubscriberIds.add(tele.getSubscriberId(subId));
6322 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323
6324 // First pass, find a number override for an active subscriber
6325 String mergeNumber = null;
6326 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6327 for (String key : prefs.keySet()) {
6328 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6329 final String subscriberId = (String) prefs.get(key);
6330 if (activeSubscriberIds.contains(subscriberId)) {
6331 final String iccId = key.substring(
6332 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6333 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6334 mergeNumber = (String) prefs.get(numberKey);
6335 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006336 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 + " for active subscriber " + subscriberId);
6338 }
6339 if (!TextUtils.isEmpty(mergeNumber)) {
6340 break;
6341 }
6342 }
6343 }
6344 }
6345
6346 // Shortcut when no active merged subscribers
6347 if (TextUtils.isEmpty(mergeNumber)) {
6348 return null;
6349 }
6350
6351 // Second pass, find all subscribers under that line override
6352 final ArraySet<String> result = new ArraySet<>();
6353 for (String key : prefs.keySet()) {
6354 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6355 final String number = (String) prefs.get(key);
6356 if (mergeNumber.equals(number)) {
6357 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6358 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6359 final String subscriberId = (String) prefs.get(subscriberKey);
6360 if (!TextUtils.isEmpty(subscriberId)) {
6361 result.add(subscriberId);
6362 }
6363 }
6364 }
6365 }
6366
6367 final String[] resultArray = result.toArray(new String[result.size()]);
6368 Arrays.sort(resultArray);
6369 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006370 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6372 }
6373 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006374 } finally {
6375 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006376 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006377 }
6378
6379 @Override
zoey chen38003472019-12-13 17:16:31 +08006380 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6381 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006382
6383 final long identity = Binder.clearCallingIdentity();
6384 try {
6385 final TelephonyManager telephonyManager = mApp.getSystemService(
6386 TelephonyManager.class);
6387 String subscriberId = telephonyManager.getSubscriberId(subId);
6388 if (subscriberId == null) {
6389 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006390 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006391 + subId);
6392 }
6393 return null;
6394 }
6395
6396 final SubscriptionInfo info = SubscriptionController.getInstance()
6397 .getSubscriptionInfo(subId);
6398 final ParcelUuid groupUuid = info.getGroupUuid();
6399 // If it doesn't belong to any group, return just subscriberId of itself.
6400 if (groupUuid == null) {
6401 return new String[]{subscriberId};
6402 }
6403
6404 // Get all subscriberIds from the group.
6405 final List<String> mergedSubscriberIds = new ArrayList<>();
6406 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006407 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006408 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006409 for (SubscriptionInfo subInfo : groupInfos) {
6410 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6411 if (subscriberId != null) {
6412 mergedSubscriberIds.add(subscriberId);
6413 }
6414 }
6415
6416 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419
6420 }
6421 }
6422
6423 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006424 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006425 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006426 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427
6428 final long identity = Binder.clearCallingIdentity();
6429 try {
6430 final Phone phone = getPhone(subId);
6431 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006435 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006436
6437 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006438 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006439 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6440 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006441 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6442 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443
6444 final long identity = Binder.clearCallingIdentity();
6445 try {
6446 final Phone phone = getPhone(subId);
6447 if (phone == null) {
6448 return false;
6449 }
6450 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6451 cdmaNonRoamingList);
6452 } finally {
6453 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006454 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006455 }
6456
6457 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006458 @Deprecated
6459 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6460 enforceModifyPermission();
6461
6462 int returnValue = 0;
6463 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006464 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006465 if(result.exception == null) {
6466 if (result.result != null) {
6467 byte[] responseData = (byte[])(result.result);
6468 if(responseData.length > oemResp.length) {
6469 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6470 responseData.length + "bytes. Buffer Size is " +
6471 oemResp.length + "bytes.");
6472 }
6473 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6474 returnValue = responseData.length;
6475 }
6476 } else {
6477 CommandException ex = (CommandException) result.exception;
6478 returnValue = ex.getCommandError().ordinal();
6479 if(returnValue > 0) returnValue *= -1;
6480 }
6481 } catch (RuntimeException e) {
6482 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6483 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6484 if(returnValue > 0) returnValue *= -1;
6485 }
6486
6487 return returnValue;
6488 }
6489
6490 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006491 public void setRadioCapability(RadioAccessFamily[] rafs) {
6492 try {
6493 ProxyController.getInstance().setRadioCapability(rafs);
6494 } catch (RuntimeException e) {
6495 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6496 }
6497 }
6498
6499 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006500 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006501 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006502 try {
6503 TelephonyPermissions
6504 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6505 mApp, phone.getSubId(), "getRadioAccessFamily");
6506 } catch (SecurityException e) {
6507 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6508 throw e;
6509 }
chen xub97461a2018-10-26 14:17:57 -07006510 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006511 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006512 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006513 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514 final long identity = Binder.clearCallingIdentity();
6515 try {
chen xub97461a2018-10-26 14:17:57 -07006516 TelephonyPermissions
6517 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6518 mApp, phone.getSubId(), "getRadioAccessFamily");
6519 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520 } finally {
6521 Binder.restoreCallingIdentity(identity);
6522 }
chen xub97461a2018-10-26 14:17:57 -07006523 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006524 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006525
6526 @Override
6527 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006528 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006529 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530
6531 final long identity = Binder.clearCallingIdentity();
6532 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006533 ImsManager.getInstance(defaultPhone.getContext(),
6534 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535 } finally {
6536 Binder.restoreCallingIdentity(identity);
6537 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006538 }
6539
6540 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006541 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006542 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6544 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006545 return false;
6546 }
Svet Ganovb320e182015-04-16 12:30:10 -07006547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 final long identity = Binder.clearCallingIdentity();
6549 try {
6550 // Check the user preference and the system-level IMS setting. Even if the user has
6551 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6552 // In the long run, we may instead need to check if there exists a connection service
6553 // which can support video calling.
6554 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006555 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 return imsManager.isVtEnabledByPlatform()
6557 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6558 && imsManager.isVtEnabledByUser();
6559 } finally {
6560 Binder.restoreCallingIdentity(identity);
6561 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006562 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006563
Andrew Leea1239f22015-03-02 17:44:07 -08006564 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006565 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6566 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006568 mApp, subId, callingPackage, callingFeatureId,
6569 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 return false;
6571 }
6572
6573 final long identity = Binder.clearCallingIdentity();
6574 try {
6575 CarrierConfigManager configManager =
6576 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006577 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6579 } finally {
6580 Binder.restoreCallingIdentity(identity);
6581 }
Andrew Leea1239f22015-03-02 17:44:07 -08006582 }
6583
6584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006585 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006587 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588 return false;
6589 }
6590
6591 final long identity = Binder.clearCallingIdentity();
6592 try {
6593 CarrierConfigManager configManager =
6594 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006595 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006596 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6597 } finally {
6598 Binder.restoreCallingIdentity(identity);
6599 }
Andrew Leea1239f22015-03-02 17:44:07 -08006600 }
6601
Andrew Lee9431b832015-03-09 18:46:45 -07006602 @Override
6603 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006604 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006605 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006606 }
6607
6608 @Override
6609 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 final long identity = Binder.clearCallingIdentity();
6611 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006612 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006613 } finally {
6614 Binder.restoreCallingIdentity(identity);
6615 }
Andrew Lee9431b832015-03-09 18:46:45 -07006616 }
6617
Hall Liuf6668912018-10-31 17:05:23 -07006618 /**
6619 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6620 * support for the feature and device firmware support.
6621 *
6622 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6623 */
6624 @Override
6625 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006627 final Phone phone = getPhone(subscriptionId);
6628 if (phone == null) {
6629 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6630 return false;
6631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006632 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006633 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6635 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006636 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637 return isCarrierSupported && isDeviceSupported;
6638 } finally {
6639 Binder.restoreCallingIdentity(identity);
6640 }
Hall Liu98187582018-01-22 19:15:32 -08006641 }
6642
Hall Liuf6668912018-10-31 17:05:23 -07006643 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006644 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6645 * RTT setting, will return true if the device and carrier both support RTT.
6646 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006647 */
6648 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 final long identity = Binder.clearCallingIdentity();
6650 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006651 boolean isRttSupported = isRttSupported(subscriptionId);
6652 boolean isUserRttSettingOn = Settings.Secure.getInt(
6653 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6654 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6655 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6656 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 } finally {
6658 Binder.restoreCallingIdentity(identity);
6659 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006660 }
6661
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006662 @Deprecated
6663 @Override
6664 public String getDeviceId(String callingPackage) {
6665 return getDeviceIdWithFeature(callingPackage, null);
6666 }
6667
Sanket Padawe7310cc72015-01-14 09:53:20 -08006668 /**
6669 * Returns the unique device ID of phone, for example, the IMEI for
6670 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6671 *
6672 * <p>Requires Permission:
6673 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6674 */
6675 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006676 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006677 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006678 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006679 return null;
6680 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006681 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006682 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006683 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006684 return null;
6685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006686
6687 final long identity = Binder.clearCallingIdentity();
6688 try {
6689 return phone.getDeviceId();
6690 } finally {
6691 Binder.restoreCallingIdentity(identity);
6692 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006693 }
6694
Ping Sunc67b7c22016-03-02 19:16:45 +08006695 /**
6696 * {@hide}
6697 * Returns the IMS Registration Status on a particular subid
6698 *
6699 * @param subId
6700 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006701 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006702 Phone phone = getPhone(subId);
6703 if (phone != null) {
6704 return phone.isImsRegistered();
6705 } else {
6706 return false;
6707 }
6708 }
6709
Santos Cordon7a1885b2015-02-03 11:15:19 -08006710 @Override
6711 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 final long identity = Binder.clearCallingIdentity();
6713 try {
6714 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6715 } finally {
6716 Binder.restoreCallingIdentity(identity);
6717 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006718 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006719
Tyler Gunnf70ed162019-04-03 15:28:53 -07006720 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006721 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006722 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006724 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006725 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6726 }
6727 final long identity = Binder.clearCallingIdentity();
6728 try {
6729 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6730 } finally {
6731 Binder.restoreCallingIdentity(identity);
6732 }
6733 }
6734
6735 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006736 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006737 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6738 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006739 final long identity = Binder.clearCallingIdentity();
6740 try {
6741 Phone phone = getPhone(subscriptionId);
6742 if (phone == null) {
6743 return null;
6744 }
6745 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6746 } finally {
6747 Binder.restoreCallingIdentity(identity);
6748 }
6749 }
6750
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006751 /**
6752 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006753 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006754 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755 final long identity = Binder.clearCallingIdentity();
6756 try {
6757 Phone phone = getPhone(subId);
6758 if (phone != null) {
6759 return phone.isWifiCallingEnabled();
6760 } else {
6761 return false;
6762 }
6763 } finally {
6764 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006765 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006766 }
6767
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006768 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006769 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006770 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006771 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 final long identity = Binder.clearCallingIdentity();
6773 try {
6774 Phone phone = getPhone(subId);
6775 if (phone != null) {
6776 return phone.isVideoEnabled();
6777 } else {
6778 return false;
6779 }
6780 } finally {
6781 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006782 }
6783 }
6784
6785 /**
6786 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6787 * defined in {@link ImsRegistrationImplBase}.
6788 */
6789 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006790 final long identity = Binder.clearCallingIdentity();
6791 try {
6792 Phone phone = getPhone(subId);
6793 if (phone != null) {
6794 return phone.getImsRegistrationTech();
6795 } else {
6796 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6797 }
6798 } finally {
6799 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006800 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006801 }
6802
Stuart Scott8eef64f2015-04-08 15:13:54 -07006803 @Override
6804 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006805 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006806 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6807 return;
6808 }
6809
Svet Ganovcc087f82015-05-12 20:35:54 -07006810 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006811
Svet Ganovcc087f82015-05-12 20:35:54 -07006812 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006813 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6814 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006815 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006816 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006817 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006818 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006819 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6820 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006821 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006822 // There has been issues when Sms raw table somehow stores orphan
6823 // fragments. They lead to garbled message when new fragments come
6824 // in and combined with those stale ones. In case this happens again,
6825 // user can reset all network settings which will clean up this table.
6826 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006827 // Clean up IMS settings as well here.
6828 int slotId = getSlotIndex(subId);
6829 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6830 ImsManager.getInstance(mApp, slotId).factoryReset();
6831 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006832
6833 // Erase modem config if erase modem on network setting is enabled.
6834 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6835 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6836 if (configValue != null && Boolean.parseBoolean(configValue)) {
6837 sendEraseModemConfig(getDefaultPhone());
6838 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006839 } finally {
6840 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006841 }
6842 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006843
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006844 private void cleanUpSmsRawTable(Context context) {
6845 ContentResolver resolver = context.getContentResolver();
6846 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6847 resolver.delete(uri, null, null);
6848 }
6849
Narayan Kamath1c496c22015-04-16 14:40:19 +01006850 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006851 public String getSimLocaleForSubscriber(int subId) {
6852 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6853 final Phone phone = getPhone(subId);
6854 if (phone == null) {
6855 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006856 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858 final long identity = Binder.clearCallingIdentity();
6859 try {
chen xu5d3637b2019-01-21 23:31:38 -08006860 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006861 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006862 if (info == null) {
6863 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6864 return null;
6865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006866 // Try and fetch the locale from the carrier properties or from the SIM language
6867 // preferences (EF-PL and EF-LI)...
6868 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006870 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6871 if (localeFromDefaultSim != null) {
6872 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6873 if (DBG) log("Using locale from subId: " + subId + " locale: "
6874 + localeFromDefaultSim);
6875 return localeFromDefaultSim.toLanguageTag();
6876 } else {
6877 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006878 }
6879 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 // The SIM language preferences only store a language (e.g. fr = French), not an
6882 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6883 // the SIM and carrier preferences does not include a country we add the country
6884 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006885 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006887 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 return mccLocale.toLanguageTag();
6889 }
6890
6891 if (DBG) log("No locale found - returning null");
6892 return null;
6893 } finally {
6894 Binder.restoreCallingIdentity(identity);
6895 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006896 }
6897
6898 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006899 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006900 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006901 }
6902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 /**
6904 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6905 */
6906 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006907 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006908 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006909 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006910
Chenjie Yu1ba97252018-01-11 18:16:20 -08006911 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006912 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006913
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006914 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006915 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6916 * representing the state of the modem.
6917 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006918 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6919 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006920 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006921 */
6922 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006923 public void requestModemActivityInfo(ResultReceiver result) {
6924 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006926
6927 final long identity = Binder.clearCallingIdentity();
6928 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006929 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930 } finally {
6931 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006932 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006933 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006934
Siddharth Rayb8114062018-06-17 15:02:38 -07006935 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6936 // less than total activity duration.
6937 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6938 if (info == null) {
6939 return false;
6940 }
6941 int activityDurationMs =
6942 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6943 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006944 int[] txTimeMs = info.getTransmitTimeMillis();
6945 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6946 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006947 }
6948 return (info.isValid()
6949 && (info.getSleepTimeMillis() <= activityDurationMs)
6950 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006951 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006952 && (totalTxTimeMs <= activityDurationMs));
6953 }
6954
Jack Yu85bd38a2015-11-09 11:34:32 -08006955 /**
6956 * {@hide}
6957 * Returns the service state information on specified subscription.
6958 */
6959 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006960 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6961 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006963 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006964 return null;
6965 }
6966
Hall Liuf19c44f2018-11-27 14:38:17 -08006967 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6968 LocationAccessPolicy.checkLocationPermission(mApp,
6969 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6970 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006971 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006972 .setCallingPid(Binder.getCallingPid())
6973 .setCallingUid(Binder.getCallingUid())
6974 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006975 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006976 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006977 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6978 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006979 .build());
6980
6981 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6982 LocationAccessPolicy.checkLocationPermission(mApp,
6983 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6984 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006985 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006986 .setCallingPid(Binder.getCallingPid())
6987 .setCallingUid(Binder.getCallingUid())
6988 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006989 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006990 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006991 .setMinSdkVersionForFine(Integer.MAX_VALUE)
6992 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006993 .build());
6994 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6995 boolean hasFinePermission =
6996 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6997 boolean hasCoarsePermission =
6998 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000 final long identity = Binder.clearCallingIdentity();
7001 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007002 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7003 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7004 Rlog.d(LOG_TAG,
7005 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7006 return null;
7007 }
7008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009 final Phone phone = getPhone(subId);
7010 if (phone == null) {
7011 return null;
7012 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007013
Hall Liuf19c44f2018-11-27 14:38:17 -08007014 ServiceState ss = phone.getServiceState();
7015
7016 // Scrub out the location info in ServiceState depending on what level of access
7017 // the caller has.
7018 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007019 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7020 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021 } finally {
7022 Binder.restoreCallingIdentity(identity);
7023 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007024 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007025
7026 /**
7027 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7028 *
7029 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7030 * voicemail ringtone.
7031 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7032 * PhoneAccount.
7033 */
7034 @Override
7035 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 final long identity = Binder.clearCallingIdentity();
7037 try {
7038 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7039 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007040 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7044 } finally {
7045 Binder.restoreCallingIdentity(identity);
7046 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007047 }
7048
7049 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007050 * Sets the per-account voicemail ringtone.
7051 *
7052 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7053 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7054 *
7055 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7056 * voicemail ringtone.
7057 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7058 * PhoneAccount.
7059 */
7060 @Override
7061 public void setVoicemailRingtoneUri(String callingPackage,
7062 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007063 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007064 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007065 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7066 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7068 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7069 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071
7072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7075 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007076 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077 }
7078 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7079 } finally {
7080 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007081 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007082 }
7083
7084 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007085 * Returns whether vibration is set for voicemail notification in Phone settings.
7086 *
7087 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7088 * voicemail vibration setting.
7089 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7090 */
7091 @Override
7092 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093 final long identity = Binder.clearCallingIdentity();
7094 try {
7095 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7096 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007097 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7101 } finally {
7102 Binder.restoreCallingIdentity(identity);
7103 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007104 }
7105
Youhan Wange64578a2016-05-02 15:32:42 -07007106 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007107 * Sets the per-account voicemail vibration.
7108 *
7109 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7110 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7111 *
7112 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7113 * voicemail vibration setting.
7114 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7115 * specific PhoneAccount.
7116 */
7117 @Override
7118 public void setVoicemailVibrationEnabled(String callingPackage,
7119 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007120 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007121 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007122 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7123 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7125 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7126 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007127 }
7128
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129 final long identity = Binder.clearCallingIdentity();
7130 try {
7131 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7132 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007133 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134 }
7135 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7136 } finally {
7137 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007138 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007139 }
7140
7141 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007142 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7143 *
7144 * @throws SecurityException if the caller does not have the required permission
7145 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007146 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007147 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007148 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007149 }
7150
7151 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007152 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7153 * permission.
7154 *
7155 * @throws SecurityException if the caller does not have the required permission
7156 */
7157 private void enforceSendSmsPermission() {
7158 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7159 }
7160
7161 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007162 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007163 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007164 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007165 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007166 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167 final long identity = Binder.clearCallingIdentity();
7168 try {
7169 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007170 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 if (componentName == null) {
7172 throw new SecurityException(
7173 "Caller not current active visual voicemail package[null]");
7174 }
7175 String vvmPackage = componentName.getPackageName();
7176 if (!callingPackage.equals(vvmPackage)) {
7177 throw new SecurityException("Caller not current active visual voicemail package["
7178 + vvmPackage + "]");
7179 }
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007182 }
7183 }
7184
7185 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007186 * Return the application ID for the app type.
7187 *
7188 * @param subId the subscription ID that this request applies to.
7189 * @param appType the uicc app type.
7190 * @return Application ID for specificied app type, or null if no uicc.
7191 */
7192 @Override
7193 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007194 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007195 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196
7197 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007198 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199 if (phone == null) {
7200 return null;
7201 }
7202 String aid = null;
7203 try {
7204 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7205 .getApplicationByType(appType).getAid();
7206 } catch (Exception e) {
7207 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7208 }
7209 return aid;
7210 } finally {
7211 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007212 }
Youhan Wange64578a2016-05-02 15:32:42 -07007213 }
7214
Youhan Wang4001d252016-05-11 10:29:41 -07007215 /**
7216 * Return the Electronic Serial Number.
7217 *
7218 * @param subId the subscription ID that this request applies to.
7219 * @return ESN or null if error.
7220 */
7221 @Override
7222 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007223 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007224 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225
7226 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007227 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 if (phone == null) {
7229 return null;
7230 }
7231 String esn = null;
7232 try {
7233 esn = phone.getEsn();
7234 } catch (Exception e) {
7235 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7236 }
7237 return esn;
7238 } finally {
7239 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007240 }
Youhan Wang4001d252016-05-11 10:29:41 -07007241 }
7242
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007243 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007244 * Return the Preferred Roaming List Version.
7245 *
7246 * @param subId the subscription ID that this request applies to.
7247 * @return PRLVersion or null if error.
7248 */
7249 @Override
7250 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007251 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007252 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253
7254 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007255 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 if (phone == null) {
7257 return null;
7258 }
7259 String cdmaPrlVersion = null;
7260 try {
7261 cdmaPrlVersion = phone.getCdmaPrlVersion();
7262 } catch (Exception e) {
7263 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7264 }
7265 return cdmaPrlVersion;
7266 } finally {
7267 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007268 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007269 }
7270
7271 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007272 * Get snapshot of Telephony histograms
7273 * @return List of Telephony histograms
7274 * @hide
7275 */
7276 @Override
7277 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7279 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280
7281 final long identity = Binder.clearCallingIdentity();
7282 try {
7283 return RIL.getTelephonyRILTimingHistograms();
7284 } finally {
7285 Binder.restoreCallingIdentity(identity);
7286 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007287 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007288
7289 /**
7290 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007291 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7292 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007293 * Require system privileges. In the future we may add this to carrier APIs.
7294 *
Michele Berionne482f8202018-11-27 18:57:59 -08007295 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007296 */
7297 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007298 @TelephonyManager.SetCarrierRestrictionResult
7299 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007300 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007301 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007302
Michele Berionne482f8202018-11-27 18:57:59 -08007303 if (carrierRestrictionRules == null) {
7304 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007305 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007307 final long identity = Binder.clearCallingIdentity();
7308 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007309 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007310 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311 } finally {
7312 Binder.restoreCallingIdentity(identity);
7313 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007314 }
7315
7316 /**
7317 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007318 * Get the allowed carrier list and the excluded carrier list, including the priority between
7319 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007320 * Require system privileges. In the future we may add this to carrier APIs.
7321 *
Michele Berionne482f8202018-11-27 18:57:59 -08007322 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007323 */
7324 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007325 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007326 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007327 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007328
7329 final long identity = Binder.clearCallingIdentity();
7330 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007331 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7332 if (response instanceof CarrierRestrictionRules) {
7333 return (CarrierRestrictionRules) response;
7334 }
7335 // Response is an Exception of some kind,
7336 // which is signalled to the user as a NULL retval
7337 return null;
7338 } catch (Exception e) {
7339 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7340 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007344 }
7345
fionaxu59545b42016-05-25 15:53:37 -07007346 /**
fionaxu59545b42016-05-25 15:53:37 -07007347 * Action set from carrier signalling broadcast receivers to enable/disable radio
7348 * @param subId the subscription ID that this action applies to.
7349 * @param enabled control enable or disable radio.
7350 * {@hide}
7351 */
7352 @Override
7353 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7354 enforceModifyPermission();
7355 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356
7357 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007358 if (phone == null) {
7359 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7360 return;
7361 }
7362 try {
7363 phone.carrierActionSetRadioEnabled(enabled);
7364 } catch (Exception e) {
7365 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007368 }
7369 }
7370
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007371 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007372 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7373 * network status based on which carrier apps could apply actions accordingly,
7374 * enable/disable default url handler for example.
7375 *
7376 * @param subId the subscription ID that this action applies to.
7377 * @param report control start/stop reporting the default network status.
7378 * {@hide}
7379 */
7380 @Override
7381 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7382 enforceModifyPermission();
7383 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384
7385 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007386 if (phone == null) {
7387 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7388 return;
7389 }
7390 try {
7391 phone.carrierActionReportDefaultNetworkStatus(report);
7392 } catch (Exception e) {
7393 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007394 } finally {
7395 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007396 }
7397 }
7398
7399 /**
fionaxud9622282017-07-17 17:51:30 -07007400 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7401 * @param subId the subscription ID that this action applies to.
7402 * {@hide}
7403 */
7404 @Override
7405 public void carrierActionResetAll(int subId) {
7406 enforceModifyPermission();
7407 final Phone phone = getPhone(subId);
7408 if (phone == null) {
7409 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7410 return;
7411 }
7412 try {
7413 phone.carrierActionResetAll();
7414 } catch (Exception e) {
7415 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7416 }
7417 }
7418
7419 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007420 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7421 * bug report is being generated.
7422 */
7423 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007424 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007425 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7426 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007427 writer.println("Permission Denial: can't dump Phone from pid="
7428 + Binder.getCallingPid()
7429 + ", uid=" + Binder.getCallingUid()
7430 + "without permission "
7431 + android.Manifest.permission.DUMP);
7432 return;
7433 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007434 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007435 }
Jack Yueb89b242016-06-22 13:27:47 -07007436
Brad Ebingerdac2f002018-04-03 15:17:52 -07007437 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007438 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7439 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7440 @NonNull String[] args) {
7441 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7442 this, in.getFileDescriptor(), out.getFileDescriptor(),
7443 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007444 }
7445
Jack Yueb89b242016-06-22 13:27:47 -07007446 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007447 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007448 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007449 * @param reason the reason the data enable change is taking place
7450 * @param enabled True if enabling the data, otherwise disabling.
7451 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007452 */
7453 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007454 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007455 boolean enabled) {
7456 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7457 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7458 try {
7459 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007460 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007461 } catch (SecurityException se) {
7462 enforceModifyPermission();
7463 }
7464 } else {
7465 enforceModifyPermission();
7466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467
7468 final long identity = Binder.clearCallingIdentity();
7469 try {
7470 Phone phone = getPhone(subId);
7471 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007472 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7473 phone.carrierActionSetMeteredApnsEnabled(enabled);
7474 } else {
7475 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 }
7478 } finally {
7479 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007480 }
7481 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007482
7483 /**
7484 * Get Client request stats
7485 * @return List of Client Request Stats
7486 * @hide
7487 */
7488 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007489 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7490 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007492 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007493 return null;
7494 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007495 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007496
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 final long identity = Binder.clearCallingIdentity();
7498 try {
7499 if (phone != null) {
7500 return phone.getClientRequestStats();
7501 }
7502
7503 return null;
7504 } finally {
7505 Binder.restoreCallingIdentity(identity);
7506 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007507 }
7508
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007509 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007510 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007511 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007512 }
Jack Yueb4124c2017-02-16 15:32:43 -08007513
7514 /**
Grace Chen70990072017-03-24 17:21:30 -07007515 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007516 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007517 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007518 * @param state State of SIM (power down, power up, pass through)
7519 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7520 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7521 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007522 *
7523 **/
7524 @Override
Grace Chen70990072017-03-24 17:21:30 -07007525 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007526 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007527 Phone phone = PhoneFactory.getPhone(slotIndex);
7528
vagdeviaf9a5b92018-08-15 16:01:53 -07007529 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 final long identity = Binder.clearCallingIdentity();
7532 try {
7533 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007534 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 }
7536 } finally {
7537 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007538 }
7539 }
Shuo Qiandd210312017-04-12 22:11:33 +00007540
Tyler Gunn65d45c22017-06-05 11:22:26 -07007541 private boolean isUssdApiAllowed(int subId) {
7542 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007543 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007544 if (configManager == null) {
7545 return false;
7546 }
7547 PersistableBundle pb = configManager.getConfigForSubId(subId);
7548 if (pb == null) {
7549 return false;
7550 }
7551 return pb.getBoolean(
7552 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7553 }
7554
Shuo Qiandd210312017-04-12 22:11:33 +00007555 /**
7556 * Check if phone is in emergency callback mode
7557 * @return true if phone is in emergency callback mode
7558 * @param subId sub id
7559 */
goneil9c5f4872017-12-05 14:07:56 -08007560 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007561 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007562 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007563 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564
7565 final long identity = Binder.clearCallingIdentity();
7566 try {
7567 if (phone != null) {
7568 return phone.isInEcm();
7569 } else {
7570 return false;
7571 }
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007574 }
7575 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007576
7577 /**
7578 * Get the current signal strength information for the given subscription.
7579 * Because this information is not updated when the device is in a low power state
7580 * it should not be relied-upon to be current.
7581 * @param subId Subscription index
7582 * @return the most recent cached signal strength info from the modem
7583 */
7584 @Override
7585 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007586 final long identity = Binder.clearCallingIdentity();
7587 try {
7588 Phone p = getPhone(subId);
7589 if (p == null) {
7590 return null;
7591 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 return p.getSignalStrength();
7594 } finally {
7595 Binder.restoreCallingIdentity(identity);
7596 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007597 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007598
Pengquan Meng77b7f132018-08-22 14:49:57 -07007599 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007600 * Get the current modem radio state for the given slot.
7601 * @param slotIndex slot index.
7602 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007603 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007604 * @return the current radio power state from the modem
7605 */
7606 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007607 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007608 Phone phone = PhoneFactory.getPhone(slotIndex);
7609 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7611 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007612 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7613 }
7614
7615 final long identity = Binder.clearCallingIdentity();
7616 try {
7617 return phone.getRadioPowerState();
7618 } finally {
7619 Binder.restoreCallingIdentity(identity);
7620 }
7621 }
7622 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7623 }
7624
7625 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007626 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7627 *
7628 * <p>Requires one of the following permissions:
7629 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7630 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7631 * privileges.
7632 *
7633 * @param subId subscription id
7634 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7635 * {@code false}.
7636 */
7637 @Override
7638 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07007639 try {
7640 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7641 null);
7642 } catch (Exception e) {
7643 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7644 mApp, subId, "isDataRoamingEnabled");
7645 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007646
Pengquan Menga1bb6272018-09-06 09:59:22 -07007647 boolean isEnabled = false;
7648 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007649 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007650 Phone phone = getPhone(subId);
7651 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007652 } finally {
7653 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007654 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007655 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007656 }
7657
7658
7659 /**
7660 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7661 *
7662 * <p> Requires permission:
7663 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7664 * privileges.
7665 *
7666 * @param subId subscription id
7667 * @param isEnabled {@code true} means enable, {@code false} means disable.
7668 */
7669 @Override
7670 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7672 mApp, subId, "setDataRoamingEnabled");
7673
Pengquan Menga1bb6272018-09-06 09:59:22 -07007674 final long identity = Binder.clearCallingIdentity();
7675 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007676 Phone phone = getPhone(subId);
7677 if (phone != null) {
7678 phone.setDataRoamingEnabled(isEnabled);
7679 }
7680 } finally {
7681 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007682 }
7683 }
7684
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007685 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007686 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007687 TelephonyPermissions
7688 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007689 mApp, subId, "isManualNetworkSelectionAllowed");
7690
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007691 boolean isAllowed = true;
7692 final long identity = Binder.clearCallingIdentity();
7693 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007694 Phone phone = getPhone(subId);
7695 if (phone != null) {
7696 isAllowed = phone.isCspPlmnEnabled();
7697 }
7698 } finally {
7699 Binder.restoreCallingIdentity(identity);
7700 }
7701 return isAllowed;
7702 }
7703
7704 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007705 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007706 // Verify that tha callingPackage belongs to the calling UID
7707 mApp.getSystemService(AppOpsManager.class)
7708 .checkPackage(Binder.getCallingUid(), callingPackage);
7709
Jordan Liu1e142fc2019-04-22 15:10:43 -07007710 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007711 try {
7712 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007713 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007714 } catch (SecurityException e) {
7715 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7716 // has carrier privileges on an active UICC
7717 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7718 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007719 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007720 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007721 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007722
7723 final long identity = Binder.clearCallingIdentity();
7724 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007725 UiccController uiccController = UiccController.getInstance();
7726 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007727 if (hasReadPermission) {
7728 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007729 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007730
7731 // Remove private info if the caller doesn't have access
7732 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7733 for (UiccCardInfo cardInfo : cardInfos) {
7734 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7735 // is available
7736 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7737 if (card == null || card.getUiccProfile() == null) {
7738 // assume no access if the card or profile is unavailable
7739 filteredInfos.add(cardInfo.getUnprivileged());
7740 continue;
7741 }
7742 UiccProfile profile = card.getUiccProfile();
7743 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7744 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7745 filteredInfos.add(cardInfo);
7746 } else {
7747 filteredInfos.add(cardInfo.getUnprivileged());
7748 }
7749 }
7750 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007751 } finally {
7752 Binder.restoreCallingIdentity(identity);
7753 }
7754 }
7755
7756 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007757 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007758 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 final long identity = Binder.clearCallingIdentity();
7761 try {
7762 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7763 if (slots == null) {
7764 Rlog.i(LOG_TAG, "slots is null.");
7765 return null;
7766 }
7767
7768 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7769 for (int i = 0; i < slots.length; i++) {
7770 UiccSlot slot = slots[i];
7771 if (slot == null) {
7772 continue;
7773 }
7774
Jordan Liu7be7e652019-05-06 18:55:02 +00007775 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776 UiccCard card = slot.getUiccCard();
7777 if (card != null) {
7778 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007779 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007780 cardId = slot.getEid();
7781 if (TextUtils.isEmpty(cardId)) {
7782 cardId = slot.getIccId();
7783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784 }
7785
Jordan Liu857451f2019-05-09 16:35:35 -07007786 if (cardId != null) {
7787 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7788 // if cardId is an EID, it's all digits so this is fine
7789 cardId = IccUtils.stripTrailingFs(cardId);
7790 }
7791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 int cardState = 0;
7793 switch (slot.getCardState()) {
7794 case CARDSTATE_ABSENT:
7795 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7796 break;
7797 case CARDSTATE_PRESENT:
7798 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7799 break;
7800 case CARDSTATE_ERROR:
7801 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7802 break;
7803 case CARDSTATE_RESTRICTED:
7804 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7805 break;
7806 default:
7807 break;
7808
7809 }
7810
7811 infos[i] = new UiccSlotInfo(
7812 slot.isActive(),
7813 slot.isEuicc(),
7814 cardId,
7815 cardState,
7816 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007817 slot.isExtendedApduSupported(),
7818 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 }
7820 return infos;
7821 } finally {
7822 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007823 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007824 }
7825
7826 @Override
7827 public boolean switchSlots(int[] physicalSlots) {
7828 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829
7830 final long identity = Binder.clearCallingIdentity();
7831 try {
7832 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7833 } finally {
7834 Binder.restoreCallingIdentity(identity);
7835 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007836 }
Jack Yu4c988042018-02-27 15:30:01 -08007837
7838 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007839 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007840 final long identity = Binder.clearCallingIdentity();
7841 try {
7842 return UiccController.getInstance().getCardIdForDefaultEuicc();
7843 } finally {
7844 Binder.restoreCallingIdentity(identity);
7845 }
7846 }
7847
Pengquan Meng85728fb2018-03-12 16:31:21 -07007848 /**
goneil47ffb6e2018-04-06 15:40:58 -07007849 * A test API to reload the UICC profile.
7850 *
7851 * <p>Requires that the calling app has permission
7852 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7853 * @hide
7854 */
7855 @Override
7856 public void refreshUiccProfile(int subId) {
7857 enforceModifyPermission();
7858
7859 final long identity = Binder.clearCallingIdentity();
7860 try {
7861 Phone phone = getPhone(subId);
7862 if (phone == null) {
7863 return;
7864 }
7865 UiccCard uiccCard = phone.getUiccCard();
7866 if (uiccCard == null) {
7867 return;
7868 }
7869 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7870 if (uiccProfile == null) {
7871 return;
7872 }
7873 uiccProfile.refresh();
7874 } finally {
7875 Binder.restoreCallingIdentity(identity);
7876 }
7877 }
7878
7879 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007880 * Returns false if the mobile data is disabled by default, otherwise return true.
7881 */
7882 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007883 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007884 }
7885
7886 /**
7887 * Returns true if the data roaming is enabled by default, i.e the system property
7888 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7889 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7890 */
7891 private boolean getDefaultDataRoamingEnabled(int subId) {
7892 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007893 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07007894 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007895 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7896 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7897 return isDataRoamingEnabled;
7898 }
7899
7900 /**
7901 * Returns the default network type for the given {@code subId}, if the default network type is
7902 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7903 */
7904 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007905 List<Integer> list = TelephonyProperties.default_network();
7906 int phoneId = mSubscriptionController.getPhoneId(subId);
7907 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7908 return list.get(phoneId);
7909 }
7910 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007911 }
fionaxua13278b2018-03-21 00:08:13 -07007912
7913 @Override
7914 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007915 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007916 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917
7918 final long identity = Binder.clearCallingIdentity();
7919 try {
7920 final Phone phone = getPhone(subId);
7921 if (phone == null) {
7922 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7923 return;
7924 }
chen xueaba88a2019-03-15 13:15:10 -07007925 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7926 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07007927 if (carrierPrivilegeRules == null) {
7928 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7929 } else {
7930 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 } finally {
7933 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007934 }
fionaxua13278b2018-03-21 00:08:13 -07007935 }
7936
7937 @Override
7938 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007939 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940
7941 final long identity = Binder.clearCallingIdentity();
7942 try {
7943 final Phone phone = getPhone(subId);
7944 if (phone == null) {
7945 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7946 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7947 }
7948 return phone.getCarrierIdListVersion();
7949 } finally {
7950 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007951 }
fionaxua13278b2018-03-21 00:08:13 -07007952 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007953
7954 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007955 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7956 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007958 mApp, subId, callingPackage, callingFeatureId,
7959 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007960 return -1;
7961 }
7962
7963 final long identity = Binder.clearCallingIdentity();
7964 try {
7965 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7966 } finally {
7967 Binder.restoreCallingIdentity(identity);
7968 }
7969 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007970
7971 @Override
7972 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007973 TelephonyPermissions
7974 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007975 mApp, subId, "getCdmaRoamingMode");
7976
7977 final long identity = Binder.clearCallingIdentity();
7978 try {
7979 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7980 } finally {
7981 Binder.restoreCallingIdentity(identity);
7982 }
7983 }
7984
7985 @Override
7986 public boolean setCdmaRoamingMode(int subId, int mode) {
7987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7988 mApp, subId, "setCdmaRoamingMode");
7989
7990 final long identity = Binder.clearCallingIdentity();
7991 try {
7992 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7993 } finally {
7994 Binder.restoreCallingIdentity(identity);
7995 }
7996 }
7997
7998 @Override
7999 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8001 mApp, subId, "setCdmaSubscriptionMode");
8002
8003 final long identity = Binder.clearCallingIdentity();
8004 try {
8005 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8006 } finally {
8007 Binder.restoreCallingIdentity(identity);
8008 }
8009 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008010
sqianc5eccab2018-10-19 18:46:41 -07008011 @Override
sqian8c685422019-02-22 15:55:18 -08008012 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008013 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008015 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8016 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008017 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8018 }
8019 final long identity = Binder.clearCallingIdentity();
8020 try {
sqian854d44b2018-12-12 16:48:18 -08008021 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8022 for (Phone phone: PhoneFactory.getPhones()) {
8023 if (phone.getEmergencyNumberTracker() != null
8024 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8025 emergencyNumberListInternal.put(
8026 phone.getSubId(),
8027 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8028 }
sqian11b7a0e2018-12-05 18:48:28 -08008029 }
sqian854d44b2018-12-12 16:48:18 -08008030 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008031 } finally {
8032 Binder.restoreCallingIdentity(identity);
8033 }
sqianc5eccab2018-10-19 18:46:41 -07008034 }
8035
8036 @Override
sqian8c685422019-02-22 15:55:18 -08008037 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008038 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008039 if (!exactMatch) {
8040 TelephonyPermissions
8041 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008042 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008043 }
8044 final long identity = Binder.clearCallingIdentity();
8045 try {
sqian854d44b2018-12-12 16:48:18 -08008046 for (Phone phone: PhoneFactory.getPhones()) {
8047 if (phone.getEmergencyNumberTracker() != null
8048 && phone.getEmergencyNumberTracker() != null) {
8049 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
8050 number, exactMatch)) {
8051 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008052 }
8053 }
sqian11b7a0e2018-12-05 18:48:28 -08008054 }
8055 return false;
8056 } finally {
8057 Binder.restoreCallingIdentity(identity);
8058 }
8059 }
8060
sqianf4ca7ed2019-01-15 18:32:07 -08008061 /**
8062 * Update emergency number list for test mode.
8063 */
8064 @Override
8065 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8066 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8067 "updateEmergencyNumberListTestMode");
8068
8069 final long identity = Binder.clearCallingIdentity();
8070 try {
8071 for (Phone phone: PhoneFactory.getPhones()) {
8072 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8073 if (tracker != null) {
8074 tracker.executeEmergencyNumberTestModeCommand(action, num);
8075 }
8076 }
8077 } finally {
8078 Binder.restoreCallingIdentity(identity);
8079 }
8080 }
8081
8082 /**
8083 * Get the full emergency number list for test mode.
8084 */
8085 @Override
8086 public List<String> getEmergencyNumberListTestMode() {
8087 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8088 "getEmergencyNumberListTestMode");
8089
8090 final long identity = Binder.clearCallingIdentity();
8091 try {
8092 Set<String> emergencyNumbers = new HashSet<>();
8093 for (Phone phone: PhoneFactory.getPhones()) {
8094 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8095 if (tracker != null) {
8096 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8097 emergencyNumbers.add(num.getNumber());
8098 }
8099 }
8100 }
8101 return new ArrayList<>(emergencyNumbers);
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
8104 }
8105 }
8106
chen xud6b45bd2018-10-30 22:27:10 -07008107 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008108 public int getEmergencyNumberDbVersion(int subId) {
8109 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8110
8111 final long identity = Binder.clearCallingIdentity();
8112 try {
8113 final Phone phone = getPhone(subId);
8114 if (phone == null) {
8115 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8116 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8117 }
8118 return phone.getEmergencyNumberDbVersion();
8119 } finally {
8120 Binder.restoreCallingIdentity(identity);
8121 }
8122 }
8123
8124 @Override
8125 public void notifyOtaEmergencyNumberDbInstalled() {
8126 enforceModifyPermission();
8127
8128 final long identity = Binder.clearCallingIdentity();
8129 try {
8130 for (Phone phone: PhoneFactory.getPhones()) {
8131 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8132 if (tracker != null) {
8133 tracker.updateOtaEmergencyNumberDatabase();
8134 }
8135 }
8136 } finally {
8137 Binder.restoreCallingIdentity(identity);
8138 }
8139 }
8140
8141 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008142 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008143 enforceActiveEmergencySessionPermission();
8144
8145 final long identity = Binder.clearCallingIdentity();
8146 try {
8147 for (Phone phone: PhoneFactory.getPhones()) {
8148 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8149 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008150 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8151 }
8152 }
8153 } finally {
8154 Binder.restoreCallingIdentity(identity);
8155 }
8156 }
8157
8158 @Override
8159 public void resetOtaEmergencyNumberDbFilePath() {
8160 enforceActiveEmergencySessionPermission();
8161
8162 final long identity = Binder.clearCallingIdentity();
8163 try {
8164 for (Phone phone: PhoneFactory.getPhones()) {
8165 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8166 if (tracker != null) {
8167 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008168 }
8169 }
8170 } finally {
8171 Binder.restoreCallingIdentity(identity);
8172 }
8173 }
8174
8175 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008176 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8177 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8178 Phone phone = getPhone(subId);
8179 if (phone == null) {
8180 return null;
8181 }
8182 final long identity = Binder.clearCallingIdentity();
8183 try {
8184 UiccProfile profile = UiccController.getInstance()
8185 .getUiccProfileForPhone(phone.getPhoneId());
8186 if (profile != null) {
8187 return profile.getCertsFromCarrierPrivilegeAccessRules();
8188 }
8189 } finally {
8190 Binder.restoreCallingIdentity(identity);
8191 }
8192 return null;
8193 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008194
8195 /**
8196 * Enable or disable a modem stack.
8197 */
8198 @Override
8199 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8200 enforceModifyPermission();
8201
8202 final long identity = Binder.clearCallingIdentity();
8203 try {
8204 Phone phone = PhoneFactory.getPhone(slotIndex);
8205 if (phone == null) {
8206 return false;
8207 } else {
8208 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8209 }
8210 } finally {
8211 Binder.restoreCallingIdentity(identity);
8212 }
8213 }
Michelecea4cf22018-12-21 15:00:11 -08008214
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008215 /**
8216 * Whether a modem stack is enabled or not.
8217 */
8218 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008219 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8220 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008221 Phone phone = PhoneFactory.getPhone(slotIndex);
8222 if (phone == null) return false;
8223
8224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008225 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8226 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008227 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8228 }
8229
8230 final long identity = Binder.clearCallingIdentity();
8231 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008232 try {
8233 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8234 } catch (NoSuchElementException ex) {
8235 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8236 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
8240 }
8241
Michelecea4cf22018-12-21 15:00:11 -08008242 @Override
Michele0ea7d782019-03-19 14:58:42 -07008243 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008244 enforceModifyPermission();
8245
8246 final long identity = Binder.clearCallingIdentity();
8247 try {
8248 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008249 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008250 .commit();
8251 } finally {
8252 Binder.restoreCallingIdentity(identity);
8253 }
8254 }
8255
8256 @Override
Michele0ea7d782019-03-19 14:58:42 -07008257 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008258 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008260 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8261 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008262 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008263 }
Michelecea4cf22018-12-21 15:00:11 -08008264
8265 final long identity = Binder.clearCallingIdentity();
8266 try {
Michele0ea7d782019-03-19 14:58:42 -07008267 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008268 } finally {
8269 Binder.restoreCallingIdentity(identity);
8270 }
8271 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008272
Michele0ea7d782019-03-19 14:58:42 -07008273 @TelephonyManager.IsMultiSimSupportedResult
8274 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008275 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8276 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8277 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008278 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8279 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008280 }
8281 // Check if the hardware supports multisim functionality. If usage of multisim is not
8282 // supported by the modem, indicate that it is restricted.
8283 PhoneCapability staticCapability =
8284 mPhoneConfigurationManager.getStaticPhoneCapability();
8285 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008286 loge("isMultiSimSupportedInternal: no static configuration available");
8287 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008288 }
Sarah Chin7caee492020-02-18 20:49:02 +00008289 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008290 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8291 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008292 }
8293 // Check if support of multiple SIMs is restricted by carrier
8294 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008295 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008296 }
8297
Michele0ea7d782019-03-19 14:58:42 -07008298 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008299 }
8300
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008301 /**
8302 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008303 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8304 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8305 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008306 * @param numOfSims number of active sims we want to switch to
8307 */
8308 @Override
8309 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008310 if (numOfSims == 1) {
8311 enforceModifyPermission();
8312 } else {
8313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8314 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8315 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008316 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008317
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008318 try {
Michele30b57b22019-03-01 12:01:14 -08008319 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008320 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008321 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8322 return;
8323 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008324 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8325 } finally {
8326 Binder.restoreCallingIdentity(identity);
8327 }
8328 }
8329
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008330 @Override
8331 public boolean isApplicationOnUicc(int subId, int appType) {
8332 enforceReadPrivilegedPermission("isApplicationOnUicc");
8333 Phone phone = getPhone(subId);
8334 if (phone == null) {
8335 return false;
8336 }
8337 final long identity = Binder.clearCallingIdentity();
8338 try {
8339 UiccCard uiccCard = phone.getUiccCard();
8340 if (uiccCard == null) {
8341 return false;
8342 }
8343 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8344 if (uiccProfile == null) {
8345 return false;
8346 }
8347 if (TelephonyManager.APPTYPE_SIM <= appType
8348 && appType <= TelephonyManager.APPTYPE_ISIM) {
8349 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8350 }
8351 return false;
8352 } finally {
8353 Binder.restoreCallingIdentity(identity);
8354 }
8355 }
8356
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008357 /**
chen xub4baa772019-04-03 10:23:41 -07008358 * Get whether making changes to modem configurations will trigger reboot.
8359 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008360 */
8361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008362 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8363 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008365 mApp, subId, callingPackage, callingFeatureId,
8366 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008367 return false;
8368 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008369 final long identity = Binder.clearCallingIdentity();
8370 try {
8371 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8372 } finally {
8373 Binder.restoreCallingIdentity(identity);
8374 }
8375 }
8376
Nathan Harold29f5f052019-02-15 13:41:57 -08008377 private void updateModemStateMetrics() {
8378 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8379 // TODO: check the state for each modem if the api is ready.
8380 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8381 }
8382
Pengquan Meng3889a572019-01-23 11:16:29 -08008383 @Override
8384 public int[] getSlotsMapping() {
8385 enforceReadPrivilegedPermission("getSlotsMapping");
8386
8387 final long identity = Binder.clearCallingIdentity();
8388 try {
8389 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8390 // All logical slots should have a mapping to a physical slot.
8391 int[] logicalSlotsMapping = new int[phoneCount];
8392 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8393 for (int i = 0; i < slotInfos.length; i++) {
8394 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8395 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8396 }
8397 }
8398 return logicalSlotsMapping;
8399 } finally {
8400 Binder.restoreCallingIdentity(identity);
8401 }
8402 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008403
8404 /**
8405 * Get the IRadio HAL Version
8406 */
8407 @Override
8408 public int getRadioHalVersion() {
8409 Phone phone = getDefaultPhone();
8410 if (phone == null) return -1;
8411 HalVersion hv = phone.getHalVersion();
8412 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8413 return hv.major * 100 + hv.minor;
8414 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008415
8416 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008417 * Get the current calling package name.
8418 * @return the current calling package name
8419 */
8420 @Override
8421 public String getCurrentPackageName() {
8422 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8423 }
8424
8425 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008426 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8427 * corresponding network requests on a subId.
8428 *
8429 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008430 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008431 * 2) APN is un-metered for this subscription, or
8432 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008433 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008434 *
8435 * @return whether data is allowed for a apn type.
8436 *
8437 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008438 */
8439 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008440 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008441 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8442 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008443
8444 // Now that all security checks passes, perform the operation as ourselves.
8445 final long identity = Binder.clearCallingIdentity();
8446 try {
8447 Phone phone = getPhone(subId);
8448 if (phone == null) return false;
8449
Jack Yu41407ee2019-05-13 16:54:09 -07008450 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008451 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
8454 }
8455 }
8456
8457 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008458 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008459 enforceReadPrivilegedPermission("isApnMetered");
8460
8461 // Now that all security checks passes, perform the operation as ourselves.
8462 final long identity = Binder.clearCallingIdentity();
8463 try {
8464 Phone phone = getPhone(subId);
8465 if (phone == null) return true; // By default return true.
8466
Jack Yu41407ee2019-05-13 16:54:09 -07008467 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008468 } finally {
8469 Binder.restoreCallingIdentity(identity);
8470 }
8471 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008472
8473 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008474 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8475 int subscriptionId, IBooleanConsumer resultCallback) {
8476 enforceModifyPermission();
8477 long token = Binder.clearCallingIdentity();
8478 try {
8479 Phone phone = getPhone(subscriptionId);
8480 if (phone == null) {
8481 try {
8482 if (resultCallback != null) {
8483 resultCallback.accept(false);
8484 }
8485 } catch (RemoteException e) {
8486 // ignore
8487 }
8488 return;
8489 }
8490 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8491 Pair.create(specifiers, (x) -> {
8492 try {
8493 if (resultCallback != null) {
8494 resultCallback.accept(x);
8495 }
8496 } catch (RemoteException e) {
8497 // ignore
8498 }
8499 });
8500 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8501 } finally {
8502 Binder.restoreCallingIdentity(token);
8503 }
8504 }
8505
8506 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008507 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008508 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008509 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8510 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8511 if (iccRecords == null) {
8512 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8513 return false;
8514 }
8515 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8516 }
8517
8518 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008519 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8520 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008521 if (callingPackage == null) {
8522 callingPackage = getCurrentPackageName();
8523 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008524 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8525 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008526 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8527 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008528 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8529 }
8530 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8531 Intent intent = new Intent();
8532 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8533 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8534 // Bring up choose default SMS subscription dialog right now
8535 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8536 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8537 mApp.startActivity(intent);
8538 }
chen xud5ca2d52019-05-28 15:20:57 -07008539
8540 @Override
8541 public String getMmsUAProfUrl(int subId) {
8542 //TODO investigate if this API should require proper permission check in R b/133791609
8543 final long identity = Binder.clearCallingIdentity();
8544 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008545 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8546 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8547 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8548 return carrierUAProfUrl;
8549 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008550 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8551 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008552 } finally {
8553 Binder.restoreCallingIdentity(identity);
8554 }
8555 }
8556
8557 @Override
8558 public String getMmsUserAgent(int subId) {
8559 //TODO investigate if this API should require proper permission check in R b/133791609
8560 final long identity = Binder.clearCallingIdentity();
8561 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008562 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8563 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8564 if (!TextUtils.isEmpty(carrierUserAgent)) {
8565 return carrierUserAgent;
8566 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08008567 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8568 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008569 } finally {
8570 Binder.restoreCallingIdentity(identity);
8571 }
8572 }
Jack Yub07d4972019-05-28 16:12:25 -07008573
8574 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008575 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8576 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07008577
Jack Yub07d4972019-05-28 16:12:25 -07008578 final long identity = Binder.clearCallingIdentity();
8579 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008580 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07008581 if (phone == null) return false;
8582
Hall Liua62f5da2020-09-25 10:42:19 -07008583 switch (policy) {
8584 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8585 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8586 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8587 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8588 default:
8589 throw new IllegalArgumentException(policy + " is not a valid policy");
8590 }
Jack Yub07d4972019-05-28 16:12:25 -07008591 } finally {
8592 Binder.restoreCallingIdentity(identity);
8593 }
8594 }
8595
8596 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07008597 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8598 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08008599 enforceModifyPermission();
8600
changbettyd5c246e2019-12-24 15:40:37 +08008601 final long identity = Binder.clearCallingIdentity();
8602 try {
Hall Liua62f5da2020-09-25 10:42:19 -07008603 Phone phone = getPhone(subscriptionId);
8604 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08008605
Hall Liua62f5da2020-09-25 10:42:19 -07008606 switch (policy) {
8607 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8608 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8609 break;
8610 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8611 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8612 break;
8613 default:
8614 throw new IllegalArgumentException(policy + " is not a valid policy");
8615 }
changbettyd5c246e2019-12-24 15:40:37 +08008616 } finally {
8617 Binder.restoreCallingIdentity(identity);
8618 }
8619 }
8620
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008621 /**
Hall Liu746e03c2020-09-25 11:13:49 -07008622 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008623 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8624 * otherwise.
8625 */
8626 @Override
8627 public void setCepEnabled(boolean isCepEnabled) {
8628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8629
8630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8633 for (Phone phone : PhoneFactory.getPhones()) {
8634 Phone defaultPhone = phone.getImsPhone();
8635 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8636 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8637 ImsPhoneCallTracker imsPhoneCallTracker =
8638 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8639 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8640 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8641 + imsPhone.getMsisdn());
8642 }
8643 }
8644 } finally {
8645 Binder.restoreCallingIdentity(identity);
8646 }
8647 }
allenwtsu46dcc572020-01-08 18:24:03 +08008648
8649 /**
8650 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8651 *
8652 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8653 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8654 * before being read.
8655 */
8656 @Override
8657 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8658 isCompressed) {
8659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8660 mApp, subId, "notifyRcsAutoConfigurationReceived");
8661 try {
8662 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8663 if (configBinder == null) {
8664 Rlog.e(LOG_TAG, "null result for getImsConfig");
8665 } else {
8666 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8667 }
8668 } catch (RemoteException e) {
8669 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8670 }
8671 }
zoey chene02881a2019-12-30 16:11:23 +08008672
8673 @Override
8674 public boolean isIccLockEnabled(int subId) {
8675 enforceReadPrivilegedPermission("isIccLockEnabled");
8676
8677 // Now that all security checks passes, perform the operation as ourselves.
8678 final long identity = Binder.clearCallingIdentity();
8679 try {
8680 Phone phone = getPhone(subId);
8681 if (phone != null && phone.getIccCard() != null) {
8682 return phone.getIccCard().getIccLockEnabled();
8683 } else {
8684 return false;
8685 }
8686 } finally {
8687 Binder.restoreCallingIdentity(identity);
8688 }
8689 }
8690
8691 /**
8692 * Set the ICC pin lock enabled or disabled.
8693 *
8694 * @return an integer representing the status of IccLock enabled or disabled in the following
8695 * three cases:
8696 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8697 * successfully.
8698 * - Positive number and zero for remaining password attempts.
8699 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8700 *
8701 */
8702 @Override
8703 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8704 enforceModifyPermission();
8705
8706 Phone phone = getPhone(subId);
8707 if (phone == null) {
8708 return 0;
8709 }
8710 // Now that all security checks passes, perform the operation as ourselves.
8711 final long identity = Binder.clearCallingIdentity();
8712 try {
8713 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8714 new Pair<Boolean, String>(enabled, password), phone, null);
8715 return attemptsRemaining;
8716
8717 } catch (Exception e) {
8718 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8719 } finally {
8720 Binder.restoreCallingIdentity(identity);
8721 }
8722 return 0;
8723 }
8724
8725 /**
8726 * Change the ICC password used in ICC pin lock.
8727 *
8728 * @return an integer representing the status of IccLock changed in the following three cases:
8729 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8730 * - Positive number and zero for remaining password attempts.
8731 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8732 *
8733 */
8734 @Override
8735 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8736 enforceModifyPermission();
8737
8738 Phone phone = getPhone(subId);
8739 if (phone == null) {
8740 return 0;
8741 }
8742 // Now that all security checks passes, perform the operation as ourselves.
8743 final long identity = Binder.clearCallingIdentity();
8744 try {
8745 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8746 new Pair<String, String>(oldPassword, newPassword), phone, null);
8747 return attemptsRemaining;
8748
8749 } catch (Exception e) {
8750 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8751 } finally {
8752 Binder.restoreCallingIdentity(identity);
8753 }
8754 return 0;
8755 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008756
8757 /**
8758 * Request for receiving user activity notification
8759 */
8760 @Override
8761 public void requestUserActivityNotification() {
8762 if (!mNotifyUserActivity.get()
8763 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8764 mNotifyUserActivity.set(true);
8765 }
8766 }
8767
8768 /**
8769 * Called when userActivity is signalled in the power manager.
8770 * This is safe to call from any thread, with any window manager locks held or not.
8771 */
8772 @Override
8773 public void userActivity() {
8774 // ***************************************
8775 // * Inherited from PhoneWindowManager *
8776 // ***************************************
8777 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8778 // WITH ITS LOCKS HELD.
8779 //
8780 // This code must be VERY careful about the locks
8781 // it acquires.
8782 // In fact, the current code acquires way too many,
8783 // and probably has lurking deadlocks.
8784
8785 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8786 throw new SecurityException("Only the OS may call notifyUserActivity()");
8787 }
8788
8789 if (mNotifyUserActivity.getAndSet(false)) {
8790 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8791 USER_ACTIVITY_NOTIFICATION_DELAY);
8792 }
8793 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008794
8795 @Override
8796 public boolean canConnectTo5GInDsdsMode() {
8797 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8798 }
Jack Yud10cdd42020-09-28 20:28:01 -07008799
8800 @Override
8801 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8802 String callingFeatureId) {
8803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8804 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8805 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8806 }
8807
8808 Phone phone = getPhone(subId);
8809 if (phone == null) {
8810 throw new RuntimeException("phone is not available");
8811 }
8812 // Now that all security checks passes, perform the operation as ourselves.
8813 final long identity = Binder.clearCallingIdentity();
8814 try {
8815 return phone.getEquivalentHomePlmns();
8816 } finally {
8817 Binder.restoreCallingIdentity(identity);
8818 }
8819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008820}