blob: 3e8d62b47fb6af798f1e134043e2f7b2b0a0f214 [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 Liuae527aa2020-09-29 17:10:18 -0700878 int errorCode = TelephonyManager
879 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800880 if (ar.exception instanceof CommandException) {
881 CommandException.Error error =
882 ((CommandException) (ar.exception)).getCommandError();
883 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700884 errorCode = TelephonyManager
885 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800886 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700887 errorCode = TelephonyManager
888 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800889 }
890 }
Hall Liua1acea22020-09-18 19:04:59 -0700891 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -0800892 }
sqian80370722020-01-29 15:02:51 -0800893 break;
Hall Liua1acea22020-09-18 19:04:59 -0700894 }
sqian80370722020-01-29 15:02:51 -0800895
Hall Liua1acea22020-09-18 19:04:59 -0700896 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800897 request = (MainThreadRequest) msg.obj;
898 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700899 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -0800900 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -0700901 ((Pair<CallForwardingInfo, Consumer<Integer>>)
902 request.argument).first;
903 request.phone.setCallForwardingOption(
904 callForwardingInfoToSet.isEnabled()
905 ? CommandsInterface.CF_ACTION_ENABLE
906 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -0800907 callForwardingInfoToSet.getReason(),
908 callForwardingInfoToSet.getNumber(),
909 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
910 break;
Hall Liua1acea22020-09-18 19:04:59 -0700911 }
sqian80370722020-01-29 15:02:51 -0800912
Hall Liua1acea22020-09-18 19:04:59 -0700913 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700916 Consumer<Integer> callback =
917 ((Pair<CallForwardingInfo, Consumer<Integer>>)
918 request.argument).second;
919 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -0800920 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -0700921 int errorCode = TelephonyManager.CallForwardingInfoCallback
922 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -0700923 if (ar.exception instanceof CommandException) {
924 CommandException.Error error =
925 ((CommandException) (ar.exception)).getCommandError();
926 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700927 errorCode = TelephonyManager.CallForwardingInfoCallback
928 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -0700929 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700930 errorCode = TelephonyManager.CallForwardingInfoCallback
931 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -0700932 }
933 }
934 callback.accept(errorCode);
935 } else {
Hall Liuae527aa2020-09-29 17:10:18 -0700936 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -0800937 }
sqian80370722020-01-29 15:02:51 -0800938 break;
Hall Liua1acea22020-09-18 19:04:59 -0700939 }
sqian80370722020-01-29 15:02:51 -0800940
Hall Liua1acea22020-09-18 19:04:59 -0700941 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -0800942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
944 getPhoneFromRequest(request).getCallWaiting(onCompleted);
945 break;
Hall Liua1acea22020-09-18 19:04:59 -0700946 }
sqian80370722020-01-29 15:02:51 -0800947
Hall Liua1acea22020-09-18 19:04:59 -0700948 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -0800949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700951 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -0800952 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
953 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800954 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800955 // Service Class is a bit mask per 3gpp 27.007.
956 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800957 if (callForwardResults.length > 1
958 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -0700959 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800960 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -0700961 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
962 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -0800963 } else {
Hall Liua1acea22020-09-18 19:04:59 -0700964 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -0800965 }
966 } else {
967 if (ar.result == null) {
968 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
969 }
970 if (ar.exception != null) {
971 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
972 }
973 if (ar.exception instanceof CommandException) {
974 CommandException.Error error =
975 ((CommandException) (ar.exception)).getCommandError();
976 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
977 callForwardingStatus =
978 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
979 }
980 }
981 }
Hall Liua1acea22020-09-18 19:04:59 -0700982 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -0800983 break;
Hall Liua1acea22020-09-18 19:04:59 -0700984 }
sqian80370722020-01-29 15:02:51 -0800985
Hall Liua1acea22020-09-18 19:04:59 -0700986 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -0800987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700989 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
990 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -0800991 break;
Hall Liua1acea22020-09-18 19:04:59 -0700992 }
sqian80370722020-01-29 15:02:51 -0800993
Hall Liua1acea22020-09-18 19:04:59 -0700994 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -0800995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700997 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
998 Consumer<Integer> callback =
999 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1000 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001001 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001002 if (ar.exception instanceof CommandException) {
1003 CommandException.Error error =
1004 ((CommandException) (ar.exception)).getCommandError();
1005 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1006 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1007 } else {
1008 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1009 }
1010 } else {
1011 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1012 }
1013 } else {
1014 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1015 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001016 }
sqian80370722020-01-29 15:02:51 -08001017 break;
Hall Liua1acea22020-09-18 19:04:59 -07001018 }
sqian80370722020-01-29 15:02:51 -08001019
Shishir Agrawal302c8692015-06-19 13:49:39 -07001020 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 CellNetworkScanResult cellScanResult;
1024 if (ar.exception == null && ar.result != null) {
1025 cellScanResult = new CellNetworkScanResult(
1026 CellNetworkScanResult.STATUS_SUCCESS,
1027 (List<OperatorInfo>) ar.result);
1028 } else {
1029 if (ar.result == null) {
1030 loge("getCellNetworkScanResults: Empty response");
1031 }
1032 if (ar.exception != null) {
1033 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1034 }
1035 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1036 if (ar.exception instanceof CommandException) {
1037 CommandException.Error error =
1038 ((CommandException) (ar.exception)).getCommandError();
1039 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1040 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1041 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1042 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1043 }
1044 }
1045 cellScanResult = new CellNetworkScanResult(errorCode, null);
1046 }
1047 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001048 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001049 break;
1050
1051 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1052 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001053 ManualNetworkSelectionArgument selArg =
1054 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001055 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1056 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001057 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1058 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001059 break;
1060
1061 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001062 ar = (AsyncResult) msg.obj;
1063 request = (MainThreadRequest) ar.userObj;
1064 if (ar.exception == null) {
1065 request.result = true;
1066 } else {
1067 request.result = false;
1068 loge("setNetworkSelectionModeManual " + ar.exception);
1069 }
1070 notifyRequester(request);
1071 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001072 break;
1073
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001074 case CMD_GET_MODEM_ACTIVITY_INFO:
1075 request = (MainThreadRequest) msg.obj;
1076 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001077 if (defaultPhone != null) {
1078 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001079 } else {
1080 ResultReceiver result = (ResultReceiver) request.argument;
1081 Bundle bundle = new Bundle();
1082 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1083 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1084 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001085 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001086 break;
1087
1088 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1089 ar = (AsyncResult) msg.obj;
1090 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001091 ResultReceiver result = (ResultReceiver) request.argument;
1092
1093 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001094 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001095 // Update the last modem activity info and the result of the request.
1096 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1097 if (isModemActivityInfoValid(info)) {
1098 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1099 int[] txTimeMs = info.getTransmitTimeMillis();
1100 int[] lastModemTxTimeMs = mLastModemActivityInfo
1101 .getTransmitTimeMillis();
1102 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1103 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1104 }
1105 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1106 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1107 + mLastModemActivityInfo.getSleepTimeMillis());
1108 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1109 + mLastModemActivityInfo.getIdleTimeMillis());
1110 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1111 mLastModemActivityInfo.setReceiveTimeMillis(
1112 info.getReceiveTimeMillis()
1113 + mLastModemActivityInfo.getReceiveTimeMillis());
1114 }
1115 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1116 mLastModemActivityInfo.getSleepTimeMillis(),
1117 mLastModemActivityInfo.getIdleTimeMillis(),
1118 mLastModemActivityInfo.getTransmitTimeMillis(),
1119 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001120 } else {
1121 if (ar.result == null) {
1122 loge("queryModemActivityInfo: Empty response");
1123 } else if (ar.exception instanceof CommandException) {
1124 loge("queryModemActivityInfo: CommandException: " +
1125 ar.exception);
1126 } else {
1127 loge("queryModemActivityInfo: Unknown exception");
1128 }
1129 }
sqian1a1be542020-03-05 11:37:28 -08001130 Bundle bundle = new Bundle();
1131 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1132 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001133 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001134 break;
1135
Meng Wang1a7c35a2016-05-05 20:56:15 -07001136 case CMD_SET_ALLOWED_CARRIERS:
1137 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001138 CarrierRestrictionRules argument =
1139 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001140 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001141 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001142 break;
1143
1144 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 if (ar.exception == null && ar.result != null) {
1148 request.result = ar.result;
1149 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001150 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1151 if (ar.exception instanceof CommandException) {
1152 loge("setAllowedCarriers: CommandException: " + ar.exception);
1153 CommandException.Error error =
1154 ((CommandException) (ar.exception)).getCommandError();
1155 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1156 request.result =
1157 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1158 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001159 } else {
1160 loge("setAllowedCarriers: Unknown exception");
1161 }
1162 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001163 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001164 break;
1165
1166 case CMD_GET_ALLOWED_CARRIERS:
1167 request = (MainThreadRequest) msg.obj;
1168 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001169 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001170 break;
1171
1172 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1173 ar = (AsyncResult) msg.obj;
1174 request = (MainThreadRequest) ar.userObj;
1175 if (ar.exception == null && ar.result != null) {
1176 request.result = ar.result;
1177 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001178 request.result = new IllegalStateException(
1179 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001180 if (ar.result == null) {
1181 loge("getAllowedCarriers: Empty response");
1182 } else if (ar.exception instanceof CommandException) {
1183 loge("getAllowedCarriers: CommandException: " +
1184 ar.exception);
1185 } else {
1186 loge("getAllowedCarriers: Unknown exception");
1187 }
1188 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001189 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001190 break;
1191
Nathan Haroldb3014052017-01-25 15:57:32 -08001192 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1193 ar = (AsyncResult) msg.obj;
1194 request = (MainThreadRequest) ar.userObj;
1195 if (ar.exception == null && ar.result != null) {
1196 request.result = ar.result;
1197 } else {
1198 request.result = new IllegalArgumentException(
1199 "Failed to retrieve Forbidden Plmns");
1200 if (ar.result == null) {
1201 loge("getForbiddenPlmns: Empty response");
1202 } else {
1203 loge("getForbiddenPlmns: Unknown exception");
1204 }
1205 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001206 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001207 break;
1208
1209 case CMD_GET_FORBIDDEN_PLMNS:
1210 request = (MainThreadRequest) msg.obj;
1211 uiccCard = getUiccCardFromRequest(request);
1212 if (uiccCard == null) {
1213 loge("getForbiddenPlmns() UiccCard is null");
1214 request.result = new IllegalArgumentException(
1215 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001216 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001217 break;
1218 }
1219 Integer appType = (Integer) request.argument;
1220 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1221 if (uiccApp == null) {
1222 loge("getForbiddenPlmns() no app with specified type -- "
1223 + appType);
1224 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001225 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001226 break;
1227 } else {
1228 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1229 + " specified type -- " + appType);
1230 }
1231 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1232 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1233 onCompleted);
1234 break;
1235
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001236 case CMD_SWITCH_SLOTS:
1237 request = (MainThreadRequest) msg.obj;
1238 int[] physicalSlots = (int[]) request.argument;
1239 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1240 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1241 break;
1242
1243 case EVENT_SWITCH_SLOTS_DONE:
1244 ar = (AsyncResult) msg.obj;
1245 request = (MainThreadRequest) ar.userObj;
1246 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001247 notifyRequester(request);
1248 break;
1249 case CMD_GET_NETWORK_SELECTION_MODE:
1250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1252 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1253 break;
1254
1255 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1256 ar = (AsyncResult) msg.obj;
1257 request = (MainThreadRequest) ar.userObj;
1258 if (ar.exception != null) {
1259 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1260 } else {
1261 int mode = ((int[]) ar.result)[0];
1262 if (mode == 0) {
1263 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1264 } else {
1265 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1266 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001267 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001268 notifyRequester(request);
1269 break;
1270 case CMD_GET_CDMA_ROAMING_MODE:
1271 request = (MainThreadRequest) msg.obj;
1272 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1273 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1274 break;
1275 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1276 ar = (AsyncResult) msg.obj;
1277 request = (MainThreadRequest) ar.userObj;
1278 if (ar.exception != null) {
1279 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1280 } else {
1281 request.result = ((int[]) ar.result)[0];
1282 }
1283 notifyRequester(request);
1284 break;
1285 case CMD_SET_CDMA_ROAMING_MODE:
1286 request = (MainThreadRequest) msg.obj;
1287 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1288 int mode = (int) request.argument;
1289 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1290 break;
1291 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1292 ar = (AsyncResult) msg.obj;
1293 request = (MainThreadRequest) ar.userObj;
1294 request.result = ar.exception == null;
1295 notifyRequester(request);
1296 break;
1297 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1298 request = (MainThreadRequest) msg.obj;
1299 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1300 int subscriptionMode = (int) request.argument;
1301 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1302 break;
1303 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
1306 request.result = ar.exception == null;
1307 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001308 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001309 case CMD_GET_ALL_CELL_INFO:
1310 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001311 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001312 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001313 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001314 case EVENT_GET_ALL_CELL_INFO_DONE:
1315 ar = (AsyncResult) msg.obj;
1316 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001317 // If a timeout occurs, the response will be null
1318 request.result = (ar.exception == null && ar.result != null)
1319 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001320 synchronized (request) {
1321 request.notifyAll();
1322 }
1323 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001324 case CMD_REQUEST_CELL_INFO_UPDATE:
1325 request = (MainThreadRequest) msg.obj;
1326 request.phone.requestCellInfoUpdate(request.workSource,
1327 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1328 break;
1329 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
1332 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1333 try {
1334 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001335 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001336 cb.onError(
1337 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1338 ar.exception.getClass().getName(),
1339 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001340 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001341 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001342 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001343 } else {
1344 // use the result as returned
1345 cb.onCellInfo((List<CellInfo>) ar.result);
1346 }
1347 } catch (RemoteException re) {
1348 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1349 }
1350 break;
1351 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001352 request = (MainThreadRequest) msg.obj;
1353 WorkSource ws = (WorkSource) request.argument;
1354 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001355 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001356 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001357 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001358 ar = (AsyncResult) msg.obj;
1359 request = (MainThreadRequest) ar.userObj;
1360 if (ar.exception == null) {
1361 request.result = ar.result;
1362 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001363 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001364 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001365 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001366 }
1367
1368 synchronized (request) {
1369 request.notifyAll();
1370 }
1371 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001372 case CMD_MODEM_REBOOT:
1373 request = (MainThreadRequest) msg.obj;
1374 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001375 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001376 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001377 case EVENT_CMD_MODEM_REBOOT_DONE:
1378 handleNullReturnEvent(msg, "rebootModem");
1379 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001380 case CMD_REQUEST_ENABLE_MODEM:
1381 request = (MainThreadRequest) msg.obj;
1382 boolean enable = (boolean) request.argument;
1383 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001384 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001385 PhoneConfigurationManager.getInstance()
1386 .enablePhone(request.phone, enable, onCompleted);
1387 break;
1388 case EVENT_ENABLE_MODEM_DONE:
1389 ar = (AsyncResult) msg.obj;
1390 request = (MainThreadRequest) ar.userObj;
1391 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001392 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001393 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001394 if ((boolean) request.result) {
1395 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1396 updateModemStateMetrics();
1397 } else {
1398 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1399 + ar.exception);
1400 }
1401 notifyRequester(request);
1402 break;
1403 case CMD_GET_MODEM_STATUS:
1404 request = (MainThreadRequest) msg.obj;
1405 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1406 PhoneConfigurationManager.getInstance()
1407 .getPhoneStatusFromModem(request.phone, onCompleted);
1408 break;
1409 case EVENT_GET_MODEM_STATUS_DONE:
1410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
1412 int id = request.phone.getPhoneId();
1413 if (ar.exception == null && ar.result != null) {
1414 request.result = ar.result;
1415 //update the cache as modem status has changed
1416 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1417 (boolean) request.result);
1418 } else {
1419 // Return true if modem status cannot be retrieved. For most cases,
1420 // modem status is on. And for older version modems, GET_MODEM_STATUS
1421 // and disable modem are not supported. Modem is always on.
1422 // TODO: this should be fixed in R to support a third
1423 // status UNKNOWN b/131631629
1424 request.result = true;
1425 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1426 + ar.exception);
1427 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001428 notifyRequester(request);
1429 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001430 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1431 request = (MainThreadRequest) msg.obj;
1432 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1433 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1434 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1435 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1436 break;
1437 }
1438 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
1441 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1442 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1443 args.second.accept(ar.exception == null);
1444 notifyRequester(request);
1445 break;
1446 }
yincheng zhaod698b842019-09-06 17:06:54 -07001447 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 if (ar.exception == null && ar.result != null) {
1451 request.result = ar.result;
1452 } else {
1453 request.result = -1;
1454 loge("Failed to set Forbidden Plmns");
1455 if (ar.result == null) {
1456 loge("setForbidenPlmns: Empty response");
1457 } else if (ar.exception != null) {
1458 loge("setForbiddenPlmns: Exception: " + ar.exception);
1459 request.result = -1;
1460 } else {
1461 loge("setForbiddenPlmns: Unknown exception");
1462 }
1463 }
1464 notifyRequester(request);
1465 break;
1466 case CMD_SET_FORBIDDEN_PLMNS:
1467 request = (MainThreadRequest) msg.obj;
1468 uiccCard = getUiccCardFromRequest(request);
1469 if (uiccCard == null) {
1470 loge("setForbiddenPlmns: UiccCard is null");
1471 request.result = -1;
1472 notifyRequester(request);
1473 break;
1474 }
1475 Pair<Integer, List<String>> setFplmnsArgs =
1476 (Pair<Integer, List<String>>) request.argument;
1477 appType = setFplmnsArgs.first;
1478 List<String> fplmns = setFplmnsArgs.second;
1479 uiccApp = uiccCard.getApplicationByType(appType);
1480 if (uiccApp == null) {
1481 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1482 request.result = -1;
1483 loge("Failed to get UICC App");
1484 notifyRequester(request);
1485 } else {
1486 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1487 ((SIMRecords) uiccApp.getIccRecords())
1488 .setForbiddenPlmns(onCompleted, fplmns);
1489 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001490 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001491 case CMD_ERASE_MODEM_CONFIG:
1492 request = (MainThreadRequest) msg.obj;
1493 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1494 defaultPhone.eraseModemConfig(onCompleted);
1495 break;
1496 case EVENT_ERASE_MODEM_CONFIG_DONE:
1497 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001498 break;
zoey chenf95ca592019-12-30 16:11:23 +08001499
1500 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1501 request = (MainThreadRequest) msg.obj;
1502 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1503 Pair<String, String> changed = (Pair<String, String>) request.argument;
1504 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1505 changed.first, changed.second, onCompleted);
1506 break;
1507 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1508 ar = (AsyncResult) msg.obj;
1509 request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null) {
1511 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1512 } else {
1513 request.result = msg.arg1;
1514 }
1515 notifyRequester(request);
1516 break;
1517
1518 case CMD_SET_ICC_LOCK_ENABLED:
1519 request = (MainThreadRequest) msg.obj;
1520 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1521 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1522 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1523 enabled.first, enabled.second, onCompleted);
1524 break;
1525 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1526 ar = (AsyncResult) msg.obj;
1527 request = (MainThreadRequest) ar.userObj;
1528 if (ar.exception == null) {
1529 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1530 } else {
1531 request.result = msg.arg1;
1532 }
1533 notifyRequester(request);
1534 break;
1535
Peter Wangdafb9ac2020-01-15 14:13:38 -08001536 case MSG_NOTIFY_USER_ACTIVITY:
1537 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001538 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001539 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1540 getDefaultPhone().getContext().sendBroadcastAsUser(
1541 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1542 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 default:
1544 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1545 break;
1546 }
1547 }
Jake Hambye994d462014-02-03 13:10:13 -08001548
Pengquan Menga1bb6272018-09-06 09:59:22 -07001549 private void notifyRequester(MainThreadRequest request) {
1550 synchronized (request) {
1551 request.notifyAll();
1552 }
1553 }
1554
Jake Hambye994d462014-02-03 13:10:13 -08001555 private void handleNullReturnEvent(Message msg, String command) {
1556 AsyncResult ar = (AsyncResult) msg.obj;
1557 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1558 if (ar.exception == null) {
1559 request.result = true;
1560 } else {
1561 request.result = false;
1562 if (ar.exception instanceof CommandException) {
1563 loge(command + ": CommandException: " + ar.exception);
1564 } else {
1565 loge(command + ": Unknown exception");
1566 }
1567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001568 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
1571
1572 /**
1573 * Posts the specified command to be executed on the main thread,
1574 * waits for the request to complete, and returns the result.
1575 * @see #sendRequestAsync
1576 */
1577 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001578 return sendRequest(
1579 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001580 }
1581
1582 /**
1583 * Posts the specified command to be executed on the main thread,
1584 * waits for the request to complete, and returns the result.
1585 * @see #sendRequestAsync
1586 */
1587 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1588 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001589 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001590 }
1591
1592 /**
1593 * Posts the specified command to be executed on the main thread,
1594 * waits for the request to complete, and returns the result.
1595 * @see #sendRequestAsync
1596 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001597 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001598 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001599 }
1600
1601 /**
1602 * Posts the specified command to be executed on the main thread,
1603 * waits for the request to complete, and returns the result.
1604 * @see #sendRequestAsync
1605 */
Nathan Harold92bed182018-10-12 18:16:49 -07001606 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1607 return sendRequest(command, argument, subId, null, workSource);
1608 }
1609
1610 /**
1611 * Posts the specified command to be executed on the main thread,
1612 * waits for the request to complete, and returns the result.
1613 * @see #sendRequestAsync
1614 */
1615 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1616 return sendRequest(
1617 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1618 }
1619
1620 /**
1621 * Posts the specified command to be executed on the main thread,
1622 * waits for the request to complete, and returns the result.
1623 * @see #sendRequestAsync
1624 */
1625 private Object sendRequest(
1626 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1628 throw new RuntimeException("This method will deadlock if called from the main thread.");
1629 }
1630
Nathan Harold92bed182018-10-12 18:16:49 -07001631 MainThreadRequest request = null;
1632 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1633 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1634 } else if (phone != null) {
1635 request = new MainThreadRequest(argument, phone, workSource);
1636 } else {
1637 request = new MainThreadRequest(argument, subId, workSource);
1638 }
1639
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 Message msg = mMainThreadHandler.obtainMessage(command, request);
1641 msg.sendToTarget();
1642
1643 // Wait for the request to complete
1644 synchronized (request) {
1645 while (request.result == null) {
1646 try {
1647 request.wait();
1648 } catch (InterruptedException e) {
1649 // Do nothing, go back and wait until the request is complete
1650 }
1651 }
1652 }
1653 return request.result;
1654 }
1655
1656 /**
1657 * Asynchronous ("fire and forget") version of sendRequest():
1658 * Posts the specified command to be executed on the main thread, and
1659 * returns immediately.
1660 * @see #sendRequest
1661 */
1662 private void sendRequestAsync(int command) {
1663 mMainThreadHandler.sendEmptyMessage(command);
1664 }
1665
1666 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001667 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001668 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001669 */
1670 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001671 sendRequestAsync(command, argument, null, null);
1672 }
1673
1674 /**
1675 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1676 * @see {@link #sendRequest(int,Object)}
1677 */
1678 private void sendRequestAsync(
1679 int command, Object argument, Phone phone, WorkSource workSource) {
1680 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001681 Message msg = mMainThreadHandler.obtainMessage(command, request);
1682 msg.sendToTarget();
1683 }
1684
1685 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 * Initialize the singleton PhoneInterfaceManager instance.
1687 * This is only done once, at startup, from PhoneApp.onCreate().
1688 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001689 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 synchronized (PhoneInterfaceManager.class) {
1691 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001692 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 } else {
1694 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1695 }
1696 return sInstance;
1697 }
1698 }
1699
1700 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001701 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001704 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001705 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1707 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001708 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001709 mTelephonySharedPreferences =
1710 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001711 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001712 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001713 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001714
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 publish();
1716 }
1717
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001718 private Phone getDefaultPhone() {
1719 Phone thePhone = getPhone(getDefaultSubscription());
1720 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1721 }
1722
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 private void publish() {
1724 if (DBG) log("publish: " + this);
1725
Peter Wangc035ce42020-01-08 21:00:22 -08001726 TelephonyFrameworkInitializer
1727 .getTelephonyServiceManager()
1728 .getTelephonyServiceRegisterer()
1729 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 }
1731
Stuart Scott584921c2015-01-15 17:10:34 -08001732 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001733 if (request.phone != null) {
1734 return request.phone;
1735 } else {
1736 return getPhoneFromSubId(request.subId);
1737 }
1738 }
1739
1740 private Phone getPhoneFromSubId(int subId) {
1741 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1742 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001743 }
1744
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001745 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1746 Phone phone = getPhoneFromRequest(request);
1747 return phone == null ? null :
1748 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1749 }
1750
Wink Saville36469e72014-06-11 15:17:00 -07001751 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001752 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001753 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001756 private void sendEraseModemConfig(Phone phone) {
1757 if (phone != null) {
1758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1759 mApp, phone.getSubId(), "eraseModemConfig");
1760 final long identity = Binder.clearCallingIdentity();
1761 try {
1762 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1763 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1764 } finally {
1765 Binder.restoreCallingIdentity(identity);
1766 }
1767 }
1768 }
1769
Peter Wang050bb052020-01-13 23:33:09 -08001770 private boolean isImsAvailableOnDevice() {
1771 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1772 if (pm == null) {
1773 // For some reason package manger is not available.. This will fail internally anyway,
1774 // so do not throw error and allow.
1775 return true;
1776 }
1777 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1778 }
1779
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001781 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001782 }
1783
Wink Savilleb564aae2014-10-23 10:18:09 -07001784 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 if (DBG) log("dial: " + number);
1786 // No permission check needed here: This is just a wrapper around the
1787 // ACTION_DIAL intent, which is available to any app since it puts up
1788 // the UI before it does anything.
1789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001790 final long identity = Binder.clearCallingIdentity();
1791 try {
1792 String url = createTelUrl(number);
1793 if (url == null) {
1794 return;
1795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 // PENDING: should we just silently fail if phone is offhook or ringing?
1798 PhoneConstants.State state = mCM.getState(subId);
1799 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1800 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1801 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1802 mApp.startActivity(intent);
1803 }
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 }
1807 }
1808
1809 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001810 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001811 }
1812
Wink Savilleb564aae2014-10-23 10:18:09 -07001813 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 if (DBG) log("call: " + number);
1815
1816 // This is just a wrapper around the ACTION_CALL intent, but we still
1817 // need to do a permission check since we're calling startActivity()
1818 // from the context of the phone app.
1819 enforceCallPermission();
1820
Jordan Liu1617b712019-07-10 15:06:26 -07001821 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 != AppOpsManager.MODE_ALLOWED) {
1823 return;
1824 }
1825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001826 final long identity = Binder.clearCallingIdentity();
1827 try {
1828 String url = createTelUrl(number);
1829 if (url == null) {
1830 return;
1831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833 boolean isValid = false;
1834 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1835 if (slist != null) {
1836 for (SubscriptionInfo subInfoRecord : slist) {
1837 if (subInfoRecord.getSubscriptionId() == subId) {
1838 isValid = true;
1839 break;
1840 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001841 }
Wink Saville08874612014-08-31 19:19:58 -07001842 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001843 if (!isValid) {
1844 return;
1845 }
Wink Saville08874612014-08-31 19:19:58 -07001846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1848 intent.putExtra(SUBSCRIPTION_KEY, subId);
1849 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1850 mApp.startActivity(intent);
1851 } finally {
1852 Binder.restoreCallingIdentity(identity);
1853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 }
1855
Wink Savilleb564aae2014-10-23 10:18:09 -07001856 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001857 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001858 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1859 }
1860
Wink Savilleb564aae2014-10-23 10:18:09 -07001861 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001862 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001863 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1864 }
1865
Wink Savilleb564aae2014-10-23 10:18:09 -07001866 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001868
1869 final long identity = Binder.clearCallingIdentity();
1870 try {
1871 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1872 checkSimPin.start();
1873 return checkSimPin.unlockSim(null, pin);
1874 } finally {
1875 Binder.restoreCallingIdentity(identity);
1876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 }
1878
Wink Savilleb564aae2014-10-23 10:18:09 -07001879 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001881
1882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1885 checkSimPuk.start();
1886 return checkSimPuk.unlockSim(puk, pin);
1887 } finally {
1888 Binder.restoreCallingIdentity(identity);
1889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
1892 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001893 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 * a synchronous one.
1895 */
1896 private static class UnlockSim extends Thread {
1897
1898 private final IccCard mSimCard;
1899
1900 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001901 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1902 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903
1904 // For replies from SimCard interface
1905 private Handler mHandler;
1906
1907 // For async handler to identify request type
1908 private static final int SUPPLY_PIN_COMPLETE = 100;
1909
1910 public UnlockSim(IccCard simCard) {
1911 mSimCard = simCard;
1912 }
1913
1914 @Override
1915 public void run() {
1916 Looper.prepare();
1917 synchronized (UnlockSim.this) {
1918 mHandler = new Handler() {
1919 @Override
1920 public void handleMessage(Message msg) {
1921 AsyncResult ar = (AsyncResult) msg.obj;
1922 switch (msg.what) {
1923 case SUPPLY_PIN_COMPLETE:
1924 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1925 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001926 mRetryCount = msg.arg1;
1927 if (ar.exception != null) {
1928 if (ar.exception instanceof CommandException &&
1929 ((CommandException)(ar.exception)).getCommandError()
1930 == CommandException.Error.PASSWORD_INCORRECT) {
1931 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001932 } //When UiccCardApp dispose,handle message and return exception
1933 else if (ar.exception instanceof CommandException &&
1934 ((CommandException) (ar.exception)).getCommandError()
1935 == CommandException.Error.ABORTED) {
1936 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001937 } else {
1938 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1939 }
1940 } else {
1941 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 mDone = true;
1944 UnlockSim.this.notifyAll();
1945 }
1946 break;
1947 }
1948 }
1949 };
1950 UnlockSim.this.notifyAll();
1951 }
1952 Looper.loop();
1953 }
1954
1955 /*
1956 * Use PIN or PUK to unlock SIM card
1957 *
1958 * If PUK is null, unlock SIM card with PIN
1959 *
1960 * If PUK is not null, unlock SIM card with PUK and set PIN code
1961 */
Wink Saville9de0f752013-10-22 19:04:03 -07001962 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963
1964 while (mHandler == null) {
1965 try {
1966 wait();
1967 } catch (InterruptedException e) {
1968 Thread.currentThread().interrupt();
1969 }
1970 }
1971 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1972
1973 if (puk == null) {
1974 mSimCard.supplyPin(pin, callback);
1975 } else {
1976 mSimCard.supplyPuk(puk, pin, callback);
1977 }
1978
1979 while (!mDone) {
1980 try {
1981 Log.d(LOG_TAG, "wait for done");
1982 wait();
1983 } catch (InterruptedException e) {
1984 // Restore the interrupted status
1985 Thread.currentThread().interrupt();
1986 }
1987 }
1988 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001989 int[] resultArray = new int[2];
1990 resultArray[0] = mResult;
1991 resultArray[1] = mRetryCount;
1992 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 }
1994 }
1995
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001996 /**
1997 * This method has been removed due to privacy and stability concerns.
1998 */
1999 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002001 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2002 return;
Wink Saville36469e72014-06-11 15:17:00 -07002003 }
2004
Nathan Harold1f889d82020-06-04 17:05:26 -07002005 @Override
2006 public void updateServiceLocationWithPackageName(String callingPackage) {
2007 mApp.getSystemService(AppOpsManager.class)
2008 .checkPackage(Binder.getCallingUid(), callingPackage);
2009
2010 final int targetSdk = getTargetSdk(callingPackage);
2011 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2012 // Callers targeting S have no business invoking this method.
2013 return;
2014 }
2015
2016 LocationAccessPolicy.LocationPermissionResult locationResult =
2017 LocationAccessPolicy.checkLocationPermission(mApp,
2018 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2019 .setCallingPackage(callingPackage)
2020 .setCallingFeatureId(null)
2021 .setCallingPid(Binder.getCallingPid())
2022 .setCallingUid(Binder.getCallingUid())
2023 .setMethod("updateServiceLocation")
2024 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2025 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2026 .build());
2027 // Apps that lack location permission have no business calling this method;
2028 // however, because no permission was declared in the public API, denials must
2029 // all be "soft".
2030 switch (locationResult) {
2031 case DENIED_HARD: /* fall through */
2032 case DENIED_SOFT:
2033 return;
2034 }
2035
2036 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002037 final long identity = Binder.clearCallingIdentity();
2038 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002039 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002041 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 }
2043 } finally {
2044 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002045 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 }
2047
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002048 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002049 @Override
2050 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002051 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002052 }
2053
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002054
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002055 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002056 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2057 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2058 callingFeatureId);
2059 }
2060
2061 @Deprecated
2062 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002063 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002064 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2065 }
2066
2067 @Override
2068 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2069 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002071 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002072 return false;
2073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074
2075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 return isRadioOnForSubscriber(subId);
2078 } finally {
2079 Binder.restoreCallingIdentity(identity);
2080 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002081 }
2082
2083 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002084 final long identity = Binder.clearCallingIdentity();
2085 try {
2086 final Phone phone = getPhone(subId);
2087 if (phone != null) {
2088 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2089 } else {
2090 return false;
2091 }
2092 } finally {
2093 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 }
2096
2097 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002098 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 }
Wink Saville36469e72014-06-11 15:17:00 -07002100
Wink Savilleb564aae2014-10-23 10:18:09 -07002101 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103
2104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 final Phone phone = getPhone(subId);
2107 if (phone != null) {
2108 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2109 }
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002112 }
Wink Saville36469e72014-06-11 15:17:00 -07002113 }
2114
2115 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002116 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002117 }
2118
Wink Savilleb564aae2014-10-23 10:18:09 -07002119 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002120 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002121
2122 final long identity = Binder.clearCallingIdentity();
2123 try {
2124 final Phone phone = getPhone(subId);
2125 if (phone == null) {
2126 return false;
2127 }
2128 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2129 toggleRadioOnOffForSubscriber(subId);
2130 }
2131 return true;
2132 } finally {
2133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 }
Wink Saville36469e72014-06-11 15:17:00 -07002136
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002137 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002138 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002139 /*
2140 * If any of the Radios are available, it will need to be
2141 * shutdown. So return true if any Radio is available.
2142 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002143 final long identity = Binder.clearCallingIdentity();
2144 try {
2145 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2146 Phone phone = PhoneFactory.getPhone(i);
2147 if (phone != null && phone.isRadioAvailable()) return true;
2148 }
2149 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2150 return false;
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002153 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002154 }
2155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002156 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002157 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002158 enforceModifyPermission();
2159
2160 final long identity = Binder.clearCallingIdentity();
2161 try {
2162 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2163 logv("Shutting down Phone " + i);
2164 shutdownRadioUsingPhoneId(i);
2165 }
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002168 }
2169 }
2170
2171 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002172 Phone phone = PhoneFactory.getPhone(phoneId);
2173 if (phone != null && phone.isRadioAvailable()) {
2174 phone.shutdownRadio();
2175 }
2176 }
2177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002179 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002180
2181 final long identity = Binder.clearCallingIdentity();
2182 try {
2183 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2184 if (defaultPhone != null) {
2185 defaultPhone.setRadioPower(turnOn);
2186 return true;
2187 } else {
2188 loge("There's no default phone.");
2189 return false;
2190 }
2191 } finally {
2192 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002193 }
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
Wink Savilleb564aae2014-10-23 10:18:09 -07002196 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002198
2199 final long identity = Binder.clearCallingIdentity();
2200 try {
2201 final Phone phone = getPhone(subId);
2202 if (phone != null) {
2203 phone.setRadioPower(turnOn);
2204 return true;
2205 } else {
2206 return false;
2207 }
2208 } finally {
2209 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 }
2212
Wink Saville36469e72014-06-11 15:17:00 -07002213 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 public boolean enableDataConnectivity() {
2216 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002217
2218 final long identity = Binder.clearCallingIdentity();
2219 try {
2220 int subId = mSubscriptionController.getDefaultDataSubId();
2221 final Phone phone = getPhone(subId);
2222 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002223 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 return true;
2225 } else {
2226 return false;
2227 }
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 }
2232
Wink Saville36469e72014-06-11 15:17:00 -07002233 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002234 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 public boolean disableDataConnectivity() {
2236 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002237
2238 final long identity = Binder.clearCallingIdentity();
2239 try {
2240 int subId = mSubscriptionController.getDefaultDataSubId();
2241 final Phone phone = getPhone(subId);
2242 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002243 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002244 return true;
2245 } else {
2246 return false;
2247 }
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002254 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255 final long identity = Binder.clearCallingIdentity();
2256 try {
2257 final Phone phone = getPhone(subId);
2258 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002259 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 } else {
2261 return false;
2262 }
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
2268 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002269 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002270 }
2271
pkanwarae03a6b2016-11-06 20:37:09 -08002272 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002273 enforceCallPermission();
2274
2275 final long identity = Binder.clearCallingIdentity();
2276 try {
2277 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2278 return;
2279 }
2280 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2281 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2282 } finally {
2283 Binder.restoreCallingIdentity(identity);
2284 }
pkanwar32d516d2016-10-14 19:37:38 -07002285 };
2286
Wink Savilleb564aae2014-10-23 10:18:09 -07002287 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289
2290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2293 return false;
2294 }
2295 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2296 } finally {
2297 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 }
2300
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002302 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002303 }
2304
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002305 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306 final long identity = Binder.clearCallingIdentity();
2307 try {
2308 Phone phone = PhoneFactory.getPhone(slotIndex);
2309 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2310 PhoneConstantConversions.convertCallState(phone.getState());
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
2313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 }
2315
Sanket Padawe356d7632015-06-22 14:03:32 -07002316 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002317 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002318 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2319 }
2320
2321 @Override
2322 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002323 final long identity = Binder.clearCallingIdentity();
2324 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002325 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326 if (phone != null) {
2327 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2328 } else {
2329 return PhoneConstantConversions.convertDataState(
2330 PhoneConstants.DataState.DISCONNECTED);
2331 }
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 }
2336
Sanket Padawe356d7632015-06-22 14:03:32 -07002337 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002338 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002339 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2340 }
2341
2342 @Override
2343 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344 final long identity = Binder.clearCallingIdentity();
2345 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002346 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347 if (phone != null) {
2348 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2349 } else {
2350 return TelephonyManager.DATA_ACTIVITY_NONE;
2351 }
2352 } finally {
2353 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 }
2356
2357 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002358 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002359 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002360 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002361
2362 LocationAccessPolicy.LocationPermissionResult locationResult =
2363 LocationAccessPolicy.checkLocationPermission(mApp,
2364 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2365 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002366 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002367 .setCallingPid(Binder.getCallingPid())
2368 .setCallingUid(Binder.getCallingUid())
2369 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002370 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002371 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2372 .build());
2373 switch (locationResult) {
2374 case DENIED_HARD:
2375 throw new SecurityException("Not allowed to access cell location");
2376 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002377 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2378 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 }
2380
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002381 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002385 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002386 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387 } finally {
2388 Binder.restoreCallingIdentity(identity);
2389 }
Svetoslav64fad262015-04-14 14:35:21 -07002390 }
2391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 @Override
Jack Yu01425032020-02-22 19:38:58 -08002393 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002394 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2395 // registered cell info, so return a NULL country instead.
2396 final long identity = Binder.clearCallingIdentity();
2397 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002398 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2399 // Get default phone in this case.
2400 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2401 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002402 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002403 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002404 if (phone == null) return "";
2405 ServiceStateTracker sst = phone.getServiceStateTracker();
2406 if (sst == null) return "";
2407 LocaleTracker lt = sst.getLocaleTracker();
2408 if (lt == null) return "";
2409 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2410 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2411 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002412 } finally {
2413 Binder.restoreCallingIdentity(identity);
2414 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002415 }
2416
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002417 /**
2418 * This method was removed due to potential issues caused by performing partial
2419 * updates of service state, and lack of a credible use case.
2420 *
2421 * This has the ability to break the telephony implementation by disabling notification of
2422 * changes in device connectivity. DO NOT USE THIS!
2423 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002424 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 public void enableLocationUpdates() {
2426 mApp.enforceCallingOrSelfPermission(
2427 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 }
2429
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002430 /**
2431 * This method was removed due to potential issues caused by performing partial
2432 * updates of service state, and lack of a credible use case.
2433 *
2434 * This has the ability to break the telephony implementation by disabling notification of
2435 * changes in device connectivity. DO NOT USE THIS!
2436 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 @Override
2438 public void disableLocationUpdates() {
2439 mApp.enforceCallingOrSelfPermission(
2440 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 }
2442
Nathan Harold31d7ff32018-10-15 20:20:30 -07002443 /**
2444 * Returns the target SDK version number for a given package name.
2445 *
Nathan Haroldec184742019-07-10 17:04:16 -07002446 * This call MUST be invoked before clearing the calling UID.
2447 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002448 * @return target SDK if the package is found or INT_MAX.
2449 */
2450 private int getTargetSdk(String packageName) {
2451 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002452 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002453 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002454 if (ai != null) return ai.targetSdkVersion;
2455 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002456 loge("Failed to get package info for pkg="
2457 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002458 }
2459 return Integer.MAX_VALUE;
2460 }
2461
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 @Override
2463 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002464 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2465 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002466 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002467 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2468 throw new SecurityException(
2469 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2470 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002471
Jordan Liu1617b712019-07-10 15:06:26 -07002472 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2474 return null;
2475 }
Svetoslav64fad262015-04-14 14:35:21 -07002476
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002477 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002479 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002480 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481
Nathan Haroldf180aac2018-06-01 18:43:55 -07002482 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2483 for (CellInfo ci : info) {
2484 if (ci instanceof CellInfoGsm) {
2485 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2486 } else if (ci instanceof CellInfoWcdma) {
2487 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002490 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 }
2492
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002493 private List<CellInfo> getCachedCellInfo() {
2494 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2495 for (Phone phone : PhoneFactory.getPhones()) {
2496 List<CellInfo> info = phone.getAllCellInfo();
2497 if (info != null) cellInfos.addAll(info);
2498 }
2499 return cellInfos;
2500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501
2502 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002503 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002504 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002505 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002506
2507 LocationAccessPolicy.LocationPermissionResult locationResult =
2508 LocationAccessPolicy.checkLocationPermission(mApp,
2509 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2510 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002511 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002512 .setCallingPid(Binder.getCallingPid())
2513 .setCallingUid(Binder.getCallingUid())
2514 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002515 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002516 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2517 .build());
2518 switch (locationResult) {
2519 case DENIED_HARD:
2520 throw new SecurityException("Not allowed to access cell info");
2521 case DENIED_SOFT:
2522 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 }
2524
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002525 final int targetSdk = getTargetSdk(callingPackage);
2526 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2527 return getCachedCellInfo();
2528 }
2529
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002530 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002531 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2535 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002536 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002537 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538 if (info != null) cellInfos.addAll(info);
2539 }
2540 return cellInfos;
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002543 }
2544 }
2545
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002546 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002547 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2548 String callingFeatureId) {
2549 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2550 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002551 }
2552
2553 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002554 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2555 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002556 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002557 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002558 }
2559
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002560 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2561 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002562 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002563 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002564
2565 LocationAccessPolicy.LocationPermissionResult locationResult =
2566 LocationAccessPolicy.checkLocationPermission(mApp,
2567 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2568 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002569 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002570 .setCallingPid(Binder.getCallingPid())
2571 .setCallingUid(Binder.getCallingUid())
2572 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002573 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2574 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002575 .build());
2576 switch (locationResult) {
2577 case DENIED_HARD:
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 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002582 throw new SecurityException("Not allowed to access cell info");
2583 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002584 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2585 // Safetynet logging for b/154934934
2586 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2587 }
Nathan Harold5320c422019-05-09 10:26:08 -07002588 try {
2589 cb.onCellInfo(new ArrayList<CellInfo>());
2590 } catch (RemoteException re) {
2591 // Drop without consequences
2592 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002593 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002594 }
2595
Nathan Harolda939a962019-05-09 10:13:47 -07002596
2597 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002598 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2599
2600 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2601 }
2602
2603 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002605 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002606 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607
2608 final long identity = Binder.clearCallingIdentity();
2609 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002610 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611 } finally {
2612 Binder.restoreCallingIdentity(identity);
2613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 }
2615
Shishir Agrawala9f32182016-04-12 12:00:16 -07002616 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002617 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002618 Phone phone = PhoneFactory.getPhone(slotIndex);
2619 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002620 return null;
2621 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002622 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002623 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002624 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002625 return null;
2626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627
2628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 return phone.getImei();
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
2633 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002634 }
2635
2636 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002637 public String getTypeAllocationCodeForSlot(int slotIndex) {
2638 Phone phone = PhoneFactory.getPhone(slotIndex);
2639 String tac = null;
2640 if (phone != null) {
2641 String imei = phone.getImei();
2642 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2643 }
2644 return tac;
2645 }
2646
2647 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002648 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002649 Phone phone = PhoneFactory.getPhone(slotIndex);
2650 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002651 return null;
2652 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002653
Jeff Davidson913390f2018-02-23 17:11:49 -08002654 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002655 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002656 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002657 return null;
2658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659
2660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 return phone.getMeid();
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
Jack Yu2af8d712017-03-15 17:14:14 -07002666 }
2667
2668 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002669 public String getManufacturerCodeForSlot(int slotIndex) {
2670 Phone phone = PhoneFactory.getPhone(slotIndex);
2671 String manufacturerCode = null;
2672 if (phone != null) {
2673 String meid = phone.getMeid();
2674 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2675 }
2676 return manufacturerCode;
2677 }
2678
2679 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002680 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2681 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002682 Phone phone = PhoneFactory.getPhone(slotIndex);
2683 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002684 return null;
2685 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002686 int subId = phone.getSubId();
2687 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002688 mApp, subId, callingPackage, callingFeatureId,
2689 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002690 return null;
2691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692
2693 final long identity = Binder.clearCallingIdentity();
2694 try {
2695 return phone.getDeviceSvn();
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
2698 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002699 }
2700
fionaxu43304da2017-11-27 22:51:16 -08002701 @Override
2702 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 final Phone phone = getPhone(subId);
2706 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2707 } finally {
2708 Binder.restoreCallingIdentity(identity);
2709 }
fionaxu43304da2017-11-27 22:51:16 -08002710 }
2711
2712 @Override
2713 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 final Phone phone = getPhone(subId);
2717 return phone == null ? null : phone.getCarrierName();
2718 } finally {
2719 Binder.restoreCallingIdentity(identity);
2720 }
fionaxu43304da2017-11-27 22:51:16 -08002721 }
2722
calvinpanffe225e2018-11-01 19:43:06 +08002723 @Override
chen xu0026ca62019-03-06 15:28:50 -08002724 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 final Phone phone = getPhone(subId);
2728 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002729 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002730 } finally {
2731 Binder.restoreCallingIdentity(identity);
2732 }
2733 }
2734
2735 @Override
chen xu0026ca62019-03-06 15:28:50 -08002736 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002737 final long identity = Binder.clearCallingIdentity();
2738 try {
2739 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002740 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002741 } finally {
2742 Binder.restoreCallingIdentity(identity);
2743 }
2744 }
2745
chen xu651eec72018-11-11 19:03:44 -08002746 @Override
chen xu864e11c2018-12-06 22:10:03 -08002747 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2748 if (!isSubscriptionMccMnc) {
2749 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2750 }
chen xu651eec72018-11-11 19:03:44 -08002751 final Phone phone = PhoneFactory.getPhone(slotIndex);
2752 if (phone == null) {
2753 return TelephonyManager.UNKNOWN_CARRIER_ID;
2754 }
2755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2758 } finally {
2759 Binder.restoreCallingIdentity(identity);
2760 }
2761 }
2762
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 //
2764 // Internal helper methods.
2765 //
2766
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002767 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2769 *
2770 * @throws SecurityException if the caller does not have the required permission
2771 */
2772 private void enforceModifyPermission() {
2773 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2774 }
2775
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002776 /**
2777 * Make sure the caller is system.
2778 *
2779 * @throws SecurityException if the caller is not system.
2780 */
2781 private void enforceSystemCaller() {
2782 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2783 throw new SecurityException("Caller must be system");
2784 }
2785 }
2786
Shuo Qianf2b2df42019-11-13 17:43:31 -08002787 private void enforceActiveEmergencySessionPermission() {
2788 mApp.enforceCallingOrSelfPermission(
2789 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2790 }
2791
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 /**
2793 * Make sure the caller has the CALL_PHONE permission.
2794 *
2795 * @throws SecurityException if the caller does not have the required permission
2796 */
2797 private void enforceCallPermission() {
2798 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2799 }
2800
paulhu423b5f22019-08-23 19:17:33 +08002801 private void enforceSettingsPermission() {
2802 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002803 }
2804
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 private String createTelUrl(String number) {
2806 if (TextUtils.isEmpty(number)) {
2807 return null;
2808 }
2809
Jake Hambye994d462014-02-03 13:10:13 -08002810 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
Ihab Awadf9e92732013-12-05 18:02:52 -08002813 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2815 }
2816
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002817 private static void logv(String msg) {
2818 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2819 }
2820
Ihab Awadf9e92732013-12-05 18:02:52 -08002821 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2823 }
2824
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002825 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002827 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002828 }
2829
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002831 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832 final long identity = Binder.clearCallingIdentity();
2833 try {
2834 final Phone phone = PhoneFactory.getPhone(slotIndex);
2835 if (phone == null) {
2836 return PhoneConstants.PHONE_TYPE_NONE;
2837 } else {
2838 return phone.getPhoneType();
2839 }
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 }
2844
2845 /**
2846 * Returns the CDMA ERI icon index to display
2847 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002848 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002849 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2850 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2851 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002852 }
2853
Sanket Padawe356d7632015-06-22 14:03:32 -07002854 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002855 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2856 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002858 mApp, subId, callingPackage, callingFeatureId,
2859 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002860 return -1;
2861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862
2863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 final Phone phone = getPhone(subId);
2866 if (phone != null) {
2867 return phone.getCdmaEriIconIndex();
2868 } else {
2869 return -1;
2870 }
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002874 }
2875
2876 /**
2877 * Returns the CDMA ERI icon mode,
2878 * 0 - ON
2879 * 1 - FLASHING
2880 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002881 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002882 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2883 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2884 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002885 }
2886
Sanket Padawe356d7632015-06-22 14:03:32 -07002887 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002888 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2889 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002891 mApp, subId, callingPackage, callingFeatureId,
2892 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002893 return -1;
2894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895
2896 final long identity = Binder.clearCallingIdentity();
2897 try {
2898 final Phone phone = getPhone(subId);
2899 if (phone != null) {
2900 return phone.getCdmaEriIconMode();
2901 } else {
2902 return -1;
2903 }
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002907 }
2908
2909 /**
2910 * Returns the CDMA ERI text,
2911 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002912 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002913 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2914 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2915 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002916 }
2917
Sanket Padawe356d7632015-06-22 14:03:32 -07002918 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002919 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2920 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002922 mApp, subId, callingPackage, callingFeatureId,
2923 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002924 return null;
2925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926
2927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 final Phone phone = getPhone(subId);
2930 if (phone != null) {
2931 return phone.getCdmaEriText();
2932 } else {
2933 return null;
2934 }
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002938 }
2939
2940 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002941 * Returns the CDMA MDN.
2942 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002943 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002944 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2946 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002947
2948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002951 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952 return phone.getLine1Number();
2953 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002954 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955 return null;
2956 }
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002959 }
2960 }
2961
2962 /**
2963 * Returns the CDMA MIN.
2964 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002965 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002966 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2968 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969
2970 final long identity = Binder.clearCallingIdentity();
2971 try {
2972 final Phone phone = getPhone(subId);
2973 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2974 return phone.getCdmaMin();
2975 } else {
2976 return null;
2977 }
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002980 }
2981 }
2982
Hall Liud892bec2018-11-30 14:51:45 -08002983 @Override
2984 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2985 INumberVerificationCallback callback, String callingPackage) {
2986 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2987 != PERMISSION_GRANTED) {
2988 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2989 }
2990 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2991
2992 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2993 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2994 throw new SecurityException("Calling package must be configured in the device config");
2995 }
2996
2997 if (range == null) {
2998 throw new NullPointerException("Range must be non-null");
2999 }
3000
3001 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003002 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003003
3004 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3005 }
3006
Junda Liuca05d5d2014-08-14 22:36:34 -07003007 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003008 * Returns true if CDMA provisioning needs to run.
3009 */
3010 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003011 final long identity = Binder.clearCallingIdentity();
3012 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003013 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014 } finally {
3015 Binder.restoreCallingIdentity(identity);
3016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003017 }
3018
3019 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003020 * Sets the voice mail number of a given subId.
3021 */
3022 @Override
3023 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003024 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3025 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3030 new Pair<String, String>(alphaTag, number), new Integer(subId));
3031 return success;
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003035 }
3036
Ta-wei Yen87c49842016-05-13 21:19:52 -07003037 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003038 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3039 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003040 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3041 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003042 if (!TextUtils.equals(callingPackage, systemDialer)) {
3043 throw new SecurityException("caller must be system dialer");
3044 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3049 if (phoneAccountHandle == null) {
3050 return null;
3051 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003052 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003053 } finally {
3054 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003055 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003056 }
3057
3058 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003059 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3060 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003061 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003063 mApp, subId, callingPackage, callingFeatureId,
3064 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003065 return null;
3066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003067
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003068 final long identity = Binder.clearCallingIdentity();
3069 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003070 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003071 } finally {
3072 Binder.restoreCallingIdentity(identity);
3073 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003074 }
3075
3076 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003077 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3078 VisualVoicemailSmsFilterSettings settings) {
3079 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080
3081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003084 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003088 }
3089
3090 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003091 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3092 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093
3094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003097 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003101 }
3102
3103 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003104 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3105 String callingPackage, int subId) {
3106 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107
3108 final long identity = Binder.clearCallingIdentity();
3109 try {
3110 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003111 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112 } finally {
3113 Binder.restoreCallingIdentity(identity);
3114 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003115 }
3116
3117 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003118 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003119 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120
3121 final long identity = Binder.clearCallingIdentity();
3122 try {
3123 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003124 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003125 } finally {
3126 Binder.restoreCallingIdentity(identity);
3127 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003128 }
3129
3130 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003131 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3132 String callingAttributionTag, int subId, String number, int port, String text,
3133 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003134 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003135 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003136 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003137 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003138 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3139 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003140 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003141
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003142 /**
fionaxu0152e512016-11-14 13:36:14 -08003143 * Sets the voice activation state of a given subId.
3144 */
3145 @Override
3146 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3148 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 final Phone phone = getPhone(subId);
3153 if (phone != null) {
3154 phone.setVoiceActivationState(activationState);
3155 } else {
3156 loge("setVoiceActivationState fails with invalid subId: " + subId);
3157 }
3158 } finally {
3159 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003160 }
3161 }
3162
3163 /**
3164 * Sets the data activation state of a given subId.
3165 */
3166 @Override
3167 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3169 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 final Phone phone = getPhone(subId);
3174 if (phone != null) {
3175 phone.setDataActivationState(activationState);
3176 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003177 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003178 }
3179 } finally {
3180 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003181 }
3182 }
3183
3184 /**
3185 * Returns the voice activation state of a given subId.
3186 */
3187 @Override
3188 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003189 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190
fionaxu0152e512016-11-14 13:36:14 -08003191 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 final long identity = Binder.clearCallingIdentity();
3193 try {
3194 if (phone != null) {
3195 return phone.getVoiceActivationState();
3196 } else {
3197 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3198 }
3199 } finally {
3200 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003201 }
3202 }
3203
3204 /**
3205 * Returns the data activation state of a given subId.
3206 */
3207 @Override
3208 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003209 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210
fionaxu0152e512016-11-14 13:36:14 -08003211 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 if (phone != null) {
3215 return phone.getDataActivationState();
3216 } else {
3217 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3218 }
3219 } finally {
3220 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003221 }
3222 }
3223
3224 /**
Wink Saville36469e72014-06-11 15:17:00 -07003225 * Returns the unread count of voicemails for a subId
3226 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003227 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003228 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3229 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003231 mApp, subId, callingPackage, callingFeatureId,
3232 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003233 return 0;
3234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 final Phone phone = getPhone(subId);
3238 if (phone != null) {
3239 return phone.getVoiceMessageCount();
3240 } else {
3241 return 0;
3242 }
3243 } finally {
3244 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003245 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003246 }
3247
3248 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003249 * returns true, if the device is in a state where both voice and data
3250 * are supported simultaneously. This can change based on location or network condition.
3251 */
3252 @Override
3253 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254 final long identity = Binder.clearCallingIdentity();
3255 try {
3256 final Phone phone = getPhone(subId);
3257 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003261 }
3262
3263 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003264 * Send the dialer code if called from the current default dialer or the caller has
3265 * carrier privilege.
3266 * @param inputCode The dialer code to send
3267 */
3268 @Override
3269 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003270 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003271 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003272 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3273 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003274 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003275 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003276 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003277 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278
3279 final long identity = Binder.clearCallingIdentity();
3280 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
fionaxu235cc5e2017-03-06 22:25:57 -08003285 }
3286
Pengquan Menga1bb6272018-09-06 09:59:22 -07003287 @Override
3288 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003289 TelephonyPermissions
3290 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3291 mApp, subId, "getNetworkSelectionMode");
3292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 if (!isActiveSubscription(subId)) {
3295 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3296 }
3297 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3298 } finally {
3299 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003300 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003301 }
3302
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003304 public boolean isInEmergencySmsMode() {
3305 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3306 final long identity = Binder.clearCallingIdentity();
3307 try {
3308 for (Phone phone : PhoneFactory.getPhones()) {
3309 if (phone.isInEmergencySmsMode()) {
3310 return true;
3311 }
3312 }
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
3316 return false;
3317 }
3318
shilu366312e2019-12-17 09:28:10 -08003319 /**
3320 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3321 * @param subId The subscription to use to check the configuration.
3322 * @param c The callback that will be used to send the result.
3323 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003324 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003325 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3326 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003327 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3328 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003329
Brad Ebinger77b832e2019-10-17 17:03:22 -07003330 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3331 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3332 "IMS not available on device.");
3333 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003334 final long token = Binder.clearCallingIdentity();
3335 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003336 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003337 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003338 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003339 } catch (ImsException e) {
3340 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003341 } finally {
3342 Binder.restoreCallingIdentity(token);
3343 }
3344 }
3345
shilu366312e2019-12-17 09:28:10 -08003346 /**
3347 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3348 * @param subId The subscription to use to check the configuration.
3349 * @param c The callback that will be used to send the result.
3350 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003351 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003352 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003353 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3354 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003355 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3356 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3357 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003358 final long token = Binder.clearCallingIdentity();
3359 try {
3360 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3361 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3362 .removeRegistrationCallbackForSubscription(c, subId);
3363 } catch (ImsException e) {
3364 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3365 + "is inactive, ignoring unregister.");
3366 // If the subscription is no longer active, just return, since the callback
3367 // will already have been removed internally.
3368 } finally {
3369 Binder.restoreCallingIdentity(token);
3370 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003371 }
3372
Brad Ebinger774ba362019-10-22 17:36:18 -07003373 /**
3374 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3375 */
3376 @Override
3377 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3378 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3379 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3380 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3381 "IMS not available on device.");
3382 }
3383 final long token = Binder.clearCallingIdentity();
3384 try {
3385 Phone phone = getPhone(subId);
3386 if (phone == null) {
3387 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3388 + subId + "'");
3389 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3390 }
3391 phone.getImsRegistrationState(regState -> {
3392 try {
3393 consumer.accept((regState == null)
3394 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3395 } catch (RemoteException e) {
3396 // Ignore if the remote process is no longer available to call back.
3397 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3398 }
3399 });
3400 } finally {
3401 Binder.restoreCallingIdentity(token);
3402 }
3403 }
3404
3405 /**
3406 * Get the transport type for the IMS service registration state.
3407 */
3408 @Override
3409 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003410 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3411 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003412 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3413 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3414 "IMS not available on device.");
3415 }
3416 final long token = Binder.clearCallingIdentity();
3417 try {
3418 Phone phone = getPhone(subId);
3419 if (phone == null) {
3420 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3421 + subId + "'");
3422 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3423 }
3424 phone.getImsRegistrationTech(regTech -> {
3425 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3426 int regTechConverted = (regTech == null)
3427 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3428 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3429 regTechConverted);
3430 try {
3431 consumer.accept(regTechConverted);
3432 } catch (RemoteException e) {
3433 // Ignore if the remote process is no longer available to call back.
3434 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3435 }
3436 });
3437 } finally {
3438 Binder.restoreCallingIdentity(token);
3439 }
3440 }
3441
shilu366312e2019-12-17 09:28:10 -08003442 /**
3443 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3444 * @param subId The subscription to use to check the configuration.
3445 * @param c The callback that will be used to send the result.
3446 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003447 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003448 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3449 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003450 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3451 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003452 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3453 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3454 "IMS not available on device.");
3455 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003456 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3457 final long token = Binder.clearCallingIdentity();
3458 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003459 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003460 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003461 } catch (ImsException e) {
3462 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003463 } finally {
3464 Binder.restoreCallingIdentity(token);
3465 }
3466 }
3467
shilu366312e2019-12-17 09:28:10 -08003468 /**
3469 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3470 * @param subId The subscription to use to check the configuration.
3471 * @param c The callback that will be used to send the result.
3472 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003473 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003474 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003475 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3476 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003477 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3478 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3479 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003480
3481 final long token = Binder.clearCallingIdentity();
3482 try {
3483 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3484 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003485 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003486 } catch (ImsException e) {
3487 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3488 + "is inactive, ignoring unregister.");
3489 // If the subscription is no longer active, just return, since the callback
3490 // will already have been removed internally.
3491 } finally {
3492 Binder.restoreCallingIdentity(token);
3493 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003494 }
3495
3496 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003497 public boolean isCapable(int subId, int capability, int regTech) {
3498 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003499 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3500 final long token = Binder.clearCallingIdentity();
3501 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003502 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003503 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003504 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3506 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003507 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003508 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3509 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003510 } finally {
3511 Binder.restoreCallingIdentity(token);
3512 }
3513 }
3514
3515 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003516 public boolean isAvailable(int subId, int capability, int regTech) {
3517 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 final long token = Binder.clearCallingIdentity();
3519 try {
3520 Phone phone = getPhone(subId);
3521 if (phone == null) return false;
3522 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003523 } catch (com.android.ims.ImsException e) {
3524 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3525 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 } finally {
3527 Binder.restoreCallingIdentity(token);
3528 }
3529 }
3530
Brad Ebinger77b832e2019-10-17 17:03:22 -07003531 /**
3532 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3533 * subscription.
3534 * @param subId The subscription to use to check the configuration.
3535 * @param callback The callback that will be used to send the result.
3536 * @param capability The MmTelFeature capability that will be used to send the result.
3537 * @param transportType The transport type of the MmTelFeature capability.
3538 */
3539 @Override
3540 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3541 int transportType) {
3542 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3543 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3544 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3545 "IMS not available on device.");
3546 }
3547 final long token = Binder.clearCallingIdentity();
3548 try {
3549 int slotId = getSlotIndex(subId);
3550 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3551 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3552 + subId + "'");
3553 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3554 }
3555 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3556 transportType, aBoolean -> {
3557 try {
3558 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3559 } catch (RemoteException e) {
3560 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3561 + "running. Ignore");
3562 }
3563 });
3564 } finally {
3565 Binder.restoreCallingIdentity(token);
3566 }
3567 }
3568
shilu366312e2019-12-17 09:28:10 -08003569 /**
3570 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3571 * @param subId The subscription to use to check the configuration.
3572 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 @Override
3574 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003575 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3576 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003577
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3579 final long token = Binder.clearCallingIdentity();
3580 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003581 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003583 } catch (ImsException e) {
3584 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 } finally {
3586 Binder.restoreCallingIdentity(token);
3587 }
3588 }
3589
3590 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003591 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003593 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003597 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003599 } catch (ImsException e) {
3600 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003601 } finally {
3602 Binder.restoreCallingIdentity(identity);
3603 }
3604 }
3605
shilu366312e2019-12-17 09:28:10 -08003606 /**
3607 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3608 * @param subId The subscription to use to check the configuration.
3609 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003611 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003612 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3613 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003617 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3618 } catch (ImsException e) {
3619 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 } finally {
3621 Binder.restoreCallingIdentity(identity);
3622 }
3623 }
3624
3625 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003626 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003628 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003629 final long identity = Binder.clearCallingIdentity();
3630 try {
3631 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003632 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003633 } catch (ImsException e) {
3634 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003635 } finally {
3636 Binder.restoreCallingIdentity(identity);
3637 }
3638 }
3639
shilu366312e2019-12-17 09:28:10 -08003640 /**
3641 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3642 * @param subId The subscription to use to check the configuration.
3643 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003644 @Override
3645 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003646 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3647 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003651 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003652 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003653 } catch (ImsException e) {
3654 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
3658 }
3659
3660 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003661 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003663 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003667 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003668 } catch (ImsException e) {
3669 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003670 } finally {
3671 Binder.restoreCallingIdentity(identity);
3672 }
3673 }
3674
shilu366312e2019-12-17 09:28:10 -08003675 /**
3676 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3677 * @param subId The subscription to use to check the configuration.
3678 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003679 @Override
3680 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003681 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3682 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003686 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003687 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003688 } catch (ImsException e) {
3689 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
3693 }
3694
3695 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003696 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003698 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003702 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003703 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003704 } catch (ImsException e) {
3705 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
3709 }
3710
3711 @Override
3712 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3714 "setVoWiFiNonPersistent");
3715 final long identity = Binder.clearCallingIdentity();
3716 try {
3717 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003718 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003719 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003720 } catch (ImsException e) {
3721 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003722 } finally {
3723 Binder.restoreCallingIdentity(identity);
3724 }
3725 }
3726
shilu366312e2019-12-17 09:28:10 -08003727 /**
3728 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3729 * @param subId The subscription to use to check the configuration.
3730 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 @Override
3732 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003733 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3734 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003739 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003740 } catch (ImsException e) {
3741 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 } finally {
3743 Binder.restoreCallingIdentity(identity);
3744 }
3745 }
3746
3747 @Override
3748 public void setVoWiFiModeSetting(int subId, int mode) {
3749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3750 "setVoWiFiModeSetting");
3751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003754 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003756 } catch (ImsException e) {
3757 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 } finally {
3759 Binder.restoreCallingIdentity(identity);
3760 }
3761 }
3762
3763 @Override
3764 public int getVoWiFiRoamingModeSetting(int subId) {
3765 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3766 final long identity = Binder.clearCallingIdentity();
3767 try {
3768 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003769 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003770 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003771 } catch (ImsException e) {
3772 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 } finally {
3774 Binder.restoreCallingIdentity(identity);
3775 }
3776 }
3777
3778 @Override
3779 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3781 "setVoWiFiRoamingModeSetting");
3782 final long identity = Binder.clearCallingIdentity();
3783 try {
3784 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003785 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003786 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003787 } catch (ImsException e) {
3788 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
3792 }
3793
3794 @Override
3795 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3797 "setRttCapabilityEnabled");
3798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003801 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3802 } catch (ImsException e) {
3803 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
3807 }
3808
shilu366312e2019-12-17 09:28:10 -08003809 /**
3810 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3811 * @param subId The subscription to use to check the configuration.
3812 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003813 @Override
3814 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003815 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3816 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003817 final long identity = Binder.clearCallingIdentity();
3818 try {
3819 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003820 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003822 } catch (ImsException e) {
3823 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 } finally {
3825 Binder.restoreCallingIdentity(identity);
3826 }
3827 }
3828
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003829 @Override
3830 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3831 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3832 final long identity = Binder.clearCallingIdentity();
3833 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003834 if (!isImsAvailableOnDevice()) {
3835 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3836 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003837 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003838 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003839 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003840 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003841 } catch (ImsException e) {
3842 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003843 } finally {
3844 Binder.restoreCallingIdentity(identity);
3845 }
3846 }
3847
3848 @Override
3849 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3850 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3851 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003852 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3853 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3854 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003855 try {
3856 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003857 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003858 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003859 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003860 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3861 + "is inactive, ignoring unregister.");
3862 // If the subscription is no longer active, just return, since the callback will already
3863 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003864 } finally {
3865 Binder.restoreCallingIdentity(identity);
3866 }
3867 }
3868
allenwtsu99c623b2020-01-03 18:24:23 +08003869
3870 private void checkModifyPhoneStatePermission(int subId, String message) {
3871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3872 message);
3873 }
3874
3875 private boolean isImsProvisioningRequired(int subId, int capability,
3876 boolean isMmtelCapability) {
3877 Phone phone = getPhone(subId);
3878 if (phone == null) {
3879 loge("phone instance null for subid " + subId);
3880 return false;
3881 }
3882 if (isMmtelCapability) {
3883 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3884 return false;
3885 }
3886 } else {
3887 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3888 return false;
3889 }
3890 }
3891 return true;
3892 }
3893
3894 @Override
3895 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3896 boolean isProvisioned) {
3897 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3898
3899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3902 if (!isImsProvisioningRequired(subId, capability, false)) {
3903 return;
3904 }
3905
3906 // this capability requires provisioning, route to the correct API.
3907 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3908 switch (capability) {
3909 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3910 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3911 ims.setEabProvisioned(isProvisioned);
3912 break;
3913 default: {
3914 throw new IllegalArgumentException("Tried to set provisioning for "
3915 + "rcs capability '" + capability + "', which does not require "
3916 + "provisioning.");
3917 }
3918 }
3919 } finally {
3920 Binder.restoreCallingIdentity(identity);
3921 }
3922
3923 }
3924
3925
3926 @Override
3927 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3928 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3932 if (!isImsProvisioningRequired(subId, capability, false)) {
3933 return true;
3934 }
3935
3936 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3937 switch (capability) {
3938 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3939 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3940 return ims.isEabProvisionedOnDevice();
3941
3942 default: {
3943 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3944 + "capability '" + capability + "', which does not require "
3945 + "provisioning.");
3946 }
3947 }
3948
3949 } finally {
3950 Binder.restoreCallingIdentity(identity);
3951 }
3952 }
3953
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003954 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003955 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3956 boolean isProvisioned) {
3957 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3958 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3959 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3960 }
allenwtsu99c623b2020-01-03 18:24:23 +08003961 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003962 final long identity = Binder.clearCallingIdentity();
3963 try {
3964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003965 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003966 return;
3967 }
3968
3969 // this capability requires provisioning, route to the correct API.
3970 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3971 switch (capability) {
3972 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3973 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3974 ims.setVolteProvisioned(isProvisioned);
3975 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3976 ims.setWfcProvisioned(isProvisioned);
3977 }
3978 break;
3979 }
3980 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3981 // There is currently no difference in VT provisioning type.
3982 ims.setVtProvisioned(isProvisioned);
3983 break;
3984 }
3985 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3986 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3987 // change the capability of the feature instead if needed.
3988 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3989 == isProvisioned) {
3990 // No change in provisioning.
3991 return;
3992 }
3993 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3994 try {
3995 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003996 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003997 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3998 + ", Exception" + e.getMessage());
3999 }
4000 break;
4001 }
4002 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004003 throw new IllegalArgumentException("Tried to set provisioning for "
4004 + "MmTel capability '" + capability + "', which does not require "
4005 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004006 }
4007 }
4008
4009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
4012 }
4013
4014 @Override
4015 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4016 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4017 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4018 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4019 }
4020 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004024 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004025 return true;
4026 }
4027
4028 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4029 switch (capability) {
4030 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4031 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4032 return ims.isVolteProvisionedOnDevice();
4033 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4034 return ims.isWfcProvisionedOnDevice();
4035 }
4036 // This should never happen, since we are checking tech above to make sure it
4037 // is either LTE or IWLAN.
4038 throw new IllegalArgumentException("Invalid radio technology for voice "
4039 + "capability.");
4040 }
4041 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4042 // There is currently no difference in VT provisioning type.
4043 return ims.isVtProvisionedOnDevice();
4044 }
4045 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4046 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4047 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4048 }
4049 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004050 throw new IllegalArgumentException(
4051 "Tried to get provisioning for MmTel capability '" + capability
4052 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004053 }
4054 }
4055
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
4059 }
4060
4061 @Override
4062 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4063 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4064 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4065 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4066 }
4067 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4068 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4069 return (provisionedBits & capability) > 0;
4070 }
4071
4072 @Override
4073 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4074 boolean isProvisioned) {
4075 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4076 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4077 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4078 }
4079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4080 "setProvisioningStatusForCapability");
4081 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4082 // If the current provisioning status for capability already matches isProvisioned,
4083 // do nothing.
4084 if (((provisionedBits & capability) > 0) == isProvisioned) {
4085 return;
4086 }
4087 if (isProvisioned) {
4088 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4089 } else {
4090 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4091 }
4092 }
4093
4094 /**
4095 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4096 * technology. The bitfield should mirror the bitfield defined by
4097 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4098 */
4099 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4100 String key = getMmTelProvisioningKey(subId, tech);
4101 // Default is no capabilities are provisioned.
4102 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4103 }
4104
4105 /**
4106 * Sets the MmTel capability provisioning bitfield (defined by
4107 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4108 * technology specified.
4109 *
4110 * Note: This is a synchronous command and should not be called on UI thread.
4111 */
4112 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4113 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4114 String key = getMmTelProvisioningKey(subId, tech);
4115 editor.putInt(key, newField);
4116 editor.commit();
4117 }
4118
4119 private static String getMmTelProvisioningKey(int subId, int tech) {
4120 // resulting key is provision_ims_mmtel_{subId}_{tech}
4121 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4122 }
4123
4124 /**
4125 * Query CarrierConfig to see if the specified capability requires provisioning for the
4126 * carrier associated with the subscription id.
4127 */
4128 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4129 int capability) {
4130 CarrierConfigManager configManager = new CarrierConfigManager(context);
4131 PersistableBundle c = configManager.getConfigForSubId(subId);
4132 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004133 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004134 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4135 false);
4136 boolean requireVoiceVtProvisioning = c.getBoolean(
4137 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4138
4139 // First check to make sure that the capability requires provisioning.
4140 switch (capability) {
4141 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4142 // intentional fallthrough
4143 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4144 if (requireVoiceVtProvisioning) {
4145 // Voice and Video requires provisioning
4146 return true;
4147 }
4148 break;
4149 }
4150 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4151 if (requireUtProvisioning) {
4152 // UT requires provisioning
4153 return true;
4154 }
4155 break;
4156 }
4157 }
4158 return false;
4159 }
4160
allenwtsu99c623b2020-01-03 18:24:23 +08004161 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4162 int capability) {
4163 CarrierConfigManager configManager = new CarrierConfigManager(context);
4164 PersistableBundle c = configManager.getConfigForSubId(subId);
4165
4166 boolean requireRcsProvisioning = c.getBoolean(
4167 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4168
4169 // First check to make sure that the capability requires provisioning.
4170 switch (capability) {
4171 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4172 // intentional fallthrough
4173 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4174 if (requireRcsProvisioning) {
4175 // OPTION or PRESENCE requires provisioning
4176 return true;
4177 }
4178 break;
4179 }
4180 }
4181 return false;
4182 }
4183
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004184 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004185 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004186 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4187 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4188 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004189 enforceReadPrivilegedPermission("getImsProvisioningInt");
4190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004193 int slotId = getSlotIndex(subId);
4194 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4195 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4196 + subId + "' for key:" + key);
4197 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4198 }
4199 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004200 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004201 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4202 + subId + "' for key:" + key);
4203 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
4207 }
4208
4209 @Override
4210 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004211 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4212 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4213 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004214 enforceReadPrivilegedPermission("getImsProvisioningString");
4215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004218 int slotId = getSlotIndex(subId);
4219 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4220 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4221 + subId + "' for key:" + key);
4222 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4223 }
4224 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004225 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004226 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4227 + subId + "' for key:" + key);
4228 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004229 } finally {
4230 Binder.restoreCallingIdentity(identity);
4231 }
4232 }
4233
4234 @Override
4235 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004236 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4237 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4238 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4240 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004241 final long identity = Binder.clearCallingIdentity();
4242 try {
4243 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004244 int slotId = getSlotIndex(subId);
4245 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4246 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4247 + subId + "' for key:" + key);
4248 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4249 }
4250 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004251 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004252 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4253 + "' for key:" + key);
4254 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
4258 }
4259
4260 @Override
4261 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004262 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4263 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4264 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4266 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004267 final long identity = Binder.clearCallingIdentity();
4268 try {
4269 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004270 int slotId = getSlotIndex(subId);
4271 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4272 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4273 + subId + "' for key:" + key);
4274 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4275 }
4276 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004277 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004278 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4279 + "' for key:" + key);
4280 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
4284 }
4285
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004286 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 int slotId = SubscriptionManager.getSlotIndex(subId);
4288 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004289 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4290 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 }
4292 return slotId;
4293 }
4294
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004295 private int getSlotIndex(int subId) {
4296 int slotId = SubscriptionManager.getSlotIndex(subId);
4297 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4298 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4299 }
4300 return slotId;
4301 }
4302
Wink Saville36469e72014-06-11 15:17:00 -07004303 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004304 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004305 */
4306 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004307 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4308 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004309 final int targetSdk = getTargetSdk(callingPackage);
4310 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004311 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004312 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004313 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004314 mApp, subId, callingPackage, callingFeatureId,
4315 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004316 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4317 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319 final long identity = Binder.clearCallingIdentity();
4320 try {
4321 final Phone phone = getPhone(subId);
4322 if (phone != null) {
4323 return phone.getServiceState().getDataNetworkType();
4324 } else {
4325 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4326 }
4327 } finally {
4328 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004330 }
4331
4332 /**
4333 * Returns the data network type
4334 */
4335 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004336 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4337 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4338 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004339 }
4340
4341 /**
4342 * Returns the data network type for a subId
4343 */
4344 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004345 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4346 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004348 mApp, subId, callingPackage, callingFeatureId,
4349 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004350 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4351 }
4352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 final Phone phone = getPhone(subId);
4356 if (phone != null) {
4357 return phone.getServiceState().getDataNetworkType();
4358 } else {
4359 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4360 }
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004364 }
4365
4366 /**
Wink Saville36469e72014-06-11 15:17:00 -07004367 * Returns the Voice network type for a subId
4368 */
4369 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004370 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4371 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004373 mApp, subId, callingPackage, callingFeatureId,
4374 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004375 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4376 }
4377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378 final long identity = Binder.clearCallingIdentity();
4379 try {
4380 final Phone phone = getPhone(subId);
4381 if (phone != null) {
4382 return phone.getServiceState().getVoiceNetworkType();
4383 } else {
4384 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4385 }
4386 } finally {
4387 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004389 }
4390
4391 /**
4392 * @return true if a ICC card is present
4393 */
4394 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004395 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004396 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4397 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004398 }
4399
4400 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004401 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004402 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004403 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004404 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 final long identity = Binder.clearCallingIdentity();
4406 try {
4407 final Phone phone = PhoneFactory.getPhone(slotIndex);
4408 if (phone != null) {
4409 return phone.getIccCard().hasIccCard();
4410 } else {
4411 return false;
4412 }
4413 } finally {
4414 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004416 }
4417
4418 /**
4419 * Return if the current radio is LTE on CDMA. This
4420 * is a tri-state return value as for a period of time
4421 * the mode may be unknown.
4422 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004423 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004424 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004425 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004426 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004427 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004428 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4429 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4430 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004431 }
4432
Sanket Padawe356d7632015-06-22 14:03:32 -07004433 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004434 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4435 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004436 try {
4437 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4438 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004439 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4440 }
4441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 final long identity = Binder.clearCallingIdentity();
4443 try {
4444 final Phone phone = getPhone(subId);
4445 if (phone == null) {
4446 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4447 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004448 return TelephonyProperties.lte_on_cdma_device()
4449 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 }
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004453 }
Wink Saville36469e72014-06-11 15:17:00 -07004454 }
4455
Wink Saville36469e72014-06-11 15:17:00 -07004456 /**
4457 * {@hide}
4458 * Returns Default subId, 0 in the case of single standby.
4459 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004460 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004461 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004462 }
4463
Shishir Agrawala9f32182016-04-12 12:00:16 -07004464 private int getSlotForDefaultSubscription() {
4465 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4466 }
4467
Wink Savilleb564aae2014-10-23 10:18:09 -07004468 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004469 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004470 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004471
Pengquan Menge92a50d2018-09-21 15:54:48 -07004472 private boolean isActiveSubscription(int subId) {
4473 return mSubscriptionController.isActiveSubId(subId);
4474 }
4475
Ihab Awadf2177b72013-11-25 13:33:23 -08004476 /**
4477 * @see android.telephony.TelephonyManager.WifiCallingChoices
4478 */
4479 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 final long identity = Binder.clearCallingIdentity();
4481 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004482 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4484 getWhenToMakeWifiCallsDefaultPreference());
4485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004488 }
4489
4490 /**
4491 * @see android.telephony.TelephonyManager.WifiCallingChoices
4492 */
4493 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494 final long identity = Binder.clearCallingIdentity();
4495 try {
4496 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004497 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004502 }
4503
Sailesh Nepald1e68152013-12-12 19:08:02 -08004504 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004505 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004506 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004507 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004508
Jordan Liu4c733742019-02-28 12:03:40 -08004509 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4510 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4511 if (phoneId == -1) {
4512 throw new IllegalArgumentException("Given slot index: " + slotIndex
4513 + " does not correspond to an active phone");
4514 }
4515 return PhoneFactory.getPhone(phoneId);
4516 }
4517
Shishir Agrawal566b7612013-10-28 14:41:00 -07004518 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004519 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4520 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4522 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004523 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004524 if (DBG) {
4525 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4526 }
4527 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4528 p2);
4529 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004530
Jordan Liu4c733742019-02-28 12:03:40 -08004531
4532 @Override
4533 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4534 int slotIndex, String callingPackage, String aid, int p2) {
4535 enforceModifyPermission();
4536 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4537 if (DBG) {
4538 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4539 }
4540 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4541 callingPackage, aid, p2);
4542 }
4543
4544 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4545 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004546 final long identity = Binder.clearCallingIdentity();
4547 try {
4548 if (TextUtils.equals(ISDR_AID, aid)) {
4549 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004550 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4551 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004552 if (bestComponent == null
4553 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4554 loge("The calling package is not allowed to access ISD-R.");
4555 throw new SecurityException(
4556 "The calling package is not allowed to access ISD-R.");
4557 }
Derek Tan740e1672017-06-27 14:56:27 -07004558 }
Derek Tan740e1672017-06-27 14:56:27 -07004559
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004561 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4562 null /* workSource */);
4563 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 return response;
4565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004568 }
4569
4570 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004571 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4573 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004574 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4575 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4576 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004577
Jordan Liu4c733742019-02-28 12:03:40 -08004578 @Override
4579 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4580 enforceModifyPermission();
4581 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4582 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4583 channel);
4584 }
4585
4586 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004587 final long identity = Binder.clearCallingIdentity();
4588 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 if (channel < 0) {
4590 return false;
4591 }
Jordan Liu4c733742019-02-28 12:03:40 -08004592 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4593 null /* workSource */);
4594 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 return success;
4596 } finally {
4597 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004598 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004599 }
4600
4601 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004602 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004603 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4605 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004606 if (DBG) {
4607 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4608 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4609 + p3 + " data=" + data);
4610 }
4611 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4612 command, p1, p2, p3, data);
4613 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004614
Jordan Liu4c733742019-02-28 12:03:40 -08004615 @Override
4616 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4617 int command, int p1, int p2, int p3, String data) {
4618 enforceModifyPermission();
4619 if (DBG) {
4620 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4621 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4622 + p3 + " data=" + data);
4623 }
4624 return iccTransmitApduLogicalChannelWithPermission(
4625 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4626 data);
4627 }
4628
4629 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4630 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 final long identity = Binder.clearCallingIdentity();
4632 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004633 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004634 return "";
4635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004638 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4639 null /* workSource */);
4640 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642 // Append the returned status code to the end of the response payload.
4643 String s = Integer.toHexString(
4644 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4645 if (response.payload != null) {
4646 s = IccUtils.bytesToHexString(response.payload) + s;
4647 }
4648 return s;
4649 } finally {
4650 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004651 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004652 }
Jake Hambye994d462014-02-03 13:10:13 -08004653
Evan Charltonc66da362014-05-16 14:06:40 -07004654 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004655 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4656 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4658 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004660 if (DBG) {
4661 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4662 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4663 }
4664 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4665 cla, command, p1, p2, p3, data);
4666 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004667
Jordan Liu4c733742019-02-28 12:03:40 -08004668 @Override
4669 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4670 int command, int p1, int p2, int p3, String data) {
4671 enforceModifyPermission();
4672 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4673 if (DBG) {
4674 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4675 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4676 + " data=" + data);
4677 }
4678
4679 return iccTransmitApduBasicChannelWithPermission(
4680 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4681 p2, p3, data);
4682 }
4683
4684 // open APDU basic channel assuming the caller has sufficient permissions
4685 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4686 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687 final long identity = Binder.clearCallingIdentity();
4688 try {
4689 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4690 && TextUtils.equals(ISDR_AID, data)) {
4691 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004692 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4693 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004694 if (bestComponent == null
4695 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4696 loge("The calling package is not allowed to select ISD-R.");
4697 throw new SecurityException(
4698 "The calling package is not allowed to select ISD-R.");
4699 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004700 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004703 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4704 null /* workSource */);
4705 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707 // Append the returned status code to the end of the response payload.
4708 String s = Integer.toHexString(
4709 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4710 if (response.payload != null) {
4711 s = IccUtils.bytesToHexString(response.payload) + s;
4712 }
4713 return s;
4714 } finally {
4715 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004716 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004717 }
4718
4719 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004720 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004721 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4723 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004725 final long identity = Binder.clearCallingIdentity();
4726 try {
4727 if (DBG) {
4728 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4729 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4730 }
4731
4732 IccIoResult response =
4733 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4734 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4735 subId);
4736
4737 if (DBG) {
4738 log("Exchange SIM_IO [R]" + response);
4739 }
4740
4741 byte[] result = null;
4742 int length = 2;
4743 if (response.payload != null) {
4744 length = 2 + response.payload.length;
4745 result = new byte[length];
4746 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4747 } else {
4748 result = new byte[length];
4749 }
4750
4751 result[length - 1] = (byte) response.sw2;
4752 result[length - 2] = (byte) response.sw1;
4753 return result;
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004756 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004757 }
4758
Nathan Haroldb3014052017-01-25 15:57:32 -08004759 /**
4760 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4761 * on a particular subscription
4762 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004763 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4764 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004766 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004767 return null;
4768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769
4770 final long identity = Binder.clearCallingIdentity();
4771 try {
4772 if (appType != TelephonyManager.APPTYPE_USIM
4773 && appType != TelephonyManager.APPTYPE_SIM) {
4774 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4775 return null;
4776 }
4777 Object response = sendRequest(
4778 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4779 if (response instanceof String[]) {
4780 return (String[]) response;
4781 }
yincheng zhaod698b842019-09-06 17:06:54 -07004782 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004784 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785 } finally {
4786 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004787 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004788 }
4789
yincheng zhaod698b842019-09-06 17:06:54 -07004790 /**
4791 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4792 * subscription.
4793 *
4794 * @param subId the id of the subscription.
4795 * @param appType the uicc app type, must be USIM or SIM.
4796 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4797 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004798 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004799 * @return number of fplmns that is successfully written to the SIM.
4800 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004801 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4802 String callingFeatureId) {
4803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4804 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004805 if (DBG) logv("no permissions for setForbiddenplmns");
4806 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4807 }
4808 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4809 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4810 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4811 }
4812 if (fplmns == null) {
4813 throw new IllegalArgumentException("Fplmn List provided is null");
4814 }
4815 for (String fplmn : fplmns) {
4816 if (!CellIdentity.isValidPlmn(fplmn)) {
4817 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4818 }
4819 }
4820 final long identity = Binder.clearCallingIdentity();
4821 try {
4822 Object response = sendRequest(
4823 CMD_SET_FORBIDDEN_PLMNS,
4824 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4825 subId);
4826 return (int) response;
4827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
4830 }
4831
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004832 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004833 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4835 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004836
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837 final long identity = Binder.clearCallingIdentity();
4838 try {
4839 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4840 if (response.payload == null) {
4841 return "";
4842 }
Evan Charltonc66da362014-05-16 14:06:40 -07004843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004844 // Append the returned status code to the end of the response payload.
4845 String s = Integer.toHexString(
4846 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4847 s = IccUtils.bytesToHexString(response.payload) + s;
4848 return s;
4849 } finally {
4850 Binder.restoreCallingIdentity(identity);
4851 }
Evan Charltonc66da362014-05-16 14:06:40 -07004852 }
4853
Jake Hambye994d462014-02-03 13:10:13 -08004854 /**
4855 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4856 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4857 *
4858 * @param itemID the ID of the item to read
4859 * @return the NV item as a String, or null on error.
4860 */
4861 @Override
4862 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004863 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4865 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866
4867 final long identity = Binder.clearCallingIdentity();
4868 try {
4869 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004870 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4872 return value;
4873 } finally {
4874 Binder.restoreCallingIdentity(identity);
4875 }
Jake Hambye994d462014-02-03 13:10:13 -08004876 }
4877
4878 /**
4879 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4880 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4881 *
4882 * @param itemID the ID of the item to read
4883 * @param itemValue the value to write, as a String
4884 * @return true on success; false on any failure
4885 */
4886 @Override
4887 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4890 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891
4892 final long identity = Binder.clearCallingIdentity();
4893 try {
4894 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4895 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004896 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4898 return success;
4899 } finally {
4900 Binder.restoreCallingIdentity(identity);
4901 }
Jake Hambye994d462014-02-03 13:10:13 -08004902 }
4903
4904 /**
4905 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4906 * Used for device configuration by some CDMA operators.
4907 *
4908 * @param preferredRoamingList byte array containing the new PRL
4909 * @return true on success; false on any failure
4910 */
4911 @Override
4912 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4914 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004915
4916 final long identity = Binder.clearCallingIdentity();
4917 try {
4918 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4919 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4920 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4921 return success;
4922 } finally {
4923 Binder.restoreCallingIdentity(identity);
4924 }
Jake Hambye994d462014-02-03 13:10:13 -08004925 }
4926
4927 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004928 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004929 * Used for device configuration by some CDMA operators.
4930 *
chen xu6dac5ab2018-10-26 17:39:23 -07004931 * @param slotIndex - device slot.
4932 *
Jake Hambye994d462014-02-03 13:10:13 -08004933 * @return true on success; false on any failure
4934 */
4935 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004936 public boolean resetModemConfig(int slotIndex) {
4937 Phone phone = PhoneFactory.getPhone(slotIndex);
4938 if (phone != null) {
4939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4940 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004941
chen xu6dac5ab2018-10-26 17:39:23 -07004942 final long identity = Binder.clearCallingIdentity();
4943 try {
4944 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4945 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4946 return success;
4947 } finally {
4948 Binder.restoreCallingIdentity(identity);
4949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 }
chen xu6dac5ab2018-10-26 17:39:23 -07004951 return false;
4952 }
4953
4954 /**
4955 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4956 *
4957 * @param slotIndex - device slot.
4958 *
4959 * @return true on success; false on any failure
4960 */
4961 @Override
4962 public boolean rebootModem(int slotIndex) {
4963 Phone phone = PhoneFactory.getPhone(slotIndex);
4964 if (phone != null) {
4965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4966 mApp, phone.getSubId(), "rebootModem");
4967
4968 final long identity = Binder.clearCallingIdentity();
4969 try {
4970 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4971 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4972 return success;
4973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
4976 }
4977 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004978 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004979
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004980 public String[] getPcscfAddress(String apnType, String callingPackage,
4981 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004982 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4984 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004985 return new String[0];
4986 }
4987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 final long identity = Binder.clearCallingIdentity();
4989 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004990 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
Wink Saville36469e72014-06-11 15:17:00 -07004994 }
4995
Brad Ebinger51f743a2017-01-23 13:50:20 -08004996 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004997 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4998 * {@link #disableIms(int)}.
4999 * @param slotIndex device slot.
5000 */
5001 public void resetIms(int slotIndex) {
5002 enforceModifyPermission();
5003
5004 final long identity = Binder.clearCallingIdentity();
5005 try {
5006 if (mImsResolver == null) {
5007 // may happen if the does not support IMS.
5008 return;
5009 }
5010 mImsResolver.disableIms(slotIndex);
5011 mImsResolver.enableIms(slotIndex);
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
5015 }
5016
5017 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005018 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5019 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005020 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005021 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005022 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023
5024 final long identity = Binder.clearCallingIdentity();
5025 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005026 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005027 // may happen if the device does not support IMS.
5028 return;
5029 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005030 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 } finally {
5032 Binder.restoreCallingIdentity(identity);
5033 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005034 }
5035
5036 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005037 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5038 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005039 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005040 public void disableIms(int slotId) {
5041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042
5043 final long identity = Binder.clearCallingIdentity();
5044 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005045 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005046 // may happen if the device does not support IMS.
5047 return;
5048 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005049 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 } finally {
5051 Binder.restoreCallingIdentity(identity);
5052 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005053 }
5054
5055 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005056 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5057 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005058 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005059 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005060 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005061 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062
5063 final long identity = Binder.clearCallingIdentity();
5064 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005065 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005066 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5067 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005068 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005069 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070 } finally {
5071 Binder.restoreCallingIdentity(identity);
5072 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005073 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005074 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005075 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5076 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005077 @Override
5078 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005079 enforceModifyPermission();
5080
5081 final long identity = Binder.clearCallingIdentity();
5082 try {
5083 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005084 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005085 } finally {
5086 Binder.restoreCallingIdentity(identity);
5087 }
5088 }
5089
5090 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005091 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005092 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005093 */
5094 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5095 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096
5097 final long identity = Binder.clearCallingIdentity();
5098 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005099 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005100 // may happen if the device does not support IMS.
5101 return null;
5102 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005103 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005107 }
5108
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005109 /**
5110 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005111 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005112 */
5113 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5114 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115
5116 final long identity = Binder.clearCallingIdentity();
5117 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005118 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005119 // may happen if the device does not support IMS.
5120 return null;
5121 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005122 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 } finally {
5124 Binder.restoreCallingIdentity(identity);
5125 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005126 }
5127
Brad Ebinger884c07b2018-02-15 16:17:40 -08005128 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005129 * Sets the ImsService Package Name that Telephony will bind to.
5130 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005131 * @param slotIndex the slot ID that the ImsService should bind for.
5132 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005133 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005134 * @param featureTypes An integer array of feature types associated with a packageName.
5135 * @param packageName The name of the package that the current configuration will be replaced
5136 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005137 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005138 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005139 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5140 int[] featureTypes, String packageName) {
5141 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5142 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5144 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005145 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 final long identity = Binder.clearCallingIdentity();
5148 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005149 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005150 // may happen if the device does not support IMS.
5151 return false;
5152 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005153 Map<Integer, String> featureConfig = new HashMap<>();
5154 for (int featureType : featureTypes) {
5155 featureConfig.put(featureType, packageName);
5156 }
5157 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5158 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005162 }
5163
5164 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005165 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005166 *
5167 * @param slotId The slot that the ImsService is associated with.
5168 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5169 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005170 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005171 * @return the package name of the ImsService configuration.
5172 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005173 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5174 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005175 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005176 TelephonyPermissions
5177 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5178 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5179 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 final long identity = Binder.clearCallingIdentity();
5182 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005183 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005184 // may happen if the device does not support IMS.
5185 return "";
5186 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005187 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005188 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5189 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 } finally {
5191 Binder.restoreCallingIdentity(identity);
5192 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005193 }
5194
Brad Ebinger77b832e2019-10-17 17:03:22 -07005195 /**
5196 * Get the MmTelFeature state associated with the requested subscription id.
5197 * @param subId The subscription that the MmTelFeature is associated with.
5198 * @param callback A callback with an integer containing the
5199 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5200 */
5201 @Override
5202 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5203 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5204 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5205 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5206 "IMS not available on device.");
5207 }
5208 final long token = Binder.clearCallingIdentity();
5209 try {
5210 int slotId = getSlotIndex(subId);
5211 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5212 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5213 + subId + "'");
5214 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5215 }
5216 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5217 try {
5218 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5219 } catch (RemoteException e) {
5220 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5221 + "Ignore");
5222 }
5223 });
5224 } finally {
5225 Binder.restoreCallingIdentity(token);
5226 }
5227 }
5228
Wink Saville36469e72014-06-11 15:17:00 -07005229 public void setImsRegistrationState(boolean registered) {
5230 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231
5232 final long identity = Binder.clearCallingIdentity();
5233 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005234 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
Wink Saville36469e72014-06-11 15:17:00 -07005238 }
5239
5240 /**
Stuart Scott54788802015-03-30 13:18:01 -07005241 * Set the network selection mode to automatic.
5242 *
5243 */
5244 @Override
5245 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5247 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248
5249 final long identity = Binder.clearCallingIdentity();
5250 try {
shilufc958392020-01-20 11:36:01 -08005251 if (!isActiveSubscription(subId)) {
5252 return;
5253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5255 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5256 } finally {
5257 Binder.restoreCallingIdentity(identity);
5258 }
Stuart Scott54788802015-03-30 13:18:01 -07005259 }
5260
Jack Yud10cdd42020-09-28 20:28:01 -07005261 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005262 * Ask the radio to connect to the input network and change selection mode to manual.
5263 *
5264 * @param subId the id of the subscription.
5265 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5266 * the operator to attach to.
5267 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5268 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5269 * normal network selection next time.
5270 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005271 */
5272 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005273 public boolean setNetworkSelectionModeManual(
5274 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5276 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005277
5278 if (!isActiveSubscription(subId)) {
5279 return false;
5280 }
5281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 final long identity = Binder.clearCallingIdentity();
5283 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005284 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005286 if (DBG) {
5287 log("setNetworkSelectionModeManual: subId: " + subId
5288 + " operator: " + operatorInfo);
5289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005294 }
shilu84f6e8b2019-12-19 13:58:01 -08005295 /**
5296 * Get the manual network selection
5297 *
5298 * @param subId the id of the subscription.
5299 *
5300 * @return the previously saved user selected PLMN
5301 */
5302 @Override
5303 public String getManualNetworkSelectionPlmn(int subId) {
5304 TelephonyPermissions
5305 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5306 mApp, subId, "getManualNetworkSelectionPlmn");
5307
5308 final long identity = Binder.clearCallingIdentity();
5309 try {
5310 if (!isActiveSubscription(subId)) {
5311 return "";
5312 }
5313
5314 final Phone phone = getPhone(subId);
5315 if (phone == null) {
5316 return "";
5317 }
5318 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5319 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5320 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
5324 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005325
5326 /**
5327 * Scans for available networks.
5328 */
5329 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005330 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5331 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5333 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005334 LocationAccessPolicy.LocationPermissionResult locationResult =
5335 LocationAccessPolicy.checkLocationPermission(mApp,
5336 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5337 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005338 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005339 .setCallingPid(Binder.getCallingPid())
5340 .setCallingUid(Binder.getCallingUid())
5341 .setMethod("getCellNetworkScanResults")
5342 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5343 .build());
5344 switch (locationResult) {
5345 case DENIED_HARD:
5346 throw new SecurityException("Not allowed to access scan results -- location");
5347 case DENIED_SOFT:
5348 return null;
5349 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350
Pengquan Menga1bb6272018-09-06 09:59:22 -07005351 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 try {
5353 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005354 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 } finally {
5357 Binder.restoreCallingIdentity(identity);
5358 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005359 }
5360
5361 /**
sqian80370722020-01-29 15:02:51 -08005362 * Get the call forwarding info, given the call forwarding reason.
5363 */
5364 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005365 public void getCallForwarding(int subId, int callForwardingReason,
5366 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005367 enforceReadPrivilegedPermission("getCallForwarding");
5368 long identity = Binder.clearCallingIdentity();
5369 try {
5370 if (DBG) {
5371 log("getCallForwarding: subId " + subId
5372 + " callForwardingReason" + callForwardingReason);
5373 }
Hall Liua1acea22020-09-18 19:04:59 -07005374
5375 Phone phone = getPhone(subId);
5376 if (phone == null) {
5377 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005378 callback.onError(
5379 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005380 } catch (RemoteException e) {
5381 // ignore
5382 }
5383 return;
5384 }
5385
5386 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5387 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5388 @Override
5389 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5390 try {
5391 callback.onCallForwardingInfoAvailable(info);
5392 } catch (RemoteException e) {
5393 // ignore
5394 }
5395 }
5396
5397 @Override
5398 public void onError(int error) {
5399 try {
5400 callback.onError(error);
5401 } catch (RemoteException e) {
5402 // ignore
5403 }
5404 }
5405 });
5406 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005407 } finally {
5408 Binder.restoreCallingIdentity(identity);
5409 }
5410 }
5411
5412 /**
5413 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5414 * reason, the number to forward, and the timeout before the forwarding is attempted.
5415 */
5416 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005417 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5418 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005419 enforceModifyPermission();
5420 long identity = Binder.clearCallingIdentity();
5421 try {
5422 if (DBG) {
5423 log("setCallForwarding: subId " + subId
5424 + " callForwardingInfo" + callForwardingInfo);
5425 }
Hall Liua1acea22020-09-18 19:04:59 -07005426
5427 Phone phone = getPhone(subId);
5428 if (phone == null) {
5429 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005430 callback.accept(
5431 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005432 } catch (RemoteException e) {
5433 // ignore
5434 }
5435 return;
5436 }
5437
5438 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5439 FunctionalUtils.ignoreRemoteException(callback::accept));
5440
5441 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005442 } finally {
5443 Binder.restoreCallingIdentity(identity);
5444 }
5445 }
5446
5447 /**
Hall Liua1acea22020-09-18 19:04:59 -07005448 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005449 */
5450 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005451 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005452 enforceReadPrivilegedPermission("getCallForwarding");
5453 long identity = Binder.clearCallingIdentity();
5454 try {
Hall Liua1acea22020-09-18 19:04:59 -07005455
5456 Phone phone = getPhone(subId);
5457 if (phone == null) {
5458 try {
5459 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5460 } catch (RemoteException e) {
5461 // ignore
5462 }
5463 return;
5464 }
5465
5466 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5467
sqian80370722020-01-29 15:02:51 -08005468 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005469 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005470 } finally {
5471 Binder.restoreCallingIdentity(identity);
5472 }
5473 }
5474
5475 /**
Hall Liua1acea22020-09-18 19:04:59 -07005476 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005477 */
5478 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005479 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005480 enforceModifyPermission();
5481 long identity = Binder.clearCallingIdentity();
5482 try {
Hall Liua1acea22020-09-18 19:04:59 -07005483 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5484
5485 Phone phone = getPhone(subId);
5486 if (phone == null) {
5487 try {
5488 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5489 } catch (RemoteException e) {
5490 // ignore
5491 }
5492 return;
5493 }
5494
5495 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5496 FunctionalUtils.ignoreRemoteException(callback::accept));
5497
5498 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501 }
5502 }
5503
5504 /**
yinxub1bed742017-04-17 11:45:04 -07005505 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005506 *
yinxub1bed742017-04-17 11:45:04 -07005507 * @param subId id of the subscription
5508 * @param request contains the radio access networks with bands/channels to scan
5509 * @param messenger callback messenger for scan results or errors
5510 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005511 * @return the id of the requested scan which can be used to stop the scan.
5512 */
5513 @Override
5514 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005515 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5517 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005518 LocationAccessPolicy.LocationPermissionResult locationResult =
5519 LocationAccessPolicy.checkLocationPermission(mApp,
5520 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5521 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005522 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005523 .setCallingPid(Binder.getCallingPid())
5524 .setCallingUid(Binder.getCallingUid())
5525 .setMethod("requestNetworkScan")
5526 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5527 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005528 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005529 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5530 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005531 if (e != null) {
5532 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5533 throw e;
5534 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005535 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005536 return TelephonyScanManager.INVALID_SCAN_ID;
5537 }
5538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 }
Hall Liu912dfd32019-04-25 14:02:26 -07005540 int callingUid = Binder.getCallingUid();
5541 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 return mNetworkScanRequestTracker.startNetworkScan(
5545 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005546 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005547 } finally {
5548 Binder.restoreCallingIdentity(identity);
5549 }
yinxu504e1392017-04-12 16:03:22 -07005550 }
5551
Hall Liub2ac8ef2019-02-28 15:56:23 -08005552 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005553 NetworkScanRequest request, int subId, String callingPackage) {
5554 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005555 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5556 boolean hasNetworkScanPermission =
5557 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5558 == PERMISSION_GRANTED;
5559
5560 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5561 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5562 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005563 }
5564
5565 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5566 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005567 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5568 return new SecurityException("Specific channels must not be"
5569 + " scanned without location access.");
5570 }
5571 }
5572 }
5573
Hall Liub2ac8ef2019-02-28 15:56:23 -08005574 return null;
5575 }
5576
yinxu504e1392017-04-12 16:03:22 -07005577 /**
5578 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005579 *
5580 * @param subId id of the subscription
5581 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005582 */
5583 @Override
5584 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5586 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587
Hall Liu912dfd32019-04-25 14:02:26 -07005588 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 final long identity = Binder.clearCallingIdentity();
5590 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005591 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 } finally {
5593 Binder.restoreCallingIdentity(identity);
5594 }
yinxu504e1392017-04-12 16:03:22 -07005595 }
5596
5597 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005598 * Get the calculated preferred network type.
5599 * Used for debugging incorrect network type.
5600 *
5601 * @return the preferred network type, defined in RILConstants.java.
5602 */
5603 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005604 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005605 final Phone defaultPhone = getDefaultPhone();
5606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005607 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005608 return RILConstants.PREFERRED_NETWORK_MODE;
5609 }
5610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 final long identity = Binder.clearCallingIdentity();
5612 try {
5613 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005614 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 } finally {
5616 Binder.restoreCallingIdentity(identity);
5617 }
Junda Liu84d15a22014-07-02 11:21:04 -07005618 }
5619
5620 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005621 * Get the preferred network type.
5622 * Used for device configuration by some CDMA operators.
5623 *
5624 * @return the preferred network type, defined in RILConstants.java.
5625 */
5626 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005627 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005628 TelephonyPermissions
5629 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5630 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005631
5632 final long identity = Binder.clearCallingIdentity();
5633 try {
5634 if (DBG) log("getPreferredNetworkType");
5635 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5636 int networkType = (result != null ? result[0] : -1);
5637 if (DBG) log("getPreferredNetworkType: " + networkType);
5638 return networkType;
5639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005642 }
5643
5644 /**
5645 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005646 *
5647 * @param networkType the preferred network type, defined in RILConstants.java.
5648 * @return true on success; false on any failure.
5649 */
5650 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005651 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5653 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654
5655 final long identity = Binder.clearCallingIdentity();
5656 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005657 Settings.Global.putInt(mApp.getContentResolver(),
5658 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005659
5660 Boolean success = (Boolean) sendRequest(
5661 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5662 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5663 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 } finally {
5665 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005666 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005667 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005668
5669 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005670 * Get the allowed network types that store in the telephony provider.
5671 *
5672 * @param subId the id of the subscription.
5673 * @return allowedNetworkTypes the allowed network types.
5674 */
5675 @Override
5676 public long getAllowedNetworkTypes(int subId) {
5677 TelephonyPermissions
5678 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5679 mApp, subId, "getAllowedNetworkTypes");
5680
5681 final long identity = Binder.clearCallingIdentity();
5682 try {
5683 return SubscriptionManager.getLongSubscriptionProperty(
5684 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
5688 }
5689
5690 /**
5691 * Set the allowed network types.
5692 *
5693 * @param subId the id of the subscription.
5694 * @param allowedNetworkTypes the allowed network types.
5695 * @return true on success; false on any failure.
5696 */
5697 @Override
5698 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5700 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005701
calvinpan089c2a62020-03-12 14:17:55 +08005702 SubscriptionManager.setSubscriptionProperty(subId,
5703 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5704 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005705
calvinpan089c2a62020-03-12 14:17:55 +08005706 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5707 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5708 RILConstants.PREFERRED_NETWORK_MODE);
5709 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005710 }
5711
5712 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005713 * Get the allowed network types for certain reason.
5714 *
5715 * @param subId the id of the subscription.
5716 * @param reason the reason the allowed network type change is taking place
5717 * @return the allowed network types.
5718 */
5719 @Override
5720 public long getAllowedNetworkTypesForReason(int subId,
5721 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5722 TelephonyPermissions
5723 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5724 mApp, subId, "getAllowedNetworkTypesForReason");
5725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5728 } finally {
5729 Binder.restoreCallingIdentity(identity);
5730 }
5731 }
5732
5733 /**
5734 * Get the effective allowed network types on the device.
5735 * This API will return an intersection of allowed network types for all reasons,
5736 * including the configuration done through setAllowedNetworkTypes
5737 *
5738 * @param subId the id of the subscription.
5739 * @return the allowed network types
5740 */
5741 @Override
5742 public long getEffectiveAllowedNetworkTypes(int subId) {
5743 TelephonyPermissions
5744 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5745 mApp, subId, "getEffectiveAllowedNetworkTypes");
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
5748 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
5752 }
5753
5754 /**
5755 * Set the allowed network types of the device and
5756 * provide the reason triggering the allowed network change.
5757 *
5758 * @param subId the id of the subscription.
5759 * @param reason the reason the allowed network type change is taking place
5760 * @param allowedNetworkTypes the allowed network types.
5761 * @return true on success; false on any failure.
5762 */
5763 @Override
5764 public boolean setAllowedNetworkTypesForReason(int subId,
5765 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5767 mApp, subId, "setAllowedNetworkTypesForReason");
5768 final long identity = Binder.clearCallingIdentity();
5769 try {
5770 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5771 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5772 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5773 RILConstants.PREFERRED_NETWORK_MODE);
5774 return setPreferredNetworkType(subId, preferredNetworkMode);
5775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
5778 }
5779
5780 /**
Miaoa84611c2019-03-15 09:21:10 +08005781 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005782 *
Miaoa84611c2019-03-15 09:21:10 +08005783 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005784 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005785 * @hide
5786 */
5787 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005788 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005789 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005791 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 try {
Miaoa84611c2019-03-15 09:21:10 +08005793 if (phone != null) {
5794 return phone.hasMatchedTetherApnSetting();
5795 } else {
5796 return false;
5797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 } finally {
5799 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005800 }
Junda Liu475951f2014-11-07 16:45:03 -08005801 }
5802
5803 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005804 * Set mobile data enabled
5805 * Used by the user through settings etc to turn on/off mobile data
5806 *
5807 * @param enable {@code true} turn turn data on, else {@code false}
5808 */
5809 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005810 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5812 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813
5814 final long identity = Binder.clearCallingIdentity();
5815 try {
5816 int phoneId = mSubscriptionController.getPhoneId(subId);
5817 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5818 Phone phone = PhoneFactory.getPhone(phoneId);
5819 if (phone != null) {
5820 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005821 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005823 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824 }
5825 } finally {
5826 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005827 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005828 }
5829
5830 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005831 * Enable or disable always reporting signal strength changes from radio.
5832 *
5833 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5834 */
5835 @Override
5836 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5837 enforceModifyPermission();
5838 enforceSystemCaller();
5839
5840 final long identity = Binder.clearCallingIdentity();
5841 final Phone phone = getPhone(subId);
5842 try {
5843 if (phone != null) {
5844 if (DBG) {
5845 log("setAlwaysReportSignalStrength: subId=" + subId
5846 + " isEnable=" + isEnable);
5847 }
5848 phone.setAlwaysReportSignalStrength(isEnable);
5849 } else {
5850 loge("setAlwaysReportSignalStrength: no phone found for subId="
5851 + subId);
5852 }
5853 } finally {
5854 Binder.restoreCallingIdentity(identity);
5855 }
5856 }
5857
5858 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005859 * Get the user enabled state of Mobile Data.
5860 *
5861 * TODO: remove and use isUserDataEnabled.
5862 * This can't be removed now because some vendor codes
5863 * calls through ITelephony directly while they should
5864 * use TelephonyManager.
5865 *
5866 * @return true on enabled
5867 */
5868 @Override
5869 public boolean getDataEnabled(int subId) {
5870 return isUserDataEnabled(subId);
5871 }
5872
5873 /**
5874 * Get whether mobile data is enabled per user setting.
5875 *
5876 * There are other factors deciding whether mobile data is actually enabled, but they are
5877 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005878 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005879 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005880 *
5881 * @return {@code true} if data is enabled else {@code false}
5882 */
5883 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005884 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005885 try {
5886 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5887 null);
5888 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5890 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005891 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892
5893 final long identity = Binder.clearCallingIdentity();
5894 try {
5895 int phoneId = mSubscriptionController.getPhoneId(subId);
5896 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5897 Phone phone = PhoneFactory.getPhone(phoneId);
5898 if (phone != null) {
5899 boolean retVal = phone.isUserDataEnabled();
5900 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5901 return retVal;
5902 } else {
5903 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5904 return false;
5905 }
5906 } finally {
5907 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005908 }
5909 }
5910
5911 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005912 * Checks if the device is capable of mobile data by considering whether whether the
5913 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5914 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005915 *
Shuo Qian985d1232020-01-08 14:30:06 -08005916 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005917 */
5918 @Override
5919 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005920 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921
5922 final long identity = Binder.clearCallingIdentity();
5923 try {
5924 int phoneId = mSubscriptionController.getPhoneId(subId);
5925 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5926 Phone phone = PhoneFactory.getPhone(phoneId);
5927 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005928 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5930 return retVal;
5931 } else {
5932 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5933 return false;
5934 }
5935 } finally {
5936 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005937 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005938 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005939
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005940 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005941 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07005942 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5943 // Skip the check if it's one of these special uids
5944 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5945 }
5946
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005947 //load access rules from carrier configs, and check those as well: b/139133814
5948 SubscriptionController subController = SubscriptionController.getInstance();
5949 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5950 || subController == null) return privilegeFromSim;
5951
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005952 PackageManager pkgMgr = phone.getContext().getPackageManager();
5953 String[] packages = pkgMgr.getPackagesForUid(uid);
5954
5955 final long identity = Binder.clearCallingIdentity();
5956 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07005957 int subId = phone.getSubId();
5958 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5959 // A test override is in place for the privileges for this subId, so don't try to
5960 // read the subscription privileges.
5961 return privilegeFromSim;
5962 }
5963 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005964 SubscriptionManager subManager = (SubscriptionManager)
5965 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5966 for (String pkg : packages) {
5967 if (subManager.canManageSubscription(subInfo, pkg)) {
5968 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5969 }
5970 }
5971 return privilegeFromSim;
5972 } finally {
5973 Binder.restoreCallingIdentity(identity);
5974 }
5975 }
5976
5977 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5978 String pkgName) {
5979 //load access rules from carrier configs, and check those as well: b/139133814
5980 SubscriptionController subController = SubscriptionController.getInstance();
5981 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5982 || subController == null) return privilegeFromSim;
5983
5984 final long identity = Binder.clearCallingIdentity();
5985 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07005986 int subId = phone.getSubId();
5987 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5988 // A test override is in place for the privileges for this subId, so don't try to
5989 // read the subscription privileges.
5990 return privilegeFromSim;
5991 }
5992 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005993 SubscriptionManager subManager = (SubscriptionManager)
5994 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5995 return subManager.canManageSubscription(subInfo, pkgName)
5996 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
6000 }
6001
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006002 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006003 public int getCarrierPrivilegeStatus(int subId) {
6004 final Phone phone = getPhone(subId);
6005 if (phone == null) {
6006 loge("getCarrierPrivilegeStatus: Invalid subId");
6007 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6008 }
6009 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006010 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006011 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006012 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6013 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006014
6015 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6016 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006017 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006018 }
Junda Liu29340342014-07-10 15:23:27 -07006019
6020 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006021 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006022 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006023 final Phone phone = getPhone(subId);
6024 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006025 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006026 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6027 }
6028 UiccProfile profile =
6029 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6030 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006031 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006032 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6033 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006034 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006035 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006036 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006037 }
6038
6039 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006040 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6041 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006042 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006043 }
6044
6045 int phoneId = SubscriptionManager.getPhoneId(subId);
6046 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006047 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006048 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006049 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6050 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006051 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6052 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6053 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006054 }
6055
6056 @Override
6057 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006058 if (TextUtils.isEmpty(pkgName))
6059 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006060 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6061 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6062 UiccCard card = UiccController.getInstance().getUiccCard(i);
6063 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006064 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006065 continue;
6066 }
6067
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006068 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6069 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6070 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006071 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6072 break;
6073 }
6074 }
6075
6076 return result;
Junda Liu29340342014-07-10 15:23:27 -07006077 }
Derek Tan89e89d42014-07-08 17:00:10 -07006078
6079 @Override
Junda Liue64de782015-04-16 17:19:16 -07006080 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6081 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6082 loge("phoneId " + phoneId + " is not valid.");
6083 return null;
6084 }
6085 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006086 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006087 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006088 return null ;
6089 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006090 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006091 }
6092
Amith Yamasani6e118872016-02-19 12:53:51 -08006093 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006094 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006095 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006096 List<String> privilegedPackages = new ArrayList<>();
6097 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006098 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6099 // has UICC in that slot.
6100 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006101 if (card.hasCarrierPrivilegeRules()) {
6102 if (packages == null) {
6103 // Only check packages in user 0 for now
6104 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006105 PackageManager.MATCH_DISABLED_COMPONENTS
6106 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006107 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006108 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006109 }
6110 for (int p = packages.size() - 1; p >= 0; p--) {
6111 PackageInfo pkgInfo = packages.get(p);
6112 if (pkgInfo != null && pkgInfo.packageName != null
6113 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006114 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006115 privilegedPackages.add(pkgInfo.packageName);
6116 }
6117 }
6118 }
6119 }
6120 return privilegedPackages;
6121 }
6122
chen xuf7e9fe82019-05-09 19:31:02 -07006123 @Override
6124 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006125 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6126
6127 final long identity = Binder.clearCallingIdentity();
6128
chen xuf7e9fe82019-05-09 19:31:02 -07006129 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006130 try {
6131 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6132 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6133 }
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006136 }
6137 return privilegedPackages;
6138 }
6139
Wink Savilleb564aae2014-10-23 10:18:09 -07006140 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006141 final Phone phone = getPhone(subId);
6142 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006143 if (card == null) {
6144 loge("getIccId: No UICC");
6145 return null;
6146 }
6147 String iccId = card.getIccId();
6148 if (TextUtils.isEmpty(iccId)) {
6149 loge("getIccId: ICC ID is null or empty.");
6150 return null;
6151 }
6152 return iccId;
6153 }
6154
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006155 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006156 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6157 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006158 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006159 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 final long identity = Binder.clearCallingIdentity();
6162 try {
6163 final String iccId = getIccId(subId);
6164 final Phone phone = getPhone(subId);
6165 if (phone == null) {
6166 return false;
6167 }
6168 final String subscriberId = phone.getSubscriberId();
6169
6170 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006171 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 + subscriberId + " to " + number);
6173 }
6174
6175 if (TextUtils.isEmpty(iccId)) {
6176 return false;
6177 }
6178
6179 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6180
6181 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6182 if (alphaTag == null) {
6183 editor.remove(alphaTagPrefKey);
6184 } else {
6185 editor.putString(alphaTagPrefKey, alphaTag);
6186 }
6187
6188 // Record both the line number and IMSI for this ICCID, since we need to
6189 // track all merged IMSIs based on line number
6190 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6191 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6192 if (number == null) {
6193 editor.remove(numberPrefKey);
6194 editor.remove(subscriberPrefKey);
6195 } else {
6196 editor.putString(numberPrefKey, number);
6197 editor.putString(subscriberPrefKey, subscriberId);
6198 }
6199
6200 editor.commit();
6201 return true;
6202 } finally {
6203 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006204 }
Derek Tan7226c842014-07-02 17:42:23 -07006205 }
6206
6207 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006208 public String getLine1NumberForDisplay(int subId, String callingPackage,
6209 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006210 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006211 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006212 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006213 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006214 return null;
6215 }
Derek Tan97ebb422014-09-05 16:55:38 -07006216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006217 final long identity = Binder.clearCallingIdentity();
6218 try {
6219 String iccId = getIccId(subId);
6220 if (iccId != null) {
6221 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6222 if (DBG_MERGE) {
6223 log("getLine1NumberForDisplay returning "
6224 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6225 }
6226 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006227 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6229 return null;
6230 } finally {
6231 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006232 }
Derek Tan7226c842014-07-02 17:42:23 -07006233 }
6234
6235 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006236 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6237 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006239 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006240 return null;
6241 }
Derek Tan97ebb422014-09-05 16:55:38 -07006242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 final long identity = Binder.clearCallingIdentity();
6244 try {
6245 String iccId = getIccId(subId);
6246 if (iccId != null) {
6247 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6248 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6249 }
6250 return null;
6251 } finally {
6252 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006253 }
Derek Tan7226c842014-07-02 17:42:23 -07006254 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006255
6256 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006257 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6258 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006259 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6260 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006262 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006263 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006264 return null;
6265 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006266
Jordan Liub49b04b2019-05-06 14:45:15 -07006267 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6268 // the process, where TelephonyManager was instantiated.
6269 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006270 final long identity = Binder.clearCallingIdentity();
6271 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006272 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273 final TelephonyManager tele = TelephonyManager.from(context);
6274 final SubscriptionManager sub = SubscriptionManager.from(context);
6275
6276 // Figure out what subscribers are currently active
6277 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278
Jordan Liub49b04b2019-05-06 14:45:15 -07006279 // Only consider subs which match the current subId
6280 // This logic can be simplified. See b/131189269 for progress.
6281 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006282 activeSubscriberIds.add(tele.getSubscriberId(subId));
6283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284
6285 // First pass, find a number override for an active subscriber
6286 String mergeNumber = null;
6287 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6288 for (String key : prefs.keySet()) {
6289 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6290 final String subscriberId = (String) prefs.get(key);
6291 if (activeSubscriberIds.contains(subscriberId)) {
6292 final String iccId = key.substring(
6293 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6294 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6295 mergeNumber = (String) prefs.get(numberKey);
6296 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006297 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 + " for active subscriber " + subscriberId);
6299 }
6300 if (!TextUtils.isEmpty(mergeNumber)) {
6301 break;
6302 }
6303 }
6304 }
6305 }
6306
6307 // Shortcut when no active merged subscribers
6308 if (TextUtils.isEmpty(mergeNumber)) {
6309 return null;
6310 }
6311
6312 // Second pass, find all subscribers under that line override
6313 final ArraySet<String> result = new ArraySet<>();
6314 for (String key : prefs.keySet()) {
6315 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6316 final String number = (String) prefs.get(key);
6317 if (mergeNumber.equals(number)) {
6318 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6319 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6320 final String subscriberId = (String) prefs.get(subscriberKey);
6321 if (!TextUtils.isEmpty(subscriberId)) {
6322 result.add(subscriberId);
6323 }
6324 }
6325 }
6326 }
6327
6328 final String[] resultArray = result.toArray(new String[result.size()]);
6329 Arrays.sort(resultArray);
6330 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006331 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6333 }
6334 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006335 } finally {
6336 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006337 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006338 }
6339
6340 @Override
zoey chen38003472019-12-13 17:16:31 +08006341 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6342 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006343
6344 final long identity = Binder.clearCallingIdentity();
6345 try {
6346 final TelephonyManager telephonyManager = mApp.getSystemService(
6347 TelephonyManager.class);
6348 String subscriberId = telephonyManager.getSubscriberId(subId);
6349 if (subscriberId == null) {
6350 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006351 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006352 + subId);
6353 }
6354 return null;
6355 }
6356
6357 final SubscriptionInfo info = SubscriptionController.getInstance()
6358 .getSubscriptionInfo(subId);
6359 final ParcelUuid groupUuid = info.getGroupUuid();
6360 // If it doesn't belong to any group, return just subscriberId of itself.
6361 if (groupUuid == null) {
6362 return new String[]{subscriberId};
6363 }
6364
6365 // Get all subscriberIds from the group.
6366 final List<String> mergedSubscriberIds = new ArrayList<>();
6367 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006368 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006369 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006370 for (SubscriptionInfo subInfo : groupInfos) {
6371 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6372 if (subscriberId != null) {
6373 mergedSubscriberIds.add(subscriberId);
6374 }
6375 }
6376
6377 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380
6381 }
6382 }
6383
6384 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006385 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006386 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006387 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388
6389 final long identity = Binder.clearCallingIdentity();
6390 try {
6391 final Phone phone = getPhone(subId);
6392 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6393 } finally {
6394 Binder.restoreCallingIdentity(identity);
6395 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006396 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006397
6398 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006399 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006400 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6401 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006402 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6403 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404
6405 final long identity = Binder.clearCallingIdentity();
6406 try {
6407 final Phone phone = getPhone(subId);
6408 if (phone == null) {
6409 return false;
6410 }
6411 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6412 cdmaNonRoamingList);
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006415 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006416 }
6417
6418 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006419 @Deprecated
6420 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6421 enforceModifyPermission();
6422
6423 int returnValue = 0;
6424 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006425 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006426 if(result.exception == null) {
6427 if (result.result != null) {
6428 byte[] responseData = (byte[])(result.result);
6429 if(responseData.length > oemResp.length) {
6430 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6431 responseData.length + "bytes. Buffer Size is " +
6432 oemResp.length + "bytes.");
6433 }
6434 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6435 returnValue = responseData.length;
6436 }
6437 } else {
6438 CommandException ex = (CommandException) result.exception;
6439 returnValue = ex.getCommandError().ordinal();
6440 if(returnValue > 0) returnValue *= -1;
6441 }
6442 } catch (RuntimeException e) {
6443 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6444 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6445 if(returnValue > 0) returnValue *= -1;
6446 }
6447
6448 return returnValue;
6449 }
6450
6451 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006452 public void setRadioCapability(RadioAccessFamily[] rafs) {
6453 try {
6454 ProxyController.getInstance().setRadioCapability(rafs);
6455 } catch (RuntimeException e) {
6456 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6457 }
6458 }
6459
6460 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006461 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006462 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006463 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006464 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006465 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467 final long identity = Binder.clearCallingIdentity();
6468 try {
chen xub97461a2018-10-26 14:17:57 -07006469 TelephonyPermissions
6470 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6471 mApp, phone.getSubId(), "getRadioAccessFamily");
6472 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473 } finally {
6474 Binder.restoreCallingIdentity(identity);
6475 }
chen xub97461a2018-10-26 14:17:57 -07006476 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006477 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006478
6479 @Override
6480 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006481 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483
6484 final long identity = Binder.clearCallingIdentity();
6485 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006486 ImsManager.getInstance(defaultPhone.getContext(),
6487 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006491 }
6492
6493 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006494 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006495 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6497 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006498 return false;
6499 }
Svet Ganovb320e182015-04-16 12:30:10 -07006500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501 final long identity = Binder.clearCallingIdentity();
6502 try {
6503 // Check the user preference and the system-level IMS setting. Even if the user has
6504 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6505 // In the long run, we may instead need to check if there exists a connection service
6506 // which can support video calling.
6507 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006508 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509 return imsManager.isVtEnabledByPlatform()
6510 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6511 && imsManager.isVtEnabledByUser();
6512 } finally {
6513 Binder.restoreCallingIdentity(identity);
6514 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006515 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006516
Andrew Leea1239f22015-03-02 17:44:07 -08006517 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006518 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6519 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006521 mApp, subId, callingPackage, callingFeatureId,
6522 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523 return false;
6524 }
6525
6526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 CarrierConfigManager configManager =
6529 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006530 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
Andrew Leea1239f22015-03-02 17:44:07 -08006535 }
6536
6537 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006538 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006540 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006541 return false;
6542 }
6543
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
6546 CarrierConfigManager configManager =
6547 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006548 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6550 } finally {
6551 Binder.restoreCallingIdentity(identity);
6552 }
Andrew Leea1239f22015-03-02 17:44:07 -08006553 }
6554
Andrew Lee9431b832015-03-09 18:46:45 -07006555 @Override
6556 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006557 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006558 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006559 }
6560
6561 @Override
6562 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563 final long identity = Binder.clearCallingIdentity();
6564 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006565 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 } finally {
6567 Binder.restoreCallingIdentity(identity);
6568 }
Andrew Lee9431b832015-03-09 18:46:45 -07006569 }
6570
Hall Liuf6668912018-10-31 17:05:23 -07006571 /**
6572 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6573 * support for the feature and device firmware support.
6574 *
6575 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6576 */
6577 @Override
6578 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006580 final Phone phone = getPhone(subscriptionId);
6581 if (phone == null) {
6582 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6583 return false;
6584 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006585 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006586 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6588 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006589 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 return isCarrierSupported && isDeviceSupported;
6591 } finally {
6592 Binder.restoreCallingIdentity(identity);
6593 }
Hall Liu98187582018-01-22 19:15:32 -08006594 }
6595
Hall Liuf6668912018-10-31 17:05:23 -07006596 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006597 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6598 * RTT setting, will return true if the device and carrier both support RTT.
6599 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006600 */
6601 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 final long identity = Binder.clearCallingIdentity();
6603 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006604 boolean isRttSupported = isRttSupported(subscriptionId);
6605 boolean isUserRttSettingOn = Settings.Secure.getInt(
6606 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6607 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6608 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6609 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006613 }
6614
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006615 @Deprecated
6616 @Override
6617 public String getDeviceId(String callingPackage) {
6618 return getDeviceIdWithFeature(callingPackage, null);
6619 }
6620
Sanket Padawe7310cc72015-01-14 09:53:20 -08006621 /**
6622 * Returns the unique device ID of phone, for example, the IMEI for
6623 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6624 *
6625 * <p>Requires Permission:
6626 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6627 */
6628 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006629 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006630 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006631 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006632 return null;
6633 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006634 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006635 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006636 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006637 return null;
6638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639
6640 final long identity = Binder.clearCallingIdentity();
6641 try {
6642 return phone.getDeviceId();
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
6645 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006646 }
6647
Ping Sunc67b7c22016-03-02 19:16:45 +08006648 /**
6649 * {@hide}
6650 * Returns the IMS Registration Status on a particular subid
6651 *
6652 * @param subId
6653 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006654 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006655 Phone phone = getPhone(subId);
6656 if (phone != null) {
6657 return phone.isImsRegistered();
6658 } else {
6659 return false;
6660 }
6661 }
6662
Santos Cordon7a1885b2015-02-03 11:15:19 -08006663 @Override
6664 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 final long identity = Binder.clearCallingIdentity();
6666 try {
6667 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6668 } finally {
6669 Binder.restoreCallingIdentity(identity);
6670 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006671 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006672
Tyler Gunnf70ed162019-04-03 15:28:53 -07006673 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006674 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006675 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006676 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006677 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006678 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6679 }
6680 final long identity = Binder.clearCallingIdentity();
6681 try {
6682 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6683 } finally {
6684 Binder.restoreCallingIdentity(identity);
6685 }
6686 }
6687
6688 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006689 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006690 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6691 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006692 final long identity = Binder.clearCallingIdentity();
6693 try {
6694 Phone phone = getPhone(subscriptionId);
6695 if (phone == null) {
6696 return null;
6697 }
6698 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6699 } finally {
6700 Binder.restoreCallingIdentity(identity);
6701 }
6702 }
6703
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006704 /**
6705 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006706 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006707 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 final long identity = Binder.clearCallingIdentity();
6709 try {
6710 Phone phone = getPhone(subId);
6711 if (phone != null) {
6712 return phone.isWifiCallingEnabled();
6713 } else {
6714 return false;
6715 }
6716 } finally {
6717 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006718 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006719 }
6720
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006721 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006722 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006723 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006724 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 final long identity = Binder.clearCallingIdentity();
6726 try {
6727 Phone phone = getPhone(subId);
6728 if (phone != null) {
6729 return phone.isVideoEnabled();
6730 } else {
6731 return false;
6732 }
6733 } finally {
6734 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006735 }
6736 }
6737
6738 /**
6739 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6740 * defined in {@link ImsRegistrationImplBase}.
6741 */
6742 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 final long identity = Binder.clearCallingIdentity();
6744 try {
6745 Phone phone = getPhone(subId);
6746 if (phone != null) {
6747 return phone.getImsRegistrationTech();
6748 } else {
6749 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6750 }
6751 } finally {
6752 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006753 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006754 }
6755
Stuart Scott8eef64f2015-04-08 15:13:54 -07006756 @Override
6757 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006758 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006759 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6760 return;
6761 }
6762
Svet Ganovcc087f82015-05-12 20:35:54 -07006763 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006764
Svet Ganovcc087f82015-05-12 20:35:54 -07006765 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006766 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6767 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006768 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006769 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006770 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006771 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6772 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006773 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006774 // There has been issues when Sms raw table somehow stores orphan
6775 // fragments. They lead to garbled message when new fragments come
6776 // in and combined with those stale ones. In case this happens again,
6777 // user can reset all network settings which will clean up this table.
6778 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006779 // Clean up IMS settings as well here.
6780 int slotId = getSlotIndex(subId);
6781 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6782 ImsManager.getInstance(mApp, slotId).factoryReset();
6783 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006784
6785 // Erase modem config if erase modem on network setting is enabled.
6786 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6787 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6788 if (configValue != null && Boolean.parseBoolean(configValue)) {
6789 sendEraseModemConfig(getDefaultPhone());
6790 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006791 } finally {
6792 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006793 }
6794 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006795
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006796 private void cleanUpSmsRawTable(Context context) {
6797 ContentResolver resolver = context.getContentResolver();
6798 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6799 resolver.delete(uri, null, null);
6800 }
6801
Narayan Kamath1c496c22015-04-16 14:40:19 +01006802 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006803 public String getSimLocaleForSubscriber(int subId) {
6804 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6805 final Phone phone = getPhone(subId);
6806 if (phone == null) {
6807 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006808 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006809 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810 final long identity = Binder.clearCallingIdentity();
6811 try {
chen xu5d3637b2019-01-21 23:31:38 -08006812 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006813 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006814 if (info == null) {
6815 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6816 return null;
6817 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006818 // Try and fetch the locale from the carrier properties or from the SIM language
6819 // preferences (EF-PL and EF-LI)...
6820 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006822 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6823 if (localeFromDefaultSim != null) {
6824 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6825 if (DBG) log("Using locale from subId: " + subId + " locale: "
6826 + localeFromDefaultSim);
6827 return localeFromDefaultSim.toLanguageTag();
6828 } else {
6829 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006830 }
6831 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833 // The SIM language preferences only store a language (e.g. fr = French), not an
6834 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6835 // the SIM and carrier preferences does not include a country we add the country
6836 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006837 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006839 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 return mccLocale.toLanguageTag();
6841 }
6842
6843 if (DBG) log("No locale found - returning null");
6844 return null;
6845 } finally {
6846 Binder.restoreCallingIdentity(identity);
6847 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006848 }
6849
6850 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006851 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006852 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006853 }
6854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855 /**
6856 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6857 */
6858 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006859 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006860 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006861 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006862
Chenjie Yu1ba97252018-01-11 18:16:20 -08006863 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006864 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006865
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006866 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006867 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6868 * representing the state of the modem.
6869 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006870 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6871 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006872 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006873 */
6874 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006875 public void requestModemActivityInfo(ResultReceiver result) {
6876 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006877 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006878
6879 final long identity = Binder.clearCallingIdentity();
6880 try {
sqian1a1be542020-03-05 11:37:28 -08006881 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882 } finally {
6883 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006884 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006885 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006886
Siddharth Rayb8114062018-06-17 15:02:38 -07006887 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6888 // less than total activity duration.
6889 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6890 if (info == null) {
6891 return false;
6892 }
6893 int activityDurationMs =
6894 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6895 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006896 int[] txTimeMs = info.getTransmitTimeMillis();
6897 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6898 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006899 }
6900 return (info.isValid()
6901 && (info.getSleepTimeMillis() <= activityDurationMs)
6902 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006903 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006904 && (totalTxTimeMs <= activityDurationMs));
6905 }
6906
Jack Yu85bd38a2015-11-09 11:34:32 -08006907 /**
6908 * {@hide}
6909 * Returns the service state information on specified subscription.
6910 */
6911 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006912 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6913 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006915 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006916 return null;
6917 }
6918
Hall Liuf19c44f2018-11-27 14:38:17 -08006919 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6920 LocationAccessPolicy.checkLocationPermission(mApp,
6921 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6922 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006923 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006924 .setCallingPid(Binder.getCallingPid())
6925 .setCallingUid(Binder.getCallingUid())
6926 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006927 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006928 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6929 .build());
6930
6931 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6932 LocationAccessPolicy.checkLocationPermission(mApp,
6933 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6934 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006935 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006936 .setCallingPid(Binder.getCallingPid())
6937 .setCallingUid(Binder.getCallingUid())
6938 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006939 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006940 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6941 .build());
6942 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6943 boolean hasFinePermission =
6944 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6945 boolean hasCoarsePermission =
6946 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948 final long identity = Binder.clearCallingIdentity();
6949 try {
6950 final Phone phone = getPhone(subId);
6951 if (phone == null) {
6952 return null;
6953 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006954
Hall Liuf19c44f2018-11-27 14:38:17 -08006955 ServiceState ss = phone.getServiceState();
6956
6957 // Scrub out the location info in ServiceState depending on what level of access
6958 // the caller has.
6959 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006960 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6961 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006962 } finally {
6963 Binder.restoreCallingIdentity(identity);
6964 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006965 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006966
6967 /**
6968 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6969 *
6970 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6971 * voicemail ringtone.
6972 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6973 * PhoneAccount.
6974 */
6975 @Override
6976 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977 final long identity = Binder.clearCallingIdentity();
6978 try {
6979 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6980 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006981 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6985 } finally {
6986 Binder.restoreCallingIdentity(identity);
6987 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006988 }
6989
6990 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006991 * Sets the per-account voicemail ringtone.
6992 *
6993 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6994 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6995 *
6996 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6997 * voicemail ringtone.
6998 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6999 * PhoneAccount.
7000 */
7001 @Override
7002 public void setVoicemailRingtoneUri(String callingPackage,
7003 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007004 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007005 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007006 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7007 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7009 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7010 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012
7013 final long identity = Binder.clearCallingIdentity();
7014 try {
7015 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7016 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007017 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 }
7019 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7020 } finally {
7021 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007022 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007023 }
7024
7025 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007026 * Returns whether vibration is set for voicemail notification in Phone settings.
7027 *
7028 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7029 * voicemail vibration setting.
7030 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7031 */
7032 @Override
7033 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 final long identity = Binder.clearCallingIdentity();
7035 try {
7036 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7037 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007038 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7042 } finally {
7043 Binder.restoreCallingIdentity(identity);
7044 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007045 }
7046
Youhan Wange64578a2016-05-02 15:32:42 -07007047 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007048 * Sets the per-account voicemail vibration.
7049 *
7050 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7051 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7052 *
7053 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7054 * voicemail vibration setting.
7055 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7056 * specific PhoneAccount.
7057 */
7058 @Override
7059 public void setVoicemailVibrationEnabled(String callingPackage,
7060 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007061 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007062 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007063 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7064 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7066 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7067 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007068 }
7069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 final long identity = Binder.clearCallingIdentity();
7071 try {
7072 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7073 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007074 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 }
7076 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7077 } finally {
7078 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007079 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007080 }
7081
7082 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007083 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7084 *
7085 * @throws SecurityException if the caller does not have the required permission
7086 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007087 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007088 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007089 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007090 }
7091
7092 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007093 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7094 * permission.
7095 *
7096 * @throws SecurityException if the caller does not have the required permission
7097 */
7098 private void enforceSendSmsPermission() {
7099 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7100 }
7101
7102 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007103 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007104 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007105 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007106 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007107 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108 final long identity = Binder.clearCallingIdentity();
7109 try {
7110 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007111 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007112 if (componentName == null) {
7113 throw new SecurityException(
7114 "Caller not current active visual voicemail package[null]");
7115 }
7116 String vvmPackage = componentName.getPackageName();
7117 if (!callingPackage.equals(vvmPackage)) {
7118 throw new SecurityException("Caller not current active visual voicemail package["
7119 + vvmPackage + "]");
7120 }
7121 } finally {
7122 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007123 }
7124 }
7125
7126 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007127 * Return the application ID for the app type.
7128 *
7129 * @param subId the subscription ID that this request applies to.
7130 * @param appType the uicc app type.
7131 * @return Application ID for specificied app type, or null if no uicc.
7132 */
7133 @Override
7134 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007135 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007136 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137
7138 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007139 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 if (phone == null) {
7141 return null;
7142 }
7143 String aid = null;
7144 try {
7145 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7146 .getApplicationByType(appType).getAid();
7147 } catch (Exception e) {
7148 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7149 }
7150 return aid;
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007153 }
Youhan Wange64578a2016-05-02 15:32:42 -07007154 }
7155
Youhan Wang4001d252016-05-11 10:29:41 -07007156 /**
7157 * Return the Electronic Serial Number.
7158 *
7159 * @param subId the subscription ID that this request applies to.
7160 * @return ESN or null if error.
7161 */
7162 @Override
7163 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007164 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007165 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166
7167 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007168 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169 if (phone == null) {
7170 return null;
7171 }
7172 String esn = null;
7173 try {
7174 esn = phone.getEsn();
7175 } catch (Exception e) {
7176 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7177 }
7178 return esn;
7179 } finally {
7180 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007181 }
Youhan Wang4001d252016-05-11 10:29:41 -07007182 }
7183
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007184 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007185 * Return the Preferred Roaming List Version.
7186 *
7187 * @param subId the subscription ID that this request applies to.
7188 * @return PRLVersion or null if error.
7189 */
7190 @Override
7191 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007192 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007193 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194
7195 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007196 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 if (phone == null) {
7198 return null;
7199 }
7200 String cdmaPrlVersion = null;
7201 try {
7202 cdmaPrlVersion = phone.getCdmaPrlVersion();
7203 } catch (Exception e) {
7204 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7205 }
7206 return cdmaPrlVersion;
7207 } finally {
7208 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007209 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007210 }
7211
7212 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007213 * Get snapshot of Telephony histograms
7214 * @return List of Telephony histograms
7215 * @hide
7216 */
7217 @Override
7218 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7220 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007221
7222 final long identity = Binder.clearCallingIdentity();
7223 try {
7224 return RIL.getTelephonyRILTimingHistograms();
7225 } finally {
7226 Binder.restoreCallingIdentity(identity);
7227 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007228 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007229
7230 /**
7231 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007232 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7233 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007234 * Require system privileges. In the future we may add this to carrier APIs.
7235 *
Michele Berionne482f8202018-11-27 18:57:59 -08007236 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007237 */
7238 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007239 @TelephonyManager.SetCarrierRestrictionResult
7240 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007241 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007242 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007243
Michele Berionne482f8202018-11-27 18:57:59 -08007244 if (carrierRestrictionRules == null) {
7245 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007246 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007248 final long identity = Binder.clearCallingIdentity();
7249 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007250 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007251 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252 } finally {
7253 Binder.restoreCallingIdentity(identity);
7254 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007255 }
7256
7257 /**
7258 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007259 * Get the allowed carrier list and the excluded carrier list, including the priority between
7260 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007261 * Require system privileges. In the future we may add this to carrier APIs.
7262 *
Michele Berionne482f8202018-11-27 18:57:59 -08007263 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007264 */
7265 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007266 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007267 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007269
7270 final long identity = Binder.clearCallingIdentity();
7271 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007272 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7273 if (response instanceof CarrierRestrictionRules) {
7274 return (CarrierRestrictionRules) response;
7275 }
7276 // Response is an Exception of some kind,
7277 // which is signalled to the user as a NULL retval
7278 return null;
7279 } catch (Exception e) {
7280 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7281 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 } finally {
7283 Binder.restoreCallingIdentity(identity);
7284 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007285 }
7286
fionaxu59545b42016-05-25 15:53:37 -07007287 /**
7288 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7289 * @param subId the subscription ID that this action applies to.
7290 * @param enabled control enable or disable metered apns.
7291 * {@hide}
7292 */
7293 @Override
7294 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7295 enforceModifyPermission();
7296 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297
7298 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007299 if (phone == null) {
7300 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7301 return;
7302 }
7303 try {
7304 phone.carrierActionSetMeteredApnsEnabled(enabled);
7305 } catch (Exception e) {
7306 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007307 } finally {
7308 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007309 }
7310 }
7311
7312 /**
7313 * Action set from carrier signalling broadcast receivers to enable/disable radio
7314 * @param subId the subscription ID that this action applies to.
7315 * @param enabled control enable or disable radio.
7316 * {@hide}
7317 */
7318 @Override
7319 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7320 enforceModifyPermission();
7321 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322
7323 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007324 if (phone == null) {
7325 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7326 return;
7327 }
7328 try {
7329 phone.carrierActionSetRadioEnabled(enabled);
7330 } catch (Exception e) {
7331 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332 } finally {
7333 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007334 }
7335 }
7336
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007337 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007338 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7339 * network status based on which carrier apps could apply actions accordingly,
7340 * enable/disable default url handler for example.
7341 *
7342 * @param subId the subscription ID that this action applies to.
7343 * @param report control start/stop reporting the default network status.
7344 * {@hide}
7345 */
7346 @Override
7347 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7348 enforceModifyPermission();
7349 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350
7351 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007352 if (phone == null) {
7353 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7354 return;
7355 }
7356 try {
7357 phone.carrierActionReportDefaultNetworkStatus(report);
7358 } catch (Exception e) {
7359 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 } finally {
7361 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007362 }
7363 }
7364
7365 /**
fionaxud9622282017-07-17 17:51:30 -07007366 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7367 * @param subId the subscription ID that this action applies to.
7368 * {@hide}
7369 */
7370 @Override
7371 public void carrierActionResetAll(int subId) {
7372 enforceModifyPermission();
7373 final Phone phone = getPhone(subId);
7374 if (phone == null) {
7375 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7376 return;
7377 }
7378 try {
7379 phone.carrierActionResetAll();
7380 } catch (Exception e) {
7381 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7382 }
7383 }
7384
7385 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007386 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7387 * bug report is being generated.
7388 */
7389 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007390 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007391 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7392 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007393 writer.println("Permission Denial: can't dump Phone from pid="
7394 + Binder.getCallingPid()
7395 + ", uid=" + Binder.getCallingUid()
7396 + "without permission "
7397 + android.Manifest.permission.DUMP);
7398 return;
7399 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007400 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007401 }
Jack Yueb89b242016-06-22 13:27:47 -07007402
Brad Ebingerdac2f002018-04-03 15:17:52 -07007403 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007404 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7405 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7406 @NonNull String[] args) {
7407 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7408 this, in.getFileDescriptor(), out.getFileDescriptor(),
7409 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007410 }
7411
Jack Yueb89b242016-06-22 13:27:47 -07007412 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007413 * Policy control of data connection. Usually used when data limit is passed.
7414 * @param enabled True if enabling the data, otherwise disabling.
7415 * @param subId Subscription index
7416 * {@hide}
7417 */
7418 @Override
7419 public void setPolicyDataEnabled(boolean enabled, int subId) {
7420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421
7422 final long identity = Binder.clearCallingIdentity();
7423 try {
7424 Phone phone = getPhone(subId);
7425 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007426 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 }
7428 } finally {
7429 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007430 }
7431 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007432
7433 /**
7434 * Get Client request stats
7435 * @return List of Client Request Stats
7436 * @hide
7437 */
7438 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007439 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7440 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007442 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007443 return null;
7444 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007445 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 final long identity = Binder.clearCallingIdentity();
7448 try {
7449 if (phone != null) {
7450 return phone.getClientRequestStats();
7451 }
7452
7453 return null;
7454 } finally {
7455 Binder.restoreCallingIdentity(identity);
7456 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007457 }
7458
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007459 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007460 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007461 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007462 }
Jack Yueb4124c2017-02-16 15:32:43 -08007463
7464 /**
Grace Chen70990072017-03-24 17:21:30 -07007465 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007466 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007467 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007468 * @param state State of SIM (power down, power up, pass through)
7469 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7470 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7471 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007472 *
7473 **/
7474 @Override
Grace Chen70990072017-03-24 17:21:30 -07007475 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007476 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007477 Phone phone = PhoneFactory.getPhone(slotIndex);
7478
vagdeviaf9a5b92018-08-15 16:01:53 -07007479 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 final long identity = Binder.clearCallingIdentity();
7482 try {
7483 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007484 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 }
7486 } finally {
7487 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007488 }
7489 }
Shuo Qiandd210312017-04-12 22:11:33 +00007490
Tyler Gunn65d45c22017-06-05 11:22:26 -07007491 private boolean isUssdApiAllowed(int subId) {
7492 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007493 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007494 if (configManager == null) {
7495 return false;
7496 }
7497 PersistableBundle pb = configManager.getConfigForSubId(subId);
7498 if (pb == null) {
7499 return false;
7500 }
7501 return pb.getBoolean(
7502 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7503 }
7504
Shuo Qiandd210312017-04-12 22:11:33 +00007505 /**
7506 * Check if phone is in emergency callback mode
7507 * @return true if phone is in emergency callback mode
7508 * @param subId sub id
7509 */
goneil9c5f4872017-12-05 14:07:56 -08007510 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007511 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007512 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007513 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514
7515 final long identity = Binder.clearCallingIdentity();
7516 try {
7517 if (phone != null) {
7518 return phone.isInEcm();
7519 } else {
7520 return false;
7521 }
7522 } finally {
7523 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007524 }
7525 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007526
7527 /**
7528 * Get the current signal strength information for the given subscription.
7529 * Because this information is not updated when the device is in a low power state
7530 * it should not be relied-upon to be current.
7531 * @param subId Subscription index
7532 * @return the most recent cached signal strength info from the modem
7533 */
7534 @Override
7535 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 final long identity = Binder.clearCallingIdentity();
7537 try {
7538 Phone p = getPhone(subId);
7539 if (p == null) {
7540 return null;
7541 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 return p.getSignalStrength();
7544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007547 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007548
Pengquan Meng77b7f132018-08-22 14:49:57 -07007549 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007550 * Get the current modem radio state for the given slot.
7551 * @param slotIndex slot index.
7552 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007553 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007554 * @return the current radio power state from the modem
7555 */
7556 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007557 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007558 Phone phone = PhoneFactory.getPhone(slotIndex);
7559 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7561 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007562 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7563 }
7564
7565 final long identity = Binder.clearCallingIdentity();
7566 try {
7567 return phone.getRadioPowerState();
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
7571 }
7572 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7573 }
7574
7575 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007576 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7577 *
7578 * <p>Requires one of the following permissions:
7579 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7580 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7581 * privileges.
7582 *
7583 * @param subId subscription id
7584 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7585 * {@code false}.
7586 */
7587 @Override
7588 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007589 try {
7590 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7591 null);
7592 } catch (Exception e) {
7593 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7594 mApp, subId, "isDataRoamingEnabled");
7595 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007596
Pengquan Menga1bb6272018-09-06 09:59:22 -07007597 boolean isEnabled = false;
7598 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007599 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007600 Phone phone = getPhone(subId);
7601 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007602 } finally {
7603 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007604 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007605 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007606 }
7607
7608
7609 /**
7610 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7611 *
7612 * <p> Requires permission:
7613 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7614 * privileges.
7615 *
7616 * @param subId subscription id
7617 * @param isEnabled {@code true} means enable, {@code false} means disable.
7618 */
7619 @Override
7620 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7622 mApp, subId, "setDataRoamingEnabled");
7623
Pengquan Menga1bb6272018-09-06 09:59:22 -07007624 final long identity = Binder.clearCallingIdentity();
7625 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007626 Phone phone = getPhone(subId);
7627 if (phone != null) {
7628 phone.setDataRoamingEnabled(isEnabled);
7629 }
7630 } finally {
7631 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007632 }
7633 }
7634
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007635 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007636 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007637 TelephonyPermissions
7638 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007639 mApp, subId, "isManualNetworkSelectionAllowed");
7640
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007641 boolean isAllowed = true;
7642 final long identity = Binder.clearCallingIdentity();
7643 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007644 Phone phone = getPhone(subId);
7645 if (phone != null) {
7646 isAllowed = phone.isCspPlmnEnabled();
7647 }
7648 } finally {
7649 Binder.restoreCallingIdentity(identity);
7650 }
7651 return isAllowed;
7652 }
7653
7654 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007655 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007656 // Verify that tha callingPackage belongs to the calling UID
7657 mApp.getSystemService(AppOpsManager.class)
7658 .checkPackage(Binder.getCallingUid(), callingPackage);
7659
Jordan Liu1e142fc2019-04-22 15:10:43 -07007660 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007661 try {
7662 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007663 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007664 } catch (SecurityException e) {
7665 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7666 // has carrier privileges on an active UICC
7667 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7668 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007669 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007670 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007671 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007672
7673 final long identity = Binder.clearCallingIdentity();
7674 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007675 UiccController uiccController = UiccController.getInstance();
7676 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007677 if (hasReadPermission) {
7678 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007679 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007680
7681 // Remove private info if the caller doesn't have access
7682 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7683 for (UiccCardInfo cardInfo : cardInfos) {
7684 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7685 // is available
7686 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7687 if (card == null || card.getUiccProfile() == null) {
7688 // assume no access if the card or profile is unavailable
7689 filteredInfos.add(cardInfo.getUnprivileged());
7690 continue;
7691 }
7692 UiccProfile profile = card.getUiccProfile();
7693 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7694 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7695 filteredInfos.add(cardInfo);
7696 } else {
7697 filteredInfos.add(cardInfo.getUnprivileged());
7698 }
7699 }
7700 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007701 } finally {
7702 Binder.restoreCallingIdentity(identity);
7703 }
7704 }
7705
7706 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007707 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007708 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 final long identity = Binder.clearCallingIdentity();
7711 try {
7712 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7713 if (slots == null) {
7714 Rlog.i(LOG_TAG, "slots is null.");
7715 return null;
7716 }
7717
7718 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7719 for (int i = 0; i < slots.length; i++) {
7720 UiccSlot slot = slots[i];
7721 if (slot == null) {
7722 continue;
7723 }
7724
Jordan Liu7be7e652019-05-06 18:55:02 +00007725 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007726 UiccCard card = slot.getUiccCard();
7727 if (card != null) {
7728 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007729 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007730 cardId = slot.getEid();
7731 if (TextUtils.isEmpty(cardId)) {
7732 cardId = slot.getIccId();
7733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 }
7735
Jordan Liu857451f2019-05-09 16:35:35 -07007736 if (cardId != null) {
7737 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7738 // if cardId is an EID, it's all digits so this is fine
7739 cardId = IccUtils.stripTrailingFs(cardId);
7740 }
7741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 int cardState = 0;
7743 switch (slot.getCardState()) {
7744 case CARDSTATE_ABSENT:
7745 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7746 break;
7747 case CARDSTATE_PRESENT:
7748 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7749 break;
7750 case CARDSTATE_ERROR:
7751 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7752 break;
7753 case CARDSTATE_RESTRICTED:
7754 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7755 break;
7756 default:
7757 break;
7758
7759 }
7760
7761 infos[i] = new UiccSlotInfo(
7762 slot.isActive(),
7763 slot.isEuicc(),
7764 cardId,
7765 cardState,
7766 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007767 slot.isExtendedApduSupported(),
7768 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 }
7770 return infos;
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007773 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007774 }
7775
7776 @Override
7777 public boolean switchSlots(int[] physicalSlots) {
7778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779
7780 final long identity = Binder.clearCallingIdentity();
7781 try {
7782 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7783 } finally {
7784 Binder.restoreCallingIdentity(identity);
7785 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007786 }
Jack Yu4c988042018-02-27 15:30:01 -08007787
7788 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007789 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007790 final long identity = Binder.clearCallingIdentity();
7791 try {
7792 return UiccController.getInstance().getCardIdForDefaultEuicc();
7793 } finally {
7794 Binder.restoreCallingIdentity(identity);
7795 }
7796 }
7797
Pengquan Meng85728fb2018-03-12 16:31:21 -07007798 /**
goneil47ffb6e2018-04-06 15:40:58 -07007799 * A test API to reload the UICC profile.
7800 *
7801 * <p>Requires that the calling app has permission
7802 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7803 * @hide
7804 */
7805 @Override
7806 public void refreshUiccProfile(int subId) {
7807 enforceModifyPermission();
7808
7809 final long identity = Binder.clearCallingIdentity();
7810 try {
7811 Phone phone = getPhone(subId);
7812 if (phone == null) {
7813 return;
7814 }
7815 UiccCard uiccCard = phone.getUiccCard();
7816 if (uiccCard == null) {
7817 return;
7818 }
7819 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7820 if (uiccProfile == null) {
7821 return;
7822 }
7823 uiccProfile.refresh();
7824 } finally {
7825 Binder.restoreCallingIdentity(identity);
7826 }
7827 }
7828
7829 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007830 * Returns false if the mobile data is disabled by default, otherwise return true.
7831 */
7832 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007833 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007834 }
7835
7836 /**
7837 * Returns true if the data roaming is enabled by default, i.e the system property
7838 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7839 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7840 */
7841 private boolean getDefaultDataRoamingEnabled(int subId) {
7842 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007843 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07007844 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007845 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7846 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7847 return isDataRoamingEnabled;
7848 }
7849
7850 /**
7851 * Returns the default network type for the given {@code subId}, if the default network type is
7852 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7853 */
7854 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007855 List<Integer> list = TelephonyProperties.default_network();
7856 int phoneId = mSubscriptionController.getPhoneId(subId);
7857 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7858 return list.get(phoneId);
7859 }
7860 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007861 }
fionaxua13278b2018-03-21 00:08:13 -07007862
7863 @Override
7864 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007865 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007866 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867
7868 final long identity = Binder.clearCallingIdentity();
7869 try {
7870 final Phone phone = getPhone(subId);
7871 if (phone == null) {
7872 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7873 return;
7874 }
chen xueaba88a2019-03-15 13:15:10 -07007875 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7876 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07007877 if (carrierPrivilegeRules == null) {
7878 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7879 } else {
7880 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882 } finally {
7883 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007884 }
fionaxua13278b2018-03-21 00:08:13 -07007885 }
7886
7887 @Override
7888 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007889 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007890
7891 final long identity = Binder.clearCallingIdentity();
7892 try {
7893 final Phone phone = getPhone(subId);
7894 if (phone == null) {
7895 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7896 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7897 }
7898 return phone.getCarrierIdListVersion();
7899 } finally {
7900 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007901 }
fionaxua13278b2018-03-21 00:08:13 -07007902 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007903
7904 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007905 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7906 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007908 mApp, subId, callingPackage, callingFeatureId,
7909 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007910 return -1;
7911 }
7912
7913 final long identity = Binder.clearCallingIdentity();
7914 try {
7915 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7916 } finally {
7917 Binder.restoreCallingIdentity(identity);
7918 }
7919 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007920
7921 @Override
7922 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007923 TelephonyPermissions
7924 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007925 mApp, subId, "getCdmaRoamingMode");
7926
7927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7930 } finally {
7931 Binder.restoreCallingIdentity(identity);
7932 }
7933 }
7934
7935 @Override
7936 public boolean setCdmaRoamingMode(int subId, int mode) {
7937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7938 mApp, subId, "setCdmaRoamingMode");
7939
7940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7943 } finally {
7944 Binder.restoreCallingIdentity(identity);
7945 }
7946 }
7947
7948 @Override
7949 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7951 mApp, subId, "setCdmaSubscriptionMode");
7952
7953 final long identity = Binder.clearCallingIdentity();
7954 try {
7955 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7956 } finally {
7957 Binder.restoreCallingIdentity(identity);
7958 }
7959 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007960
sqianc5eccab2018-10-19 18:46:41 -07007961 @Override
sqian8c685422019-02-22 15:55:18 -08007962 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007963 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007965 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7966 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007967 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7968 }
7969 final long identity = Binder.clearCallingIdentity();
7970 try {
sqian854d44b2018-12-12 16:48:18 -08007971 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7972 for (Phone phone: PhoneFactory.getPhones()) {
7973 if (phone.getEmergencyNumberTracker() != null
7974 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7975 emergencyNumberListInternal.put(
7976 phone.getSubId(),
7977 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7978 }
sqian11b7a0e2018-12-05 18:48:28 -08007979 }
sqian854d44b2018-12-12 16:48:18 -08007980 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
sqianc5eccab2018-10-19 18:46:41 -07007984 }
7985
7986 @Override
sqian8c685422019-02-22 15:55:18 -08007987 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007988 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007989 if (!exactMatch) {
7990 TelephonyPermissions
7991 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007992 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007993 }
7994 final long identity = Binder.clearCallingIdentity();
7995 try {
sqian854d44b2018-12-12 16:48:18 -08007996 for (Phone phone: PhoneFactory.getPhones()) {
7997 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09007998 && phone.getEmergencyNumberTracker()
7999 .isEmergencyNumber(number, exactMatch)) {
8000 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008001 }
sqian11b7a0e2018-12-05 18:48:28 -08008002 }
8003 return false;
8004 } finally {
8005 Binder.restoreCallingIdentity(identity);
8006 }
8007 }
8008
sqianf4ca7ed2019-01-15 18:32:07 -08008009 /**
8010 * Update emergency number list for test mode.
8011 */
8012 @Override
8013 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8014 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8015 "updateEmergencyNumberListTestMode");
8016
8017 final long identity = Binder.clearCallingIdentity();
8018 try {
8019 for (Phone phone: PhoneFactory.getPhones()) {
8020 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8021 if (tracker != null) {
8022 tracker.executeEmergencyNumberTestModeCommand(action, num);
8023 }
8024 }
8025 } finally {
8026 Binder.restoreCallingIdentity(identity);
8027 }
8028 }
8029
8030 /**
8031 * Get the full emergency number list for test mode.
8032 */
8033 @Override
8034 public List<String> getEmergencyNumberListTestMode() {
8035 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8036 "getEmergencyNumberListTestMode");
8037
8038 final long identity = Binder.clearCallingIdentity();
8039 try {
8040 Set<String> emergencyNumbers = new HashSet<>();
8041 for (Phone phone: PhoneFactory.getPhones()) {
8042 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8043 if (tracker != null) {
8044 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8045 emergencyNumbers.add(num.getNumber());
8046 }
8047 }
8048 }
8049 return new ArrayList<>(emergencyNumbers);
8050 } finally {
8051 Binder.restoreCallingIdentity(identity);
8052 }
8053 }
8054
chen xud6b45bd2018-10-30 22:27:10 -07008055 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008056 public int getEmergencyNumberDbVersion(int subId) {
8057 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8058
8059 final long identity = Binder.clearCallingIdentity();
8060 try {
8061 final Phone phone = getPhone(subId);
8062 if (phone == null) {
8063 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8064 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8065 }
8066 return phone.getEmergencyNumberDbVersion();
8067 } finally {
8068 Binder.restoreCallingIdentity(identity);
8069 }
8070 }
8071
8072 @Override
8073 public void notifyOtaEmergencyNumberDbInstalled() {
8074 enforceModifyPermission();
8075
8076 final long identity = Binder.clearCallingIdentity();
8077 try {
8078 for (Phone phone: PhoneFactory.getPhones()) {
8079 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8080 if (tracker != null) {
8081 tracker.updateOtaEmergencyNumberDatabase();
8082 }
8083 }
8084 } finally {
8085 Binder.restoreCallingIdentity(identity);
8086 }
8087 }
8088
8089 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008090 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008091 enforceActiveEmergencySessionPermission();
8092
8093 final long identity = Binder.clearCallingIdentity();
8094 try {
8095 for (Phone phone: PhoneFactory.getPhones()) {
8096 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8097 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008098 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8099 }
8100 }
8101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103 }
8104 }
8105
8106 @Override
8107 public void resetOtaEmergencyNumberDbFilePath() {
8108 enforceActiveEmergencySessionPermission();
8109
8110 final long identity = Binder.clearCallingIdentity();
8111 try {
8112 for (Phone phone: PhoneFactory.getPhones()) {
8113 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8114 if (tracker != null) {
8115 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008116 }
8117 }
8118 } finally {
8119 Binder.restoreCallingIdentity(identity);
8120 }
8121 }
8122
8123 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008124 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8125 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8126 Phone phone = getPhone(subId);
8127 if (phone == null) {
8128 return null;
8129 }
8130 final long identity = Binder.clearCallingIdentity();
8131 try {
8132 UiccProfile profile = UiccController.getInstance()
8133 .getUiccProfileForPhone(phone.getPhoneId());
8134 if (profile != null) {
8135 return profile.getCertsFromCarrierPrivilegeAccessRules();
8136 }
8137 } finally {
8138 Binder.restoreCallingIdentity(identity);
8139 }
8140 return null;
8141 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008142
8143 /**
8144 * Enable or disable a modem stack.
8145 */
8146 @Override
8147 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8148 enforceModifyPermission();
8149
8150 final long identity = Binder.clearCallingIdentity();
8151 try {
8152 Phone phone = PhoneFactory.getPhone(slotIndex);
8153 if (phone == null) {
8154 return false;
8155 } else {
8156 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8157 }
8158 } finally {
8159 Binder.restoreCallingIdentity(identity);
8160 }
8161 }
Michelecea4cf22018-12-21 15:00:11 -08008162
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008163 /**
8164 * Whether a modem stack is enabled or not.
8165 */
8166 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008167 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8168 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008169 Phone phone = PhoneFactory.getPhone(slotIndex);
8170 if (phone == null) return false;
8171
8172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008173 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8174 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008175 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8176 }
8177
8178 final long identity = Binder.clearCallingIdentity();
8179 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008180 try {
8181 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8182 } catch (NoSuchElementException ex) {
8183 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8184 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008185 } finally {
8186 Binder.restoreCallingIdentity(identity);
8187 }
8188 }
8189
Michelecea4cf22018-12-21 15:00:11 -08008190 @Override
Michele0ea7d782019-03-19 14:58:42 -07008191 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008192 enforceModifyPermission();
8193
8194 final long identity = Binder.clearCallingIdentity();
8195 try {
8196 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008197 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008198 .commit();
8199 } finally {
8200 Binder.restoreCallingIdentity(identity);
8201 }
8202 }
8203
8204 @Override
Michele0ea7d782019-03-19 14:58:42 -07008205 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008206 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008208 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8209 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008210 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008211 }
Michelecea4cf22018-12-21 15:00:11 -08008212
8213 final long identity = Binder.clearCallingIdentity();
8214 try {
Michele0ea7d782019-03-19 14:58:42 -07008215 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008216 } finally {
8217 Binder.restoreCallingIdentity(identity);
8218 }
8219 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008220
Michele0ea7d782019-03-19 14:58:42 -07008221 @TelephonyManager.IsMultiSimSupportedResult
8222 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008223 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8224 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8225 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008226 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8227 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008228 }
8229 // Check if the hardware supports multisim functionality. If usage of multisim is not
8230 // supported by the modem, indicate that it is restricted.
8231 PhoneCapability staticCapability =
8232 mPhoneConfigurationManager.getStaticPhoneCapability();
8233 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008234 loge("isMultiSimSupportedInternal: no static configuration available");
8235 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008236 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008237 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008238 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8239 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008240 }
8241 // Check if support of multiple SIMs is restricted by carrier
8242 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008243 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008244 }
8245
Michele0ea7d782019-03-19 14:58:42 -07008246 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008247 }
8248
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008249 /**
8250 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008251 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8252 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8253 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008254 * @param numOfSims number of active sims we want to switch to
8255 */
8256 @Override
8257 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008258 if (numOfSims == 1) {
8259 enforceModifyPermission();
8260 } else {
8261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8262 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8263 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008264 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008265
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008266 try {
Michele30b57b22019-03-01 12:01:14 -08008267 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008268 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008269 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8270 return;
8271 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008272 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8273 } finally {
8274 Binder.restoreCallingIdentity(identity);
8275 }
8276 }
8277
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008278 @Override
8279 public boolean isApplicationOnUicc(int subId, int appType) {
8280 enforceReadPrivilegedPermission("isApplicationOnUicc");
8281 Phone phone = getPhone(subId);
8282 if (phone == null) {
8283 return false;
8284 }
8285 final long identity = Binder.clearCallingIdentity();
8286 try {
8287 UiccCard uiccCard = phone.getUiccCard();
8288 if (uiccCard == null) {
8289 return false;
8290 }
8291 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8292 if (uiccProfile == null) {
8293 return false;
8294 }
8295 if (TelephonyManager.APPTYPE_SIM <= appType
8296 && appType <= TelephonyManager.APPTYPE_ISIM) {
8297 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8298 }
8299 return false;
8300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
8303 }
8304
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008305 /**
chen xub4baa772019-04-03 10:23:41 -07008306 * Get whether making changes to modem configurations will trigger reboot.
8307 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008308 */
8309 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008310 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8311 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008313 mApp, subId, callingPackage, callingFeatureId,
8314 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008315 return false;
8316 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008317 final long identity = Binder.clearCallingIdentity();
8318 try {
8319 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8320 } finally {
8321 Binder.restoreCallingIdentity(identity);
8322 }
8323 }
8324
Nathan Harold29f5f052019-02-15 13:41:57 -08008325 private void updateModemStateMetrics() {
8326 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8327 // TODO: check the state for each modem if the api is ready.
8328 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8329 }
8330
Pengquan Meng3889a572019-01-23 11:16:29 -08008331 @Override
8332 public int[] getSlotsMapping() {
8333 enforceReadPrivilegedPermission("getSlotsMapping");
8334
8335 final long identity = Binder.clearCallingIdentity();
8336 try {
8337 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8338 // All logical slots should have a mapping to a physical slot.
8339 int[] logicalSlotsMapping = new int[phoneCount];
8340 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8341 for (int i = 0; i < slotInfos.length; i++) {
8342 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8343 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8344 }
8345 }
8346 return logicalSlotsMapping;
8347 } finally {
8348 Binder.restoreCallingIdentity(identity);
8349 }
8350 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008351
8352 /**
8353 * Get the IRadio HAL Version
8354 */
8355 @Override
8356 public int getRadioHalVersion() {
8357 Phone phone = getDefaultPhone();
8358 if (phone == null) return -1;
8359 HalVersion hv = phone.getHalVersion();
8360 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8361 return hv.major * 100 + hv.minor;
8362 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008363
8364 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008365 * Get the current calling package name.
8366 * @return the current calling package name
8367 */
8368 @Override
8369 public String getCurrentPackageName() {
8370 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8371 }
8372
8373 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008374 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8375 * corresponding network requests on a subId.
8376 *
8377 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008378 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008379 * 2) APN is un-metered for this subscription, or
8380 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008381 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008382 *
8383 * @return whether data is allowed for a apn type.
8384 *
8385 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008386 */
8387 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008388 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008389 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8390 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008391
8392 // Now that all security checks passes, perform the operation as ourselves.
8393 final long identity = Binder.clearCallingIdentity();
8394 try {
8395 Phone phone = getPhone(subId);
8396 if (phone == null) return false;
8397
Jack Yu41407ee2019-05-13 16:54:09 -07008398 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008399 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8400 } finally {
8401 Binder.restoreCallingIdentity(identity);
8402 }
8403 }
8404
8405 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008406 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008407 enforceReadPrivilegedPermission("isApnMetered");
8408
8409 // Now that all security checks passes, perform the operation as ourselves.
8410 final long identity = Binder.clearCallingIdentity();
8411 try {
8412 Phone phone = getPhone(subId);
8413 if (phone == null) return true; // By default return true.
8414
Jack Yu41407ee2019-05-13 16:54:09 -07008415 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008416 } finally {
8417 Binder.restoreCallingIdentity(identity);
8418 }
8419 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008420
8421 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008422 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8423 int subscriptionId, IBooleanConsumer resultCallback) {
8424 enforceModifyPermission();
8425 long token = Binder.clearCallingIdentity();
8426 try {
8427 Phone phone = getPhone(subscriptionId);
8428 if (phone == null) {
8429 try {
8430 if (resultCallback != null) {
8431 resultCallback.accept(false);
8432 }
8433 } catch (RemoteException e) {
8434 // ignore
8435 }
8436 return;
8437 }
8438 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8439 Pair.create(specifiers, (x) -> {
8440 try {
8441 if (resultCallback != null) {
8442 resultCallback.accept(x);
8443 }
8444 } catch (RemoteException e) {
8445 // ignore
8446 }
8447 });
8448 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8449 } finally {
8450 Binder.restoreCallingIdentity(token);
8451 }
8452 }
8453
8454 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008455 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008456 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008457 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8458 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8459 if (iccRecords == null) {
8460 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8461 return false;
8462 }
8463 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8464 }
8465
8466 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008467 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8468 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008469 if (callingPackage == null) {
8470 callingPackage = getCurrentPackageName();
8471 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008472 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8473 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008474 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8475 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008476 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8477 }
8478 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8479 Intent intent = new Intent();
8480 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8481 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8482 // Bring up choose default SMS subscription dialog right now
8483 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8484 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8485 mApp.startActivity(intent);
8486 }
chen xud5ca2d52019-05-28 15:20:57 -07008487
8488 @Override
8489 public String getMmsUAProfUrl(int subId) {
8490 //TODO investigate if this API should require proper permission check in R b/133791609
8491 final long identity = Binder.clearCallingIdentity();
8492 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008493 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8494 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8495 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8496 return carrierUAProfUrl;
8497 }
chen xud5ca2d52019-05-28 15:20:57 -07008498 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8499 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8500 } finally {
8501 Binder.restoreCallingIdentity(identity);
8502 }
8503 }
8504
8505 @Override
8506 public String getMmsUserAgent(int subId) {
8507 //TODO investigate if this API should require proper permission check in R b/133791609
8508 final long identity = Binder.clearCallingIdentity();
8509 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008510 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8511 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8512 if (!TextUtils.isEmpty(carrierUserAgent)) {
8513 return carrierUserAgent;
8514 }
chen xud5ca2d52019-05-28 15:20:57 -07008515 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8516 .getString(com.android.internal.R.string.config_mms_user_agent);
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
8520 }
Jack Yub07d4972019-05-28 16:12:25 -07008521
8522 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008523 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8524 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8525
8526 final long identity = Binder.clearCallingIdentity();
8527 try {
8528 Phone phone = getPhone(subscriptionId);
8529 if (phone == null) return false;
8530
8531 switch (policy) {
8532 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8533 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8534 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8535 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8536 default:
8537 throw new IllegalArgumentException(policy + " is not a valid policy");
8538 }
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
8541 }
8542 }
8543
8544 @Override
8545 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8546 boolean enabled) {
8547 enforceModifyPermission();
8548
8549 final long identity = Binder.clearCallingIdentity();
8550 try {
8551 Phone phone = getPhone(subscriptionId);
8552 if (phone == null) return;
8553
8554 switch (policy) {
8555 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8556 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8557 break;
8558 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8559 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8560 break;
8561 default:
8562 throw new IllegalArgumentException(policy + " is not a valid policy");
8563 }
8564 } finally {
8565 Binder.restoreCallingIdentity(identity);
8566 }
8567 }
8568
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008569 /**
Hall Liub48cf452020-09-25 11:13:49 -07008570 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008571 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8572 * otherwise.
8573 */
8574 @Override
8575 public void setCepEnabled(boolean isCepEnabled) {
8576 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8577
8578 final long identity = Binder.clearCallingIdentity();
8579 try {
8580 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8581 for (Phone phone : PhoneFactory.getPhones()) {
8582 Phone defaultPhone = phone.getImsPhone();
8583 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8584 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8585 ImsPhoneCallTracker imsPhoneCallTracker =
8586 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8587 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8588 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8589 + imsPhone.getMsisdn());
8590 }
8591 }
8592 } finally {
8593 Binder.restoreCallingIdentity(identity);
8594 }
8595 }
allenwtsu46dcc572020-01-08 18:24:03 +08008596
8597 /**
8598 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8599 *
8600 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8601 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8602 * before being read.
8603 */
8604 @Override
8605 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8606 isCompressed) {
8607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8608 mApp, subId, "notifyRcsAutoConfigurationReceived");
8609 try {
8610 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8611 if (configBinder == null) {
8612 Rlog.e(LOG_TAG, "null result for getImsConfig");
8613 } else {
8614 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8615 }
8616 } catch (RemoteException e) {
8617 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8618 }
8619 }
zoey chenf95ca592019-12-30 16:11:23 +08008620
8621 @Override
8622 public boolean isIccLockEnabled(int subId) {
8623 enforceReadPrivilegedPermission("isIccLockEnabled");
8624
8625 // Now that all security checks passes, perform the operation as ourselves.
8626 final long identity = Binder.clearCallingIdentity();
8627 try {
8628 Phone phone = getPhone(subId);
8629 if (phone != null && phone.getIccCard() != null) {
8630 return phone.getIccCard().getIccLockEnabled();
8631 } else {
8632 return false;
8633 }
8634 } finally {
8635 Binder.restoreCallingIdentity(identity);
8636 }
8637 }
8638
8639 /**
zoey chene02881a2019-12-30 16:11:23 +08008640 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008641 *
zoey chene02881a2019-12-30 16:11:23 +08008642 * @return an integer representing the status of IccLock enabled or disabled in the following
8643 * three cases:
8644 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8645 * successfully.
8646 * - Positive number and zero for remaining password attempts.
8647 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008648 *
8649 */
8650 @Override
8651 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8652 enforceModifyPermission();
8653
8654 Phone phone = getPhone(subId);
8655 if (phone == null) {
8656 return 0;
8657 }
8658 // Now that all security checks passes, perform the operation as ourselves.
8659 final long identity = Binder.clearCallingIdentity();
8660 try {
8661 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8662 new Pair<Boolean, String>(enabled, password), phone, null);
8663 return attemptsRemaining;
8664
8665 } catch (Exception e) {
8666 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8667 } finally {
8668 Binder.restoreCallingIdentity(identity);
8669 }
8670 return 0;
8671 }
8672
8673 /**
8674 * Change the ICC password used in ICC pin lock.
8675 *
zoey chene02881a2019-12-30 16:11:23 +08008676 * @return an integer representing the status of IccLock changed in the following three cases:
8677 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8678 * - Positive number and zero for remaining password attempts.
8679 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008680 *
8681 */
8682 @Override
8683 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8684 enforceModifyPermission();
8685
8686 Phone phone = getPhone(subId);
8687 if (phone == null) {
8688 return 0;
8689 }
8690 // Now that all security checks passes, perform the operation as ourselves.
8691 final long identity = Binder.clearCallingIdentity();
8692 try {
8693 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8694 new Pair<String, String>(oldPassword, newPassword), phone, null);
8695 return attemptsRemaining;
8696
8697 } catch (Exception e) {
8698 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
8702 return 0;
8703 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008704
Peter Wangdafb9ac2020-01-15 14:13:38 -08008705 /**
8706 * Request for receiving user activity notification
8707 */
8708 @Override
8709 public void requestUserActivityNotification() {
8710 if (!mNotifyUserActivity.get()
8711 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8712 mNotifyUserActivity.set(true);
8713 }
8714 }
8715
8716 /**
8717 * Called when userActivity is signalled in the power manager.
8718 * This is safe to call from any thread, with any window manager locks held or not.
8719 */
8720 @Override
8721 public void userActivity() {
8722 // ***************************************
8723 // * Inherited from PhoneWindowManager *
8724 // ***************************************
8725 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8726 // WITH ITS LOCKS HELD.
8727 //
8728 // This code must be VERY careful about the locks
8729 // it acquires.
8730 // In fact, the current code acquires way too many,
8731 // and probably has lurking deadlocks.
8732
8733 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8734 throw new SecurityException("Only the OS may call notifyUserActivity()");
8735 }
8736
8737 if (mNotifyUserActivity.getAndSet(false)) {
8738 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8739 USER_ACTIVITY_NOTIFICATION_DELAY);
8740 }
8741 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008742
Malcolm Chen884180b2020-04-13 11:59:40 -07008743 @Override
8744 public boolean canConnectTo5GInDsdsMode() {
8745 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8746 }
Jack Yud10cdd42020-09-28 20:28:01 -07008747
8748 @Override
8749 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8750 String callingFeatureId) {
8751 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8752 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8753 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8754 }
8755
8756 Phone phone = getPhone(subId);
8757 if (phone == null) {
8758 throw new RuntimeException("phone is not available");
8759 }
8760 // Now that all security checks passes, perform the operation as ourselves.
8761 final long identity = Binder.clearCallingIdentity();
8762 try {
8763 return phone.getEquivalentHomePlmns();
8764 } finally {
8765 Binder.restoreCallingIdentity(identity);
8766 }
8767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008768}