blob: c131c0eb26565aede3fe4066772b3500ecf1da66 [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;
changbetty363e8ac2019-12-06 18:16:37 +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;
Shuo Qianb15c6be2020-03-05 17:55:34 -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 Qian5bac1ee2020-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 Nalluri8ff344d2019-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 Kim8d298d42018-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 Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -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 zhaod698b842019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wangd64acad2019-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 Ebinger774ba362019-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 Ebinger77b832e2019-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 Liuaa4283b2020-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;
sqian80370722020-01-29 15:02:51 -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;
sqian80370722020-01-29 15:02:51 -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 Liud0d1dc92020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-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;
Taesu Leef8fbed92019-10-07 18:47:02 +0900162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-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 chen84e2b212019-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 Liua1acea22020-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 Wang050bb052020-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 Liud0d1dc92020-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 zhaod698b842019-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 Nalluri8ff344d2019-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 chenf95ca592019-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 Liud0d1dc92020-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;
sqian80370722020-01-29 15:02:51 -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 Ebinger05f52c22019-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 Davidson0103e8c2020-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 Nalluri8ff344d2019-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 Liua1acea22020-09-18 19:04:59 -0700834 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-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);
sqian80370722020-01-29 15:02:51 -0800842 break;
Hall Liua1acea22020-09-18 19:04:59 -0700843 }
844 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700847 TelephonyManager.CallForwardingInfoCallback callback =
848 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
849 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800850 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700851 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -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 Liua1acea22020-09-18 19:04:59 -0700858 callForwardingInfo = new CallForwardingInfo(true,
859 callForwardInfo.reason,
860 callForwardInfo.number,
861 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800862 break;
863 }
864 }
865 // Didn't find a call forward info for voice call.
866 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700867 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
868 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800869 }
Hall Liua1acea22020-09-18 19:04:59 -0700870 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -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 Liua1acea22020-09-18 19:04:59 -0700878 int errorCode = CallForwardingInfo.ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800879 if (ar.exception instanceof CommandException) {
880 CommandException.Error error =
881 ((CommandException) (ar.exception)).getCommandError();
882 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liua1acea22020-09-18 19:04:59 -0700883 errorCode = CallForwardingInfo.ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800884 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liua1acea22020-09-18 19:04:59 -0700885 errorCode = CallForwardingInfo.ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800886 }
887 }
Hall Liua1acea22020-09-18 19:04:59 -0700888 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -0800889 }
sqian80370722020-01-29 15:02:51 -0800890 break;
Hall Liua1acea22020-09-18 19:04:59 -0700891 }
sqian80370722020-01-29 15:02:51 -0800892
Hall Liua1acea22020-09-18 19:04:59 -0700893 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800894 request = (MainThreadRequest) msg.obj;
895 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700896 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -0800897 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -0700898 ((Pair<CallForwardingInfo, Consumer<Integer>>)
899 request.argument).first;
900 request.phone.setCallForwardingOption(
901 callForwardingInfoToSet.isEnabled()
902 ? CommandsInterface.CF_ACTION_ENABLE
903 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -0800904 callForwardingInfoToSet.getReason(),
905 callForwardingInfoToSet.getNumber(),
906 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
907 break;
Hall Liua1acea22020-09-18 19:04:59 -0700908 }
sqian80370722020-01-29 15:02:51 -0800909
Hall Liua1acea22020-09-18 19:04:59 -0700910 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700913 Consumer<Integer> callback =
914 ((Pair<CallForwardingInfo, Consumer<Integer>>)
915 request.argument).second;
916 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -0800917 loge("setCallForwarding exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -0700918 int errorCode = CallForwardingInfo.ERROR_UNKNOWN;
919 if (ar.exception instanceof CommandException) {
920 CommandException.Error error =
921 ((CommandException) (ar.exception)).getCommandError();
922 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
923 errorCode = CallForwardingInfo.ERROR_FDN_CHECK_FAILURE;
924 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
925 errorCode = CallForwardingInfo.ERROR_NOT_SUPPORTED;
926 }
927 }
928 callback.accept(errorCode);
929 } else {
930 callback.accept(CallForwardingInfo.SUCCESS);
sqian80370722020-01-29 15:02:51 -0800931 }
sqian80370722020-01-29 15:02:51 -0800932 break;
Hall Liua1acea22020-09-18 19:04:59 -0700933 }
sqian80370722020-01-29 15:02:51 -0800934
Hall Liua1acea22020-09-18 19:04:59 -0700935 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -0800936 request = (MainThreadRequest) msg.obj;
937 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
938 getPhoneFromRequest(request).getCallWaiting(onCompleted);
939 break;
Hall Liua1acea22020-09-18 19:04:59 -0700940 }
sqian80370722020-01-29 15:02:51 -0800941
Hall Liua1acea22020-09-18 19:04:59 -0700942 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -0800943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700945 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -0800946 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
947 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800948 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800949 // Service Class is a bit mask per 3gpp 27.007.
950 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800951 if (callForwardResults.length > 1
952 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -0700953 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800954 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -0700955 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
956 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -0800957 } else {
Hall Liua1acea22020-09-18 19:04:59 -0700958 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -0800959 }
960 } else {
961 if (ar.result == null) {
962 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
963 }
964 if (ar.exception != null) {
965 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
966 }
967 if (ar.exception instanceof CommandException) {
968 CommandException.Error error =
969 ((CommandException) (ar.exception)).getCommandError();
970 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
971 callForwardingStatus =
972 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
973 }
974 }
975 }
Hall Liua1acea22020-09-18 19:04:59 -0700976 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -0800977 break;
Hall Liua1acea22020-09-18 19:04:59 -0700978 }
sqian80370722020-01-29 15:02:51 -0800979
Hall Liua1acea22020-09-18 19:04:59 -0700980 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -0800981 request = (MainThreadRequest) msg.obj;
982 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700983 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
984 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -0800985 break;
Hall Liua1acea22020-09-18 19:04:59 -0700986 }
sqian80370722020-01-29 15:02:51 -0800987
Hall Liua1acea22020-09-18 19:04:59 -0700988 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -0800989 ar = (AsyncResult) msg.obj;
990 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700991 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
992 Consumer<Integer> callback =
993 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
994 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -0800995 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -0700996 if (ar.exception instanceof CommandException) {
997 CommandException.Error error =
998 ((CommandException) (ar.exception)).getCommandError();
999 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1000 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1001 } else {
1002 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1003 }
1004 } else {
1005 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1006 }
1007 } else {
1008 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1009 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001010 }
sqian80370722020-01-29 15:02:51 -08001011 break;
Hall Liua1acea22020-09-18 19:04:59 -07001012 }
sqian80370722020-01-29 15:02:51 -08001013
Shishir Agrawal302c8692015-06-19 13:49:39 -07001014 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
1017 CellNetworkScanResult cellScanResult;
1018 if (ar.exception == null && ar.result != null) {
1019 cellScanResult = new CellNetworkScanResult(
1020 CellNetworkScanResult.STATUS_SUCCESS,
1021 (List<OperatorInfo>) ar.result);
1022 } else {
1023 if (ar.result == null) {
1024 loge("getCellNetworkScanResults: Empty response");
1025 }
1026 if (ar.exception != null) {
1027 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1028 }
1029 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1030 if (ar.exception instanceof CommandException) {
1031 CommandException.Error error =
1032 ((CommandException) (ar.exception)).getCommandError();
1033 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1034 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1035 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1036 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1037 }
1038 }
1039 cellScanResult = new CellNetworkScanResult(errorCode, null);
1040 }
1041 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001042 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001043 break;
1044
1045 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1046 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001047 ManualNetworkSelectionArgument selArg =
1048 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001049 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1050 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001051 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1052 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001053 break;
1054
1055 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 if (ar.exception == null) {
1059 request.result = true;
1060 } else {
1061 request.result = false;
1062 loge("setNetworkSelectionModeManual " + ar.exception);
1063 }
1064 notifyRequester(request);
1065 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001066 break;
1067
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001068 case CMD_GET_MODEM_ACTIVITY_INFO:
1069 request = (MainThreadRequest) msg.obj;
1070 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001071 if (defaultPhone != null) {
1072 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001073 } else {
1074 ResultReceiver result = (ResultReceiver) request.argument;
1075 Bundle bundle = new Bundle();
1076 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1077 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1078 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001079 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001080 break;
1081
1082 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001085 ResultReceiver result = (ResultReceiver) request.argument;
1086
1087 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001088 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001089 // Update the last modem activity info and the result of the request.
1090 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1091 if (isModemActivityInfoValid(info)) {
1092 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1093 int[] txTimeMs = info.getTransmitTimeMillis();
1094 int[] lastModemTxTimeMs = mLastModemActivityInfo
1095 .getTransmitTimeMillis();
1096 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1097 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1098 }
1099 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1100 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1101 + mLastModemActivityInfo.getSleepTimeMillis());
1102 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1103 + mLastModemActivityInfo.getIdleTimeMillis());
1104 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1105 mLastModemActivityInfo.setReceiveTimeMillis(
1106 info.getReceiveTimeMillis()
1107 + mLastModemActivityInfo.getReceiveTimeMillis());
1108 }
1109 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1110 mLastModemActivityInfo.getSleepTimeMillis(),
1111 mLastModemActivityInfo.getIdleTimeMillis(),
1112 mLastModemActivityInfo.getTransmitTimeMillis(),
1113 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001114 } else {
1115 if (ar.result == null) {
1116 loge("queryModemActivityInfo: Empty response");
1117 } else if (ar.exception instanceof CommandException) {
1118 loge("queryModemActivityInfo: CommandException: " +
1119 ar.exception);
1120 } else {
1121 loge("queryModemActivityInfo: Unknown exception");
1122 }
1123 }
sqian1a1be542020-03-05 11:37:28 -08001124 Bundle bundle = new Bundle();
1125 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1126 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001127 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001128 break;
1129
Meng Wang1a7c35a2016-05-05 20:56:15 -07001130 case CMD_SET_ALLOWED_CARRIERS:
1131 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001132 CarrierRestrictionRules argument =
1133 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001134 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001135 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001136 break;
1137
1138 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1139 ar = (AsyncResult) msg.obj;
1140 request = (MainThreadRequest) ar.userObj;
1141 if (ar.exception == null && ar.result != null) {
1142 request.result = ar.result;
1143 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001144 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1145 if (ar.exception instanceof CommandException) {
1146 loge("setAllowedCarriers: CommandException: " + ar.exception);
1147 CommandException.Error error =
1148 ((CommandException) (ar.exception)).getCommandError();
1149 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1150 request.result =
1151 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1152 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001153 } else {
1154 loge("setAllowedCarriers: Unknown exception");
1155 }
1156 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001157 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001158 break;
1159
1160 case CMD_GET_ALLOWED_CARRIERS:
1161 request = (MainThreadRequest) msg.obj;
1162 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001163 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001164 break;
1165
1166 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1167 ar = (AsyncResult) msg.obj;
1168 request = (MainThreadRequest) ar.userObj;
1169 if (ar.exception == null && ar.result != null) {
1170 request.result = ar.result;
1171 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001172 request.result = new IllegalStateException(
1173 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001174 if (ar.result == null) {
1175 loge("getAllowedCarriers: Empty response");
1176 } else if (ar.exception instanceof CommandException) {
1177 loge("getAllowedCarriers: CommandException: " +
1178 ar.exception);
1179 } else {
1180 loge("getAllowedCarriers: Unknown exception");
1181 }
1182 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001183 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001184 break;
1185
Nathan Haroldb3014052017-01-25 15:57:32 -08001186 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1187 ar = (AsyncResult) msg.obj;
1188 request = (MainThreadRequest) ar.userObj;
1189 if (ar.exception == null && ar.result != null) {
1190 request.result = ar.result;
1191 } else {
1192 request.result = new IllegalArgumentException(
1193 "Failed to retrieve Forbidden Plmns");
1194 if (ar.result == null) {
1195 loge("getForbiddenPlmns: Empty response");
1196 } else {
1197 loge("getForbiddenPlmns: Unknown exception");
1198 }
1199 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001200 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001201 break;
1202
1203 case CMD_GET_FORBIDDEN_PLMNS:
1204 request = (MainThreadRequest) msg.obj;
1205 uiccCard = getUiccCardFromRequest(request);
1206 if (uiccCard == null) {
1207 loge("getForbiddenPlmns() UiccCard is null");
1208 request.result = new IllegalArgumentException(
1209 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001210 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001211 break;
1212 }
1213 Integer appType = (Integer) request.argument;
1214 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1215 if (uiccApp == null) {
1216 loge("getForbiddenPlmns() no app with specified type -- "
1217 + appType);
1218 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001219 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001220 break;
1221 } else {
1222 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1223 + " specified type -- " + appType);
1224 }
1225 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1226 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1227 onCompleted);
1228 break;
1229
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001230 case CMD_SWITCH_SLOTS:
1231 request = (MainThreadRequest) msg.obj;
1232 int[] physicalSlots = (int[]) request.argument;
1233 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1234 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1235 break;
1236
1237 case EVENT_SWITCH_SLOTS_DONE:
1238 ar = (AsyncResult) msg.obj;
1239 request = (MainThreadRequest) ar.userObj;
1240 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001241 notifyRequester(request);
1242 break;
1243 case CMD_GET_NETWORK_SELECTION_MODE:
1244 request = (MainThreadRequest) msg.obj;
1245 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1246 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1247 break;
1248
1249 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1250 ar = (AsyncResult) msg.obj;
1251 request = (MainThreadRequest) ar.userObj;
1252 if (ar.exception != null) {
1253 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1254 } else {
1255 int mode = ((int[]) ar.result)[0];
1256 if (mode == 0) {
1257 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1258 } else {
1259 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1260 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001261 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001262 notifyRequester(request);
1263 break;
1264 case CMD_GET_CDMA_ROAMING_MODE:
1265 request = (MainThreadRequest) msg.obj;
1266 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1267 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1268 break;
1269 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1270 ar = (AsyncResult) msg.obj;
1271 request = (MainThreadRequest) ar.userObj;
1272 if (ar.exception != null) {
1273 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1274 } else {
1275 request.result = ((int[]) ar.result)[0];
1276 }
1277 notifyRequester(request);
1278 break;
1279 case CMD_SET_CDMA_ROAMING_MODE:
1280 request = (MainThreadRequest) msg.obj;
1281 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1282 int mode = (int) request.argument;
1283 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1284 break;
1285 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1286 ar = (AsyncResult) msg.obj;
1287 request = (MainThreadRequest) ar.userObj;
1288 request.result = ar.exception == null;
1289 notifyRequester(request);
1290 break;
1291 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1292 request = (MainThreadRequest) msg.obj;
1293 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1294 int subscriptionMode = (int) request.argument;
1295 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1296 break;
1297 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1298 ar = (AsyncResult) msg.obj;
1299 request = (MainThreadRequest) ar.userObj;
1300 request.result = ar.exception == null;
1301 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001302 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001303 case CMD_GET_ALL_CELL_INFO:
1304 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001305 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001306 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001307 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001308 case EVENT_GET_ALL_CELL_INFO_DONE:
1309 ar = (AsyncResult) msg.obj;
1310 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001311 // If a timeout occurs, the response will be null
1312 request.result = (ar.exception == null && ar.result != null)
1313 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001314 synchronized (request) {
1315 request.notifyAll();
1316 }
1317 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001318 case CMD_REQUEST_CELL_INFO_UPDATE:
1319 request = (MainThreadRequest) msg.obj;
1320 request.phone.requestCellInfoUpdate(request.workSource,
1321 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1322 break;
1323 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1324 ar = (AsyncResult) msg.obj;
1325 request = (MainThreadRequest) ar.userObj;
1326 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1327 try {
1328 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001329 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001330 cb.onError(
1331 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1332 ar.exception.getClass().getName(),
1333 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001334 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001335 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001336 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001337 } else {
1338 // use the result as returned
1339 cb.onCellInfo((List<CellInfo>) ar.result);
1340 }
1341 } catch (RemoteException re) {
1342 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1343 }
1344 break;
1345 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001346 request = (MainThreadRequest) msg.obj;
1347 WorkSource ws = (WorkSource) request.argument;
1348 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001349 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001350 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001351 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001352 ar = (AsyncResult) msg.obj;
1353 request = (MainThreadRequest) ar.userObj;
1354 if (ar.exception == null) {
1355 request.result = ar.result;
1356 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001357 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001358 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001359 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001360 }
1361
1362 synchronized (request) {
1363 request.notifyAll();
1364 }
1365 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001366 case CMD_MODEM_REBOOT:
1367 request = (MainThreadRequest) msg.obj;
1368 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001369 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001370 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001371 case EVENT_CMD_MODEM_REBOOT_DONE:
1372 handleNullReturnEvent(msg, "rebootModem");
1373 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001374 case CMD_REQUEST_ENABLE_MODEM:
1375 request = (MainThreadRequest) msg.obj;
1376 boolean enable = (boolean) request.argument;
1377 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001378 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001379 PhoneConfigurationManager.getInstance()
1380 .enablePhone(request.phone, enable, onCompleted);
1381 break;
1382 case EVENT_ENABLE_MODEM_DONE:
1383 ar = (AsyncResult) msg.obj;
1384 request = (MainThreadRequest) ar.userObj;
1385 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001386 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001387 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001388 if ((boolean) request.result) {
1389 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1390 updateModemStateMetrics();
1391 } else {
1392 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1393 + ar.exception);
1394 }
1395 notifyRequester(request);
1396 break;
1397 case CMD_GET_MODEM_STATUS:
1398 request = (MainThreadRequest) msg.obj;
1399 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1400 PhoneConfigurationManager.getInstance()
1401 .getPhoneStatusFromModem(request.phone, onCompleted);
1402 break;
1403 case EVENT_GET_MODEM_STATUS_DONE:
1404 ar = (AsyncResult) msg.obj;
1405 request = (MainThreadRequest) ar.userObj;
1406 int id = request.phone.getPhoneId();
1407 if (ar.exception == null && ar.result != null) {
1408 request.result = ar.result;
1409 //update the cache as modem status has changed
1410 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1411 (boolean) request.result);
1412 } else {
1413 // Return true if modem status cannot be retrieved. For most cases,
1414 // modem status is on. And for older version modems, GET_MODEM_STATUS
1415 // and disable modem are not supported. Modem is always on.
1416 // TODO: this should be fixed in R to support a third
1417 // status UNKNOWN b/131631629
1418 request.result = true;
1419 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1420 + ar.exception);
1421 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001422 notifyRequester(request);
1423 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001424 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1425 request = (MainThreadRequest) msg.obj;
1426 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1427 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1428 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1429 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1430 break;
1431 }
1432 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1433 ar = (AsyncResult) msg.obj;
1434 request = (MainThreadRequest) ar.userObj;
1435 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1436 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1437 args.second.accept(ar.exception == null);
1438 notifyRequester(request);
1439 break;
1440 }
yincheng zhaod698b842019-09-06 17:06:54 -07001441 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1442 ar = (AsyncResult) msg.obj;
1443 request = (MainThreadRequest) ar.userObj;
1444 if (ar.exception == null && ar.result != null) {
1445 request.result = ar.result;
1446 } else {
1447 request.result = -1;
1448 loge("Failed to set Forbidden Plmns");
1449 if (ar.result == null) {
1450 loge("setForbidenPlmns: Empty response");
1451 } else if (ar.exception != null) {
1452 loge("setForbiddenPlmns: Exception: " + ar.exception);
1453 request.result = -1;
1454 } else {
1455 loge("setForbiddenPlmns: Unknown exception");
1456 }
1457 }
1458 notifyRequester(request);
1459 break;
1460 case CMD_SET_FORBIDDEN_PLMNS:
1461 request = (MainThreadRequest) msg.obj;
1462 uiccCard = getUiccCardFromRequest(request);
1463 if (uiccCard == null) {
1464 loge("setForbiddenPlmns: UiccCard is null");
1465 request.result = -1;
1466 notifyRequester(request);
1467 break;
1468 }
1469 Pair<Integer, List<String>> setFplmnsArgs =
1470 (Pair<Integer, List<String>>) request.argument;
1471 appType = setFplmnsArgs.first;
1472 List<String> fplmns = setFplmnsArgs.second;
1473 uiccApp = uiccCard.getApplicationByType(appType);
1474 if (uiccApp == null) {
1475 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1476 request.result = -1;
1477 loge("Failed to get UICC App");
1478 notifyRequester(request);
1479 } else {
1480 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1481 ((SIMRecords) uiccApp.getIccRecords())
1482 .setForbiddenPlmns(onCompleted, fplmns);
1483 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001484 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001485 case CMD_ERASE_MODEM_CONFIG:
1486 request = (MainThreadRequest) msg.obj;
1487 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1488 defaultPhone.eraseModemConfig(onCompleted);
1489 break;
1490 case EVENT_ERASE_MODEM_CONFIG_DONE:
1491 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001492 break;
zoey chenf95ca592019-12-30 16:11:23 +08001493
1494 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1495 request = (MainThreadRequest) msg.obj;
1496 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1497 Pair<String, String> changed = (Pair<String, String>) request.argument;
1498 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1499 changed.first, changed.second, onCompleted);
1500 break;
1501 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1502 ar = (AsyncResult) msg.obj;
1503 request = (MainThreadRequest) ar.userObj;
1504 if (ar.exception == null) {
1505 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1506 } else {
1507 request.result = msg.arg1;
1508 }
1509 notifyRequester(request);
1510 break;
1511
1512 case CMD_SET_ICC_LOCK_ENABLED:
1513 request = (MainThreadRequest) msg.obj;
1514 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1515 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1516 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1517 enabled.first, enabled.second, onCompleted);
1518 break;
1519 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1520 ar = (AsyncResult) msg.obj;
1521 request = (MainThreadRequest) ar.userObj;
1522 if (ar.exception == null) {
1523 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1524 } else {
1525 request.result = msg.arg1;
1526 }
1527 notifyRequester(request);
1528 break;
1529
Peter Wangdafb9ac2020-01-15 14:13:38 -08001530 case MSG_NOTIFY_USER_ACTIVITY:
1531 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001532 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001533 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1534 getDefaultPhone().getContext().sendBroadcastAsUser(
1535 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1536 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001537 default:
1538 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1539 break;
1540 }
1541 }
Jake Hambye994d462014-02-03 13:10:13 -08001542
Pengquan Menga1bb6272018-09-06 09:59:22 -07001543 private void notifyRequester(MainThreadRequest request) {
1544 synchronized (request) {
1545 request.notifyAll();
1546 }
1547 }
1548
Jake Hambye994d462014-02-03 13:10:13 -08001549 private void handleNullReturnEvent(Message msg, String command) {
1550 AsyncResult ar = (AsyncResult) msg.obj;
1551 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1552 if (ar.exception == null) {
1553 request.result = true;
1554 } else {
1555 request.result = false;
1556 if (ar.exception instanceof CommandException) {
1557 loge(command + ": CommandException: " + ar.exception);
1558 } else {
1559 loge(command + ": Unknown exception");
1560 }
1561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001562 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
1566 /**
1567 * Posts the specified command to be executed on the main thread,
1568 * waits for the request to complete, and returns the result.
1569 * @see #sendRequestAsync
1570 */
1571 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001572 return sendRequest(
1573 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001574 }
1575
1576 /**
1577 * Posts the specified command to be executed on the main thread,
1578 * waits for the request to complete, and returns the result.
1579 * @see #sendRequestAsync
1580 */
1581 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1582 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001583 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001584 }
1585
1586 /**
1587 * Posts the specified command to be executed on the main thread,
1588 * waits for the request to complete, and returns the result.
1589 * @see #sendRequestAsync
1590 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001591 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001592 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001593 }
1594
1595 /**
1596 * Posts the specified command to be executed on the main thread,
1597 * waits for the request to complete, and returns the result.
1598 * @see #sendRequestAsync
1599 */
Nathan Harold92bed182018-10-12 18:16:49 -07001600 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1601 return sendRequest(command, argument, subId, null, workSource);
1602 }
1603
1604 /**
1605 * Posts the specified command to be executed on the main thread,
1606 * waits for the request to complete, and returns the result.
1607 * @see #sendRequestAsync
1608 */
1609 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1610 return sendRequest(
1611 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1612 }
1613
1614 /**
1615 * Posts the specified command to be executed on the main thread,
1616 * waits for the request to complete, and returns the result.
1617 * @see #sendRequestAsync
1618 */
1619 private Object sendRequest(
1620 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1622 throw new RuntimeException("This method will deadlock if called from the main thread.");
1623 }
1624
Nathan Harold92bed182018-10-12 18:16:49 -07001625 MainThreadRequest request = null;
1626 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1627 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1628 } else if (phone != null) {
1629 request = new MainThreadRequest(argument, phone, workSource);
1630 } else {
1631 request = new MainThreadRequest(argument, subId, workSource);
1632 }
1633
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 Message msg = mMainThreadHandler.obtainMessage(command, request);
1635 msg.sendToTarget();
1636
1637 // Wait for the request to complete
1638 synchronized (request) {
1639 while (request.result == null) {
1640 try {
1641 request.wait();
1642 } catch (InterruptedException e) {
1643 // Do nothing, go back and wait until the request is complete
1644 }
1645 }
1646 }
1647 return request.result;
1648 }
1649
1650 /**
1651 * Asynchronous ("fire and forget") version of sendRequest():
1652 * Posts the specified command to be executed on the main thread, and
1653 * returns immediately.
1654 * @see #sendRequest
1655 */
1656 private void sendRequestAsync(int command) {
1657 mMainThreadHandler.sendEmptyMessage(command);
1658 }
1659
1660 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001661 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001662 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001663 */
1664 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001665 sendRequestAsync(command, argument, null, null);
1666 }
1667
1668 /**
1669 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1670 * @see {@link #sendRequest(int,Object)}
1671 */
1672 private void sendRequestAsync(
1673 int command, Object argument, Phone phone, WorkSource workSource) {
1674 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001675 Message msg = mMainThreadHandler.obtainMessage(command, request);
1676 msg.sendToTarget();
1677 }
1678
1679 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 * Initialize the singleton PhoneInterfaceManager instance.
1681 * This is only done once, at startup, from PhoneApp.onCreate().
1682 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001683 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 synchronized (PhoneInterfaceManager.class) {
1685 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001686 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 } else {
1688 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1689 }
1690 return sInstance;
1691 }
1692 }
1693
1694 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001695 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001698 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001699 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1701 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001702 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001703 mTelephonySharedPreferences =
1704 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001705 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001706 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001707 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001708
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 publish();
1710 }
1711
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001712 private Phone getDefaultPhone() {
1713 Phone thePhone = getPhone(getDefaultSubscription());
1714 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1715 }
1716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 private void publish() {
1718 if (DBG) log("publish: " + this);
1719
Peter Wangc035ce42020-01-08 21:00:22 -08001720 TelephonyFrameworkInitializer
1721 .getTelephonyServiceManager()
1722 .getTelephonyServiceRegisterer()
1723 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Stuart Scott584921c2015-01-15 17:10:34 -08001726 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001727 if (request.phone != null) {
1728 return request.phone;
1729 } else {
1730 return getPhoneFromSubId(request.subId);
1731 }
1732 }
1733
1734 private Phone getPhoneFromSubId(int subId) {
1735 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1736 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001737 }
1738
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001739 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1740 Phone phone = getPhoneFromRequest(request);
1741 return phone == null ? null :
1742 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1743 }
1744
Wink Saville36469e72014-06-11 15:17:00 -07001745 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001746 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001747 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001750 private void sendEraseModemConfig(Phone phone) {
1751 if (phone != null) {
1752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1753 mApp, phone.getSubId(), "eraseModemConfig");
1754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1757 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1758 } finally {
1759 Binder.restoreCallingIdentity(identity);
1760 }
1761 }
1762 }
1763
Peter Wang050bb052020-01-13 23:33:09 -08001764 private boolean isImsAvailableOnDevice() {
1765 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1766 if (pm == null) {
1767 // For some reason package manger is not available.. This will fail internally anyway,
1768 // so do not throw error and allow.
1769 return true;
1770 }
1771 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1772 }
1773
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001775 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001776 }
1777
Wink Savilleb564aae2014-10-23 10:18:09 -07001778 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 if (DBG) log("dial: " + number);
1780 // No permission check needed here: This is just a wrapper around the
1781 // ACTION_DIAL intent, which is available to any app since it puts up
1782 // the UI before it does anything.
1783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784 final long identity = Binder.clearCallingIdentity();
1785 try {
1786 String url = createTelUrl(number);
1787 if (url == null) {
1788 return;
1789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001791 // PENDING: should we just silently fail if phone is offhook or ringing?
1792 PhoneConstants.State state = mCM.getState(subId);
1793 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1794 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1795 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1796 mApp.startActivity(intent);
1797 }
1798 } finally {
1799 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 }
1801 }
1802
1803 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001804 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001805 }
1806
Wink Savilleb564aae2014-10-23 10:18:09 -07001807 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 if (DBG) log("call: " + number);
1809
1810 // This is just a wrapper around the ACTION_CALL intent, but we still
1811 // need to do a permission check since we're calling startActivity()
1812 // from the context of the phone app.
1813 enforceCallPermission();
1814
Jordan Liu1617b712019-07-10 15:06:26 -07001815 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 != AppOpsManager.MODE_ALLOWED) {
1817 return;
1818 }
1819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 String url = createTelUrl(number);
1823 if (url == null) {
1824 return;
1825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001827 boolean isValid = false;
1828 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1829 if (slist != null) {
1830 for (SubscriptionInfo subInfoRecord : slist) {
1831 if (subInfoRecord.getSubscriptionId() == subId) {
1832 isValid = true;
1833 break;
1834 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001835 }
Wink Saville08874612014-08-31 19:19:58 -07001836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001837 if (!isValid) {
1838 return;
1839 }
Wink Saville08874612014-08-31 19:19:58 -07001840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001841 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1842 intent.putExtra(SUBSCRIPTION_KEY, subId);
1843 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1844 mApp.startActivity(intent);
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
1847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 }
1849
Wink Savilleb564aae2014-10-23 10:18:09 -07001850 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001851 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001852 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1853 }
1854
Wink Savilleb564aae2014-10-23 10:18:09 -07001855 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001856 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001857 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1858 }
1859
Wink Savilleb564aae2014-10-23 10:18:09 -07001860 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001862
1863 final long identity = Binder.clearCallingIdentity();
1864 try {
1865 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1866 checkSimPin.start();
1867 return checkSimPin.unlockSim(null, pin);
1868 } finally {
1869 Binder.restoreCallingIdentity(identity);
1870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 }
1872
Wink Savilleb564aae2014-10-23 10:18:09 -07001873 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001875
1876 final long identity = Binder.clearCallingIdentity();
1877 try {
1878 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1879 checkSimPuk.start();
1880 return checkSimPuk.unlockSim(puk, pin);
1881 } finally {
1882 Binder.restoreCallingIdentity(identity);
1883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
1886 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001887 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 * a synchronous one.
1889 */
1890 private static class UnlockSim extends Thread {
1891
1892 private final IccCard mSimCard;
1893
1894 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001895 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1896 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897
1898 // For replies from SimCard interface
1899 private Handler mHandler;
1900
1901 // For async handler to identify request type
1902 private static final int SUPPLY_PIN_COMPLETE = 100;
1903
1904 public UnlockSim(IccCard simCard) {
1905 mSimCard = simCard;
1906 }
1907
1908 @Override
1909 public void run() {
1910 Looper.prepare();
1911 synchronized (UnlockSim.this) {
1912 mHandler = new Handler() {
1913 @Override
1914 public void handleMessage(Message msg) {
1915 AsyncResult ar = (AsyncResult) msg.obj;
1916 switch (msg.what) {
1917 case SUPPLY_PIN_COMPLETE:
1918 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1919 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001920 mRetryCount = msg.arg1;
1921 if (ar.exception != null) {
1922 if (ar.exception instanceof CommandException &&
1923 ((CommandException)(ar.exception)).getCommandError()
1924 == CommandException.Error.PASSWORD_INCORRECT) {
1925 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001926 } //When UiccCardApp dispose,handle message and return exception
1927 else if (ar.exception instanceof CommandException &&
1928 ((CommandException) (ar.exception)).getCommandError()
1929 == CommandException.Error.ABORTED) {
1930 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001931 } else {
1932 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1933 }
1934 } else {
1935 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 mDone = true;
1938 UnlockSim.this.notifyAll();
1939 }
1940 break;
1941 }
1942 }
1943 };
1944 UnlockSim.this.notifyAll();
1945 }
1946 Looper.loop();
1947 }
1948
1949 /*
1950 * Use PIN or PUK to unlock SIM card
1951 *
1952 * If PUK is null, unlock SIM card with PIN
1953 *
1954 * If PUK is not null, unlock SIM card with PUK and set PIN code
1955 */
Wink Saville9de0f752013-10-22 19:04:03 -07001956 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957
1958 while (mHandler == null) {
1959 try {
1960 wait();
1961 } catch (InterruptedException e) {
1962 Thread.currentThread().interrupt();
1963 }
1964 }
1965 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1966
1967 if (puk == null) {
1968 mSimCard.supplyPin(pin, callback);
1969 } else {
1970 mSimCard.supplyPuk(puk, pin, callback);
1971 }
1972
1973 while (!mDone) {
1974 try {
1975 Log.d(LOG_TAG, "wait for done");
1976 wait();
1977 } catch (InterruptedException e) {
1978 // Restore the interrupted status
1979 Thread.currentThread().interrupt();
1980 }
1981 }
1982 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001983 int[] resultArray = new int[2];
1984 resultArray[0] = mResult;
1985 resultArray[1] = mRetryCount;
1986 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 }
1988 }
1989
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001990 /**
1991 * This method has been removed due to privacy and stability concerns.
1992 */
1993 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001995 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
1996 return;
Wink Saville36469e72014-06-11 15:17:00 -07001997 }
1998
Nathan Harold1f889d82020-06-04 17:05:26 -07001999 @Override
2000 public void updateServiceLocationWithPackageName(String callingPackage) {
2001 mApp.getSystemService(AppOpsManager.class)
2002 .checkPackage(Binder.getCallingUid(), callingPackage);
2003
2004 final int targetSdk = getTargetSdk(callingPackage);
2005 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2006 // Callers targeting S have no business invoking this method.
2007 return;
2008 }
2009
2010 LocationAccessPolicy.LocationPermissionResult locationResult =
2011 LocationAccessPolicy.checkLocationPermission(mApp,
2012 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2013 .setCallingPackage(callingPackage)
2014 .setCallingFeatureId(null)
2015 .setCallingPid(Binder.getCallingPid())
2016 .setCallingUid(Binder.getCallingUid())
2017 .setMethod("updateServiceLocation")
2018 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2019 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2020 .build());
2021 // Apps that lack location permission have no business calling this method;
2022 // however, because no permission was declared in the public API, denials must
2023 // all be "soft".
2024 switch (locationResult) {
2025 case DENIED_HARD: /* fall through */
2026 case DENIED_SOFT:
2027 return;
2028 }
2029
2030 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002031 final long identity = Binder.clearCallingIdentity();
2032 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002033 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002034 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002035 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036 }
2037 } finally {
2038 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002039 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 }
2041
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002042 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002043 @Override
2044 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002045 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002046 }
2047
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002048
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002049 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002050 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2051 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2052 callingFeatureId);
2053 }
2054
2055 @Deprecated
2056 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002057 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002058 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2059 }
2060
2061 @Override
2062 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2063 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002065 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002066 return false;
2067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002068
2069 final long identity = Binder.clearCallingIdentity();
2070 try {
2071 return isRadioOnForSubscriber(subId);
2072 } finally {
2073 Binder.restoreCallingIdentity(identity);
2074 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002075 }
2076
2077 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 final long identity = Binder.clearCallingIdentity();
2079 try {
2080 final Phone phone = getPhone(subId);
2081 if (phone != null) {
2082 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2083 } else {
2084 return false;
2085 }
2086 } finally {
2087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 }
2090
2091 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002092 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 }
Wink Saville36469e72014-06-11 15:17:00 -07002094
Wink Savilleb564aae2014-10-23 10:18:09 -07002095 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002097
2098 final long identity = Binder.clearCallingIdentity();
2099 try {
2100 final Phone phone = getPhone(subId);
2101 if (phone != null) {
2102 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2103 }
2104 } finally {
2105 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002106 }
Wink Saville36469e72014-06-11 15:17:00 -07002107 }
2108
2109 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002110 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002111 }
2112
Wink Savilleb564aae2014-10-23 10:18:09 -07002113 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002114 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002115
2116 final long identity = Binder.clearCallingIdentity();
2117 try {
2118 final Phone phone = getPhone(subId);
2119 if (phone == null) {
2120 return false;
2121 }
2122 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2123 toggleRadioOnOffForSubscriber(subId);
2124 }
2125 return true;
2126 } finally {
2127 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002128 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 }
Wink Saville36469e72014-06-11 15:17:00 -07002130
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002131 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002132 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002133 /*
2134 * If any of the Radios are available, it will need to be
2135 * shutdown. So return true if any Radio is available.
2136 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002137 final long identity = Binder.clearCallingIdentity();
2138 try {
2139 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2140 Phone phone = PhoneFactory.getPhone(i);
2141 if (phone != null && phone.isRadioAvailable()) return true;
2142 }
2143 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2144 return false;
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002147 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002148 }
2149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002150 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002151 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152 enforceModifyPermission();
2153
2154 final long identity = Binder.clearCallingIdentity();
2155 try {
2156 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2157 logv("Shutting down Phone " + i);
2158 shutdownRadioUsingPhoneId(i);
2159 }
2160 } finally {
2161 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002162 }
2163 }
2164
2165 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002166 Phone phone = PhoneFactory.getPhone(phoneId);
2167 if (phone != null && phone.isRadioAvailable()) {
2168 phone.shutdownRadio();
2169 }
2170 }
2171
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002173 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174
2175 final long identity = Binder.clearCallingIdentity();
2176 try {
2177 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2178 if (defaultPhone != null) {
2179 defaultPhone.setRadioPower(turnOn);
2180 return true;
2181 } else {
2182 loge("There's no default phone.");
2183 return false;
2184 }
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002187 }
Wink Saville36469e72014-06-11 15:17:00 -07002188 }
2189
Wink Savilleb564aae2014-10-23 10:18:09 -07002190 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002192
2193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 final Phone phone = getPhone(subId);
2196 if (phone != null) {
2197 phone.setRadioPower(turnOn);
2198 return true;
2199 } else {
2200 return false;
2201 }
2202 } finally {
2203 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 }
2206
Wink Saville36469e72014-06-11 15:17:00 -07002207 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002208 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 public boolean enableDataConnectivity() {
2210 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002211
2212 final long identity = Binder.clearCallingIdentity();
2213 try {
2214 int subId = mSubscriptionController.getDefaultDataSubId();
2215 final Phone phone = getPhone(subId);
2216 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002217 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002218 return true;
2219 } else {
2220 return false;
2221 }
2222 } finally {
2223 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 }
2226
Wink Saville36469e72014-06-11 15:17:00 -07002227 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002228 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 public boolean disableDataConnectivity() {
2230 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231
2232 final long identity = Binder.clearCallingIdentity();
2233 try {
2234 int subId = mSubscriptionController.getDefaultDataSubId();
2235 final Phone phone = getPhone(subId);
2236 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002237 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238 return true;
2239 } else {
2240 return false;
2241 }
2242 } finally {
2243 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002248 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002249 final long identity = Binder.clearCallingIdentity();
2250 try {
2251 final Phone phone = getPhone(subId);
2252 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002253 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002254 } else {
2255 return false;
2256 }
2257 } finally {
2258 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 }
2261
2262 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002263 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002264 }
2265
pkanwarae03a6b2016-11-06 20:37:09 -08002266 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002267 enforceCallPermission();
2268
2269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2272 return;
2273 }
2274 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2275 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2276 } finally {
2277 Binder.restoreCallingIdentity(identity);
2278 }
pkanwar32d516d2016-10-14 19:37:38 -07002279 };
2280
Wink Savilleb564aae2014-10-23 10:18:09 -07002281 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002283
2284 final long identity = Binder.clearCallingIdentity();
2285 try {
2286 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2287 return false;
2288 }
2289 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2290 } finally {
2291 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002296 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002297 }
2298
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002299 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002300 final long identity = Binder.clearCallingIdentity();
2301 try {
2302 Phone phone = PhoneFactory.getPhone(slotIndex);
2303 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2304 PhoneConstantConversions.convertCallState(phone.getState());
2305 } finally {
2306 Binder.restoreCallingIdentity(identity);
2307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309
Sanket Padawe356d7632015-06-22 14:03:32 -07002310 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002311 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002312 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2313 }
2314
2315 @Override
2316 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002317 final long identity = Binder.clearCallingIdentity();
2318 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002319 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002320 if (phone != null) {
2321 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2322 } else {
2323 return PhoneConstantConversions.convertDataState(
2324 PhoneConstants.DataState.DISCONNECTED);
2325 }
2326 } finally {
2327 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 }
2330
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002332 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002333 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2334 }
2335
2336 @Override
2337 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338 final long identity = Binder.clearCallingIdentity();
2339 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002340 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341 if (phone != null) {
2342 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2343 } else {
2344 return TelephonyManager.DATA_ACTIVITY_NONE;
2345 }
2346 } finally {
2347 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 }
2350
2351 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002352 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002353 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002354 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002355
2356 LocationAccessPolicy.LocationPermissionResult locationResult =
2357 LocationAccessPolicy.checkLocationPermission(mApp,
2358 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2359 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002360 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002361 .setCallingPid(Binder.getCallingPid())
2362 .setCallingUid(Binder.getCallingUid())
2363 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002364 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002365 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2366 .build());
2367 switch (locationResult) {
2368 case DENIED_HARD:
2369 throw new SecurityException("Not allowed to access cell location");
2370 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002371 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2372 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 }
2374
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376 final long identity = Binder.clearCallingIdentity();
2377 try {
2378 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002379 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002380 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002381 } finally {
2382 Binder.restoreCallingIdentity(identity);
2383 }
Svetoslav64fad262015-04-14 14:35:21 -07002384 }
2385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 @Override
Jack Yu01425032020-02-22 19:38:58 -08002387 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002388 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2389 // registered cell info, so return a NULL country instead.
2390 final long identity = Binder.clearCallingIdentity();
2391 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002392 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2393 // Get default phone in this case.
2394 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2395 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002396 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002398 if (phone == null) return "";
2399 ServiceStateTracker sst = phone.getServiceStateTracker();
2400 if (sst == null) return "";
2401 LocaleTracker lt = sst.getLocaleTracker();
2402 if (lt == null) return "";
2403 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2404 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2405 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002406 } finally {
2407 Binder.restoreCallingIdentity(identity);
2408 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002409 }
2410
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002411 /**
2412 * This method was removed due to potential issues caused by performing partial
2413 * updates of service state, and lack of a credible use case.
2414 *
2415 * This has the ability to break the telephony implementation by disabling notification of
2416 * changes in device connectivity. DO NOT USE THIS!
2417 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002418 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 public void enableLocationUpdates() {
2420 mApp.enforceCallingOrSelfPermission(
2421 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 }
2423
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002424 /**
2425 * This method was removed due to potential issues caused by performing partial
2426 * updates of service state, and lack of a credible use case.
2427 *
2428 * This has the ability to break the telephony implementation by disabling notification of
2429 * changes in device connectivity. DO NOT USE THIS!
2430 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 @Override
2432 public void disableLocationUpdates() {
2433 mApp.enforceCallingOrSelfPermission(
2434 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
2436
Nathan Harold31d7ff32018-10-15 20:20:30 -07002437 /**
2438 * Returns the target SDK version number for a given package name.
2439 *
Nathan Haroldec184742019-07-10 17:04:16 -07002440 * This call MUST be invoked before clearing the calling UID.
2441 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002442 * @return target SDK if the package is found or INT_MAX.
2443 */
2444 private int getTargetSdk(String packageName) {
2445 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002446 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002447 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002448 if (ai != null) return ai.targetSdkVersion;
2449 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002450 loge("Failed to get package info for pkg="
2451 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002452 }
2453 return Integer.MAX_VALUE;
2454 }
2455
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 @Override
2457 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002458 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2459 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002460 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002461 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2462 throw new SecurityException(
2463 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2464 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002465
Jordan Liu1617b712019-07-10 15:06:26 -07002466 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2468 return null;
2469 }
Svetoslav64fad262015-04-14 14:35:21 -07002470
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002471 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002473 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002474 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475
Nathan Haroldf180aac2018-06-01 18:43:55 -07002476 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2477 for (CellInfo ci : info) {
2478 if (ci instanceof CellInfoGsm) {
2479 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2480 } else if (ci instanceof CellInfoWcdma) {
2481 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002484 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002487 private List<CellInfo> getCachedCellInfo() {
2488 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2489 for (Phone phone : PhoneFactory.getPhones()) {
2490 List<CellInfo> info = phone.getAllCellInfo();
2491 if (info != null) cellInfos.addAll(info);
2492 }
2493 return cellInfos;
2494 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495
2496 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002497 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002498 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002499 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002500
2501 LocationAccessPolicy.LocationPermissionResult locationResult =
2502 LocationAccessPolicy.checkLocationPermission(mApp,
2503 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2504 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002505 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002506 .setCallingPid(Binder.getCallingPid())
2507 .setCallingUid(Binder.getCallingUid())
2508 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002509 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002510 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2511 .build());
2512 switch (locationResult) {
2513 case DENIED_HARD:
2514 throw new SecurityException("Not allowed to access cell info");
2515 case DENIED_SOFT:
2516 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002519 final int targetSdk = getTargetSdk(callingPackage);
2520 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2521 return getCachedCellInfo();
2522 }
2523
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002524 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002525 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002526 final long identity = Binder.clearCallingIdentity();
2527 try {
2528 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2529 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002530 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002531 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532 if (info != null) cellInfos.addAll(info);
2533 }
2534 return cellInfos;
2535 } finally {
2536 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 }
2538 }
2539
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002540 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002541 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2542 String callingFeatureId) {
2543 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2544 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002545 }
2546
2547 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002548 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2549 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002550 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002551 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002552 }
2553
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002554 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2555 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002556 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002557 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002558
2559 LocationAccessPolicy.LocationPermissionResult locationResult =
2560 LocationAccessPolicy.checkLocationPermission(mApp,
2561 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2562 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002563 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002564 .setCallingPid(Binder.getCallingPid())
2565 .setCallingUid(Binder.getCallingUid())
2566 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002567 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2568 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002569 .build());
2570 switch (locationResult) {
2571 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002572 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2573 // Safetynet logging for b/154934934
2574 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2575 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002576 throw new SecurityException("Not allowed to access cell info");
2577 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002578 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2579 // Safetynet logging for b/154934934
2580 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2581 }
Nathan Harold5320c422019-05-09 10:26:08 -07002582 try {
2583 cb.onCellInfo(new ArrayList<CellInfo>());
2584 } catch (RemoteException re) {
2585 // Drop without consequences
2586 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002587 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002588 }
2589
Nathan Harolda939a962019-05-09 10:13:47 -07002590
2591 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002592 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2593
2594 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2595 }
2596
2597 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002599 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002600 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601
2602 final long identity = Binder.clearCallingIdentity();
2603 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002604 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605 } finally {
2606 Binder.restoreCallingIdentity(identity);
2607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
2609
Shishir Agrawala9f32182016-04-12 12:00:16 -07002610 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002611 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002612 Phone phone = PhoneFactory.getPhone(slotIndex);
2613 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002614 return null;
2615 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002616 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002617 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002618 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002619 return null;
2620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621
2622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 return phone.getImei();
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002628 }
2629
2630 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002631 public String getTypeAllocationCodeForSlot(int slotIndex) {
2632 Phone phone = PhoneFactory.getPhone(slotIndex);
2633 String tac = null;
2634 if (phone != null) {
2635 String imei = phone.getImei();
2636 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2637 }
2638 return tac;
2639 }
2640
2641 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002642 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002643 Phone phone = PhoneFactory.getPhone(slotIndex);
2644 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002645 return null;
2646 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002647
Jeff Davidson913390f2018-02-23 17:11:49 -08002648 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002649 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002650 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002651 return null;
2652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653
2654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 return phone.getMeid();
2657 } finally {
2658 Binder.restoreCallingIdentity(identity);
2659 }
Jack Yu2af8d712017-03-15 17:14:14 -07002660 }
2661
2662 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002663 public String getManufacturerCodeForSlot(int slotIndex) {
2664 Phone phone = PhoneFactory.getPhone(slotIndex);
2665 String manufacturerCode = null;
2666 if (phone != null) {
2667 String meid = phone.getMeid();
2668 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2669 }
2670 return manufacturerCode;
2671 }
2672
2673 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002674 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2675 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002676 Phone phone = PhoneFactory.getPhone(slotIndex);
2677 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002678 return null;
2679 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002680 int subId = phone.getSubId();
2681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002682 mApp, subId, callingPackage, callingFeatureId,
2683 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002684 return null;
2685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
2687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 return phone.getDeviceSvn();
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
2692 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002693 }
2694
fionaxu43304da2017-11-27 22:51:16 -08002695 @Override
2696 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 final Phone phone = getPhone(subId);
2700 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2701 } finally {
2702 Binder.restoreCallingIdentity(identity);
2703 }
fionaxu43304da2017-11-27 22:51:16 -08002704 }
2705
2706 @Override
2707 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708 final long identity = Binder.clearCallingIdentity();
2709 try {
2710 final Phone phone = getPhone(subId);
2711 return phone == null ? null : phone.getCarrierName();
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
2714 }
fionaxu43304da2017-11-27 22:51:16 -08002715 }
2716
calvinpanffe225e2018-11-01 19:43:06 +08002717 @Override
chen xu0026ca62019-03-06 15:28:50 -08002718 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 final Phone phone = getPhone(subId);
2722 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002723 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002724 } finally {
2725 Binder.restoreCallingIdentity(identity);
2726 }
2727 }
2728
2729 @Override
chen xu0026ca62019-03-06 15:28:50 -08002730 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002731 final long identity = Binder.clearCallingIdentity();
2732 try {
2733 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002734 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002735 } finally {
2736 Binder.restoreCallingIdentity(identity);
2737 }
2738 }
2739
chen xu651eec72018-11-11 19:03:44 -08002740 @Override
chen xu864e11c2018-12-06 22:10:03 -08002741 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2742 if (!isSubscriptionMccMnc) {
2743 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2744 }
chen xu651eec72018-11-11 19:03:44 -08002745 final Phone phone = PhoneFactory.getPhone(slotIndex);
2746 if (phone == null) {
2747 return TelephonyManager.UNKNOWN_CARRIER_ID;
2748 }
2749 final long identity = Binder.clearCallingIdentity();
2750 try {
2751 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
2754 }
2755 }
2756
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 //
2758 // Internal helper methods.
2759 //
2760
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002761 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2763 *
2764 * @throws SecurityException if the caller does not have the required permission
2765 */
2766 private void enforceModifyPermission() {
2767 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2768 }
2769
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002770 /**
2771 * Make sure the caller is system.
2772 *
2773 * @throws SecurityException if the caller is not system.
2774 */
2775 private void enforceSystemCaller() {
2776 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2777 throw new SecurityException("Caller must be system");
2778 }
2779 }
2780
Shuo Qianf2b2df42019-11-13 17:43:31 -08002781 private void enforceActiveEmergencySessionPermission() {
2782 mApp.enforceCallingOrSelfPermission(
2783 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2784 }
2785
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002786 /**
2787 * Make sure the caller has the CALL_PHONE permission.
2788 *
2789 * @throws SecurityException if the caller does not have the required permission
2790 */
2791 private void enforceCallPermission() {
2792 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2793 }
2794
paulhu423b5f22019-08-23 19:17:33 +08002795 private void enforceSettingsPermission() {
2796 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002797 }
2798
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 private String createTelUrl(String number) {
2800 if (TextUtils.isEmpty(number)) {
2801 return null;
2802 }
2803
Jake Hambye994d462014-02-03 13:10:13 -08002804 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 }
2806
Ihab Awadf9e92732013-12-05 18:02:52 -08002807 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002808 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2809 }
2810
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002811 private static void logv(String msg) {
2812 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2813 }
2814
Ihab Awadf9e92732013-12-05 18:02:52 -08002815 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2817 }
2818
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002819 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002821 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002822 }
2823
Sanket Padawe356d7632015-06-22 14:03:32 -07002824 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002825 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 final long identity = Binder.clearCallingIdentity();
2827 try {
2828 final Phone phone = PhoneFactory.getPhone(slotIndex);
2829 if (phone == null) {
2830 return PhoneConstants.PHONE_TYPE_NONE;
2831 } else {
2832 return phone.getPhoneType();
2833 }
2834 } finally {
2835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002837 }
2838
2839 /**
2840 * Returns the CDMA ERI icon index to display
2841 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002842 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002843 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2844 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2845 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002846 }
2847
Sanket Padawe356d7632015-06-22 14:03:32 -07002848 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002849 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2850 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002852 mApp, subId, callingPackage, callingFeatureId,
2853 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002854 return -1;
2855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856
2857 final long identity = Binder.clearCallingIdentity();
2858 try {
2859 final Phone phone = getPhone(subId);
2860 if (phone != null) {
2861 return phone.getCdmaEriIconIndex();
2862 } else {
2863 return -1;
2864 }
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002867 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868 }
2869
2870 /**
2871 * Returns the CDMA ERI icon mode,
2872 * 0 - ON
2873 * 1 - FLASHING
2874 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002875 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002876 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2877 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2878 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002879 }
2880
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002882 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2883 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002885 mApp, subId, callingPackage, callingFeatureId,
2886 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002887 return -1;
2888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889
2890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 final Phone phone = getPhone(subId);
2893 if (phone != null) {
2894 return phone.getCdmaEriIconMode();
2895 } else {
2896 return -1;
2897 }
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 }
2902
2903 /**
2904 * Returns the CDMA ERI text,
2905 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002906 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002907 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2908 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2909 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002910 }
2911
Sanket Padawe356d7632015-06-22 14:03:32 -07002912 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002913 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2914 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002916 mApp, subId, callingPackage, callingFeatureId,
2917 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002918 return null;
2919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920
2921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 final Phone phone = getPhone(subId);
2924 if (phone != null) {
2925 return phone.getCdmaEriText();
2926 } else {
2927 return null;
2928 }
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002931 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 }
2933
2934 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002935 * Returns the CDMA MDN.
2936 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002937 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002938 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2940 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941
2942 final long identity = Binder.clearCallingIdentity();
2943 try {
2944 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002945 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 return phone.getLine1Number();
2947 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002948 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949 return null;
2950 }
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002953 }
2954 }
2955
2956 /**
2957 * Returns the CDMA MIN.
2958 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002959 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002960 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2962 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963
2964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 final Phone phone = getPhone(subId);
2967 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2968 return phone.getCdmaMin();
2969 } else {
2970 return null;
2971 }
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002974 }
2975 }
2976
Hall Liud892bec2018-11-30 14:51:45 -08002977 @Override
2978 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2979 INumberVerificationCallback callback, String callingPackage) {
2980 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2981 != PERMISSION_GRANTED) {
2982 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2983 }
2984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2985
2986 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2987 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2988 throw new SecurityException("Calling package must be configured in the device config");
2989 }
2990
2991 if (range == null) {
2992 throw new NullPointerException("Range must be non-null");
2993 }
2994
2995 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002996 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002997
2998 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2999 }
3000
Junda Liuca05d5d2014-08-14 22:36:34 -07003001 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003002 * Returns true if CDMA provisioning needs to run.
3003 */
3004 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 final long identity = Binder.clearCallingIdentity();
3006 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003007 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 }
3012
3013 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003014 * Sets the voice mail number of a given subId.
3015 */
3016 @Override
3017 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003018 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3019 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020
3021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3024 new Pair<String, String>(alphaTag, number), new Integer(subId));
3025 return success;
3026 } finally {
3027 Binder.restoreCallingIdentity(identity);
3028 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003029 }
3030
Ta-wei Yen87c49842016-05-13 21:19:52 -07003031 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003032 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3033 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003034 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3035 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003036 if (!TextUtils.equals(callingPackage, systemDialer)) {
3037 throw new SecurityException("caller must be system dialer");
3038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039
3040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3043 if (phoneAccountHandle == null) {
3044 return null;
3045 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003046 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047 } finally {
3048 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003049 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003050 }
3051
3052 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003053 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3054 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003055 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003057 mApp, subId, callingPackage, callingFeatureId,
3058 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003059 return null;
3060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003062 final long identity = Binder.clearCallingIdentity();
3063 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003064 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003068 }
3069
3070 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003071 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3072 VisualVoicemailSmsFilterSettings settings) {
3073 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003078 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003082 }
3083
3084 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003085 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003087
3088 final long identity = Binder.clearCallingIdentity();
3089 try {
3090 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003091 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003095 }
3096
3097 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003098 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3099 String callingPackage, int subId) {
3100 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003105 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003109 }
3110
3111 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003112 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114
3115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003118 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003122 }
3123
3124 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003125 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3126 String callingAttributionTag, int subId, String number, int port, String text,
3127 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003128 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003129 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003130 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003131 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003132 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3133 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003134 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003135
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003136 /**
fionaxu0152e512016-11-14 13:36:14 -08003137 * Sets the voice activation state of a given subId.
3138 */
3139 @Override
3140 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3142 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003143
3144 final long identity = Binder.clearCallingIdentity();
3145 try {
3146 final Phone phone = getPhone(subId);
3147 if (phone != null) {
3148 phone.setVoiceActivationState(activationState);
3149 } else {
3150 loge("setVoiceActivationState fails with invalid subId: " + subId);
3151 }
3152 } finally {
3153 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003154 }
3155 }
3156
3157 /**
3158 * Sets the data activation state of a given subId.
3159 */
3160 @Override
3161 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3163 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 final Phone phone = getPhone(subId);
3168 if (phone != null) {
3169 phone.setDataActivationState(activationState);
3170 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003171 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172 }
3173 } finally {
3174 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003175 }
3176 }
3177
3178 /**
3179 * Returns the voice activation state of a given subId.
3180 */
3181 @Override
3182 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003183 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
fionaxu0152e512016-11-14 13:36:14 -08003185 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 if (phone != null) {
3189 return phone.getVoiceActivationState();
3190 } else {
3191 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3192 }
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003195 }
3196 }
3197
3198 /**
3199 * Returns the data activation state of a given subId.
3200 */
3201 @Override
3202 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003203 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204
fionaxu0152e512016-11-14 13:36:14 -08003205 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 if (phone != null) {
3209 return phone.getDataActivationState();
3210 } else {
3211 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3212 }
3213 } finally {
3214 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003215 }
3216 }
3217
3218 /**
Wink Saville36469e72014-06-11 15:17:00 -07003219 * Returns the unread count of voicemails for a subId
3220 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003221 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003222 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3223 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003225 mApp, subId, callingPackage, callingFeatureId,
3226 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003227 return 0;
3228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 final Phone phone = getPhone(subId);
3232 if (phone != null) {
3233 return phone.getVoiceMessageCount();
3234 } else {
3235 return 0;
3236 }
3237 } finally {
3238 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003240 }
3241
3242 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003243 * returns true, if the device is in a state where both voice and data
3244 * are supported simultaneously. This can change based on location or network condition.
3245 */
3246 @Override
3247 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 final Phone phone = getPhone(subId);
3251 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3252 } finally {
3253 Binder.restoreCallingIdentity(identity);
3254 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003255 }
3256
3257 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003258 * Send the dialer code if called from the current default dialer or the caller has
3259 * carrier privilege.
3260 * @param inputCode The dialer code to send
3261 */
3262 @Override
3263 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003264 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003265 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003266 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3267 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003268 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003269 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003270 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272
3273 final long identity = Binder.clearCallingIdentity();
3274 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003275 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276 } finally {
3277 Binder.restoreCallingIdentity(identity);
3278 }
fionaxu235cc5e2017-03-06 22:25:57 -08003279 }
3280
Pengquan Menga1bb6272018-09-06 09:59:22 -07003281 @Override
3282 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003283 TelephonyPermissions
3284 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3285 mApp, subId, "getNetworkSelectionMode");
3286 final long identity = Binder.clearCallingIdentity();
3287 try {
3288 if (!isActiveSubscription(subId)) {
3289 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3290 }
3291 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003294 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003295 }
3296
Brad Ebinger35c841c2018-10-01 10:40:55 -07003297 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003298 public boolean isInEmergencySmsMode() {
3299 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 for (Phone phone : PhoneFactory.getPhones()) {
3303 if (phone.isInEmergencySmsMode()) {
3304 return true;
3305 }
3306 }
3307 } finally {
3308 Binder.restoreCallingIdentity(identity);
3309 }
3310 return false;
3311 }
3312
shilu366312e2019-12-17 09:28:10 -08003313 /**
3314 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3315 * @param subId The subscription to use to check the configuration.
3316 * @param c The callback that will be used to send the result.
3317 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003318 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003319 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3320 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003321 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3322 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003323
Brad Ebinger77b832e2019-10-17 17:03:22 -07003324 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3325 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3326 "IMS not available on device.");
3327 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003328 final long token = Binder.clearCallingIdentity();
3329 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003330 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003331 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003332 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003333 } catch (ImsException e) {
3334 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003335 } finally {
3336 Binder.restoreCallingIdentity(token);
3337 }
3338 }
3339
shilu366312e2019-12-17 09:28:10 -08003340 /**
3341 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3342 * @param subId The subscription to use to check the configuration.
3343 * @param c The callback that will be used to send the result.
3344 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003346 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003347 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3348 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003349 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3350 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3351 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003352 final long token = Binder.clearCallingIdentity();
3353 try {
3354 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3355 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3356 .removeRegistrationCallbackForSubscription(c, subId);
3357 } catch (ImsException e) {
3358 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3359 + "is inactive, ignoring unregister.");
3360 // If the subscription is no longer active, just return, since the callback
3361 // will already have been removed internally.
3362 } finally {
3363 Binder.restoreCallingIdentity(token);
3364 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 }
3366
Brad Ebinger774ba362019-10-22 17:36:18 -07003367 /**
3368 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3369 */
3370 @Override
3371 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3372 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3373 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3374 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3375 "IMS not available on device.");
3376 }
3377 final long token = Binder.clearCallingIdentity();
3378 try {
3379 Phone phone = getPhone(subId);
3380 if (phone == null) {
3381 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3382 + subId + "'");
3383 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3384 }
3385 phone.getImsRegistrationState(regState -> {
3386 try {
3387 consumer.accept((regState == null)
3388 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3389 } catch (RemoteException e) {
3390 // Ignore if the remote process is no longer available to call back.
3391 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3392 }
3393 });
3394 } finally {
3395 Binder.restoreCallingIdentity(token);
3396 }
3397 }
3398
3399 /**
3400 * Get the transport type for the IMS service registration state.
3401 */
3402 @Override
3403 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003404 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3405 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003406 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3407 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3408 "IMS not available on device.");
3409 }
3410 final long token = Binder.clearCallingIdentity();
3411 try {
3412 Phone phone = getPhone(subId);
3413 if (phone == null) {
3414 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3415 + subId + "'");
3416 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3417 }
3418 phone.getImsRegistrationTech(regTech -> {
3419 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3420 int regTechConverted = (regTech == null)
3421 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3422 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3423 regTechConverted);
3424 try {
3425 consumer.accept(regTechConverted);
3426 } catch (RemoteException e) {
3427 // Ignore if the remote process is no longer available to call back.
3428 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3429 }
3430 });
3431 } finally {
3432 Binder.restoreCallingIdentity(token);
3433 }
3434 }
3435
shilu366312e2019-12-17 09:28:10 -08003436 /**
3437 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3438 * @param subId The subscription to use to check the configuration.
3439 * @param c The callback that will be used to send the result.
3440 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003442 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3443 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003444 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3445 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003446 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3447 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3448 "IMS not available on device.");
3449 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003450 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3451 final long token = Binder.clearCallingIdentity();
3452 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003453 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003454 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003455 } catch (ImsException e) {
3456 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003457 } finally {
3458 Binder.restoreCallingIdentity(token);
3459 }
3460 }
3461
shilu366312e2019-12-17 09:28:10 -08003462 /**
3463 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3464 * @param subId The subscription to use to check the configuration.
3465 * @param c The callback that will be used to send the result.
3466 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003467 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003468 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003469 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3470 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003471 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3472 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3473 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003474
3475 final long token = Binder.clearCallingIdentity();
3476 try {
3477 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3478 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003479 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003480 } catch (ImsException e) {
3481 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3482 + "is inactive, ignoring unregister.");
3483 // If the subscription is no longer active, just return, since the callback
3484 // will already have been removed internally.
3485 } finally {
3486 Binder.restoreCallingIdentity(token);
3487 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003488 }
3489
3490 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003491 public boolean isCapable(int subId, int capability, int regTech) {
3492 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3494 final long token = Binder.clearCallingIdentity();
3495 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003496 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003497 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003498 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003499 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3500 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003501 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003502 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3503 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003504 } finally {
3505 Binder.restoreCallingIdentity(token);
3506 }
3507 }
3508
3509 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003510 public boolean isAvailable(int subId, int capability, int regTech) {
3511 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003512 final long token = Binder.clearCallingIdentity();
3513 try {
3514 Phone phone = getPhone(subId);
3515 if (phone == null) return false;
3516 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003517 } catch (com.android.ims.ImsException e) {
3518 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3519 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003520 } finally {
3521 Binder.restoreCallingIdentity(token);
3522 }
3523 }
3524
Brad Ebinger77b832e2019-10-17 17:03:22 -07003525 /**
3526 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3527 * subscription.
3528 * @param subId The subscription to use to check the configuration.
3529 * @param callback The callback that will be used to send the result.
3530 * @param capability The MmTelFeature capability that will be used to send the result.
3531 * @param transportType The transport type of the MmTelFeature capability.
3532 */
3533 @Override
3534 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3535 int transportType) {
3536 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3537 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3538 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3539 "IMS not available on device.");
3540 }
3541 final long token = Binder.clearCallingIdentity();
3542 try {
3543 int slotId = getSlotIndex(subId);
3544 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3545 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3546 + subId + "'");
3547 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3548 }
3549 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3550 transportType, aBoolean -> {
3551 try {
3552 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3553 } catch (RemoteException e) {
3554 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3555 + "running. Ignore");
3556 }
3557 });
3558 } finally {
3559 Binder.restoreCallingIdentity(token);
3560 }
3561 }
3562
shilu366312e2019-12-17 09:28:10 -08003563 /**
3564 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3565 * @param subId The subscription to use to check the configuration.
3566 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003567 @Override
3568 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003569 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3570 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003571
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3573 final long token = Binder.clearCallingIdentity();
3574 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003575 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003577 } catch (ImsException e) {
3578 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003579 } finally {
3580 Binder.restoreCallingIdentity(token);
3581 }
3582 }
3583
3584 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003585 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003587 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003593 } catch (ImsException e) {
3594 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
3598 }
3599
shilu366312e2019-12-17 09:28:10 -08003600 /**
3601 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3602 * @param subId The subscription to use to check the configuration.
3603 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003605 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003606 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3607 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 final long identity = Binder.clearCallingIdentity();
3609 try {
3610 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003611 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3612 } catch (ImsException e) {
3613 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
3617 }
3618
3619 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003620 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003622 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003626 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003627 } catch (ImsException e) {
3628 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
3632 }
3633
shilu366312e2019-12-17 09:28:10 -08003634 /**
3635 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3636 * @param subId The subscription to use to check the configuration.
3637 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003638 @Override
3639 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003640 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3641 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003645 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003646 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003647 } catch (ImsException e) {
3648 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
3652 }
3653
3654 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003655 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003657 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003661 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003662 } catch (ImsException e) {
3663 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003664 } finally {
3665 Binder.restoreCallingIdentity(identity);
3666 }
3667 }
3668
shilu366312e2019-12-17 09:28:10 -08003669 /**
3670 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3671 * @param subId The subscription to use to check the configuration.
3672 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003673 @Override
3674 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003675 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3676 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003680 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003681 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003682 } catch (ImsException e) {
3683 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003684 } finally {
3685 Binder.restoreCallingIdentity(identity);
3686 }
3687 }
3688
3689 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003690 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003692 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 final long identity = Binder.clearCallingIdentity();
3694 try {
3695 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003696 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003698 } catch (ImsException e) {
3699 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 } finally {
3701 Binder.restoreCallingIdentity(identity);
3702 }
3703 }
3704
3705 @Override
3706 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3708 "setVoWiFiNonPersistent");
3709 final long identity = Binder.clearCallingIdentity();
3710 try {
3711 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003712 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003713 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003714 } catch (ImsException e) {
3715 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
3719 }
3720
shilu366312e2019-12-17 09:28:10 -08003721 /**
3722 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3723 * @param subId The subscription to use to check the configuration.
3724 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 @Override
3726 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003727 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3728 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 final long identity = Binder.clearCallingIdentity();
3730 try {
3731 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003732 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003734 } catch (ImsException e) {
3735 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
3739 }
3740
3741 @Override
3742 public void setVoWiFiModeSetting(int subId, int mode) {
3743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3744 "setVoWiFiModeSetting");
3745 final long identity = Binder.clearCallingIdentity();
3746 try {
3747 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003748 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003749 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003750 } catch (ImsException e) {
3751 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 } finally {
3753 Binder.restoreCallingIdentity(identity);
3754 }
3755 }
3756
3757 @Override
3758 public int getVoWiFiRoamingModeSetting(int subId) {
3759 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3760 final long identity = Binder.clearCallingIdentity();
3761 try {
3762 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003763 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003764 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003765 } catch (ImsException e) {
3766 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003767 } finally {
3768 Binder.restoreCallingIdentity(identity);
3769 }
3770 }
3771
3772 @Override
3773 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3775 "setVoWiFiRoamingModeSetting");
3776 final long identity = Binder.clearCallingIdentity();
3777 try {
3778 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003779 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003780 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003781 } catch (ImsException e) {
3782 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003783 } finally {
3784 Binder.restoreCallingIdentity(identity);
3785 }
3786 }
3787
3788 @Override
3789 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3791 "setRttCapabilityEnabled");
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003795 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3796 } catch (ImsException e) {
3797 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003798 } finally {
3799 Binder.restoreCallingIdentity(identity);
3800 }
3801 }
3802
shilu366312e2019-12-17 09:28:10 -08003803 /**
3804 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3805 * @param subId The subscription to use to check the configuration.
3806 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003807 @Override
3808 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003809 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3810 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003814 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003815 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003816 } catch (ImsException e) {
3817 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
3821 }
3822
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003823 @Override
3824 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3825 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3826 final long identity = Binder.clearCallingIdentity();
3827 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003828 if (!isImsAvailableOnDevice()) {
3829 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3830 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003831 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003832 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003833 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003834 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003835 } catch (ImsException e) {
3836 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003837 } finally {
3838 Binder.restoreCallingIdentity(identity);
3839 }
3840 }
3841
3842 @Override
3843 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3844 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3845 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003846 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3847 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3848 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003849 try {
3850 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003851 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003852 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003853 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003854 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3855 + "is inactive, ignoring unregister.");
3856 // If the subscription is no longer active, just return, since the callback will already
3857 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003858 } finally {
3859 Binder.restoreCallingIdentity(identity);
3860 }
3861 }
3862
allenwtsu99c623b2020-01-03 18:24:23 +08003863
3864 private void checkModifyPhoneStatePermission(int subId, String message) {
3865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3866 message);
3867 }
3868
3869 private boolean isImsProvisioningRequired(int subId, int capability,
3870 boolean isMmtelCapability) {
3871 Phone phone = getPhone(subId);
3872 if (phone == null) {
3873 loge("phone instance null for subid " + subId);
3874 return false;
3875 }
3876 if (isMmtelCapability) {
3877 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3878 return false;
3879 }
3880 } else {
3881 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3882 return false;
3883 }
3884 }
3885 return true;
3886 }
3887
3888 @Override
3889 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3890 boolean isProvisioned) {
3891 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3892
3893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3896 if (!isImsProvisioningRequired(subId, capability, false)) {
3897 return;
3898 }
3899
3900 // this capability requires provisioning, route to the correct API.
3901 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3902 switch (capability) {
3903 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3904 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3905 ims.setEabProvisioned(isProvisioned);
3906 break;
3907 default: {
3908 throw new IllegalArgumentException("Tried to set provisioning for "
3909 + "rcs capability '" + capability + "', which does not require "
3910 + "provisioning.");
3911 }
3912 }
3913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
3916
3917 }
3918
3919
3920 @Override
3921 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3922 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3923 final long identity = Binder.clearCallingIdentity();
3924 try {
3925 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3926 if (!isImsProvisioningRequired(subId, capability, false)) {
3927 return true;
3928 }
3929
3930 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3931 switch (capability) {
3932 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3933 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3934 return ims.isEabProvisionedOnDevice();
3935
3936 default: {
3937 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3938 + "capability '" + capability + "', which does not require "
3939 + "provisioning.");
3940 }
3941 }
3942
3943 } finally {
3944 Binder.restoreCallingIdentity(identity);
3945 }
3946 }
3947
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003948 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003949 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3950 boolean isProvisioned) {
3951 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3952 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3953 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3954 }
allenwtsu99c623b2020-01-03 18:24:23 +08003955 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003959 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003960 return;
3961 }
3962
3963 // this capability requires provisioning, route to the correct API.
3964 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3965 switch (capability) {
3966 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3967 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3968 ims.setVolteProvisioned(isProvisioned);
3969 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3970 ims.setWfcProvisioned(isProvisioned);
3971 }
3972 break;
3973 }
3974 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3975 // There is currently no difference in VT provisioning type.
3976 ims.setVtProvisioned(isProvisioned);
3977 break;
3978 }
3979 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3980 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3981 // change the capability of the feature instead if needed.
3982 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3983 == isProvisioned) {
3984 // No change in provisioning.
3985 return;
3986 }
3987 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3988 try {
3989 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003990 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003991 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3992 + ", Exception" + e.getMessage());
3993 }
3994 break;
3995 }
3996 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003997 throw new IllegalArgumentException("Tried to set provisioning for "
3998 + "MmTel capability '" + capability + "', which does not require "
3999 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004000 }
4001 }
4002
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
4005 }
4006 }
4007
4008 @Override
4009 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4010 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4011 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4012 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4013 }
4014 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4015 final long identity = Binder.clearCallingIdentity();
4016 try {
4017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004018 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004019 return true;
4020 }
4021
4022 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4023 switch (capability) {
4024 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4025 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4026 return ims.isVolteProvisionedOnDevice();
4027 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4028 return ims.isWfcProvisionedOnDevice();
4029 }
4030 // This should never happen, since we are checking tech above to make sure it
4031 // is either LTE or IWLAN.
4032 throw new IllegalArgumentException("Invalid radio technology for voice "
4033 + "capability.");
4034 }
4035 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4036 // There is currently no difference in VT provisioning type.
4037 return ims.isVtProvisionedOnDevice();
4038 }
4039 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4040 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4041 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4042 }
4043 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004044 throw new IllegalArgumentException(
4045 "Tried to get provisioning for MmTel capability '" + capability
4046 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004047 }
4048 }
4049
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
4052 }
4053 }
4054
4055 @Override
4056 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4057 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4058 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4059 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4060 }
4061 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4062 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4063 return (provisionedBits & capability) > 0;
4064 }
4065
4066 @Override
4067 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4068 boolean isProvisioned) {
4069 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4070 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4071 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4072 }
4073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4074 "setProvisioningStatusForCapability");
4075 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4076 // If the current provisioning status for capability already matches isProvisioned,
4077 // do nothing.
4078 if (((provisionedBits & capability) > 0) == isProvisioned) {
4079 return;
4080 }
4081 if (isProvisioned) {
4082 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4083 } else {
4084 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4085 }
4086 }
4087
4088 /**
4089 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4090 * technology. The bitfield should mirror the bitfield defined by
4091 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4092 */
4093 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4094 String key = getMmTelProvisioningKey(subId, tech);
4095 // Default is no capabilities are provisioned.
4096 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4097 }
4098
4099 /**
4100 * Sets the MmTel capability provisioning bitfield (defined by
4101 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4102 * technology specified.
4103 *
4104 * Note: This is a synchronous command and should not be called on UI thread.
4105 */
4106 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4107 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4108 String key = getMmTelProvisioningKey(subId, tech);
4109 editor.putInt(key, newField);
4110 editor.commit();
4111 }
4112
4113 private static String getMmTelProvisioningKey(int subId, int tech) {
4114 // resulting key is provision_ims_mmtel_{subId}_{tech}
4115 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4116 }
4117
4118 /**
4119 * Query CarrierConfig to see if the specified capability requires provisioning for the
4120 * carrier associated with the subscription id.
4121 */
4122 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4123 int capability) {
4124 CarrierConfigManager configManager = new CarrierConfigManager(context);
4125 PersistableBundle c = configManager.getConfigForSubId(subId);
4126 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004127 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004128 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4129 false);
4130 boolean requireVoiceVtProvisioning = c.getBoolean(
4131 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4132
4133 // First check to make sure that the capability requires provisioning.
4134 switch (capability) {
4135 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4136 // intentional fallthrough
4137 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4138 if (requireVoiceVtProvisioning) {
4139 // Voice and Video requires provisioning
4140 return true;
4141 }
4142 break;
4143 }
4144 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4145 if (requireUtProvisioning) {
4146 // UT requires provisioning
4147 return true;
4148 }
4149 break;
4150 }
4151 }
4152 return false;
4153 }
4154
allenwtsu99c623b2020-01-03 18:24:23 +08004155 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4156 int capability) {
4157 CarrierConfigManager configManager = new CarrierConfigManager(context);
4158 PersistableBundle c = configManager.getConfigForSubId(subId);
4159
4160 boolean requireRcsProvisioning = c.getBoolean(
4161 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4162
4163 // First check to make sure that the capability requires provisioning.
4164 switch (capability) {
4165 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4166 // intentional fallthrough
4167 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4168 if (requireRcsProvisioning) {
4169 // OPTION or PRESENCE requires provisioning
4170 return true;
4171 }
4172 break;
4173 }
4174 }
4175 return false;
4176 }
4177
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004178 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004179 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004180 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4181 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4182 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004183 enforceReadPrivilegedPermission("getImsProvisioningInt");
4184 final long identity = Binder.clearCallingIdentity();
4185 try {
4186 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004187 int slotId = getSlotIndex(subId);
4188 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4189 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4190 + subId + "' for key:" + key);
4191 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4192 }
4193 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004194 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004195 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4196 + subId + "' for key:" + key);
4197 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004198 } finally {
4199 Binder.restoreCallingIdentity(identity);
4200 }
4201 }
4202
4203 @Override
4204 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004205 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4206 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4207 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004208 enforceReadPrivilegedPermission("getImsProvisioningString");
4209 final long identity = Binder.clearCallingIdentity();
4210 try {
4211 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004212 int slotId = getSlotIndex(subId);
4213 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4214 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4215 + subId + "' for key:" + key);
4216 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4217 }
4218 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004219 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004220 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4221 + subId + "' for key:" + key);
4222 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004223 } finally {
4224 Binder.restoreCallingIdentity(identity);
4225 }
4226 }
4227
4228 @Override
4229 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004230 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4231 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4232 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4234 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004235 final long identity = Binder.clearCallingIdentity();
4236 try {
4237 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004238 int slotId = getSlotIndex(subId);
4239 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4240 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4241 + subId + "' for key:" + key);
4242 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4243 }
4244 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004245 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004246 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4247 + "' for key:" + key);
4248 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004249 } finally {
4250 Binder.restoreCallingIdentity(identity);
4251 }
4252 }
4253
4254 @Override
4255 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004256 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4257 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4258 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4260 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004264 int slotId = getSlotIndex(subId);
4265 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4266 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4267 + subId + "' for key:" + key);
4268 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4269 }
4270 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004271 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004272 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4273 + "' for key:" + key);
4274 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004275 } finally {
4276 Binder.restoreCallingIdentity(identity);
4277 }
4278 }
4279
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004280 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 int slotId = SubscriptionManager.getSlotIndex(subId);
4282 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004283 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4284 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 }
4286 return slotId;
4287 }
4288
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004289 private int getSlotIndex(int subId) {
4290 int slotId = SubscriptionManager.getSlotIndex(subId);
4291 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4292 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4293 }
4294 return slotId;
4295 }
4296
Wink Saville36469e72014-06-11 15:17:00 -07004297 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004298 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004299 */
4300 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004301 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4302 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004303 final int targetSdk = getTargetSdk(callingPackage);
4304 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004305 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004306 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004307 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004308 mApp, subId, callingPackage, callingFeatureId,
4309 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004310 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4311 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 final Phone phone = getPhone(subId);
4316 if (phone != null) {
4317 return phone.getServiceState().getDataNetworkType();
4318 } else {
4319 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4320 }
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004324 }
4325
4326 /**
4327 * Returns the data network type
4328 */
4329 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004330 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4331 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4332 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004333 }
4334
4335 /**
4336 * Returns the data network type for a subId
4337 */
4338 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004339 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4340 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004341 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004342 mApp, subId, callingPackage, callingFeatureId,
4343 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004344 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4345 }
4346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347 final long identity = Binder.clearCallingIdentity();
4348 try {
4349 final Phone phone = getPhone(subId);
4350 if (phone != null) {
4351 return phone.getServiceState().getDataNetworkType();
4352 } else {
4353 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4354 }
4355 } finally {
4356 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004358 }
4359
4360 /**
Wink Saville36469e72014-06-11 15:17:00 -07004361 * Returns the Voice network type for a subId
4362 */
4363 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004364 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4365 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004367 mApp, subId, callingPackage, callingFeatureId,
4368 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004369 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4370 }
4371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372 final long identity = Binder.clearCallingIdentity();
4373 try {
4374 final Phone phone = getPhone(subId);
4375 if (phone != null) {
4376 return phone.getServiceState().getVoiceNetworkType();
4377 } else {
4378 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4379 }
4380 } finally {
4381 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004383 }
4384
4385 /**
4386 * @return true if a ICC card is present
4387 */
4388 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004389 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004390 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4391 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004392 }
4393
4394 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004395 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004396 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004397 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004398 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004399 final long identity = Binder.clearCallingIdentity();
4400 try {
4401 final Phone phone = PhoneFactory.getPhone(slotIndex);
4402 if (phone != null) {
4403 return phone.getIccCard().hasIccCard();
4404 } else {
4405 return false;
4406 }
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004410 }
4411
4412 /**
4413 * Return if the current radio is LTE on CDMA. This
4414 * is a tri-state return value as for a period of time
4415 * the mode may be unknown.
4416 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004417 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004418 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004419 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004420 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004421 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004422 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4423 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4424 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004425 }
4426
Sanket Padawe356d7632015-06-22 14:03:32 -07004427 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004428 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4429 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004430 try {
4431 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4432 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004433 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4434 }
4435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436 final long identity = Binder.clearCallingIdentity();
4437 try {
4438 final Phone phone = getPhone(subId);
4439 if (phone == null) {
4440 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4441 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004442 return TelephonyProperties.lte_on_cdma_device()
4443 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 }
4445 } finally {
4446 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004447 }
Wink Saville36469e72014-06-11 15:17:00 -07004448 }
4449
Wink Saville36469e72014-06-11 15:17:00 -07004450 /**
4451 * {@hide}
4452 * Returns Default subId, 0 in the case of single standby.
4453 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004454 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004455 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004456 }
4457
Shishir Agrawala9f32182016-04-12 12:00:16 -07004458 private int getSlotForDefaultSubscription() {
4459 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4460 }
4461
Wink Savilleb564aae2014-10-23 10:18:09 -07004462 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004463 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004464 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004465
Pengquan Menge92a50d2018-09-21 15:54:48 -07004466 private boolean isActiveSubscription(int subId) {
4467 return mSubscriptionController.isActiveSubId(subId);
4468 }
4469
Ihab Awadf2177b72013-11-25 13:33:23 -08004470 /**
4471 * @see android.telephony.TelephonyManager.WifiCallingChoices
4472 */
4473 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 final long identity = Binder.clearCallingIdentity();
4475 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004476 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4478 getWhenToMakeWifiCallsDefaultPreference());
4479 } finally {
4480 Binder.restoreCallingIdentity(identity);
4481 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004482 }
4483
4484 /**
4485 * @see android.telephony.TelephonyManager.WifiCallingChoices
4486 */
4487 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004488 final long identity = Binder.clearCallingIdentity();
4489 try {
4490 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004491 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4493 } finally {
4494 Binder.restoreCallingIdentity(identity);
4495 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004496 }
4497
Sailesh Nepald1e68152013-12-12 19:08:02 -08004498 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004499 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004500 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004501 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004502
Jordan Liu4c733742019-02-28 12:03:40 -08004503 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4504 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4505 if (phoneId == -1) {
4506 throw new IllegalArgumentException("Given slot index: " + slotIndex
4507 + " does not correspond to an active phone");
4508 }
4509 return PhoneFactory.getPhone(phoneId);
4510 }
4511
Shishir Agrawal566b7612013-10-28 14:41:00 -07004512 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004513 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4514 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4516 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004518 if (DBG) {
4519 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4520 }
4521 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4522 p2);
4523 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004524
Jordan Liu4c733742019-02-28 12:03:40 -08004525
4526 @Override
4527 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4528 int slotIndex, String callingPackage, String aid, int p2) {
4529 enforceModifyPermission();
4530 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4531 if (DBG) {
4532 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4533 }
4534 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4535 callingPackage, aid, p2);
4536 }
4537
4538 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4539 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 final long identity = Binder.clearCallingIdentity();
4541 try {
4542 if (TextUtils.equals(ISDR_AID, aid)) {
4543 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004544 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4545 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004546 if (bestComponent == null
4547 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4548 loge("The calling package is not allowed to access ISD-R.");
4549 throw new SecurityException(
4550 "The calling package is not allowed to access ISD-R.");
4551 }
Derek Tan740e1672017-06-27 14:56:27 -07004552 }
Derek Tan740e1672017-06-27 14:56:27 -07004553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004555 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4556 null /* workSource */);
4557 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004558 return response;
4559 } finally {
4560 Binder.restoreCallingIdentity(identity);
4561 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004562 }
4563
4564 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004565 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4567 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004568 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4569 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4570 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004571
Jordan Liu4c733742019-02-28 12:03:40 -08004572 @Override
4573 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4574 enforceModifyPermission();
4575 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4576 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4577 channel);
4578 }
4579
4580 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 final long identity = Binder.clearCallingIdentity();
4582 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004583 if (channel < 0) {
4584 return false;
4585 }
Jordan Liu4c733742019-02-28 12:03:40 -08004586 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4587 null /* workSource */);
4588 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 return success;
4590 } finally {
4591 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004592 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004593 }
4594
4595 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004596 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004597 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4599 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004600 if (DBG) {
4601 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4602 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4603 + p3 + " data=" + data);
4604 }
4605 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4606 command, p1, p2, p3, data);
4607 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004608
Jordan Liu4c733742019-02-28 12:03:40 -08004609 @Override
4610 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4611 int command, int p1, int p2, int p3, String data) {
4612 enforceModifyPermission();
4613 if (DBG) {
4614 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4615 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4616 + p3 + " data=" + data);
4617 }
4618 return iccTransmitApduLogicalChannelWithPermission(
4619 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4620 data);
4621 }
4622
4623 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4624 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 final long identity = Binder.clearCallingIdentity();
4626 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004627 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628 return "";
4629 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004630
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004632 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4633 null /* workSource */);
4634 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636 // Append the returned status code to the end of the response payload.
4637 String s = Integer.toHexString(
4638 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4639 if (response.payload != null) {
4640 s = IccUtils.bytesToHexString(response.payload) + s;
4641 }
4642 return s;
4643 } finally {
4644 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004645 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004646 }
Jake Hambye994d462014-02-03 13:10:13 -08004647
Evan Charltonc66da362014-05-16 14:06:40 -07004648 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004649 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4650 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4652 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004654 if (DBG) {
4655 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4656 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4657 }
4658 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4659 cla, command, p1, p2, p3, data);
4660 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004661
Jordan Liu4c733742019-02-28 12:03:40 -08004662 @Override
4663 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4664 int command, int p1, int p2, int p3, String data) {
4665 enforceModifyPermission();
4666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4667 if (DBG) {
4668 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4669 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4670 + " data=" + data);
4671 }
4672
4673 return iccTransmitApduBasicChannelWithPermission(
4674 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4675 p2, p3, data);
4676 }
4677
4678 // open APDU basic channel assuming the caller has sufficient permissions
4679 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4680 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 final long identity = Binder.clearCallingIdentity();
4682 try {
4683 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4684 && TextUtils.equals(ISDR_AID, data)) {
4685 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004686 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4687 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 if (bestComponent == null
4689 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4690 loge("The calling package is not allowed to select ISD-R.");
4691 throw new SecurityException(
4692 "The calling package is not allowed to select ISD-R.");
4693 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004694 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004697 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4698 null /* workSource */);
4699 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004701 // Append the returned status code to the end of the response payload.
4702 String s = Integer.toHexString(
4703 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4704 if (response.payload != null) {
4705 s = IccUtils.bytesToHexString(response.payload) + s;
4706 }
4707 return s;
4708 } finally {
4709 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004710 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004711 }
4712
4713 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004714 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004715 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4717 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 final long identity = Binder.clearCallingIdentity();
4720 try {
4721 if (DBG) {
4722 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4723 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4724 }
4725
4726 IccIoResult response =
4727 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4728 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4729 subId);
4730
4731 if (DBG) {
4732 log("Exchange SIM_IO [R]" + response);
4733 }
4734
4735 byte[] result = null;
4736 int length = 2;
4737 if (response.payload != null) {
4738 length = 2 + response.payload.length;
4739 result = new byte[length];
4740 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4741 } else {
4742 result = new byte[length];
4743 }
4744
4745 result[length - 1] = (byte) response.sw2;
4746 result[length - 2] = (byte) response.sw1;
4747 return result;
4748 } finally {
4749 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004750 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004751 }
4752
Nathan Haroldb3014052017-01-25 15:57:32 -08004753 /**
4754 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4755 * on a particular subscription
4756 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004757 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4758 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004760 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004761 return null;
4762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763
4764 final long identity = Binder.clearCallingIdentity();
4765 try {
4766 if (appType != TelephonyManager.APPTYPE_USIM
4767 && appType != TelephonyManager.APPTYPE_SIM) {
4768 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4769 return null;
4770 }
4771 Object response = sendRequest(
4772 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4773 if (response instanceof String[]) {
4774 return (String[]) response;
4775 }
yincheng zhaod698b842019-09-06 17:06:54 -07004776 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004778 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 } finally {
4780 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004781 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004782 }
4783
yincheng zhaod698b842019-09-06 17:06:54 -07004784 /**
4785 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4786 * subscription.
4787 *
4788 * @param subId the id of the subscription.
4789 * @param appType the uicc app type, must be USIM or SIM.
4790 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4791 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004792 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004793 * @return number of fplmns that is successfully written to the SIM.
4794 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004795 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4796 String callingFeatureId) {
4797 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4798 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004799 if (DBG) logv("no permissions for setForbiddenplmns");
4800 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4801 }
4802 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4803 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4804 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4805 }
4806 if (fplmns == null) {
4807 throw new IllegalArgumentException("Fplmn List provided is null");
4808 }
4809 for (String fplmn : fplmns) {
4810 if (!CellIdentity.isValidPlmn(fplmn)) {
4811 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4812 }
4813 }
4814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 Object response = sendRequest(
4817 CMD_SET_FORBIDDEN_PLMNS,
4818 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4819 subId);
4820 return (int) response;
4821 } finally {
4822 Binder.restoreCallingIdentity(identity);
4823 }
4824 }
4825
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004826 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004827 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4829 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4834 if (response.payload == null) {
4835 return "";
4836 }
Evan Charltonc66da362014-05-16 14:06:40 -07004837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004838 // Append the returned status code to the end of the response payload.
4839 String s = Integer.toHexString(
4840 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4841 s = IccUtils.bytesToHexString(response.payload) + s;
4842 return s;
4843 } finally {
4844 Binder.restoreCallingIdentity(identity);
4845 }
Evan Charltonc66da362014-05-16 14:06:40 -07004846 }
4847
Jake Hambye994d462014-02-03 13:10:13 -08004848 /**
4849 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4850 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4851 *
4852 * @param itemID the ID of the item to read
4853 * @return the NV item as a String, or null on error.
4854 */
4855 @Override
4856 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004857 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4859 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860
4861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004864 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4866 return value;
4867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
Jake Hambye994d462014-02-03 13:10:13 -08004870 }
4871
4872 /**
4873 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4874 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4875 *
4876 * @param itemID the ID of the item to read
4877 * @param itemValue the value to write, as a String
4878 * @return true on success; false on any failure
4879 */
4880 @Override
4881 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004882 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4884 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004885
4886 final long identity = Binder.clearCallingIdentity();
4887 try {
4888 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4889 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004890 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4892 return success;
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
Jake Hambye994d462014-02-03 13:10:13 -08004896 }
4897
4898 /**
4899 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4900 * Used for device configuration by some CDMA operators.
4901 *
4902 * @param preferredRoamingList byte array containing the new PRL
4903 * @return true on success; false on any failure
4904 */
4905 @Override
4906 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4908 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909
4910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4913 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4914 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4915 return success;
4916 } finally {
4917 Binder.restoreCallingIdentity(identity);
4918 }
Jake Hambye994d462014-02-03 13:10:13 -08004919 }
4920
4921 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004922 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004923 * Used for device configuration by some CDMA operators.
4924 *
chen xu6dac5ab2018-10-26 17:39:23 -07004925 * @param slotIndex - device slot.
4926 *
Jake Hambye994d462014-02-03 13:10:13 -08004927 * @return true on success; false on any failure
4928 */
4929 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004930 public boolean resetModemConfig(int slotIndex) {
4931 Phone phone = PhoneFactory.getPhone(slotIndex);
4932 if (phone != null) {
4933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4934 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935
chen xu6dac5ab2018-10-26 17:39:23 -07004936 final long identity = Binder.clearCallingIdentity();
4937 try {
4938 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4939 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4940 return success;
4941 } finally {
4942 Binder.restoreCallingIdentity(identity);
4943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 }
chen xu6dac5ab2018-10-26 17:39:23 -07004945 return false;
4946 }
4947
4948 /**
4949 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4950 *
4951 * @param slotIndex - device slot.
4952 *
4953 * @return true on success; false on any failure
4954 */
4955 @Override
4956 public boolean rebootModem(int slotIndex) {
4957 Phone phone = PhoneFactory.getPhone(slotIndex);
4958 if (phone != null) {
4959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4960 mApp, phone.getSubId(), "rebootModem");
4961
4962 final long identity = Binder.clearCallingIdentity();
4963 try {
4964 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4965 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4966 return success;
4967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
4970 }
4971 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004972 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004973
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004974 public String[] getPcscfAddress(String apnType, String callingPackage,
4975 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004976 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4978 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004979 return new String[0];
4980 }
4981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 final long identity = Binder.clearCallingIdentity();
4983 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004984 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 } finally {
4986 Binder.restoreCallingIdentity(identity);
4987 }
Wink Saville36469e72014-06-11 15:17:00 -07004988 }
4989
Brad Ebinger51f743a2017-01-23 13:50:20 -08004990 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004991 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4992 * {@link #disableIms(int)}.
4993 * @param slotIndex device slot.
4994 */
4995 public void resetIms(int slotIndex) {
4996 enforceModifyPermission();
4997
4998 final long identity = Binder.clearCallingIdentity();
4999 try {
5000 if (mImsResolver == null) {
5001 // may happen if the does not support IMS.
5002 return;
5003 }
5004 mImsResolver.disableIms(slotIndex);
5005 mImsResolver.enableIms(slotIndex);
5006 } finally {
5007 Binder.restoreCallingIdentity(identity);
5008 }
5009 }
5010
5011 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005012 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5013 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005014 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005015 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005016 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017
5018 final long identity = Binder.clearCallingIdentity();
5019 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005020 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005021 // may happen if the device does not support IMS.
5022 return;
5023 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005024 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025 } finally {
5026 Binder.restoreCallingIdentity(identity);
5027 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005028 }
5029
5030 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005031 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5032 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005033 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005034 public void disableIms(int slotId) {
5035 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036
5037 final long identity = Binder.clearCallingIdentity();
5038 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005039 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005040 // may happen if the device does not support IMS.
5041 return;
5042 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005043 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 } finally {
5045 Binder.restoreCallingIdentity(identity);
5046 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005047 }
5048
5049 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005050 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5051 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005052 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005053 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005054 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005055 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056
5057 final long identity = Binder.clearCallingIdentity();
5058 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005059 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005060 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5061 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005062 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005063 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005067 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005068 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005069 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5070 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005071 @Override
5072 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005073 enforceModifyPermission();
5074
5075 final long identity = Binder.clearCallingIdentity();
5076 try {
5077 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005078 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005079 } finally {
5080 Binder.restoreCallingIdentity(identity);
5081 }
5082 }
5083
5084 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005085 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005086 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005087 */
5088 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5089 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090
5091 final long identity = Binder.clearCallingIdentity();
5092 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005093 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005094 // may happen if the device does not support IMS.
5095 return null;
5096 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005097 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005101 }
5102
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005103 /**
5104 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005105 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005106 */
5107 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5108 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109
5110 final long identity = Binder.clearCallingIdentity();
5111 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005112 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005113 // may happen if the device does not support IMS.
5114 return null;
5115 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005116 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 } finally {
5118 Binder.restoreCallingIdentity(identity);
5119 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005120 }
5121
Brad Ebinger884c07b2018-02-15 16:17:40 -08005122 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005123 * Sets the ImsService Package Name that Telephony will bind to.
5124 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005125 * @param slotIndex the slot ID that the ImsService should bind for.
5126 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005127 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005128 * @param featureTypes An integer array of feature types associated with a packageName.
5129 * @param packageName The name of the package that the current configuration will be replaced
5130 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005131 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005132 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005133 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5134 int[] featureTypes, String packageName) {
5135 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5136 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5138 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005139 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141 final long identity = Binder.clearCallingIdentity();
5142 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005143 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005144 // may happen if the device does not support IMS.
5145 return false;
5146 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005147 Map<Integer, String> featureConfig = new HashMap<>();
5148 for (int featureType : featureTypes) {
5149 featureConfig.put(featureType, packageName);
5150 }
5151 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5152 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005156 }
5157
5158 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005159 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005160 *
5161 * @param slotId The slot that the ImsService is associated with.
5162 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5163 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005164 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005165 * @return the package name of the ImsService configuration.
5166 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005167 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5168 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005169 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005170 TelephonyPermissions
5171 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5172 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5173 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175 final long identity = Binder.clearCallingIdentity();
5176 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005177 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005178 // may happen if the device does not support IMS.
5179 return "";
5180 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005181 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005182 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5183 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005187 }
5188
Brad Ebinger77b832e2019-10-17 17:03:22 -07005189 /**
5190 * Get the MmTelFeature state associated with the requested subscription id.
5191 * @param subId The subscription that the MmTelFeature is associated with.
5192 * @param callback A callback with an integer containing the
5193 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5194 */
5195 @Override
5196 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5197 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5198 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5199 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5200 "IMS not available on device.");
5201 }
5202 final long token = Binder.clearCallingIdentity();
5203 try {
5204 int slotId = getSlotIndex(subId);
5205 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5206 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5207 + subId + "'");
5208 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5209 }
5210 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5211 try {
5212 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5213 } catch (RemoteException e) {
5214 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5215 + "Ignore");
5216 }
5217 });
5218 } finally {
5219 Binder.restoreCallingIdentity(token);
5220 }
5221 }
5222
Wink Saville36469e72014-06-11 15:17:00 -07005223 public void setImsRegistrationState(boolean registered) {
5224 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225
5226 final long identity = Binder.clearCallingIdentity();
5227 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005228 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 } finally {
5230 Binder.restoreCallingIdentity(identity);
5231 }
Wink Saville36469e72014-06-11 15:17:00 -07005232 }
5233
5234 /**
Stuart Scott54788802015-03-30 13:18:01 -07005235 * Set the network selection mode to automatic.
5236 *
5237 */
5238 @Override
5239 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5241 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242
5243 final long identity = Binder.clearCallingIdentity();
5244 try {
shilufc958392020-01-20 11:36:01 -08005245 if (!isActiveSubscription(subId)) {
5246 return;
5247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5249 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5250 } finally {
5251 Binder.restoreCallingIdentity(identity);
5252 }
Stuart Scott54788802015-03-30 13:18:01 -07005253 }
5254
Jack Yud10cdd42020-09-28 20:28:01 -07005255 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005256 * Ask the radio to connect to the input network and change selection mode to manual.
5257 *
5258 * @param subId the id of the subscription.
5259 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5260 * the operator to attach to.
5261 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5262 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5263 * normal network selection next time.
5264 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005265 */
5266 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005267 public boolean setNetworkSelectionModeManual(
5268 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5270 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005271
5272 if (!isActiveSubscription(subId)) {
5273 return false;
5274 }
5275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 final long identity = Binder.clearCallingIdentity();
5277 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005278 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005280 if (DBG) {
5281 log("setNetworkSelectionModeManual: subId: " + subId
5282 + " operator: " + operatorInfo);
5283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005288 }
shilu84f6e8b2019-12-19 13:58:01 -08005289 /**
5290 * Get the manual network selection
5291 *
5292 * @param subId the id of the subscription.
5293 *
5294 * @return the previously saved user selected PLMN
5295 */
5296 @Override
5297 public String getManualNetworkSelectionPlmn(int subId) {
5298 TelephonyPermissions
5299 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5300 mApp, subId, "getManualNetworkSelectionPlmn");
5301
5302 final long identity = Binder.clearCallingIdentity();
5303 try {
5304 if (!isActiveSubscription(subId)) {
5305 return "";
5306 }
5307
5308 final Phone phone = getPhone(subId);
5309 if (phone == null) {
5310 return "";
5311 }
5312 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5313 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5314 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
5318 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005319
5320 /**
5321 * Scans for available networks.
5322 */
5323 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005324 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5325 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5327 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005328 LocationAccessPolicy.LocationPermissionResult locationResult =
5329 LocationAccessPolicy.checkLocationPermission(mApp,
5330 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5331 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005332 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005333 .setCallingPid(Binder.getCallingPid())
5334 .setCallingUid(Binder.getCallingUid())
5335 .setMethod("getCellNetworkScanResults")
5336 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5337 .build());
5338 switch (locationResult) {
5339 case DENIED_HARD:
5340 throw new SecurityException("Not allowed to access scan results -- location");
5341 case DENIED_SOFT:
5342 return null;
5343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344
Pengquan Menga1bb6272018-09-06 09:59:22 -07005345 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346 try {
5347 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005348 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 } finally {
5351 Binder.restoreCallingIdentity(identity);
5352 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005353 }
5354
5355 /**
sqian80370722020-01-29 15:02:51 -08005356 * Get the call forwarding info, given the call forwarding reason.
5357 */
5358 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005359 public void getCallForwarding(int subId, int callForwardingReason,
5360 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005361 enforceReadPrivilegedPermission("getCallForwarding");
5362 long identity = Binder.clearCallingIdentity();
5363 try {
5364 if (DBG) {
5365 log("getCallForwarding: subId " + subId
5366 + " callForwardingReason" + callForwardingReason);
5367 }
Hall Liua1acea22020-09-18 19:04:59 -07005368
5369 Phone phone = getPhone(subId);
5370 if (phone == null) {
5371 try {
5372 callback.onError(CallForwardingInfo.ERROR_UNKNOWN);
5373 } catch (RemoteException e) {
5374 // ignore
5375 }
5376 return;
5377 }
5378
5379 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5380 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5381 @Override
5382 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5383 try {
5384 callback.onCallForwardingInfoAvailable(info);
5385 } catch (RemoteException e) {
5386 // ignore
5387 }
5388 }
5389
5390 @Override
5391 public void onError(int error) {
5392 try {
5393 callback.onError(error);
5394 } catch (RemoteException e) {
5395 // ignore
5396 }
5397 }
5398 });
5399 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005400 } finally {
5401 Binder.restoreCallingIdentity(identity);
5402 }
5403 }
5404
5405 /**
5406 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5407 * reason, the number to forward, and the timeout before the forwarding is attempted.
5408 */
5409 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005410 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5411 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005412 enforceModifyPermission();
5413 long identity = Binder.clearCallingIdentity();
5414 try {
5415 if (DBG) {
5416 log("setCallForwarding: subId " + subId
5417 + " callForwardingInfo" + callForwardingInfo);
5418 }
Hall Liua1acea22020-09-18 19:04:59 -07005419
5420 Phone phone = getPhone(subId);
5421 if (phone == null) {
5422 try {
5423 callback.accept(CallForwardingInfo.ERROR_UNKNOWN);
5424 } catch (RemoteException e) {
5425 // ignore
5426 }
5427 return;
5428 }
5429
5430 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5431 FunctionalUtils.ignoreRemoteException(callback::accept));
5432
5433 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005434 } finally {
5435 Binder.restoreCallingIdentity(identity);
5436 }
5437 }
5438
5439 /**
Hall Liua1acea22020-09-18 19:04:59 -07005440 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005441 */
5442 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005443 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005444 enforceReadPrivilegedPermission("getCallForwarding");
5445 long identity = Binder.clearCallingIdentity();
5446 try {
Hall Liua1acea22020-09-18 19:04:59 -07005447
5448 Phone phone = getPhone(subId);
5449 if (phone == null) {
5450 try {
5451 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5452 } catch (RemoteException e) {
5453 // ignore
5454 }
5455 return;
5456 }
5457
5458 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5459
sqian80370722020-01-29 15:02:51 -08005460 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005461 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005462 } finally {
5463 Binder.restoreCallingIdentity(identity);
5464 }
5465 }
5466
5467 /**
Hall Liua1acea22020-09-18 19:04:59 -07005468 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005469 */
5470 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005471 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005472 enforceModifyPermission();
5473 long identity = Binder.clearCallingIdentity();
5474 try {
Hall Liua1acea22020-09-18 19:04:59 -07005475 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5476
5477 Phone phone = getPhone(subId);
5478 if (phone == null) {
5479 try {
5480 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5481 } catch (RemoteException e) {
5482 // ignore
5483 }
5484 return;
5485 }
5486
5487 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5488 FunctionalUtils.ignoreRemoteException(callback::accept));
5489
5490 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005491 } finally {
5492 Binder.restoreCallingIdentity(identity);
5493 }
5494 }
5495
5496 /**
yinxub1bed742017-04-17 11:45:04 -07005497 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005498 *
yinxub1bed742017-04-17 11:45:04 -07005499 * @param subId id of the subscription
5500 * @param request contains the radio access networks with bands/channels to scan
5501 * @param messenger callback messenger for scan results or errors
5502 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005503 * @return the id of the requested scan which can be used to stop the scan.
5504 */
5505 @Override
5506 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005507 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5509 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005510 LocationAccessPolicy.LocationPermissionResult locationResult =
5511 LocationAccessPolicy.checkLocationPermission(mApp,
5512 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5513 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005514 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005515 .setCallingPid(Binder.getCallingPid())
5516 .setCallingUid(Binder.getCallingUid())
5517 .setMethod("requestNetworkScan")
5518 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5519 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005520 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005521 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005522 if (e != null) {
5523 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5524 throw e;
5525 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005526 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005527 return TelephonyScanManager.INVALID_SCAN_ID;
5528 }
5529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 }
Hall Liu912dfd32019-04-25 14:02:26 -07005531 int callingUid = Binder.getCallingUid();
5532 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005533 final long identity = Binder.clearCallingIdentity();
5534 try {
5535 return mNetworkScanRequestTracker.startNetworkScan(
5536 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005537 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005538 } finally {
5539 Binder.restoreCallingIdentity(identity);
5540 }
yinxu504e1392017-04-12 16:03:22 -07005541 }
5542
Hall Liub2ac8ef2019-02-28 15:56:23 -08005543 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005544 NetworkScanRequest request, int subId) {
5545 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5546 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5547 boolean hasNetworkScanPermission =
5548 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5549 == PERMISSION_GRANTED;
5550
5551 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5552 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5553 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005554 }
5555
5556 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5557 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005558 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5559 return new SecurityException("Specific channels must not be"
5560 + " scanned without location access.");
5561 }
5562 }
5563 }
5564
Hall Liub2ac8ef2019-02-28 15:56:23 -08005565 return null;
5566 }
5567
yinxu504e1392017-04-12 16:03:22 -07005568 /**
5569 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005570 *
5571 * @param subId id of the subscription
5572 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005573 */
5574 @Override
5575 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5577 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578
Hall Liu912dfd32019-04-25 14:02:26 -07005579 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 final long identity = Binder.clearCallingIdentity();
5581 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005582 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
yinxu504e1392017-04-12 16:03:22 -07005586 }
5587
5588 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005589 * Get the calculated preferred network type.
5590 * Used for debugging incorrect network type.
5591 *
5592 * @return the preferred network type, defined in RILConstants.java.
5593 */
5594 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005595 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005596 final Phone defaultPhone = getDefaultPhone();
5597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005598 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005599 return RILConstants.PREFERRED_NETWORK_MODE;
5600 }
5601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602 final long identity = Binder.clearCallingIdentity();
5603 try {
5604 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005605 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
Junda Liu84d15a22014-07-02 11:21:04 -07005609 }
5610
5611 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005612 * Get the preferred network type.
5613 * Used for device configuration by some CDMA operators.
5614 *
5615 * @return the preferred network type, defined in RILConstants.java.
5616 */
5617 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005618 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005619 TelephonyPermissions
5620 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5621 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622
5623 final long identity = Binder.clearCallingIdentity();
5624 try {
5625 if (DBG) log("getPreferredNetworkType");
5626 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5627 int networkType = (result != null ? result[0] : -1);
5628 if (DBG) log("getPreferredNetworkType: " + networkType);
5629 return networkType;
5630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005633 }
5634
5635 /**
5636 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005637 *
5638 * @param networkType the preferred network type, defined in RILConstants.java.
5639 * @return true on success; false on any failure.
5640 */
5641 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005642 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5644 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645
5646 final long identity = Binder.clearCallingIdentity();
5647 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005648 Settings.Global.putInt(mApp.getContentResolver(),
5649 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005650
5651 Boolean success = (Boolean) sendRequest(
5652 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5653 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5654 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 } finally {
5656 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005657 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005658 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005659
5660 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005661 * Get the allowed network types that store in the telephony provider.
5662 *
5663 * @param subId the id of the subscription.
5664 * @return allowedNetworkTypes the allowed network types.
5665 */
5666 @Override
5667 public long getAllowedNetworkTypes(int subId) {
5668 TelephonyPermissions
5669 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5670 mApp, subId, "getAllowedNetworkTypes");
5671
5672 final long identity = Binder.clearCallingIdentity();
5673 try {
5674 return SubscriptionManager.getLongSubscriptionProperty(
5675 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5676 } finally {
5677 Binder.restoreCallingIdentity(identity);
5678 }
5679 }
5680
5681 /**
5682 * Set the allowed network types.
5683 *
5684 * @param subId the id of the subscription.
5685 * @param allowedNetworkTypes the allowed network types.
5686 * @return true on success; false on any failure.
5687 */
5688 @Override
5689 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5691 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005692
calvinpan089c2a62020-03-12 14:17:55 +08005693 SubscriptionManager.setSubscriptionProperty(subId,
5694 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5695 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005696
calvinpan089c2a62020-03-12 14:17:55 +08005697 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5698 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5699 RILConstants.PREFERRED_NETWORK_MODE);
5700 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005701 }
5702
5703 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005704 * Get the allowed network types for certain reason.
5705 *
5706 * @param subId the id of the subscription.
5707 * @param reason the reason the allowed network type change is taking place
5708 * @return the allowed network types.
5709 */
5710 @Override
5711 public long getAllowedNetworkTypesForReason(int subId,
5712 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5713 TelephonyPermissions
5714 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5715 mApp, subId, "getAllowedNetworkTypesForReason");
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5719 } finally {
5720 Binder.restoreCallingIdentity(identity);
5721 }
5722 }
5723
5724 /**
5725 * Get the effective allowed network types on the device.
5726 * This API will return an intersection of allowed network types for all reasons,
5727 * including the configuration done through setAllowedNetworkTypes
5728 *
5729 * @param subId the id of the subscription.
5730 * @return the allowed network types
5731 */
5732 @Override
5733 public long getEffectiveAllowedNetworkTypes(int subId) {
5734 TelephonyPermissions
5735 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5736 mApp, subId, "getEffectiveAllowedNetworkTypes");
5737 final long identity = Binder.clearCallingIdentity();
5738 try {
5739 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
5743 }
5744
5745 /**
5746 * Set the allowed network types of the device and
5747 * provide the reason triggering the allowed network change.
5748 *
5749 * @param subId the id of the subscription.
5750 * @param reason the reason the allowed network type change is taking place
5751 * @param allowedNetworkTypes the allowed network types.
5752 * @return true on success; false on any failure.
5753 */
5754 @Override
5755 public boolean setAllowedNetworkTypesForReason(int subId,
5756 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5758 mApp, subId, "setAllowedNetworkTypesForReason");
5759 final long identity = Binder.clearCallingIdentity();
5760 try {
5761 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5762 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5763 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5764 RILConstants.PREFERRED_NETWORK_MODE);
5765 return setPreferredNetworkType(subId, preferredNetworkMode);
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
5769 }
5770
5771 /**
Miaoa84611c2019-03-15 09:21:10 +08005772 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005773 *
Miaoa84611c2019-03-15 09:21:10 +08005774 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005775 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005776 * @hide
5777 */
5778 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005779 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005780 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005782 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783 try {
Miaoa84611c2019-03-15 09:21:10 +08005784 if (phone != null) {
5785 return phone.hasMatchedTetherApnSetting();
5786 } else {
5787 return false;
5788 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789 } finally {
5790 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005791 }
Junda Liu475951f2014-11-07 16:45:03 -08005792 }
5793
5794 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005795 * Set mobile data enabled
5796 * Used by the user through settings etc to turn on/off mobile data
5797 *
5798 * @param enable {@code true} turn turn data on, else {@code false}
5799 */
5800 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005801 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5803 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804
5805 final long identity = Binder.clearCallingIdentity();
5806 try {
5807 int phoneId = mSubscriptionController.getPhoneId(subId);
5808 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5809 Phone phone = PhoneFactory.getPhone(phoneId);
5810 if (phone != null) {
5811 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005812 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005814 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 }
5816 } finally {
5817 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005818 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005819 }
5820
5821 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005822 * Enable or disable always reporting signal strength changes from radio.
5823 *
5824 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5825 */
5826 @Override
5827 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5828 enforceModifyPermission();
5829 enforceSystemCaller();
5830
5831 final long identity = Binder.clearCallingIdentity();
5832 final Phone phone = getPhone(subId);
5833 try {
5834 if (phone != null) {
5835 if (DBG) {
5836 log("setAlwaysReportSignalStrength: subId=" + subId
5837 + " isEnable=" + isEnable);
5838 }
5839 phone.setAlwaysReportSignalStrength(isEnable);
5840 } else {
5841 loge("setAlwaysReportSignalStrength: no phone found for subId="
5842 + subId);
5843 }
5844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
5847 }
5848
5849 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005850 * Get the user enabled state of Mobile Data.
5851 *
5852 * TODO: remove and use isUserDataEnabled.
5853 * This can't be removed now because some vendor codes
5854 * calls through ITelephony directly while they should
5855 * use TelephonyManager.
5856 *
5857 * @return true on enabled
5858 */
5859 @Override
5860 public boolean getDataEnabled(int subId) {
5861 return isUserDataEnabled(subId);
5862 }
5863
5864 /**
5865 * Get whether mobile data is enabled per user setting.
5866 *
5867 * There are other factors deciding whether mobile data is actually enabled, but they are
5868 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005869 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005870 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005871 *
5872 * @return {@code true} if data is enabled else {@code false}
5873 */
5874 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005875 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005876 try {
5877 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5878 null);
5879 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5881 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005882 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883
5884 final long identity = Binder.clearCallingIdentity();
5885 try {
5886 int phoneId = mSubscriptionController.getPhoneId(subId);
5887 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5888 Phone phone = PhoneFactory.getPhone(phoneId);
5889 if (phone != null) {
5890 boolean retVal = phone.isUserDataEnabled();
5891 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5892 return retVal;
5893 } else {
5894 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5895 return false;
5896 }
5897 } finally {
5898 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005899 }
5900 }
5901
5902 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005903 * Checks if the device is capable of mobile data by considering whether whether the
5904 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5905 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005906 *
Shuo Qian985d1232020-01-08 14:30:06 -08005907 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005908 */
5909 @Override
5910 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005911 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912
5913 final long identity = Binder.clearCallingIdentity();
5914 try {
5915 int phoneId = mSubscriptionController.getPhoneId(subId);
5916 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5917 Phone phone = PhoneFactory.getPhone(phoneId);
5918 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005919 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5921 return retVal;
5922 } else {
5923 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5924 return false;
5925 }
5926 } finally {
5927 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005928 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005929 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005930
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005931 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005932 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07005933 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5934 // Skip the check if it's one of these special uids
5935 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5936 }
5937
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005938 //load access rules from carrier configs, and check those as well: b/139133814
5939 SubscriptionController subController = SubscriptionController.getInstance();
5940 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5941 || subController == null) return privilegeFromSim;
5942
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005943 PackageManager pkgMgr = phone.getContext().getPackageManager();
5944 String[] packages = pkgMgr.getPackagesForUid(uid);
5945
5946 final long identity = Binder.clearCallingIdentity();
5947 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07005948 int subId = phone.getSubId();
5949 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5950 // A test override is in place for the privileges for this subId, so don't try to
5951 // read the subscription privileges.
5952 return privilegeFromSim;
5953 }
5954 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005955 SubscriptionManager subManager = (SubscriptionManager)
5956 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5957 for (String pkg : packages) {
5958 if (subManager.canManageSubscription(subInfo, pkg)) {
5959 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5960 }
5961 }
5962 return privilegeFromSim;
5963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
5966 }
5967
5968 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5969 String pkgName) {
5970 //load access rules from carrier configs, and check those as well: b/139133814
5971 SubscriptionController subController = SubscriptionController.getInstance();
5972 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5973 || subController == null) return privilegeFromSim;
5974
5975 final long identity = Binder.clearCallingIdentity();
5976 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07005977 int subId = phone.getSubId();
5978 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5979 // A test override is in place for the privileges for this subId, so don't try to
5980 // read the subscription privileges.
5981 return privilegeFromSim;
5982 }
5983 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005984 SubscriptionManager subManager = (SubscriptionManager)
5985 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5986 return subManager.canManageSubscription(subInfo, pkgName)
5987 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
5991 }
5992
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005993 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005994 public int getCarrierPrivilegeStatus(int subId) {
5995 final Phone phone = getPhone(subId);
5996 if (phone == null) {
5997 loge("getCarrierPrivilegeStatus: Invalid subId");
5998 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5999 }
6000 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006001 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006002 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006003 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6004 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006005
6006 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6007 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006008 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006009 }
Junda Liu29340342014-07-10 15:23:27 -07006010
6011 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006012 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006013 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006014 final Phone phone = getPhone(subId);
6015 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006016 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006017 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6018 }
6019 UiccProfile profile =
6020 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6021 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006022 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006023 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6024 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006025 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006026 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006027 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006028 }
6029
6030 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006031 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6032 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006033 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006034 }
6035
6036 int phoneId = SubscriptionManager.getPhoneId(subId);
6037 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006038 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006039 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006040 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6041 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006042 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6043 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6044 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006045 }
6046
6047 @Override
6048 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006049 if (TextUtils.isEmpty(pkgName))
6050 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006051 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6052 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6053 UiccCard card = UiccController.getInstance().getUiccCard(i);
6054 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006055 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006056 continue;
6057 }
6058
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006059 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6060 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6061 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006062 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6063 break;
6064 }
6065 }
6066
6067 return result;
Junda Liu29340342014-07-10 15:23:27 -07006068 }
Derek Tan89e89d42014-07-08 17:00:10 -07006069
6070 @Override
Junda Liue64de782015-04-16 17:19:16 -07006071 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6072 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6073 loge("phoneId " + phoneId + " is not valid.");
6074 return null;
6075 }
6076 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006077 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006078 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006079 return null ;
6080 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006081 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006082 }
6083
Amith Yamasani6e118872016-02-19 12:53:51 -08006084 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006085 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006086 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006087 List<String> privilegedPackages = new ArrayList<>();
6088 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006089 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6090 // has UICC in that slot.
6091 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006092 if (card.hasCarrierPrivilegeRules()) {
6093 if (packages == null) {
6094 // Only check packages in user 0 for now
6095 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006096 PackageManager.MATCH_DISABLED_COMPONENTS
6097 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006098 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006099 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006100 }
6101 for (int p = packages.size() - 1; p >= 0; p--) {
6102 PackageInfo pkgInfo = packages.get(p);
6103 if (pkgInfo != null && pkgInfo.packageName != null
6104 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006105 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006106 privilegedPackages.add(pkgInfo.packageName);
6107 }
6108 }
6109 }
6110 }
6111 return privilegedPackages;
6112 }
6113
chen xuf7e9fe82019-05-09 19:31:02 -07006114 @Override
6115 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006116 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6117
6118 final long identity = Binder.clearCallingIdentity();
6119
chen xuf7e9fe82019-05-09 19:31:02 -07006120 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006121 try {
6122 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6123 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6124 }
6125 } finally {
6126 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006127 }
6128 return privilegedPackages;
6129 }
6130
Wink Savilleb564aae2014-10-23 10:18:09 -07006131 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006132 final Phone phone = getPhone(subId);
6133 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006134 if (card == null) {
6135 loge("getIccId: No UICC");
6136 return null;
6137 }
6138 String iccId = card.getIccId();
6139 if (TextUtils.isEmpty(iccId)) {
6140 loge("getIccId: ICC ID is null or empty.");
6141 return null;
6142 }
6143 return iccId;
6144 }
6145
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006146 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006147 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6148 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006149 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006150 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 final long identity = Binder.clearCallingIdentity();
6153 try {
6154 final String iccId = getIccId(subId);
6155 final Phone phone = getPhone(subId);
6156 if (phone == null) {
6157 return false;
6158 }
6159 final String subscriberId = phone.getSubscriberId();
6160
6161 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006162 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 + subscriberId + " to " + number);
6164 }
6165
6166 if (TextUtils.isEmpty(iccId)) {
6167 return false;
6168 }
6169
6170 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6171
6172 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6173 if (alphaTag == null) {
6174 editor.remove(alphaTagPrefKey);
6175 } else {
6176 editor.putString(alphaTagPrefKey, alphaTag);
6177 }
6178
6179 // Record both the line number and IMSI for this ICCID, since we need to
6180 // track all merged IMSIs based on line number
6181 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6182 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6183 if (number == null) {
6184 editor.remove(numberPrefKey);
6185 editor.remove(subscriberPrefKey);
6186 } else {
6187 editor.putString(numberPrefKey, number);
6188 editor.putString(subscriberPrefKey, subscriberId);
6189 }
6190
6191 editor.commit();
6192 return true;
6193 } finally {
6194 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006195 }
Derek Tan7226c842014-07-02 17:42:23 -07006196 }
6197
6198 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006199 public String getLine1NumberForDisplay(int subId, String callingPackage,
6200 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006201 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006203 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006204 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006205 return null;
6206 }
Derek Tan97ebb422014-09-05 16:55:38 -07006207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208 final long identity = Binder.clearCallingIdentity();
6209 try {
6210 String iccId = getIccId(subId);
6211 if (iccId != null) {
6212 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6213 if (DBG_MERGE) {
6214 log("getLine1NumberForDisplay returning "
6215 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6216 }
6217 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006218 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006219 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6220 return null;
6221 } finally {
6222 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006223 }
Derek Tan7226c842014-07-02 17:42:23 -07006224 }
6225
6226 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006227 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6228 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006230 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006231 return null;
6232 }
Derek Tan97ebb422014-09-05 16:55:38 -07006233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234 final long identity = Binder.clearCallingIdentity();
6235 try {
6236 String iccId = getIccId(subId);
6237 if (iccId != null) {
6238 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6239 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6240 }
6241 return null;
6242 } finally {
6243 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006244 }
Derek Tan7226c842014-07-02 17:42:23 -07006245 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006246
6247 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006248 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6249 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006250 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6251 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006252 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006253 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006254 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006255 return null;
6256 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006257
Jordan Liub49b04b2019-05-06 14:45:15 -07006258 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6259 // the process, where TelephonyManager was instantiated.
6260 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006261 final long identity = Binder.clearCallingIdentity();
6262 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006263 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006264 final TelephonyManager tele = TelephonyManager.from(context);
6265 final SubscriptionManager sub = SubscriptionManager.from(context);
6266
6267 // Figure out what subscribers are currently active
6268 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269
Jordan Liub49b04b2019-05-06 14:45:15 -07006270 // Only consider subs which match the current subId
6271 // This logic can be simplified. See b/131189269 for progress.
6272 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006273 activeSubscriberIds.add(tele.getSubscriberId(subId));
6274 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275
6276 // First pass, find a number override for an active subscriber
6277 String mergeNumber = null;
6278 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6279 for (String key : prefs.keySet()) {
6280 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6281 final String subscriberId = (String) prefs.get(key);
6282 if (activeSubscriberIds.contains(subscriberId)) {
6283 final String iccId = key.substring(
6284 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6285 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6286 mergeNumber = (String) prefs.get(numberKey);
6287 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006288 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 + " for active subscriber " + subscriberId);
6290 }
6291 if (!TextUtils.isEmpty(mergeNumber)) {
6292 break;
6293 }
6294 }
6295 }
6296 }
6297
6298 // Shortcut when no active merged subscribers
6299 if (TextUtils.isEmpty(mergeNumber)) {
6300 return null;
6301 }
6302
6303 // Second pass, find all subscribers under that line override
6304 final ArraySet<String> result = new ArraySet<>();
6305 for (String key : prefs.keySet()) {
6306 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6307 final String number = (String) prefs.get(key);
6308 if (mergeNumber.equals(number)) {
6309 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6310 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6311 final String subscriberId = (String) prefs.get(subscriberKey);
6312 if (!TextUtils.isEmpty(subscriberId)) {
6313 result.add(subscriberId);
6314 }
6315 }
6316 }
6317 }
6318
6319 final String[] resultArray = result.toArray(new String[result.size()]);
6320 Arrays.sort(resultArray);
6321 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006322 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6324 }
6325 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006326 } finally {
6327 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006328 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006329 }
6330
6331 @Override
zoey chen38003472019-12-13 17:16:31 +08006332 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6333 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006334
6335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 final TelephonyManager telephonyManager = mApp.getSystemService(
6338 TelephonyManager.class);
6339 String subscriberId = telephonyManager.getSubscriberId(subId);
6340 if (subscriberId == null) {
6341 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006342 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006343 + subId);
6344 }
6345 return null;
6346 }
6347
6348 final SubscriptionInfo info = SubscriptionController.getInstance()
6349 .getSubscriptionInfo(subId);
6350 final ParcelUuid groupUuid = info.getGroupUuid();
6351 // If it doesn't belong to any group, return just subscriberId of itself.
6352 if (groupUuid == null) {
6353 return new String[]{subscriberId};
6354 }
6355
6356 // Get all subscriberIds from the group.
6357 final List<String> mergedSubscriberIds = new ArrayList<>();
6358 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006359 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006360 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006361 for (SubscriptionInfo subInfo : groupInfos) {
6362 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6363 if (subscriberId != null) {
6364 mergedSubscriberIds.add(subscriberId);
6365 }
6366 }
6367
6368 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371
6372 }
6373 }
6374
6375 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006376 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006377 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006378 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379
6380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 final Phone phone = getPhone(subId);
6383 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006387 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006388
6389 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006390 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006391 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6392 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006393 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6394 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006395
6396 final long identity = Binder.clearCallingIdentity();
6397 try {
6398 final Phone phone = getPhone(subId);
6399 if (phone == null) {
6400 return false;
6401 }
6402 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6403 cdmaNonRoamingList);
6404 } finally {
6405 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006406 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006407 }
6408
6409 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006410 @Deprecated
6411 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6412 enforceModifyPermission();
6413
6414 int returnValue = 0;
6415 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006416 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006417 if(result.exception == null) {
6418 if (result.result != null) {
6419 byte[] responseData = (byte[])(result.result);
6420 if(responseData.length > oemResp.length) {
6421 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6422 responseData.length + "bytes. Buffer Size is " +
6423 oemResp.length + "bytes.");
6424 }
6425 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6426 returnValue = responseData.length;
6427 }
6428 } else {
6429 CommandException ex = (CommandException) result.exception;
6430 returnValue = ex.getCommandError().ordinal();
6431 if(returnValue > 0) returnValue *= -1;
6432 }
6433 } catch (RuntimeException e) {
6434 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6435 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6436 if(returnValue > 0) returnValue *= -1;
6437 }
6438
6439 return returnValue;
6440 }
6441
6442 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006443 public void setRadioCapability(RadioAccessFamily[] rafs) {
6444 try {
6445 ProxyController.getInstance().setRadioCapability(rafs);
6446 } catch (RuntimeException e) {
6447 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6448 }
6449 }
6450
6451 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006452 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006453 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006454 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006455 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006456 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458 final long identity = Binder.clearCallingIdentity();
6459 try {
chen xub97461a2018-10-26 14:17:57 -07006460 TelephonyPermissions
6461 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6462 mApp, phone.getSubId(), "getRadioAccessFamily");
6463 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006464 } finally {
6465 Binder.restoreCallingIdentity(identity);
6466 }
chen xub97461a2018-10-26 14:17:57 -07006467 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006468 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006469
6470 @Override
6471 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006472 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006473 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474
6475 final long identity = Binder.clearCallingIdentity();
6476 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006477 ImsManager.getInstance(defaultPhone.getContext(),
6478 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006479 } finally {
6480 Binder.restoreCallingIdentity(identity);
6481 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006482 }
6483
6484 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006485 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006486 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6488 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006489 return false;
6490 }
Svet Ganovb320e182015-04-16 12:30:10 -07006491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 // Check the user preference and the system-level IMS setting. Even if the user has
6495 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6496 // In the long run, we may instead need to check if there exists a connection service
6497 // which can support video calling.
6498 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006499 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006500 return imsManager.isVtEnabledByPlatform()
6501 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6502 && imsManager.isVtEnabledByUser();
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006506 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006507
Andrew Leea1239f22015-03-02 17:44:07 -08006508 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006509 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6510 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006511 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006512 mApp, subId, callingPackage, callingFeatureId,
6513 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514 return false;
6515 }
6516
6517 final long identity = Binder.clearCallingIdentity();
6518 try {
6519 CarrierConfigManager configManager =
6520 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006521 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6523 } finally {
6524 Binder.restoreCallingIdentity(identity);
6525 }
Andrew Leea1239f22015-03-02 17:44:07 -08006526 }
6527
6528 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006529 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006531 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532 return false;
6533 }
6534
6535 final long identity = Binder.clearCallingIdentity();
6536 try {
6537 CarrierConfigManager configManager =
6538 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006539 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
Andrew Leea1239f22015-03-02 17:44:07 -08006544 }
6545
Andrew Lee9431b832015-03-09 18:46:45 -07006546 @Override
6547 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006548 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006549 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006550 }
6551
6552 @Override
6553 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554 final long identity = Binder.clearCallingIdentity();
6555 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006556 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 } finally {
6558 Binder.restoreCallingIdentity(identity);
6559 }
Andrew Lee9431b832015-03-09 18:46:45 -07006560 }
6561
Hall Liuf6668912018-10-31 17:05:23 -07006562 /**
6563 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6564 * support for the feature and device firmware support.
6565 *
6566 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6567 */
6568 @Override
6569 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006571 final Phone phone = getPhone(subscriptionId);
6572 if (phone == null) {
6573 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6574 return false;
6575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006577 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6579 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006580 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 return isCarrierSupported && isDeviceSupported;
6582 } finally {
6583 Binder.restoreCallingIdentity(identity);
6584 }
Hall Liu98187582018-01-22 19:15:32 -08006585 }
6586
Hall Liuf6668912018-10-31 17:05:23 -07006587 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006588 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6589 * RTT setting, will return true if the device and carrier both support RTT.
6590 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006591 */
6592 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593 final long identity = Binder.clearCallingIdentity();
6594 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006595 boolean isRttSupported = isRttSupported(subscriptionId);
6596 boolean isUserRttSettingOn = Settings.Secure.getInt(
6597 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6598 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6599 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6600 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 } finally {
6602 Binder.restoreCallingIdentity(identity);
6603 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006604 }
6605
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006606 @Deprecated
6607 @Override
6608 public String getDeviceId(String callingPackage) {
6609 return getDeviceIdWithFeature(callingPackage, null);
6610 }
6611
Sanket Padawe7310cc72015-01-14 09:53:20 -08006612 /**
6613 * Returns the unique device ID of phone, for example, the IMEI for
6614 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6615 *
6616 * <p>Requires Permission:
6617 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6618 */
6619 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006620 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006621 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006622 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006623 return null;
6624 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006625 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006626 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006627 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006628 return null;
6629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006630
6631 final long identity = Binder.clearCallingIdentity();
6632 try {
6633 return phone.getDeviceId();
6634 } finally {
6635 Binder.restoreCallingIdentity(identity);
6636 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006637 }
6638
Ping Sunc67b7c22016-03-02 19:16:45 +08006639 /**
6640 * {@hide}
6641 * Returns the IMS Registration Status on a particular subid
6642 *
6643 * @param subId
6644 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006645 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006646 Phone phone = getPhone(subId);
6647 if (phone != null) {
6648 return phone.isImsRegistered();
6649 } else {
6650 return false;
6651 }
6652 }
6653
Santos Cordon7a1885b2015-02-03 11:15:19 -08006654 @Override
6655 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656 final long identity = Binder.clearCallingIdentity();
6657 try {
6658 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
6661 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006662 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006663
Tyler Gunnf70ed162019-04-03 15:28:53 -07006664 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006665 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006666 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006668 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006669 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6670 }
6671 final long identity = Binder.clearCallingIdentity();
6672 try {
6673 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6674 } finally {
6675 Binder.restoreCallingIdentity(identity);
6676 }
6677 }
6678
6679 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006680 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006681 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6682 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006683 final long identity = Binder.clearCallingIdentity();
6684 try {
6685 Phone phone = getPhone(subscriptionId);
6686 if (phone == null) {
6687 return null;
6688 }
6689 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6690 } finally {
6691 Binder.restoreCallingIdentity(identity);
6692 }
6693 }
6694
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006695 /**
6696 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006697 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006698 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 final long identity = Binder.clearCallingIdentity();
6700 try {
6701 Phone phone = getPhone(subId);
6702 if (phone != null) {
6703 return phone.isWifiCallingEnabled();
6704 } else {
6705 return false;
6706 }
6707 } finally {
6708 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006709 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006710 }
6711
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006712 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006713 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006714 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006715 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 final long identity = Binder.clearCallingIdentity();
6717 try {
6718 Phone phone = getPhone(subId);
6719 if (phone != null) {
6720 return phone.isVideoEnabled();
6721 } else {
6722 return false;
6723 }
6724 } finally {
6725 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006726 }
6727 }
6728
6729 /**
6730 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6731 * defined in {@link ImsRegistrationImplBase}.
6732 */
6733 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006734 final long identity = Binder.clearCallingIdentity();
6735 try {
6736 Phone phone = getPhone(subId);
6737 if (phone != null) {
6738 return phone.getImsRegistrationTech();
6739 } else {
6740 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6741 }
6742 } finally {
6743 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006744 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006745 }
6746
Stuart Scott8eef64f2015-04-08 15:13:54 -07006747 @Override
6748 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006749 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006750 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6751 return;
6752 }
6753
Svet Ganovcc087f82015-05-12 20:35:54 -07006754 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006755
Svet Ganovcc087f82015-05-12 20:35:54 -07006756 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006757 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6758 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006759 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006760 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006761 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006762 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6763 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006764 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006765 // There has been issues when Sms raw table somehow stores orphan
6766 // fragments. They lead to garbled message when new fragments come
6767 // in and combined with those stale ones. In case this happens again,
6768 // user can reset all network settings which will clean up this table.
6769 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006770 // Clean up IMS settings as well here.
6771 int slotId = getSlotIndex(subId);
6772 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6773 ImsManager.getInstance(mApp, slotId).factoryReset();
6774 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006775
6776 // Erase modem config if erase modem on network setting is enabled.
6777 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6778 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6779 if (configValue != null && Boolean.parseBoolean(configValue)) {
6780 sendEraseModemConfig(getDefaultPhone());
6781 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006782 } finally {
6783 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006784 }
6785 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006786
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006787 private void cleanUpSmsRawTable(Context context) {
6788 ContentResolver resolver = context.getContentResolver();
6789 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6790 resolver.delete(uri, null, null);
6791 }
6792
Narayan Kamath1c496c22015-04-16 14:40:19 +01006793 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006794 public String getSimLocaleForSubscriber(int subId) {
6795 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6796 final Phone phone = getPhone(subId);
6797 if (phone == null) {
6798 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006799 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801 final long identity = Binder.clearCallingIdentity();
6802 try {
chen xu5d3637b2019-01-21 23:31:38 -08006803 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006804 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006805 if (info == null) {
6806 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6807 return null;
6808 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 // Try and fetch the locale from the carrier properties or from the SIM language
6810 // preferences (EF-PL and EF-LI)...
6811 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006812 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006813 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6814 if (localeFromDefaultSim != null) {
6815 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6816 if (DBG) log("Using locale from subId: " + subId + " locale: "
6817 + localeFromDefaultSim);
6818 return localeFromDefaultSim.toLanguageTag();
6819 } else {
6820 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 }
6822 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824 // The SIM language preferences only store a language (e.g. fr = French), not an
6825 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6826 // the SIM and carrier preferences does not include a country we add the country
6827 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006828 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006830 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831 return mccLocale.toLanguageTag();
6832 }
6833
6834 if (DBG) log("No locale found - returning null");
6835 return null;
6836 } finally {
6837 Binder.restoreCallingIdentity(identity);
6838 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006839 }
6840
6841 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006842 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006843 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006844 }
6845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006846 /**
6847 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6848 */
6849 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006850 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006851 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006852 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006853
Chenjie Yu1ba97252018-01-11 18:16:20 -08006854 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006855 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006856
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006857 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006858 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6859 * representing the state of the modem.
6860 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006861 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6862 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006863 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006864 */
6865 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006866 public void requestModemActivityInfo(ResultReceiver result) {
6867 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006868 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869
6870 final long identity = Binder.clearCallingIdentity();
6871 try {
sqian1a1be542020-03-05 11:37:28 -08006872 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 } finally {
6874 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006875 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006876 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006877
Siddharth Rayb8114062018-06-17 15:02:38 -07006878 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6879 // less than total activity duration.
6880 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6881 if (info == null) {
6882 return false;
6883 }
6884 int activityDurationMs =
6885 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6886 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006887 int[] txTimeMs = info.getTransmitTimeMillis();
6888 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6889 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006890 }
6891 return (info.isValid()
6892 && (info.getSleepTimeMillis() <= activityDurationMs)
6893 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006894 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006895 && (totalTxTimeMs <= activityDurationMs));
6896 }
6897
Jack Yu85bd38a2015-11-09 11:34:32 -08006898 /**
6899 * {@hide}
6900 * Returns the service state information on specified subscription.
6901 */
6902 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006903 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6904 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006906 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006907 return null;
6908 }
6909
Hall Liuf19c44f2018-11-27 14:38:17 -08006910 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6911 LocationAccessPolicy.checkLocationPermission(mApp,
6912 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6913 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006914 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006915 .setCallingPid(Binder.getCallingPid())
6916 .setCallingUid(Binder.getCallingUid())
6917 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006918 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006919 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6920 .build());
6921
6922 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6923 LocationAccessPolicy.checkLocationPermission(mApp,
6924 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6925 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006926 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006927 .setCallingPid(Binder.getCallingPid())
6928 .setCallingUid(Binder.getCallingUid())
6929 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006930 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006931 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6932 .build());
6933 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6934 boolean hasFinePermission =
6935 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6936 boolean hasCoarsePermission =
6937 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 final long identity = Binder.clearCallingIdentity();
6940 try {
6941 final Phone phone = getPhone(subId);
6942 if (phone == null) {
6943 return null;
6944 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006945
Hall Liuf19c44f2018-11-27 14:38:17 -08006946 ServiceState ss = phone.getServiceState();
6947
6948 // Scrub out the location info in ServiceState depending on what level of access
6949 // the caller has.
6950 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006951 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6952 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 } finally {
6954 Binder.restoreCallingIdentity(identity);
6955 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006956 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006957
6958 /**
6959 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6960 *
6961 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6962 * voicemail ringtone.
6963 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6964 * PhoneAccount.
6965 */
6966 @Override
6967 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 final long identity = Binder.clearCallingIdentity();
6969 try {
6970 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6971 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006972 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006975 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6976 } finally {
6977 Binder.restoreCallingIdentity(identity);
6978 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006979 }
6980
6981 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006982 * Sets the per-account voicemail ringtone.
6983 *
6984 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6985 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6986 *
6987 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6988 * voicemail ringtone.
6989 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6990 * PhoneAccount.
6991 */
6992 @Override
6993 public void setVoicemailRingtoneUri(String callingPackage,
6994 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006995 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006996 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006997 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6998 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7000 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7001 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003
7004 final long identity = Binder.clearCallingIdentity();
7005 try {
7006 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7007 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007008 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009 }
7010 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7011 } finally {
7012 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007013 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007014 }
7015
7016 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007017 * Returns whether vibration is set for voicemail notification in Phone settings.
7018 *
7019 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7020 * voicemail vibration setting.
7021 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7022 */
7023 @Override
7024 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 final long identity = Binder.clearCallingIdentity();
7026 try {
7027 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7028 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007029 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7033 } finally {
7034 Binder.restoreCallingIdentity(identity);
7035 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007036 }
7037
Youhan Wange64578a2016-05-02 15:32:42 -07007038 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007039 * Sets the per-account voicemail vibration.
7040 *
7041 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7042 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7043 *
7044 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7045 * voicemail vibration setting.
7046 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7047 * specific PhoneAccount.
7048 */
7049 @Override
7050 public void setVoicemailVibrationEnabled(String callingPackage,
7051 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007052 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007053 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007054 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7055 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7057 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7058 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007059 }
7060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 final long identity = Binder.clearCallingIdentity();
7062 try {
7063 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7064 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007065 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066 }
7067 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7068 } finally {
7069 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007070 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007071 }
7072
7073 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007074 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7075 *
7076 * @throws SecurityException if the caller does not have the required permission
7077 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007078 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007079 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007080 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007081 }
7082
7083 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007084 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7085 * permission.
7086 *
7087 * @throws SecurityException if the caller does not have the required permission
7088 */
7089 private void enforceSendSmsPermission() {
7090 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7091 }
7092
7093 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007094 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007095 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007096 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007097 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007098 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099 final long identity = Binder.clearCallingIdentity();
7100 try {
7101 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007102 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103 if (componentName == null) {
7104 throw new SecurityException(
7105 "Caller not current active visual voicemail package[null]");
7106 }
7107 String vvmPackage = componentName.getPackageName();
7108 if (!callingPackage.equals(vvmPackage)) {
7109 throw new SecurityException("Caller not current active visual voicemail package["
7110 + vvmPackage + "]");
7111 }
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007114 }
7115 }
7116
7117 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007118 * Return the application ID for the app type.
7119 *
7120 * @param subId the subscription ID that this request applies to.
7121 * @param appType the uicc app type.
7122 * @return Application ID for specificied app type, or null if no uicc.
7123 */
7124 @Override
7125 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007126 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007127 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128
7129 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007130 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 if (phone == null) {
7132 return null;
7133 }
7134 String aid = null;
7135 try {
7136 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7137 .getApplicationByType(appType).getAid();
7138 } catch (Exception e) {
7139 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7140 }
7141 return aid;
7142 } finally {
7143 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007144 }
Youhan Wange64578a2016-05-02 15:32:42 -07007145 }
7146
Youhan Wang4001d252016-05-11 10:29:41 -07007147 /**
7148 * Return the Electronic Serial Number.
7149 *
7150 * @param subId the subscription ID that this request applies to.
7151 * @return ESN or null if error.
7152 */
7153 @Override
7154 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007155 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007156 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157
7158 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007159 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 if (phone == null) {
7161 return null;
7162 }
7163 String esn = null;
7164 try {
7165 esn = phone.getEsn();
7166 } catch (Exception e) {
7167 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7168 }
7169 return esn;
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007172 }
Youhan Wang4001d252016-05-11 10:29:41 -07007173 }
7174
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007175 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007176 * Return the Preferred Roaming List Version.
7177 *
7178 * @param subId the subscription ID that this request applies to.
7179 * @return PRLVersion or null if error.
7180 */
7181 @Override
7182 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007183 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007184 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185
7186 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007187 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188 if (phone == null) {
7189 return null;
7190 }
7191 String cdmaPrlVersion = null;
7192 try {
7193 cdmaPrlVersion = phone.getCdmaPrlVersion();
7194 } catch (Exception e) {
7195 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7196 }
7197 return cdmaPrlVersion;
7198 } finally {
7199 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007200 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007201 }
7202
7203 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007204 * Get snapshot of Telephony histograms
7205 * @return List of Telephony histograms
7206 * @hide
7207 */
7208 @Override
7209 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7211 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212
7213 final long identity = Binder.clearCallingIdentity();
7214 try {
7215 return RIL.getTelephonyRILTimingHistograms();
7216 } finally {
7217 Binder.restoreCallingIdentity(identity);
7218 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007219 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007220
7221 /**
7222 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007223 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7224 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007225 * Require system privileges. In the future we may add this to carrier APIs.
7226 *
Michele Berionne482f8202018-11-27 18:57:59 -08007227 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007228 */
7229 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007230 @TelephonyManager.SetCarrierRestrictionResult
7231 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007232 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007233 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007234
Michele Berionne482f8202018-11-27 18:57:59 -08007235 if (carrierRestrictionRules == null) {
7236 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007237 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 final long identity = Binder.clearCallingIdentity();
7240 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007241 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007242 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 } finally {
7244 Binder.restoreCallingIdentity(identity);
7245 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007246 }
7247
7248 /**
7249 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007250 * Get the allowed carrier list and the excluded carrier list, including the priority between
7251 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007252 * Require system privileges. In the future we may add this to carrier APIs.
7253 *
Michele Berionne482f8202018-11-27 18:57:59 -08007254 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007255 */
7256 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007257 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007258 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007259 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260
7261 final long identity = Binder.clearCallingIdentity();
7262 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007263 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7264 if (response instanceof CarrierRestrictionRules) {
7265 return (CarrierRestrictionRules) response;
7266 }
7267 // Response is an Exception of some kind,
7268 // which is signalled to the user as a NULL retval
7269 return null;
7270 } catch (Exception e) {
7271 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7272 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007273 } finally {
7274 Binder.restoreCallingIdentity(identity);
7275 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007276 }
7277
fionaxu59545b42016-05-25 15:53:37 -07007278 /**
7279 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7280 * @param subId the subscription ID that this action applies to.
7281 * @param enabled control enable or disable metered apns.
7282 * {@hide}
7283 */
7284 @Override
7285 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7286 enforceModifyPermission();
7287 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007288
7289 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007290 if (phone == null) {
7291 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7292 return;
7293 }
7294 try {
7295 phone.carrierActionSetMeteredApnsEnabled(enabled);
7296 } catch (Exception e) {
7297 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298 } finally {
7299 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007300 }
7301 }
7302
7303 /**
7304 * Action set from carrier signalling broadcast receivers to enable/disable radio
7305 * @param subId the subscription ID that this action applies to.
7306 * @param enabled control enable or disable radio.
7307 * {@hide}
7308 */
7309 @Override
7310 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7311 enforceModifyPermission();
7312 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313
7314 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007315 if (phone == null) {
7316 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7317 return;
7318 }
7319 try {
7320 phone.carrierActionSetRadioEnabled(enabled);
7321 } catch (Exception e) {
7322 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007323 } finally {
7324 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007325 }
7326 }
7327
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007328 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007329 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7330 * network status based on which carrier apps could apply actions accordingly,
7331 * enable/disable default url handler for example.
7332 *
7333 * @param subId the subscription ID that this action applies to.
7334 * @param report control start/stop reporting the default network status.
7335 * {@hide}
7336 */
7337 @Override
7338 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7339 enforceModifyPermission();
7340 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341
7342 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007343 if (phone == null) {
7344 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7345 return;
7346 }
7347 try {
7348 phone.carrierActionReportDefaultNetworkStatus(report);
7349 } catch (Exception e) {
7350 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 } finally {
7352 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007353 }
7354 }
7355
7356 /**
fionaxud9622282017-07-17 17:51:30 -07007357 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7358 * @param subId the subscription ID that this action applies to.
7359 * {@hide}
7360 */
7361 @Override
7362 public void carrierActionResetAll(int subId) {
7363 enforceModifyPermission();
7364 final Phone phone = getPhone(subId);
7365 if (phone == null) {
7366 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7367 return;
7368 }
7369 try {
7370 phone.carrierActionResetAll();
7371 } catch (Exception e) {
7372 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7373 }
7374 }
7375
7376 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007377 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7378 * bug report is being generated.
7379 */
7380 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007381 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007382 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7383 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007384 writer.println("Permission Denial: can't dump Phone from pid="
7385 + Binder.getCallingPid()
7386 + ", uid=" + Binder.getCallingUid()
7387 + "without permission "
7388 + android.Manifest.permission.DUMP);
7389 return;
7390 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007391 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007392 }
Jack Yueb89b242016-06-22 13:27:47 -07007393
Brad Ebingerdac2f002018-04-03 15:17:52 -07007394 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007395 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7396 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7397 @NonNull String[] args) {
7398 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7399 this, in.getFileDescriptor(), out.getFileDescriptor(),
7400 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007401 }
7402
Jack Yueb89b242016-06-22 13:27:47 -07007403 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007404 * Policy control of data connection. Usually used when data limit is passed.
7405 * @param enabled True if enabling the data, otherwise disabling.
7406 * @param subId Subscription index
7407 * {@hide}
7408 */
7409 @Override
7410 public void setPolicyDataEnabled(boolean enabled, int subId) {
7411 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007412
7413 final long identity = Binder.clearCallingIdentity();
7414 try {
7415 Phone phone = getPhone(subId);
7416 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007417 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418 }
7419 } finally {
7420 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007421 }
7422 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007423
7424 /**
7425 * Get Client request stats
7426 * @return List of Client Request Stats
7427 * @hide
7428 */
7429 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007430 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7431 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007433 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007434 return null;
7435 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007436 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 final long identity = Binder.clearCallingIdentity();
7439 try {
7440 if (phone != null) {
7441 return phone.getClientRequestStats();
7442 }
7443
7444 return null;
7445 } finally {
7446 Binder.restoreCallingIdentity(identity);
7447 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007448 }
7449
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007450 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007451 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007452 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007453 }
Jack Yueb4124c2017-02-16 15:32:43 -08007454
7455 /**
Grace Chen70990072017-03-24 17:21:30 -07007456 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007457 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007458 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007459 * @param state State of SIM (power down, power up, pass through)
7460 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7461 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7462 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007463 *
7464 **/
7465 @Override
Grace Chen70990072017-03-24 17:21:30 -07007466 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007467 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007468 Phone phone = PhoneFactory.getPhone(slotIndex);
7469
vagdeviaf9a5b92018-08-15 16:01:53 -07007470 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 final long identity = Binder.clearCallingIdentity();
7473 try {
7474 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007475 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 }
7477 } finally {
7478 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007479 }
7480 }
Shuo Qiandd210312017-04-12 22:11:33 +00007481
Tyler Gunn65d45c22017-06-05 11:22:26 -07007482 private boolean isUssdApiAllowed(int subId) {
7483 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007484 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007485 if (configManager == null) {
7486 return false;
7487 }
7488 PersistableBundle pb = configManager.getConfigForSubId(subId);
7489 if (pb == null) {
7490 return false;
7491 }
7492 return pb.getBoolean(
7493 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7494 }
7495
Shuo Qiandd210312017-04-12 22:11:33 +00007496 /**
7497 * Check if phone is in emergency callback mode
7498 * @return true if phone is in emergency callback mode
7499 * @param subId sub id
7500 */
goneil9c5f4872017-12-05 14:07:56 -08007501 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007502 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007503 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007504 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
7508 if (phone != null) {
7509 return phone.isInEcm();
7510 } else {
7511 return false;
7512 }
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007515 }
7516 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007517
7518 /**
7519 * Get the current signal strength information for the given subscription.
7520 * Because this information is not updated when the device is in a low power state
7521 * it should not be relied-upon to be current.
7522 * @param subId Subscription index
7523 * @return the most recent cached signal strength info from the modem
7524 */
7525 @Override
7526 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 Phone p = getPhone(subId);
7530 if (p == null) {
7531 return null;
7532 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 return p.getSignalStrength();
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007538 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007539
Pengquan Meng77b7f132018-08-22 14:49:57 -07007540 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007541 * Get the current modem radio state for the given slot.
7542 * @param slotIndex slot index.
7543 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007544 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007545 * @return the current radio power state from the modem
7546 */
7547 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007548 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007549 Phone phone = PhoneFactory.getPhone(slotIndex);
7550 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007551 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7552 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007553 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7554 }
7555
7556 final long identity = Binder.clearCallingIdentity();
7557 try {
7558 return phone.getRadioPowerState();
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
7561 }
7562 }
7563 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7564 }
7565
7566 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007567 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7568 *
7569 * <p>Requires one of the following permissions:
7570 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7571 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7572 * privileges.
7573 *
7574 * @param subId subscription id
7575 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7576 * {@code false}.
7577 */
7578 @Override
7579 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007580 try {
7581 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7582 null);
7583 } catch (Exception e) {
7584 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7585 mApp, subId, "isDataRoamingEnabled");
7586 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007587
Pengquan Menga1bb6272018-09-06 09:59:22 -07007588 boolean isEnabled = false;
7589 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007590 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007591 Phone phone = getPhone(subId);
7592 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007593 } finally {
7594 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007595 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007596 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007597 }
7598
7599
7600 /**
7601 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7602 *
7603 * <p> Requires permission:
7604 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7605 * privileges.
7606 *
7607 * @param subId subscription id
7608 * @param isEnabled {@code true} means enable, {@code false} means disable.
7609 */
7610 @Override
7611 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7613 mApp, subId, "setDataRoamingEnabled");
7614
Pengquan Menga1bb6272018-09-06 09:59:22 -07007615 final long identity = Binder.clearCallingIdentity();
7616 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007617 Phone phone = getPhone(subId);
7618 if (phone != null) {
7619 phone.setDataRoamingEnabled(isEnabled);
7620 }
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007623 }
7624 }
7625
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007626 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007627 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007628 TelephonyPermissions
7629 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007630 mApp, subId, "isManualNetworkSelectionAllowed");
7631
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007632 boolean isAllowed = true;
7633 final long identity = Binder.clearCallingIdentity();
7634 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007635 Phone phone = getPhone(subId);
7636 if (phone != null) {
7637 isAllowed = phone.isCspPlmnEnabled();
7638 }
7639 } finally {
7640 Binder.restoreCallingIdentity(identity);
7641 }
7642 return isAllowed;
7643 }
7644
7645 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007646 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007647 // Verify that tha callingPackage belongs to the calling UID
7648 mApp.getSystemService(AppOpsManager.class)
7649 .checkPackage(Binder.getCallingUid(), callingPackage);
7650
Jordan Liu1e142fc2019-04-22 15:10:43 -07007651 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007652 try {
7653 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007654 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007655 } catch (SecurityException e) {
7656 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7657 // has carrier privileges on an active UICC
7658 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7659 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007660 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007661 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007662 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007663
7664 final long identity = Binder.clearCallingIdentity();
7665 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007666 UiccController uiccController = UiccController.getInstance();
7667 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007668 if (hasReadPermission) {
7669 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007670 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007671
7672 // Remove private info if the caller doesn't have access
7673 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7674 for (UiccCardInfo cardInfo : cardInfos) {
7675 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7676 // is available
7677 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7678 if (card == null || card.getUiccProfile() == null) {
7679 // assume no access if the card or profile is unavailable
7680 filteredInfos.add(cardInfo.getUnprivileged());
7681 continue;
7682 }
7683 UiccProfile profile = card.getUiccProfile();
7684 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7685 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7686 filteredInfos.add(cardInfo);
7687 } else {
7688 filteredInfos.add(cardInfo.getUnprivileged());
7689 }
7690 }
7691 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007692 } finally {
7693 Binder.restoreCallingIdentity(identity);
7694 }
7695 }
7696
7697 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007698 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007699 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7704 if (slots == null) {
7705 Rlog.i(LOG_TAG, "slots is null.");
7706 return null;
7707 }
7708
7709 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7710 for (int i = 0; i < slots.length; i++) {
7711 UiccSlot slot = slots[i];
7712 if (slot == null) {
7713 continue;
7714 }
7715
Jordan Liu7be7e652019-05-06 18:55:02 +00007716 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 UiccCard card = slot.getUiccCard();
7718 if (card != null) {
7719 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007720 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007721 cardId = slot.getEid();
7722 if (TextUtils.isEmpty(cardId)) {
7723 cardId = slot.getIccId();
7724 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725 }
7726
Jordan Liu857451f2019-05-09 16:35:35 -07007727 if (cardId != null) {
7728 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7729 // if cardId is an EID, it's all digits so this is fine
7730 cardId = IccUtils.stripTrailingFs(cardId);
7731 }
7732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007733 int cardState = 0;
7734 switch (slot.getCardState()) {
7735 case CARDSTATE_ABSENT:
7736 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7737 break;
7738 case CARDSTATE_PRESENT:
7739 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7740 break;
7741 case CARDSTATE_ERROR:
7742 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7743 break;
7744 case CARDSTATE_RESTRICTED:
7745 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7746 break;
7747 default:
7748 break;
7749
7750 }
7751
7752 infos[i] = new UiccSlotInfo(
7753 slot.isActive(),
7754 slot.isEuicc(),
7755 cardId,
7756 cardState,
7757 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007758 slot.isExtendedApduSupported(),
7759 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 }
7761 return infos;
7762 } finally {
7763 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007764 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007765 }
7766
7767 @Override
7768 public boolean switchSlots(int[] physicalSlots) {
7769 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770
7771 final long identity = Binder.clearCallingIdentity();
7772 try {
7773 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7774 } finally {
7775 Binder.restoreCallingIdentity(identity);
7776 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007777 }
Jack Yu4c988042018-02-27 15:30:01 -08007778
7779 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007780 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007781 final long identity = Binder.clearCallingIdentity();
7782 try {
7783 return UiccController.getInstance().getCardIdForDefaultEuicc();
7784 } finally {
7785 Binder.restoreCallingIdentity(identity);
7786 }
7787 }
7788
Pengquan Meng85728fb2018-03-12 16:31:21 -07007789 /**
goneil47ffb6e2018-04-06 15:40:58 -07007790 * A test API to reload the UICC profile.
7791 *
7792 * <p>Requires that the calling app has permission
7793 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7794 * @hide
7795 */
7796 @Override
7797 public void refreshUiccProfile(int subId) {
7798 enforceModifyPermission();
7799
7800 final long identity = Binder.clearCallingIdentity();
7801 try {
7802 Phone phone = getPhone(subId);
7803 if (phone == null) {
7804 return;
7805 }
7806 UiccCard uiccCard = phone.getUiccCard();
7807 if (uiccCard == null) {
7808 return;
7809 }
7810 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7811 if (uiccProfile == null) {
7812 return;
7813 }
7814 uiccProfile.refresh();
7815 } finally {
7816 Binder.restoreCallingIdentity(identity);
7817 }
7818 }
7819
7820 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007821 * Returns false if the mobile data is disabled by default, otherwise return true.
7822 */
7823 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007824 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007825 }
7826
7827 /**
7828 * Returns true if the data roaming is enabled by default, i.e the system property
7829 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7830 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7831 */
7832 private boolean getDefaultDataRoamingEnabled(int subId) {
7833 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007834 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07007835 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007836 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7837 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7838 return isDataRoamingEnabled;
7839 }
7840
7841 /**
7842 * Returns the default network type for the given {@code subId}, if the default network type is
7843 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7844 */
7845 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007846 List<Integer> list = TelephonyProperties.default_network();
7847 int phoneId = mSubscriptionController.getPhoneId(subId);
7848 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7849 return list.get(phoneId);
7850 }
7851 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007852 }
fionaxua13278b2018-03-21 00:08:13 -07007853
7854 @Override
7855 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007856 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858
7859 final long identity = Binder.clearCallingIdentity();
7860 try {
7861 final Phone phone = getPhone(subId);
7862 if (phone == null) {
7863 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7864 return;
7865 }
chen xueaba88a2019-03-15 13:15:10 -07007866 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7867 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07007868 if (carrierPrivilegeRules == null) {
7869 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7870 } else {
7871 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 } finally {
7874 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007875 }
fionaxua13278b2018-03-21 00:08:13 -07007876 }
7877
7878 @Override
7879 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007880 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007881
7882 final long identity = Binder.clearCallingIdentity();
7883 try {
7884 final Phone phone = getPhone(subId);
7885 if (phone == null) {
7886 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7887 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7888 }
7889 return phone.getCarrierIdListVersion();
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007892 }
fionaxua13278b2018-03-21 00:08:13 -07007893 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007894
7895 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007896 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7897 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007899 mApp, subId, callingPackage, callingFeatureId,
7900 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007901 return -1;
7902 }
7903
7904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7907 } finally {
7908 Binder.restoreCallingIdentity(identity);
7909 }
7910 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007911
7912 @Override
7913 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007914 TelephonyPermissions
7915 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007916 mApp, subId, "getCdmaRoamingMode");
7917
7918 final long identity = Binder.clearCallingIdentity();
7919 try {
7920 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7921 } finally {
7922 Binder.restoreCallingIdentity(identity);
7923 }
7924 }
7925
7926 @Override
7927 public boolean setCdmaRoamingMode(int subId, int mode) {
7928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7929 mApp, subId, "setCdmaRoamingMode");
7930
7931 final long identity = Binder.clearCallingIdentity();
7932 try {
7933 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
7936 }
7937 }
7938
7939 @Override
7940 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7942 mApp, subId, "setCdmaSubscriptionMode");
7943
7944 final long identity = Binder.clearCallingIdentity();
7945 try {
7946 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7947 } finally {
7948 Binder.restoreCallingIdentity(identity);
7949 }
7950 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007951
sqianc5eccab2018-10-19 18:46:41 -07007952 @Override
sqian8c685422019-02-22 15:55:18 -08007953 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007954 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007956 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7957 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007958 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7959 }
7960 final long identity = Binder.clearCallingIdentity();
7961 try {
sqian854d44b2018-12-12 16:48:18 -08007962 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7963 for (Phone phone: PhoneFactory.getPhones()) {
7964 if (phone.getEmergencyNumberTracker() != null
7965 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7966 emergencyNumberListInternal.put(
7967 phone.getSubId(),
7968 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7969 }
sqian11b7a0e2018-12-05 18:48:28 -08007970 }
sqian854d44b2018-12-12 16:48:18 -08007971 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007972 } finally {
7973 Binder.restoreCallingIdentity(identity);
7974 }
sqianc5eccab2018-10-19 18:46:41 -07007975 }
7976
7977 @Override
sqian8c685422019-02-22 15:55:18 -08007978 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007979 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007980 if (!exactMatch) {
7981 TelephonyPermissions
7982 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007983 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007984 }
7985 final long identity = Binder.clearCallingIdentity();
7986 try {
sqian854d44b2018-12-12 16:48:18 -08007987 for (Phone phone: PhoneFactory.getPhones()) {
7988 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09007989 && phone.getEmergencyNumberTracker()
7990 .isEmergencyNumber(number, exactMatch)) {
7991 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007992 }
sqian11b7a0e2018-12-05 18:48:28 -08007993 }
7994 return false;
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
7997 }
7998 }
7999
sqianf4ca7ed2019-01-15 18:32:07 -08008000 /**
8001 * Update emergency number list for test mode.
8002 */
8003 @Override
8004 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8005 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8006 "updateEmergencyNumberListTestMode");
8007
8008 final long identity = Binder.clearCallingIdentity();
8009 try {
8010 for (Phone phone: PhoneFactory.getPhones()) {
8011 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8012 if (tracker != null) {
8013 tracker.executeEmergencyNumberTestModeCommand(action, num);
8014 }
8015 }
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
8018 }
8019 }
8020
8021 /**
8022 * Get the full emergency number list for test mode.
8023 */
8024 @Override
8025 public List<String> getEmergencyNumberListTestMode() {
8026 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8027 "getEmergencyNumberListTestMode");
8028
8029 final long identity = Binder.clearCallingIdentity();
8030 try {
8031 Set<String> emergencyNumbers = new HashSet<>();
8032 for (Phone phone: PhoneFactory.getPhones()) {
8033 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8034 if (tracker != null) {
8035 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8036 emergencyNumbers.add(num.getNumber());
8037 }
8038 }
8039 }
8040 return new ArrayList<>(emergencyNumbers);
8041 } finally {
8042 Binder.restoreCallingIdentity(identity);
8043 }
8044 }
8045
chen xud6b45bd2018-10-30 22:27:10 -07008046 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008047 public int getEmergencyNumberDbVersion(int subId) {
8048 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8049
8050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 final Phone phone = getPhone(subId);
8053 if (phone == null) {
8054 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8055 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8056 }
8057 return phone.getEmergencyNumberDbVersion();
8058 } finally {
8059 Binder.restoreCallingIdentity(identity);
8060 }
8061 }
8062
8063 @Override
8064 public void notifyOtaEmergencyNumberDbInstalled() {
8065 enforceModifyPermission();
8066
8067 final long identity = Binder.clearCallingIdentity();
8068 try {
8069 for (Phone phone: PhoneFactory.getPhones()) {
8070 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8071 if (tracker != null) {
8072 tracker.updateOtaEmergencyNumberDatabase();
8073 }
8074 }
8075 } finally {
8076 Binder.restoreCallingIdentity(identity);
8077 }
8078 }
8079
8080 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008081 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008082 enforceActiveEmergencySessionPermission();
8083
8084 final long identity = Binder.clearCallingIdentity();
8085 try {
8086 for (Phone phone: PhoneFactory.getPhones()) {
8087 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8088 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008089 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8090 }
8091 }
8092 } finally {
8093 Binder.restoreCallingIdentity(identity);
8094 }
8095 }
8096
8097 @Override
8098 public void resetOtaEmergencyNumberDbFilePath() {
8099 enforceActiveEmergencySessionPermission();
8100
8101 final long identity = Binder.clearCallingIdentity();
8102 try {
8103 for (Phone phone: PhoneFactory.getPhones()) {
8104 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8105 if (tracker != null) {
8106 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008107 }
8108 }
8109 } finally {
8110 Binder.restoreCallingIdentity(identity);
8111 }
8112 }
8113
8114 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008115 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8116 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8117 Phone phone = getPhone(subId);
8118 if (phone == null) {
8119 return null;
8120 }
8121 final long identity = Binder.clearCallingIdentity();
8122 try {
8123 UiccProfile profile = UiccController.getInstance()
8124 .getUiccProfileForPhone(phone.getPhoneId());
8125 if (profile != null) {
8126 return profile.getCertsFromCarrierPrivilegeAccessRules();
8127 }
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
8131 return null;
8132 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008133
8134 /**
8135 * Enable or disable a modem stack.
8136 */
8137 @Override
8138 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8139 enforceModifyPermission();
8140
8141 final long identity = Binder.clearCallingIdentity();
8142 try {
8143 Phone phone = PhoneFactory.getPhone(slotIndex);
8144 if (phone == null) {
8145 return false;
8146 } else {
8147 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8148 }
8149 } finally {
8150 Binder.restoreCallingIdentity(identity);
8151 }
8152 }
Michelecea4cf22018-12-21 15:00:11 -08008153
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008154 /**
8155 * Whether a modem stack is enabled or not.
8156 */
8157 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008158 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8159 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008160 Phone phone = PhoneFactory.getPhone(slotIndex);
8161 if (phone == null) return false;
8162
8163 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008164 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8165 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008166 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8167 }
8168
8169 final long identity = Binder.clearCallingIdentity();
8170 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008171 try {
8172 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8173 } catch (NoSuchElementException ex) {
8174 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8175 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008176 } finally {
8177 Binder.restoreCallingIdentity(identity);
8178 }
8179 }
8180
Michelecea4cf22018-12-21 15:00:11 -08008181 @Override
Michele0ea7d782019-03-19 14:58:42 -07008182 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008183 enforceModifyPermission();
8184
8185 final long identity = Binder.clearCallingIdentity();
8186 try {
8187 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008188 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008189 .commit();
8190 } finally {
8191 Binder.restoreCallingIdentity(identity);
8192 }
8193 }
8194
8195 @Override
Michele0ea7d782019-03-19 14:58:42 -07008196 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008197 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008199 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8200 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008201 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008202 }
Michelecea4cf22018-12-21 15:00:11 -08008203
8204 final long identity = Binder.clearCallingIdentity();
8205 try {
Michele0ea7d782019-03-19 14:58:42 -07008206 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008207 } finally {
8208 Binder.restoreCallingIdentity(identity);
8209 }
8210 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008211
Michele0ea7d782019-03-19 14:58:42 -07008212 @TelephonyManager.IsMultiSimSupportedResult
8213 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008214 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8215 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8216 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008217 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8218 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008219 }
8220 // Check if the hardware supports multisim functionality. If usage of multisim is not
8221 // supported by the modem, indicate that it is restricted.
8222 PhoneCapability staticCapability =
8223 mPhoneConfigurationManager.getStaticPhoneCapability();
8224 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008225 loge("isMultiSimSupportedInternal: no static configuration available");
8226 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008227 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008228 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008229 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8230 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008231 }
8232 // Check if support of multiple SIMs is restricted by carrier
8233 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008234 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008235 }
8236
Michele0ea7d782019-03-19 14:58:42 -07008237 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008238 }
8239
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008240 /**
8241 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008242 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8243 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8244 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008245 * @param numOfSims number of active sims we want to switch to
8246 */
8247 @Override
8248 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008249 if (numOfSims == 1) {
8250 enforceModifyPermission();
8251 } else {
8252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8253 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8254 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008255 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008256
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008257 try {
Michele30b57b22019-03-01 12:01:14 -08008258 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008259 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008260 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8261 return;
8262 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008263 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8264 } finally {
8265 Binder.restoreCallingIdentity(identity);
8266 }
8267 }
8268
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008269 @Override
8270 public boolean isApplicationOnUicc(int subId, int appType) {
8271 enforceReadPrivilegedPermission("isApplicationOnUicc");
8272 Phone phone = getPhone(subId);
8273 if (phone == null) {
8274 return false;
8275 }
8276 final long identity = Binder.clearCallingIdentity();
8277 try {
8278 UiccCard uiccCard = phone.getUiccCard();
8279 if (uiccCard == null) {
8280 return false;
8281 }
8282 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8283 if (uiccProfile == null) {
8284 return false;
8285 }
8286 if (TelephonyManager.APPTYPE_SIM <= appType
8287 && appType <= TelephonyManager.APPTYPE_ISIM) {
8288 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8289 }
8290 return false;
8291 } finally {
8292 Binder.restoreCallingIdentity(identity);
8293 }
8294 }
8295
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008296 /**
chen xub4baa772019-04-03 10:23:41 -07008297 * Get whether making changes to modem configurations will trigger reboot.
8298 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008299 */
8300 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008301 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8302 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008304 mApp, subId, callingPackage, callingFeatureId,
8305 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008306 return false;
8307 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008308 final long identity = Binder.clearCallingIdentity();
8309 try {
8310 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8311 } finally {
8312 Binder.restoreCallingIdentity(identity);
8313 }
8314 }
8315
Nathan Harold29f5f052019-02-15 13:41:57 -08008316 private void updateModemStateMetrics() {
8317 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8318 // TODO: check the state for each modem if the api is ready.
8319 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8320 }
8321
Pengquan Meng3889a572019-01-23 11:16:29 -08008322 @Override
8323 public int[] getSlotsMapping() {
8324 enforceReadPrivilegedPermission("getSlotsMapping");
8325
8326 final long identity = Binder.clearCallingIdentity();
8327 try {
8328 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8329 // All logical slots should have a mapping to a physical slot.
8330 int[] logicalSlotsMapping = new int[phoneCount];
8331 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8332 for (int i = 0; i < slotInfos.length; i++) {
8333 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8334 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8335 }
8336 }
8337 return logicalSlotsMapping;
8338 } finally {
8339 Binder.restoreCallingIdentity(identity);
8340 }
8341 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008342
8343 /**
8344 * Get the IRadio HAL Version
8345 */
8346 @Override
8347 public int getRadioHalVersion() {
8348 Phone phone = getDefaultPhone();
8349 if (phone == null) return -1;
8350 HalVersion hv = phone.getHalVersion();
8351 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8352 return hv.major * 100 + hv.minor;
8353 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008354
8355 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008356 * Get the current calling package name.
8357 * @return the current calling package name
8358 */
8359 @Override
8360 public String getCurrentPackageName() {
8361 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8362 }
8363
8364 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008365 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8366 * corresponding network requests on a subId.
8367 *
8368 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008369 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008370 * 2) APN is un-metered for this subscription, or
8371 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008372 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008373 *
8374 * @return whether data is allowed for a apn type.
8375 *
8376 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008377 */
8378 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008379 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008380 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8381 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008382
8383 // Now that all security checks passes, perform the operation as ourselves.
8384 final long identity = Binder.clearCallingIdentity();
8385 try {
8386 Phone phone = getPhone(subId);
8387 if (phone == null) return false;
8388
Jack Yu41407ee2019-05-13 16:54:09 -07008389 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008390 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8391 } finally {
8392 Binder.restoreCallingIdentity(identity);
8393 }
8394 }
8395
8396 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008397 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008398 enforceReadPrivilegedPermission("isApnMetered");
8399
8400 // Now that all security checks passes, perform the operation as ourselves.
8401 final long identity = Binder.clearCallingIdentity();
8402 try {
8403 Phone phone = getPhone(subId);
8404 if (phone == null) return true; // By default return true.
8405
Jack Yu41407ee2019-05-13 16:54:09 -07008406 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008407 } finally {
8408 Binder.restoreCallingIdentity(identity);
8409 }
8410 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008411
8412 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008413 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8414 int subscriptionId, IBooleanConsumer resultCallback) {
8415 enforceModifyPermission();
8416 long token = Binder.clearCallingIdentity();
8417 try {
8418 Phone phone = getPhone(subscriptionId);
8419 if (phone == null) {
8420 try {
8421 if (resultCallback != null) {
8422 resultCallback.accept(false);
8423 }
8424 } catch (RemoteException e) {
8425 // ignore
8426 }
8427 return;
8428 }
8429 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8430 Pair.create(specifiers, (x) -> {
8431 try {
8432 if (resultCallback != null) {
8433 resultCallback.accept(x);
8434 }
8435 } catch (RemoteException e) {
8436 // ignore
8437 }
8438 });
8439 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8440 } finally {
8441 Binder.restoreCallingIdentity(token);
8442 }
8443 }
8444
8445 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008446 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008447 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008448 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8449 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8450 if (iccRecords == null) {
8451 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8452 return false;
8453 }
8454 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8455 }
8456
8457 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008458 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8459 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008460 if (callingPackage == null) {
8461 callingPackage = getCurrentPackageName();
8462 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008463 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8464 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008465 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8466 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008467 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8468 }
8469 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8470 Intent intent = new Intent();
8471 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8472 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8473 // Bring up choose default SMS subscription dialog right now
8474 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8475 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8476 mApp.startActivity(intent);
8477 }
chen xud5ca2d52019-05-28 15:20:57 -07008478
8479 @Override
8480 public String getMmsUAProfUrl(int subId) {
8481 //TODO investigate if this API should require proper permission check in R b/133791609
8482 final long identity = Binder.clearCallingIdentity();
8483 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008484 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8485 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8486 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8487 return carrierUAProfUrl;
8488 }
chen xud5ca2d52019-05-28 15:20:57 -07008489 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8490 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
8493 }
8494 }
8495
8496 @Override
8497 public String getMmsUserAgent(int subId) {
8498 //TODO investigate if this API should require proper permission check in R b/133791609
8499 final long identity = Binder.clearCallingIdentity();
8500 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008501 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8502 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8503 if (!TextUtils.isEmpty(carrierUserAgent)) {
8504 return carrierUserAgent;
8505 }
chen xud5ca2d52019-05-28 15:20:57 -07008506 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8507 .getString(com.android.internal.R.string.config_mms_user_agent);
8508 } finally {
8509 Binder.restoreCallingIdentity(identity);
8510 }
8511 }
Jack Yub07d4972019-05-28 16:12:25 -07008512
8513 @Override
8514 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8515 enforceModifyPermission();
8516
8517 // Now that all security checks passes, perform the operation as ourselves.
8518 final long identity = Binder.clearCallingIdentity();
8519 try {
8520 Phone phone = getPhone(subId);
8521 if (phone == null) return false;
8522
8523 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8524 } finally {
8525 Binder.restoreCallingIdentity(identity);
8526 }
8527 }
8528
8529 @Override
8530 public boolean isDataAllowedInVoiceCall(int subId) {
8531 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8532
8533 // Now that all security checks passes, perform the operation as ourselves.
8534 final long identity = Binder.clearCallingIdentity();
8535 try {
8536 Phone phone = getPhone(subId);
8537 if (phone == null) return false;
8538
8539 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8540 } finally {
8541 Binder.restoreCallingIdentity(identity);
8542 }
8543 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008544
changbetty97defcf2019-12-24 15:40:37 +08008545 @Override
8546 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8547 enforceModifyPermission();
8548
8549 // Now that all security checks passes, perform the operation as ourselves.
8550 final long identity = Binder.clearCallingIdentity();
8551 try {
8552 Phone phone = getPhone(subId);
8553 if (phone == null) return false;
8554
8555 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8556 } finally {
8557 Binder.restoreCallingIdentity(identity);
8558 }
8559 }
8560
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008561 /**
8562 * Updates whether conference event pacakge handling is enabled.
8563 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8564 * otherwise.
8565 */
8566 @Override
8567 public void setCepEnabled(boolean isCepEnabled) {
8568 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8569
8570 final long identity = Binder.clearCallingIdentity();
8571 try {
8572 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8573 for (Phone phone : PhoneFactory.getPhones()) {
8574 Phone defaultPhone = phone.getImsPhone();
8575 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8576 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8577 ImsPhoneCallTracker imsPhoneCallTracker =
8578 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8579 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8580 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8581 + imsPhone.getMsisdn());
8582 }
8583 }
8584 } finally {
8585 Binder.restoreCallingIdentity(identity);
8586 }
8587 }
allenwtsu46dcc572020-01-08 18:24:03 +08008588
8589 /**
8590 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8591 *
8592 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8593 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8594 * before being read.
8595 */
8596 @Override
8597 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8598 isCompressed) {
8599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8600 mApp, subId, "notifyRcsAutoConfigurationReceived");
8601 try {
8602 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8603 if (configBinder == null) {
8604 Rlog.e(LOG_TAG, "null result for getImsConfig");
8605 } else {
8606 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8607 }
8608 } catch (RemoteException e) {
8609 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8610 }
8611 }
zoey chenf95ca592019-12-30 16:11:23 +08008612
8613 @Override
8614 public boolean isIccLockEnabled(int subId) {
8615 enforceReadPrivilegedPermission("isIccLockEnabled");
8616
8617 // Now that all security checks passes, perform the operation as ourselves.
8618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 Phone phone = getPhone(subId);
8621 if (phone != null && phone.getIccCard() != null) {
8622 return phone.getIccCard().getIccLockEnabled();
8623 } else {
8624 return false;
8625 }
8626 } finally {
8627 Binder.restoreCallingIdentity(identity);
8628 }
8629 }
8630
8631 /**
zoey chene02881a2019-12-30 16:11:23 +08008632 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008633 *
zoey chene02881a2019-12-30 16:11:23 +08008634 * @return an integer representing the status of IccLock enabled or disabled in the following
8635 * three cases:
8636 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8637 * successfully.
8638 * - Positive number and zero for remaining password attempts.
8639 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008640 *
8641 */
8642 @Override
8643 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8644 enforceModifyPermission();
8645
8646 Phone phone = getPhone(subId);
8647 if (phone == null) {
8648 return 0;
8649 }
8650 // Now that all security checks passes, perform the operation as ourselves.
8651 final long identity = Binder.clearCallingIdentity();
8652 try {
8653 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8654 new Pair<Boolean, String>(enabled, password), phone, null);
8655 return attemptsRemaining;
8656
8657 } catch (Exception e) {
8658 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8659 } finally {
8660 Binder.restoreCallingIdentity(identity);
8661 }
8662 return 0;
8663 }
8664
8665 /**
8666 * Change the ICC password used in ICC pin lock.
8667 *
zoey chene02881a2019-12-30 16:11:23 +08008668 * @return an integer representing the status of IccLock changed in the following three cases:
8669 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8670 * - Positive number and zero for remaining password attempts.
8671 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008672 *
8673 */
8674 @Override
8675 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8676 enforceModifyPermission();
8677
8678 Phone phone = getPhone(subId);
8679 if (phone == null) {
8680 return 0;
8681 }
8682 // Now that all security checks passes, perform the operation as ourselves.
8683 final long identity = Binder.clearCallingIdentity();
8684 try {
8685 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8686 new Pair<String, String>(oldPassword, newPassword), phone, null);
8687 return attemptsRemaining;
8688
8689 } catch (Exception e) {
8690 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8691 } finally {
8692 Binder.restoreCallingIdentity(identity);
8693 }
8694 return 0;
8695 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008696
Peter Wangdafb9ac2020-01-15 14:13:38 -08008697 /**
8698 * Request for receiving user activity notification
8699 */
8700 @Override
8701 public void requestUserActivityNotification() {
8702 if (!mNotifyUserActivity.get()
8703 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8704 mNotifyUserActivity.set(true);
8705 }
8706 }
8707
8708 /**
8709 * Called when userActivity is signalled in the power manager.
8710 * This is safe to call from any thread, with any window manager locks held or not.
8711 */
8712 @Override
8713 public void userActivity() {
8714 // ***************************************
8715 // * Inherited from PhoneWindowManager *
8716 // ***************************************
8717 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8718 // WITH ITS LOCKS HELD.
8719 //
8720 // This code must be VERY careful about the locks
8721 // it acquires.
8722 // In fact, the current code acquires way too many,
8723 // and probably has lurking deadlocks.
8724
8725 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8726 throw new SecurityException("Only the OS may call notifyUserActivity()");
8727 }
8728
8729 if (mNotifyUserActivity.getAndSet(false)) {
8730 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8731 USER_ACTIVITY_NOTIFICATION_DELAY);
8732 }
8733 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008734
Malcolm Chen884180b2020-04-13 11:59:40 -07008735 @Override
8736 public boolean canConnectTo5GInDsdsMode() {
8737 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8738 }
Jack Yud10cdd42020-09-28 20:28:01 -07008739
8740 @Override
8741 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8742 String callingFeatureId) {
8743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8744 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8745 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8746 }
8747
8748 Phone phone = getPhone(subId);
8749 if (phone == null) {
8750 throw new RuntimeException("phone is not available");
8751 }
8752 // Now that all security checks passes, perform the operation as ourselves.
8753 final long identity = Binder.clearCallingIdentity();
8754 try {
8755 return phone.getEquivalentHomePlmns();
8756 } finally {
8757 Binder.restoreCallingIdentity(identity);
8758 }
8759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008760}