blob: d0a4b69b6a0e48842099bbaa66599b21e0d95b2b [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800123import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800130import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800132import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800133import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700134import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800135import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800137import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700138import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700139import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700142import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800143import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700144import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700145import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700146import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700147import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700148import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700149import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700150import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700151import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800152import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800153import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700155import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800156import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700157import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800158import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700159import com.android.internal.telephony.imsphone.ImsPhone;
160import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800161import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800164import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700167import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800170import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000171import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800172import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700173import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800174import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700175import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800177import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700178import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700179import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800180import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800181
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700182import java.io.FileDescriptor;
183import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800185import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800186import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800187import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800188import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100189import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800190import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700191import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800192import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800193import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800194import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196/**
197 * Implementation of the ITelephony interface.
198 */
Santos Cordon117fee72014-05-16 17:56:12 -0700199public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200 private static final String LOG_TAG = "PhoneInterfaceManager";
201 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
202 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204
205 // Message codes used with mMainThreadHandler
206 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700207 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
208 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700209 private static final int CMD_OPEN_CHANNEL = 9;
210 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
211 private static final int CMD_CLOSE_CHANNEL = 11;
212 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800213 private static final int CMD_NV_READ_ITEM = 13;
214 private static final int EVENT_NV_READ_ITEM_DONE = 14;
215 private static final int CMD_NV_WRITE_ITEM = 15;
216 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
217 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
218 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700219 private static final int CMD_RESET_MODEM_CONFIG = 19;
220 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800221 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
222 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
223 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
224 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800225 private static final int CMD_SEND_ENVELOPE = 25;
226 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000227 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
228 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700229 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
230 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
231 private static final int CMD_EXCHANGE_SIM_IO = 31;
232 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800233 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
234 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700235 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700237 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
238 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700239 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
240 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
241 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
242 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700243 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
244 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
245 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
246 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700247 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800248 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
249 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000250 private static final int CMD_SWITCH_SLOTS = 50;
251 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700252 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
253 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
254 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
255 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
256 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
257 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
258 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
259 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700260 private static final int CMD_GET_ALL_CELL_INFO = 60;
261 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
262 private static final int CMD_GET_CELL_LOCATION = 62;
263 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_MODEM_REBOOT = 64;
265 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700266 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
267 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800268 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
269 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700270 private static final int CMD_GET_MODEM_STATUS = 70;
271 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700272 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
273 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700274 private static final int CMD_ERASE_MODEM_CONFIG = 74;
275 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800276 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
277 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
278 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
279 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800280 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
281 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800282 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800283 private static final int CMD_GET_CALL_FORWARDING = 83;
284 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
285 private static final int CMD_SET_CALL_FORWARDING = 85;
286 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
287 private static final int CMD_GET_CALL_WAITING = 87;
288 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
289 private static final int CMD_SET_CALL_WAITING = 89;
290 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800292 // Parameters of select command.
293 private static final int SELECT_COMMAND = 0xA4;
294 private static final int SELECT_P1 = 0x04;
295 private static final int SELECT_P2 = 0;
296 private static final int SELECT_P3 = 0x10;
297
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298 /** The singleton instance. */
299 private static PhoneInterfaceManager sInstance;
300
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800303 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700304 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800305 private AppOpsManager mAppOps;
306 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800307 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800308 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700309 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310
Peter Wangdafb9ac2020-01-15 14:13:38 -0800311 /** User Activity */
312 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
314
Derek Tan97ebb422014-09-05 16:55:38 -0700315 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
316 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800317 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800318 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700319
Michelecea4cf22018-12-21 15:00:11 -0800320 // String to store multi SIM allowed
321 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
322
Derek Tan740e1672017-06-27 14:56:27 -0700323 // The AID of ISD-R.
324 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
325
yinxub1bed742017-04-17 11:45:04 -0700326 private NetworkScanRequestTracker mNetworkScanRequestTracker;
327
David Kelly5e06a7f2018-03-12 14:10:59 +0000328 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
329 private static final int MANUFACTURER_CODE_LENGTH = 8;
330
Derek Tan89e89d42014-07-08 17:00:10 -0700331 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700332 * Experiment flag to enable erase modem config on reset network, default value is false
333 */
334 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
335 "reset_network_erase_modem_config_enabled";
336
337 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700338 * A request object to use for transmitting data to an ICC.
339 */
340 private static final class IccAPDUArgument {
341 public int channel, cla, command, p1, p2, p3;
342 public String data;
343
344 public IccAPDUArgument(int channel, int cla, int command,
345 int p1, int p2, int p3, String data) {
346 this.channel = channel;
347 this.cla = cla;
348 this.command = command;
349 this.p1 = p1;
350 this.p2 = p2;
351 this.p3 = p3;
352 this.data = data;
353 }
354 }
355
356 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700357 * A request object to use for transmitting data to an ICC.
358 */
359 private static final class ManualNetworkSelectionArgument {
360 public OperatorInfo operatorInfo;
361 public boolean persistSelection;
362
363 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
364 this.operatorInfo = operatorInfo;
365 this.persistSelection = persistSelection;
366 }
367 }
368
369 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
371 * request after sending. The main thread will notify the request when it is complete.
372 */
373 private static final class MainThreadRequest {
374 /** The argument to use for the request */
375 public Object argument;
376 /** The result of the request that is run on the main thread */
377 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800378 // The subscriber id that this request applies to. Defaults to
379 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
380 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Nathan Harold92bed182018-10-12 18:16:49 -0700382 // In cases where subId is unavailable, the caller needs to specify the phone.
383 public Phone phone;
384
vagdeviaf9a5b92018-08-15 16:01:53 -0700385 public WorkSource workSource;
386
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 public MainThreadRequest(Object argument) {
388 this.argument = argument;
389 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800390
Nathan Harold92bed182018-10-12 18:16:49 -0700391 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
392 this.argument = argument;
393 if (phone != null) {
394 this.phone = phone;
395 }
396 this.workSource = workSource;
397 }
398
vagdeviaf9a5b92018-08-15 16:01:53 -0700399 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800400 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800401 if (subId != null) {
402 this.subId = subId;
403 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700404 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 }
407
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800408 private static final class IncomingThirdPartyCallArgs {
409 public final ComponentName component;
410 public final String callId;
411 public final String callerDisplayName;
412
413 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
414 String callerDisplayName) {
415 this.component = component;
416 this.callId = callId;
417 this.callerDisplayName = callerDisplayName;
418 }
419 }
420
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 /**
422 * A handler that processes messages on the main thread in the phone process. Since many
423 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
424 * inbound binder threads to the main thread in the phone process. The Binder thread
425 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
426 * on, which will be notified when the operation completes and will contain the result of the
427 * request.
428 *
429 * <p>If a MainThreadRequest object is provided in the msg.obj field,
430 * note that request.result must be set to something non-null for the calling thread to
431 * unblock.
432 */
433 private final class MainThreadHandler extends Handler {
434 @Override
435 public void handleMessage(Message msg) {
436 MainThreadRequest request;
437 Message onCompleted;
438 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800439 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800441 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442
443 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700444 case CMD_HANDLE_USSD_REQUEST: {
445 request = (MainThreadRequest) msg.obj;
446 final Phone phone = getPhoneFromRequest(request);
447 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
448 String ussdRequest = ussdObject.first;
449 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700450
Pengquan Menga1bb6272018-09-06 09:59:22 -0700451 if (!isUssdApiAllowed(request.subId)) {
452 // Carrier does not support use of this API, return failure.
453 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
454 UssdResponse response = new UssdResponse(ussdRequest, null);
455 Bundle returnData = new Bundle();
456 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
457 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700458
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 request.result = true;
460 notifyRequester(request);
461 return;
462 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700463
Pengquan Menga1bb6272018-09-06 09:59:22 -0700464 try {
465 request.result = phone != null
466 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
467 } catch (CallStateException cse) {
468 request.result = false;
469 }
470 // Wake up the requesting thread
471 notifyRequester(request);
472 break;
pkanwar32d516d2016-10-14 19:37:38 -0700473 }
474
Yorke Lee716f67e2015-06-17 15:39:16 -0700475 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700477 final Phone phone = getPhoneFromRequest(request);
478 request.result = phone != null ?
479 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
480 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 if (uiccCard == null) {
491 loge("iccTransmitApduLogicalChannel: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700494 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
496 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 iccArgument.channel, iccArgument.cla, iccArgument.command,
499 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700500 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700501 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700502 break;
503
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 ar = (AsyncResult) msg.obj;
506 request = (MainThreadRequest) ar.userObj;
507 if (ar.exception == null && ar.result != null) {
508 request.result = ar.result;
509 } else {
510 request.result = new IccIoResult(0x6F, 0, (byte[])null);
511 if (ar.result == null) {
512 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800513 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700514 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800515 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 } else {
517 loge("iccTransmitApduLogicalChannel: Unknown exception");
518 }
519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700521 break;
522
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
524 request = (MainThreadRequest) msg.obj;
525 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800526 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 if (uiccCard == null) {
528 loge("iccTransmitApduBasicChannel: No UICC");
529 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 } else {
532 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
533 request);
534 uiccCard.iccTransmitApduBasicChannel(
535 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
536 iccArgument.p3, iccArgument.data, onCompleted);
537 }
538 break;
539
540 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
541 ar = (AsyncResult) msg.obj;
542 request = (MainThreadRequest) ar.userObj;
543 if (ar.exception == null && ar.result != null) {
544 request.result = ar.result;
545 } else {
546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
547 if (ar.result == null) {
548 loge("iccTransmitApduBasicChannel: Empty response");
549 } else if (ar.exception instanceof CommandException) {
550 loge("iccTransmitApduBasicChannel: CommandException: " +
551 ar.exception);
552 } else {
553 loge("iccTransmitApduBasicChannel: Unknown exception");
554 }
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 break;
558
559 case CMD_EXCHANGE_SIM_IO:
560 request = (MainThreadRequest) msg.obj;
561 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 if (uiccCard == null) {
564 loge("iccExchangeSimIO: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
569 request);
570 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
571 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
572 iccArgument.data, onCompleted);
573 }
574 break;
575
576 case EVENT_EXCHANGE_SIM_IO_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
581 } else {
582 request.result = new IccIoResult(0x6f, 0, (byte[])null);
583 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 break;
586
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 case CMD_SEND_ENVELOPE:
588 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800589 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 if (uiccCard == null) {
591 loge("sendEnvelopeWithStatus: No UICC");
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
595 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
596 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
597 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800598 break;
599
600 case EVENT_SEND_ENVELOPE_DONE:
601 ar = (AsyncResult) msg.obj;
602 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700603 if (ar.exception == null && ar.result != null) {
604 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800605 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700606 request.result = new IccIoResult(0x6F, 0, (byte[])null);
607 if (ar.result == null) {
608 loge("sendEnvelopeWithStatus: Empty response");
609 } else if (ar.exception instanceof CommandException) {
610 loge("sendEnvelopeWithStatus: CommandException: " +
611 ar.exception);
612 } else {
613 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
614 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800615 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800617 break;
618
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 case CMD_OPEN_CHANNEL:
620 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800621 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800622 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 if (uiccCard == null) {
624 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800625 request.result = new IccOpenLogicalChannelResponse(-1,
626 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 } else {
629 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800630 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
631 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 break;
634
635 case EVENT_OPEN_CHANNEL_DONE:
636 ar = (AsyncResult) msg.obj;
637 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 int[] result = (int[]) ar.result;
641 int channelId = result[0];
642 byte[] selectResponse = null;
643 if (result.length > 1) {
644 selectResponse = new byte[result.length - 1];
645 for (int i = 1; i < result.length; ++i) {
646 selectResponse[i - 1] = (byte) result[i];
647 }
648 }
649 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700650 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 if (ar.result == null) {
653 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 if (ar.exception != null) {
656 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
657 }
658
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700659 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700660 if (ar.exception instanceof CommandException) {
661 CommandException.Error error =
662 ((CommandException) (ar.exception)).getCommandError();
663 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700664 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700665 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700666 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 }
668 }
669 openChannelResp = new IccOpenLogicalChannelResponse(
670 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700672 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 break;
675
676 case CMD_CLOSE_CHANNEL:
677 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800678 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 if (uiccCard == null) {
680 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900681 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700682 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 } else {
684 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
685 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
686 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 break;
688
689 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800690 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
691 break;
692
693 case CMD_NV_READ_ITEM:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
697 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 ar = (AsyncResult) msg.obj;
702 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800703 if (ar.exception == null && ar.result != null) {
704 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800706 request.result = "";
707 if (ar.result == null) {
708 loge("nvReadItem: Empty response");
709 } else if (ar.exception instanceof CommandException) {
710 loge("nvReadItem: CommandException: " +
711 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800713 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 }
715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 break;
718
Jake Hambye994d462014-02-03 13:10:13 -0800719 case CMD_NV_WRITE_ITEM:
720 request = (MainThreadRequest) msg.obj;
721 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
722 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800723 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700724 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800725 break;
726
727 case EVENT_NV_WRITE_ITEM_DONE:
728 handleNullReturnEvent(msg, "nvWriteItem");
729 break;
730
731 case CMD_NV_WRITE_CDMA_PRL:
732 request = (MainThreadRequest) msg.obj;
733 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800734 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800735 break;
736
737 case EVENT_NV_WRITE_CDMA_PRL_DONE:
738 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
739 break;
740
chen xu6dac5ab2018-10-26 17:39:23 -0700741 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800742 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700743 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800744 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800745 break;
746
chen xu6dac5ab2018-10-26 17:39:23 -0700747 case EVENT_RESET_MODEM_CONFIG_DONE:
748 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800749 break;
750
Jake Hamby7c27be32014-03-03 13:25:59 -0800751 case CMD_GET_PREFERRED_NETWORK_TYPE:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700754 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800755 break;
756
757 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
758 ar = (AsyncResult) msg.obj;
759 request = (MainThreadRequest) ar.userObj;
760 if (ar.exception == null && ar.result != null) {
761 request.result = ar.result; // Integer
762 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800763 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800764 if (ar.result == null) {
765 loge("getPreferredNetworkType: Empty response");
766 } else if (ar.exception instanceof CommandException) {
767 loge("getPreferredNetworkType: CommandException: " +
768 ar.exception);
769 } else {
770 loge("getPreferredNetworkType: Unknown exception");
771 }
772 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800774 break;
775
776 case CMD_SET_PREFERRED_NETWORK_TYPE:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
779 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700780 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800781 break;
782
783 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
784 handleNullReturnEvent(msg, "setPreferredNetworkType");
785 break;
786
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000787 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
788 request = (MainThreadRequest)msg.obj;
789 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800790 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000791 break;
792
793 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
794 ar = (AsyncResult)msg.obj;
795 request = (MainThreadRequest)ar.userObj;
796 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700797 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000798 break;
799
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800800 case CMD_SET_VOICEMAIL_NUMBER:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
803 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800804 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
805 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800806 break;
807
808 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
809 handleNullReturnEvent(msg, "setVoicemailNumber");
810 break;
811
Stuart Scott54788802015-03-30 13:18:01 -0700812 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
815 request);
816 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
817 break;
818
819 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
820 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
821 break;
822
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 case CMD_PERFORM_NETWORK_SCAN:
824 request = (MainThreadRequest) msg.obj;
825 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
826 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
827 break;
828
Shuo Qian4a594052020-01-23 11:59:30 -0800829 case CMD_GET_CALL_FORWARDING:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
832 int callForwardingReason = (Integer) request.argument;
833 getPhoneFromRequest(request).getCallForwardingOption(
834 callForwardingReason, onCompleted);
835 break;
836
837 case EVENT_GET_CALL_FORWARDING_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 CallForwardingInfo callForwardingInfo = null;
841 if (ar.exception == null && ar.result != null) {
842 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
843 for (CallForwardInfo callForwardInfo : callForwardInfos) {
844 // Service Class is a bit mask per 3gpp 27.007. Search for
845 // any service for voice call.
846 if ((callForwardInfo.serviceClass
847 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
848 callForwardingInfo = new CallForwardingInfo(
849 callForwardInfo.serviceClass, callForwardInfo.reason,
850 callForwardInfo.number,
851 callForwardInfo.timeSeconds);
852 break;
853 }
854 }
855 // Didn't find a call forward info for voice call.
856 if (callForwardingInfo == null) {
857 callForwardingInfo = new CallForwardingInfo(
858 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
859 0 /* reason */, null /* number */, 0 /* timeout */);
860 }
861 } else {
862 if (ar.result == null) {
863 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
864 }
865 if (ar.exception != null) {
866 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
867 }
868 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
869 if (ar.exception instanceof CommandException) {
870 CommandException.Error error =
871 ((CommandException) (ar.exception)).getCommandError();
872 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
873 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
874 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
875 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
876 }
877 }
878 callForwardingInfo = new CallForwardingInfo(
879 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
880 }
881 request.result = callForwardingInfo;
882 notifyRequester(request);
883 break;
884
885 case CMD_SET_CALL_FORWARDING:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
888 CallForwardingInfo callForwardingInfoToSet =
889 (CallForwardingInfo) request.argument;
890 getPhoneFromRequest(request).setCallForwardingOption(
891 callForwardingInfoToSet.getStatus(),
892 callForwardingInfoToSet.getReason(),
893 callForwardingInfoToSet.getNumber(),
894 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
895 break;
896
897 case EVENT_SET_CALL_FORWARDING_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null) {
901 request.result = true;
902 } else {
903 request.result = false;
904 loge("setCallForwarding exception: " + ar.exception);
905 }
906 notifyRequester(request);
907 break;
908
909 case CMD_GET_CALL_WAITING:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
912 getPhoneFromRequest(request).getCallWaiting(onCompleted);
913 break;
914
915 case EVENT_GET_CALL_WAITING_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
919 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800920 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800921 // Service Class is a bit mask per 3gpp 27.007.
922 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800923 if (callForwardResults.length > 1
924 && ((callForwardResults[1]
925 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
926 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800927 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
928 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
929 } else {
930 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
931 }
932 } else {
933 if (ar.result == null) {
934 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
935 }
936 if (ar.exception != null) {
937 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
938 }
939 if (ar.exception instanceof CommandException) {
940 CommandException.Error error =
941 ((CommandException) (ar.exception)).getCommandError();
942 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
943 callForwardingStatus =
944 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
945 }
946 }
947 }
948 request.result = callForwardingStatus;
949 notifyRequester(request);
950 break;
951
952 case CMD_SET_CALL_WAITING:
953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
955 boolean isEnable = (Boolean) request.argument;
956 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
957 break;
958
959 case EVENT_SET_CALL_WAITING_DONE:
960 ar = (AsyncResult) msg.obj;
961 request = (MainThreadRequest) ar.userObj;
962 if (ar.exception == null) {
963 request.result = true;
964 } else {
965 request.result = false;
966 loge("setCallWaiting exception: " + ar.exception);
967 }
968 notifyRequester(request);
969 break;
970
Shishir Agrawal302c8692015-06-19 13:49:39 -0700971 case EVENT_PERFORM_NETWORK_SCAN_DONE:
972 ar = (AsyncResult) msg.obj;
973 request = (MainThreadRequest) ar.userObj;
974 CellNetworkScanResult cellScanResult;
975 if (ar.exception == null && ar.result != null) {
976 cellScanResult = new CellNetworkScanResult(
977 CellNetworkScanResult.STATUS_SUCCESS,
978 (List<OperatorInfo>) ar.result);
979 } else {
980 if (ar.result == null) {
981 loge("getCellNetworkScanResults: Empty response");
982 }
983 if (ar.exception != null) {
984 loge("getCellNetworkScanResults: Exception: " + ar.exception);
985 }
986 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
987 if (ar.exception instanceof CommandException) {
988 CommandException.Error error =
989 ((CommandException) (ar.exception)).getCommandError();
990 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
991 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
992 } else if (error == CommandException.Error.GENERIC_FAILURE) {
993 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
994 }
995 }
996 cellScanResult = new CellNetworkScanResult(errorCode, null);
997 }
998 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700999 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001000 break;
1001
1002 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1003 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001004 ManualNetworkSelectionArgument selArg =
1005 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001006 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1007 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001008 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1009 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001010 break;
1011
1012 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception == null) {
1016 request.result = true;
1017 } else {
1018 request.result = false;
1019 loge("setNetworkSelectionModeManual " + ar.exception);
1020 }
1021 notifyRequester(request);
1022 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001023 break;
1024
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001025 case CMD_GET_MODEM_ACTIVITY_INFO:
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001028 if (defaultPhone != null) {
1029 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
1030 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001031 break;
1032
1033 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1034 ar = (AsyncResult) msg.obj;
1035 request = (MainThreadRequest) ar.userObj;
1036 if (ar.exception == null && ar.result != null) {
1037 request.result = ar.result;
1038 } else {
1039 if (ar.result == null) {
1040 loge("queryModemActivityInfo: Empty response");
1041 } else if (ar.exception instanceof CommandException) {
1042 loge("queryModemActivityInfo: CommandException: " +
1043 ar.exception);
1044 } else {
1045 loge("queryModemActivityInfo: Unknown exception");
1046 }
1047 }
Amit Mahajand4766222016-01-28 15:28:28 -08001048 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
1049 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -08001050 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -08001051 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001052 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001053 break;
1054
Meng Wang1a7c35a2016-05-05 20:56:15 -07001055 case CMD_SET_ALLOWED_CARRIERS:
1056 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001057 CarrierRestrictionRules argument =
1058 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001059 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001060 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001061 break;
1062
1063 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
1066 if (ar.exception == null && ar.result != null) {
1067 request.result = ar.result;
1068 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001069 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1070 if (ar.exception instanceof CommandException) {
1071 loge("setAllowedCarriers: CommandException: " + ar.exception);
1072 CommandException.Error error =
1073 ((CommandException) (ar.exception)).getCommandError();
1074 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1075 request.result =
1076 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1077 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001078 } else {
1079 loge("setAllowedCarriers: Unknown exception");
1080 }
1081 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001082 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001083 break;
1084
1085 case CMD_GET_ALLOWED_CARRIERS:
1086 request = (MainThreadRequest) msg.obj;
1087 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001088 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001089 break;
1090
1091 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1092 ar = (AsyncResult) msg.obj;
1093 request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null && ar.result != null) {
1095 request.result = ar.result;
1096 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001097 request.result = new IllegalStateException(
1098 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001099 if (ar.result == null) {
1100 loge("getAllowedCarriers: Empty response");
1101 } else if (ar.exception instanceof CommandException) {
1102 loge("getAllowedCarriers: CommandException: " +
1103 ar.exception);
1104 } else {
1105 loge("getAllowedCarriers: Unknown exception");
1106 }
1107 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001108 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001109 break;
1110
Nathan Haroldb3014052017-01-25 15:57:32 -08001111 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1112 ar = (AsyncResult) msg.obj;
1113 request = (MainThreadRequest) ar.userObj;
1114 if (ar.exception == null && ar.result != null) {
1115 request.result = ar.result;
1116 } else {
1117 request.result = new IllegalArgumentException(
1118 "Failed to retrieve Forbidden Plmns");
1119 if (ar.result == null) {
1120 loge("getForbiddenPlmns: Empty response");
1121 } else {
1122 loge("getForbiddenPlmns: Unknown exception");
1123 }
1124 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001125 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001126 break;
1127
1128 case CMD_GET_FORBIDDEN_PLMNS:
1129 request = (MainThreadRequest) msg.obj;
1130 uiccCard = getUiccCardFromRequest(request);
1131 if (uiccCard == null) {
1132 loge("getForbiddenPlmns() UiccCard is null");
1133 request.result = new IllegalArgumentException(
1134 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001135 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001136 break;
1137 }
1138 Integer appType = (Integer) request.argument;
1139 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1140 if (uiccApp == null) {
1141 loge("getForbiddenPlmns() no app with specified type -- "
1142 + appType);
1143 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001144 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001145 break;
1146 } else {
1147 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1148 + " specified type -- " + appType);
1149 }
1150 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1151 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1152 onCompleted);
1153 break;
1154
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001155 case CMD_SWITCH_SLOTS:
1156 request = (MainThreadRequest) msg.obj;
1157 int[] physicalSlots = (int[]) request.argument;
1158 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1159 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1160 break;
1161
1162 case EVENT_SWITCH_SLOTS_DONE:
1163 ar = (AsyncResult) msg.obj;
1164 request = (MainThreadRequest) ar.userObj;
1165 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001166 notifyRequester(request);
1167 break;
1168 case CMD_GET_NETWORK_SELECTION_MODE:
1169 request = (MainThreadRequest) msg.obj;
1170 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1171 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1172 break;
1173
1174 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1175 ar = (AsyncResult) msg.obj;
1176 request = (MainThreadRequest) ar.userObj;
1177 if (ar.exception != null) {
1178 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1179 } else {
1180 int mode = ((int[]) ar.result)[0];
1181 if (mode == 0) {
1182 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1183 } else {
1184 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1185 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001186 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001187 notifyRequester(request);
1188 break;
1189 case CMD_GET_CDMA_ROAMING_MODE:
1190 request = (MainThreadRequest) msg.obj;
1191 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1192 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1193 break;
1194 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1195 ar = (AsyncResult) msg.obj;
1196 request = (MainThreadRequest) ar.userObj;
1197 if (ar.exception != null) {
1198 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1199 } else {
1200 request.result = ((int[]) ar.result)[0];
1201 }
1202 notifyRequester(request);
1203 break;
1204 case CMD_SET_CDMA_ROAMING_MODE:
1205 request = (MainThreadRequest) msg.obj;
1206 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1207 int mode = (int) request.argument;
1208 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1209 break;
1210 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
1213 request.result = ar.exception == null;
1214 notifyRequester(request);
1215 break;
1216 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1217 request = (MainThreadRequest) msg.obj;
1218 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1219 int subscriptionMode = (int) request.argument;
1220 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1221 break;
1222 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1223 ar = (AsyncResult) msg.obj;
1224 request = (MainThreadRequest) ar.userObj;
1225 request.result = ar.exception == null;
1226 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001227 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001228 case CMD_GET_ALL_CELL_INFO:
1229 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001230 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001231 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001232 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001233 case EVENT_GET_ALL_CELL_INFO_DONE:
1234 ar = (AsyncResult) msg.obj;
1235 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001236 // If a timeout occurs, the response will be null
1237 request.result = (ar.exception == null && ar.result != null)
1238 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001239 synchronized (request) {
1240 request.notifyAll();
1241 }
1242 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001243 case CMD_REQUEST_CELL_INFO_UPDATE:
1244 request = (MainThreadRequest) msg.obj;
1245 request.phone.requestCellInfoUpdate(request.workSource,
1246 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1247 break;
1248 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1249 ar = (AsyncResult) msg.obj;
1250 request = (MainThreadRequest) ar.userObj;
1251 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1252 try {
1253 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001254 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001255 cb.onError(
1256 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1257 ar.exception.getClass().getName(),
1258 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001259 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001260 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001261 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001262 } else {
1263 // use the result as returned
1264 cb.onCellInfo((List<CellInfo>) ar.result);
1265 }
1266 } catch (RemoteException re) {
1267 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1268 }
1269 break;
1270 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001271 request = (MainThreadRequest) msg.obj;
1272 WorkSource ws = (WorkSource) request.argument;
1273 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001274 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001275 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001276 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001277 ar = (AsyncResult) msg.obj;
1278 request = (MainThreadRequest) ar.userObj;
1279 if (ar.exception == null) {
1280 request.result = ar.result;
1281 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001282 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001283 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001284 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001285 }
1286
1287 synchronized (request) {
1288 request.notifyAll();
1289 }
1290 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001291 case CMD_MODEM_REBOOT:
1292 request = (MainThreadRequest) msg.obj;
1293 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001294 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001295 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001296 case EVENT_CMD_MODEM_REBOOT_DONE:
1297 handleNullReturnEvent(msg, "rebootModem");
1298 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001299 case CMD_REQUEST_ENABLE_MODEM:
1300 request = (MainThreadRequest) msg.obj;
1301 boolean enable = (boolean) request.argument;
1302 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001303 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001304 PhoneConfigurationManager.getInstance()
1305 .enablePhone(request.phone, enable, onCompleted);
1306 break;
1307 case EVENT_ENABLE_MODEM_DONE:
1308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
1310 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001311 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001312 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001313 if ((boolean) request.result) {
1314 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1315 updateModemStateMetrics();
1316 } else {
1317 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1318 + ar.exception);
1319 }
1320 notifyRequester(request);
1321 break;
1322 case CMD_GET_MODEM_STATUS:
1323 request = (MainThreadRequest) msg.obj;
1324 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1325 PhoneConfigurationManager.getInstance()
1326 .getPhoneStatusFromModem(request.phone, onCompleted);
1327 break;
1328 case EVENT_GET_MODEM_STATUS_DONE:
1329 ar = (AsyncResult) msg.obj;
1330 request = (MainThreadRequest) ar.userObj;
1331 int id = request.phone.getPhoneId();
1332 if (ar.exception == null && ar.result != null) {
1333 request.result = ar.result;
1334 //update the cache as modem status has changed
1335 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1336 (boolean) request.result);
1337 } else {
1338 // Return true if modem status cannot be retrieved. For most cases,
1339 // modem status is on. And for older version modems, GET_MODEM_STATUS
1340 // and disable modem are not supported. Modem is always on.
1341 // TODO: this should be fixed in R to support a third
1342 // status UNKNOWN b/131631629
1343 request.result = true;
1344 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1345 + ar.exception);
1346 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001347 notifyRequester(request);
1348 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001349 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1350 request = (MainThreadRequest) msg.obj;
1351 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1352 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1353 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1354 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1355 break;
1356 }
1357 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1358 ar = (AsyncResult) msg.obj;
1359 request = (MainThreadRequest) ar.userObj;
1360 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1361 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1362 args.second.accept(ar.exception == null);
1363 notifyRequester(request);
1364 break;
1365 }
yincheng zhao2737e882019-09-06 17:06:54 -07001366 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1367 ar = (AsyncResult) msg.obj;
1368 request = (MainThreadRequest) ar.userObj;
1369 if (ar.exception == null && ar.result != null) {
1370 request.result = ar.result;
1371 } else {
1372 request.result = -1;
1373 loge("Failed to set Forbidden Plmns");
1374 if (ar.result == null) {
1375 loge("setForbidenPlmns: Empty response");
1376 } else if (ar.exception != null) {
1377 loge("setForbiddenPlmns: Exception: " + ar.exception);
1378 request.result = -1;
1379 } else {
1380 loge("setForbiddenPlmns: Unknown exception");
1381 }
1382 }
1383 notifyRequester(request);
1384 break;
1385 case CMD_SET_FORBIDDEN_PLMNS:
1386 request = (MainThreadRequest) msg.obj;
1387 uiccCard = getUiccCardFromRequest(request);
1388 if (uiccCard == null) {
1389 loge("setForbiddenPlmns: UiccCard is null");
1390 request.result = -1;
1391 notifyRequester(request);
1392 break;
1393 }
1394 Pair<Integer, List<String>> setFplmnsArgs =
1395 (Pair<Integer, List<String>>) request.argument;
1396 appType = setFplmnsArgs.first;
1397 List<String> fplmns = setFplmnsArgs.second;
1398 uiccApp = uiccCard.getApplicationByType(appType);
1399 if (uiccApp == null) {
1400 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1401 request.result = -1;
1402 loge("Failed to get UICC App");
1403 notifyRequester(request);
1404 } else {
1405 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1406 ((SIMRecords) uiccApp.getIccRecords())
1407 .setForbiddenPlmns(onCompleted, fplmns);
1408 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001409 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001410 case CMD_ERASE_MODEM_CONFIG:
1411 request = (MainThreadRequest) msg.obj;
1412 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1413 defaultPhone.eraseModemConfig(onCompleted);
1414 break;
1415 case EVENT_ERASE_MODEM_CONFIG_DONE:
1416 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001417 break;
zoey chene02881a2019-12-30 16:11:23 +08001418
1419 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1422 Pair<String, String> changed = (Pair<String, String>) request.argument;
1423 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1424 changed.first, changed.second, onCompleted);
1425 break;
1426 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1427 ar = (AsyncResult) msg.obj;
1428 request = (MainThreadRequest) ar.userObj;
1429 if (ar.exception == null) {
1430 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1431 } else {
1432 request.result = msg.arg1;
1433 }
1434 notifyRequester(request);
1435 break;
1436
1437 case CMD_SET_ICC_LOCK_ENABLED:
1438 request = (MainThreadRequest) msg.obj;
1439 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1440 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1441 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1442 enabled.first, enabled.second, onCompleted);
1443 break;
1444 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1445 ar = (AsyncResult) msg.obj;
1446 request = (MainThreadRequest) ar.userObj;
1447 if (ar.exception == null) {
1448 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1449 } else {
1450 request.result = msg.arg1;
1451 }
1452 notifyRequester(request);
1453 break;
1454
Peter Wangdafb9ac2020-01-15 14:13:38 -08001455 case MSG_NOTIFY_USER_ACTIVITY:
1456 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001457 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001458 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1459 getDefaultPhone().getContext().sendBroadcastAsUser(
1460 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1461 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 default:
1463 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1464 break;
1465 }
1466 }
Jake Hambye994d462014-02-03 13:10:13 -08001467
Pengquan Menga1bb6272018-09-06 09:59:22 -07001468 private void notifyRequester(MainThreadRequest request) {
1469 synchronized (request) {
1470 request.notifyAll();
1471 }
1472 }
1473
Jake Hambye994d462014-02-03 13:10:13 -08001474 private void handleNullReturnEvent(Message msg, String command) {
1475 AsyncResult ar = (AsyncResult) msg.obj;
1476 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1477 if (ar.exception == null) {
1478 request.result = true;
1479 } else {
1480 request.result = false;
1481 if (ar.exception instanceof CommandException) {
1482 loge(command + ": CommandException: " + ar.exception);
1483 } else {
1484 loge(command + ": Unknown exception");
1485 }
1486 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001487 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 }
1490
1491 /**
1492 * Posts the specified command to be executed on the main thread,
1493 * waits for the request to complete, and returns the result.
1494 * @see #sendRequestAsync
1495 */
1496 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001497 return sendRequest(
1498 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001499 }
1500
1501 /**
1502 * Posts the specified command to be executed on the main thread,
1503 * waits for the request to complete, and returns the result.
1504 * @see #sendRequestAsync
1505 */
1506 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1507 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001508 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001509 }
1510
1511 /**
1512 * Posts the specified command to be executed on the main thread,
1513 * waits for the request to complete, and returns the result.
1514 * @see #sendRequestAsync
1515 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001516 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001517 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001518 }
1519
1520 /**
1521 * Posts the specified command to be executed on the main thread,
1522 * waits for the request to complete, and returns the result.
1523 * @see #sendRequestAsync
1524 */
Nathan Harold92bed182018-10-12 18:16:49 -07001525 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1526 return sendRequest(command, argument, subId, null, workSource);
1527 }
1528
1529 /**
1530 * Posts the specified command to be executed on the main thread,
1531 * waits for the request to complete, and returns the result.
1532 * @see #sendRequestAsync
1533 */
1534 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1535 return sendRequest(
1536 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1537 }
1538
1539 /**
1540 * Posts the specified command to be executed on the main thread,
1541 * waits for the request to complete, and returns the result.
1542 * @see #sendRequestAsync
1543 */
1544 private Object sendRequest(
1545 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001546 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1547 throw new RuntimeException("This method will deadlock if called from the main thread.");
1548 }
1549
Nathan Harold92bed182018-10-12 18:16:49 -07001550 MainThreadRequest request = null;
1551 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1552 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1553 } else if (phone != null) {
1554 request = new MainThreadRequest(argument, phone, workSource);
1555 } else {
1556 request = new MainThreadRequest(argument, subId, workSource);
1557 }
1558
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 Message msg = mMainThreadHandler.obtainMessage(command, request);
1560 msg.sendToTarget();
1561
1562 // Wait for the request to complete
1563 synchronized (request) {
1564 while (request.result == null) {
1565 try {
1566 request.wait();
1567 } catch (InterruptedException e) {
1568 // Do nothing, go back and wait until the request is complete
1569 }
1570 }
1571 }
1572 return request.result;
1573 }
1574
1575 /**
1576 * Asynchronous ("fire and forget") version of sendRequest():
1577 * Posts the specified command to be executed on the main thread, and
1578 * returns immediately.
1579 * @see #sendRequest
1580 */
1581 private void sendRequestAsync(int command) {
1582 mMainThreadHandler.sendEmptyMessage(command);
1583 }
1584
1585 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001586 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001587 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001588 */
1589 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001590 sendRequestAsync(command, argument, null, null);
1591 }
1592
1593 /**
1594 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1595 * @see {@link #sendRequest(int,Object)}
1596 */
1597 private void sendRequestAsync(
1598 int command, Object argument, Phone phone, WorkSource workSource) {
1599 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001600 Message msg = mMainThreadHandler.obtainMessage(command, request);
1601 msg.sendToTarget();
1602 }
1603
1604 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 * Initialize the singleton PhoneInterfaceManager instance.
1606 * This is only done once, at startup, from PhoneApp.onCreate().
1607 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001608 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 synchronized (PhoneInterfaceManager.class) {
1610 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001611 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 } else {
1613 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1614 }
1615 return sInstance;
1616 }
1617 }
1618
1619 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001620 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001623 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001624 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1626 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001627 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001628 mTelephonySharedPreferences =
1629 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001630 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001631 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001632 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001633
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 publish();
1635 }
1636
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001637 private Phone getDefaultPhone() {
1638 Phone thePhone = getPhone(getDefaultSubscription());
1639 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1640 }
1641
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 private void publish() {
1643 if (DBG) log("publish: " + this);
1644
Peter Wangc035ce42020-01-08 21:00:22 -08001645 TelephonyFrameworkInitializer
1646 .getTelephonyServiceManager()
1647 .getTelephonyServiceRegisterer()
1648 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 }
1650
Stuart Scott584921c2015-01-15 17:10:34 -08001651 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001652 if (request.phone != null) {
1653 return request.phone;
1654 } else {
1655 return getPhoneFromSubId(request.subId);
1656 }
1657 }
1658
1659 private Phone getPhoneFromSubId(int subId) {
1660 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1661 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001662 }
1663
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001664 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1665 Phone phone = getPhoneFromRequest(request);
1666 return phone == null ? null :
1667 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1668 }
1669
Wink Saville36469e72014-06-11 15:17:00 -07001670 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001671 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001672 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674
Naina Nallurid63128d2019-09-17 14:10:30 -07001675 private void sendEraseModemConfig(Phone phone) {
1676 if (phone != null) {
1677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1678 mApp, phone.getSubId(), "eraseModemConfig");
1679 final long identity = Binder.clearCallingIdentity();
1680 try {
1681 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1682 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1683 } finally {
1684 Binder.restoreCallingIdentity(identity);
1685 }
1686 }
1687 }
1688
Peter Wang44b186e2020-01-13 23:33:09 -08001689 private boolean isImsAvailableOnDevice() {
1690 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1691 if (pm == null) {
1692 // For some reason package manger is not available.. This will fail internally anyway,
1693 // so do not throw error and allow.
1694 return true;
1695 }
1696 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1697 }
1698
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001700 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001701 }
1702
Wink Savilleb564aae2014-10-23 10:18:09 -07001703 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 if (DBG) log("dial: " + number);
1705 // No permission check needed here: This is just a wrapper around the
1706 // ACTION_DIAL intent, which is available to any app since it puts up
1707 // the UI before it does anything.
1708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001709 final long identity = Binder.clearCallingIdentity();
1710 try {
1711 String url = createTelUrl(number);
1712 if (url == null) {
1713 return;
1714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716 // PENDING: should we just silently fail if phone is offhook or ringing?
1717 PhoneConstants.State state = mCM.getState(subId);
1718 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1719 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1720 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1721 mApp.startActivity(intent);
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726 }
1727
1728 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001729 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001730 }
1731
Wink Savilleb564aae2014-10-23 10:18:09 -07001732 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 if (DBG) log("call: " + number);
1734
1735 // This is just a wrapper around the ACTION_CALL intent, but we still
1736 // need to do a permission check since we're calling startActivity()
1737 // from the context of the phone app.
1738 enforceCallPermission();
1739
Jordan Liu1617b712019-07-10 15:06:26 -07001740 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 != AppOpsManager.MODE_ALLOWED) {
1742 return;
1743 }
1744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 String url = createTelUrl(number);
1748 if (url == null) {
1749 return;
1750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752 boolean isValid = false;
1753 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1754 if (slist != null) {
1755 for (SubscriptionInfo subInfoRecord : slist) {
1756 if (subInfoRecord.getSubscriptionId() == subId) {
1757 isValid = true;
1758 break;
1759 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001760 }
Wink Saville08874612014-08-31 19:19:58 -07001761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762 if (!isValid) {
1763 return;
1764 }
Wink Saville08874612014-08-31 19:19:58 -07001765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001766 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1767 intent.putExtra(SUBSCRIPTION_KEY, subId);
1768 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1769 mApp.startActivity(intent);
1770 } finally {
1771 Binder.restoreCallingIdentity(identity);
1772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
Wink Savilleb564aae2014-10-23 10:18:09 -07001775 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001776 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001777 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1778 }
1779
Wink Savilleb564aae2014-10-23 10:18:09 -07001780 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001781 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001782 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1783 }
1784
Wink Savilleb564aae2014-10-23 10:18:09 -07001785 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001787
1788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1791 checkSimPin.start();
1792 return checkSimPin.unlockSim(null, pin);
1793 } finally {
1794 Binder.restoreCallingIdentity(identity);
1795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 }
1797
Wink Savilleb564aae2014-10-23 10:18:09 -07001798 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800
1801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1804 checkSimPuk.start();
1805 return checkSimPuk.unlockSim(puk, pin);
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
1808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
1811 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001812 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 * a synchronous one.
1814 */
1815 private static class UnlockSim extends Thread {
1816
1817 private final IccCard mSimCard;
1818
1819 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001820 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1821 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822
1823 // For replies from SimCard interface
1824 private Handler mHandler;
1825
1826 // For async handler to identify request type
1827 private static final int SUPPLY_PIN_COMPLETE = 100;
1828
1829 public UnlockSim(IccCard simCard) {
1830 mSimCard = simCard;
1831 }
1832
1833 @Override
1834 public void run() {
1835 Looper.prepare();
1836 synchronized (UnlockSim.this) {
1837 mHandler = new Handler() {
1838 @Override
1839 public void handleMessage(Message msg) {
1840 AsyncResult ar = (AsyncResult) msg.obj;
1841 switch (msg.what) {
1842 case SUPPLY_PIN_COMPLETE:
1843 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1844 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001845 mRetryCount = msg.arg1;
1846 if (ar.exception != null) {
1847 if (ar.exception instanceof CommandException &&
1848 ((CommandException)(ar.exception)).getCommandError()
1849 == CommandException.Error.PASSWORD_INCORRECT) {
1850 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1851 } else {
1852 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1853 }
1854 } else {
1855 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 mDone = true;
1858 UnlockSim.this.notifyAll();
1859 }
1860 break;
1861 }
1862 }
1863 };
1864 UnlockSim.this.notifyAll();
1865 }
1866 Looper.loop();
1867 }
1868
1869 /*
1870 * Use PIN or PUK to unlock SIM card
1871 *
1872 * If PUK is null, unlock SIM card with PIN
1873 *
1874 * If PUK is not null, unlock SIM card with PUK and set PIN code
1875 */
Wink Saville9de0f752013-10-22 19:04:03 -07001876 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877
1878 while (mHandler == null) {
1879 try {
1880 wait();
1881 } catch (InterruptedException e) {
1882 Thread.currentThread().interrupt();
1883 }
1884 }
1885 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1886
1887 if (puk == null) {
1888 mSimCard.supplyPin(pin, callback);
1889 } else {
1890 mSimCard.supplyPuk(puk, pin, callback);
1891 }
1892
1893 while (!mDone) {
1894 try {
1895 Log.d(LOG_TAG, "wait for done");
1896 wait();
1897 } catch (InterruptedException e) {
1898 // Restore the interrupted status
1899 Thread.currentThread().interrupt();
1900 }
1901 }
1902 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001903 int[] resultArray = new int[2];
1904 resultArray[0] = mResult;
1905 resultArray[1] = mRetryCount;
1906 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908 }
1909
1910 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001911 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001912
1913 }
1914
Wink Savilleb564aae2014-10-23 10:18:09 -07001915 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 // No permission check needed here: this call is harmless, and it's
1917 // needed for the ServiceState.requestStateUpdate() call (which is
1918 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001919 final long identity = Binder.clearCallingIdentity();
1920 try {
1921 final Phone phone = getPhone(subId);
1922 if (phone != null) {
1923 phone.updateServiceLocation();
1924 }
1925 } finally {
1926 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 }
1929
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001930 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001931 @Override
1932 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001933 return isRadioOnWithFeature(callingPackage, null);
1934 }
1935
1936
1937 @Override
1938 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1939 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1940 callingFeatureId);
1941 }
1942
1943 @Deprecated
1944 @Override
1945 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1946 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001947 }
1948
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001949 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001950 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1951 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001953 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001954 return false;
1955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001956
1957 final long identity = Binder.clearCallingIdentity();
1958 try {
1959 return isRadioOnForSubscriber(subId);
1960 } finally {
1961 Binder.restoreCallingIdentity(identity);
1962 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001963 }
1964
1965 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 final long identity = Binder.clearCallingIdentity();
1967 try {
1968 final Phone phone = getPhone(subId);
1969 if (phone != null) {
1970 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1971 } else {
1972 return false;
1973 }
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
1978
1979 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001980 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 }
Wink Saville36469e72014-06-11 15:17:00 -07001982
Wink Savilleb564aae2014-10-23 10:18:09 -07001983 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985
1986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 final Phone phone = getPhone(subId);
1989 if (phone != null) {
1990 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1991 }
1992 } finally {
1993 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 }
Wink Saville36469e72014-06-11 15:17:00 -07001995 }
1996
1997 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001998 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001999 }
2000
Wink Savilleb564aae2014-10-23 10:18:09 -07002001 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002002 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002003
2004 final long identity = Binder.clearCallingIdentity();
2005 try {
2006 final Phone phone = getPhone(subId);
2007 if (phone == null) {
2008 return false;
2009 }
2010 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2011 toggleRadioOnOffForSubscriber(subId);
2012 }
2013 return true;
2014 } finally {
2015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
Wink Saville36469e72014-06-11 15:17:00 -07002018
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002019 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002020 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002021 /*
2022 * If any of the Radios are available, it will need to be
2023 * shutdown. So return true if any Radio is available.
2024 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025 final long identity = Binder.clearCallingIdentity();
2026 try {
2027 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2028 Phone phone = PhoneFactory.getPhone(i);
2029 if (phone != null && phone.isRadioAvailable()) return true;
2030 }
2031 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2032 return false;
2033 } finally {
2034 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002035 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002036 }
2037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002039 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 enforceModifyPermission();
2041
2042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2045 logv("Shutting down Phone " + i);
2046 shutdownRadioUsingPhoneId(i);
2047 }
2048 } finally {
2049 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002050 }
2051 }
2052
2053 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002054 Phone phone = PhoneFactory.getPhone(phoneId);
2055 if (phone != null && phone.isRadioAvailable()) {
2056 phone.shutdownRadio();
2057 }
2058 }
2059
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002061 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062
2063 final long identity = Binder.clearCallingIdentity();
2064 try {
2065 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2066 if (defaultPhone != null) {
2067 defaultPhone.setRadioPower(turnOn);
2068 return true;
2069 } else {
2070 loge("There's no default phone.");
2071 return false;
2072 }
2073 } finally {
2074 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002075 }
Wink Saville36469e72014-06-11 15:17:00 -07002076 }
2077
Wink Savilleb564aae2014-10-23 10:18:09 -07002078 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080
2081 final long identity = Binder.clearCallingIdentity();
2082 try {
2083 final Phone phone = getPhone(subId);
2084 if (phone != null) {
2085 phone.setRadioPower(turnOn);
2086 return true;
2087 } else {
2088 return false;
2089 }
2090 } finally {
2091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 }
2094
Wink Saville36469e72014-06-11 15:17:00 -07002095 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002096 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 public boolean enableDataConnectivity() {
2098 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099
2100 final long identity = Binder.clearCallingIdentity();
2101 try {
2102 int subId = mSubscriptionController.getDefaultDataSubId();
2103 final Phone phone = getPhone(subId);
2104 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002105 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106 return true;
2107 } else {
2108 return false;
2109 }
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114
Wink Saville36469e72014-06-11 15:17:00 -07002115 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002116 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117 public boolean disableDataConnectivity() {
2118 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002119
2120 final long identity = Binder.clearCallingIdentity();
2121 try {
2122 int subId = mSubscriptionController.getDefaultDataSubId();
2123 final Phone phone = getPhone(subId);
2124 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002125 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002126 return true;
2127 } else {
2128 return false;
2129 }
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 }
2134
Sanket Padawe356d7632015-06-22 14:03:32 -07002135 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002136 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002137 final long identity = Binder.clearCallingIdentity();
2138 try {
2139 final Phone phone = getPhone(subId);
2140 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002141 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002142 } else {
2143 return false;
2144 }
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 }
2149
2150 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002151 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002152 }
2153
pkanwarae03a6b2016-11-06 20:37:09 -08002154 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002155 enforceCallPermission();
2156
2157 final long identity = Binder.clearCallingIdentity();
2158 try {
2159 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2160 return;
2161 }
2162 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2163 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
2166 }
pkanwar32d516d2016-10-14 19:37:38 -07002167 };
2168
Wink Savilleb564aae2014-10-23 10:18:09 -07002169 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2175 return false;
2176 }
2177 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002184 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002185 }
2186
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002187 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188 final long identity = Binder.clearCallingIdentity();
2189 try {
2190 Phone phone = PhoneFactory.getPhone(slotIndex);
2191 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2192 PhoneConstantConversions.convertCallState(phone.getState());
2193 } finally {
2194 Binder.restoreCallingIdentity(identity);
2195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 }
2197
Sanket Padawe356d7632015-06-22 14:03:32 -07002198 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002199 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002200 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2201 }
2202
2203 @Override
2204 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205 final long identity = Binder.clearCallingIdentity();
2206 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002207 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208 if (phone != null) {
2209 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2210 } else {
2211 return PhoneConstantConversions.convertDataState(
2212 PhoneConstants.DataState.DISCONNECTED);
2213 }
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Sanket Padawe356d7632015-06-22 14:03:32 -07002219 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002220 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002221 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2222 }
2223
2224 @Override
2225 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226 final long identity = Binder.clearCallingIdentity();
2227 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002228 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229 if (phone != null) {
2230 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2231 } else {
2232 return TelephonyManager.DATA_ACTIVITY_NONE;
2233 }
2234 } finally {
2235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 }
2238
2239 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002240 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002241 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002242 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002243
2244 LocationAccessPolicy.LocationPermissionResult locationResult =
2245 LocationAccessPolicy.checkLocationPermission(mApp,
2246 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2247 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002248 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002249 .setCallingPid(Binder.getCallingPid())
2250 .setCallingUid(Binder.getCallingUid())
2251 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002252 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002253 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2254 .build());
2255 switch (locationResult) {
2256 case DENIED_HARD:
2257 throw new SecurityException("Not allowed to access cell location");
2258 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002259 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2260 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 }
2262
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002267 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002268 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269 } finally {
2270 Binder.restoreCallingIdentity(identity);
2271 }
Svetoslav64fad262015-04-14 14:35:21 -07002272 }
2273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002275 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2276 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002277 if (!TextUtils.isEmpty(callingPackage)) {
2278 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2280 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002281 return "";
2282 }
2283 }
2284
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002285 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2286 // registered cell info, so return a NULL country instead.
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002289 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2290 // Get default phone in this case.
2291 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2292 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002293 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002294 // Todo: fix this when we can get the actual cellular network info when the device
2295 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002296 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002297 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2298 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002299 return "";
2300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 Phone phone = PhoneFactory.getPhone(phoneId);
2302 if (phone != null) {
2303 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002304 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 if (sst != null) {
2306 LocaleTracker lt = sst.getLocaleTracker();
2307 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002308 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2309 return lt.getCurrentCountry();
2310 } else if (emergencyNumberTracker != null) {
2311 return emergencyNumberTracker.getEmergencyCountryIso();
2312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002313 }
2314 }
2315 }
2316 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002317 } finally {
2318 Binder.restoreCallingIdentity(identity);
2319 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002320 }
2321
2322 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002324 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002325 }
2326
Sanket Padawe356d7632015-06-22 14:03:32 -07002327 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 mApp.enforceCallingOrSelfPermission(
2330 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002331
2332 final long identity = Binder.clearCallingIdentity();
2333 try {
2334 final Phone phone = getPhone(subId);
2335 if (phone != null) {
2336 phone.enableLocationUpdates();
2337 }
2338 } finally {
2339 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 }
2342
2343 @Override
2344 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002345 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002346 }
2347
Sanket Padawe356d7632015-06-22 14:03:32 -07002348 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002349 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 mApp.enforceCallingOrSelfPermission(
2351 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352
2353 final long identity = Binder.clearCallingIdentity();
2354 try {
2355 final Phone phone = getPhone(subId);
2356 if (phone != null) {
2357 phone.disableLocationUpdates();
2358 }
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 }
2363
Nathan Harold31d7ff32018-10-15 20:20:30 -07002364 /**
2365 * Returns the target SDK version number for a given package name.
2366 *
Nathan Haroldec184742019-07-10 17:04:16 -07002367 * This call MUST be invoked before clearing the calling UID.
2368 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002369 * @return target SDK if the package is found or INT_MAX.
2370 */
2371 private int getTargetSdk(String packageName) {
2372 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002373 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002374 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002375 if (ai != null) return ai.targetSdkVersion;
2376 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002377 loge("Failed to get package info for pkg="
2378 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002379 }
2380 return Integer.MAX_VALUE;
2381 }
2382
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 @Override
2384 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002385 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2386 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002387 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002388 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2389 throw new SecurityException(
2390 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2391 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002392
Jordan Liu1617b712019-07-10 15:06:26 -07002393 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2395 return null;
2396 }
Svetoslav64fad262015-04-14 14:35:21 -07002397
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002398 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002400 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002401 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402
Nathan Haroldf180aac2018-06-01 18:43:55 -07002403 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2404 for (CellInfo ci : info) {
2405 if (ci instanceof CellInfoGsm) {
2406 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2407 } else if (ci instanceof CellInfoWcdma) {
2408 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002411 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 }
2413
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002414 private List<CellInfo> getCachedCellInfo() {
2415 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2416 for (Phone phone : PhoneFactory.getPhones()) {
2417 List<CellInfo> info = phone.getAllCellInfo();
2418 if (info != null) cellInfos.addAll(info);
2419 }
2420 return cellInfos;
2421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422
2423 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002424 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002425 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002426 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002427
2428 LocationAccessPolicy.LocationPermissionResult locationResult =
2429 LocationAccessPolicy.checkLocationPermission(mApp,
2430 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2431 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002432 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002433 .setCallingPid(Binder.getCallingPid())
2434 .setCallingUid(Binder.getCallingUid())
2435 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002436 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002437 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2438 .build());
2439 switch (locationResult) {
2440 case DENIED_HARD:
2441 throw new SecurityException("Not allowed to access cell info");
2442 case DENIED_SOFT:
2443 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 }
2445
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002446 final int targetSdk = getTargetSdk(callingPackage);
2447 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2448 return getCachedCellInfo();
2449 }
2450
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002451 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002452 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2456 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002457 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002458 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 if (info != null) cellInfos.addAll(info);
2460 }
2461 return cellInfos;
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465 }
2466
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002467 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002468 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2469 String callingFeatureId) {
2470 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2471 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002472 }
2473
2474 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002475 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2476 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002477 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002478 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002479 }
2480
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002481 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2482 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002483 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002484 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002485
2486 LocationAccessPolicy.LocationPermissionResult locationResult =
2487 LocationAccessPolicy.checkLocationPermission(mApp,
2488 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2489 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002490 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002491 .setCallingPid(Binder.getCallingPid())
2492 .setCallingUid(Binder.getCallingUid())
2493 .setMethod("requestCellInfoUpdate")
2494 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2495 .build());
2496 switch (locationResult) {
2497 case DENIED_HARD:
2498 throw new SecurityException("Not allowed to access cell info");
2499 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002500 try {
2501 cb.onCellInfo(new ArrayList<CellInfo>());
2502 } catch (RemoteException re) {
2503 // Drop without consequences
2504 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002505 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002506 }
2507
Nathan Harolda939a962019-05-09 10:13:47 -07002508
2509 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002510 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2511
2512 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2513 }
2514
2515 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002517 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002518 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002522 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 } finally {
2524 Binder.restoreCallingIdentity(identity);
2525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 }
2527
Shishir Agrawala9f32182016-04-12 12:00:16 -07002528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002530 Phone phone = PhoneFactory.getPhone(slotIndex);
2531 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002532 return null;
2533 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002534 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002535 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002536 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002537 return null;
2538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539
2540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 return phone.getImei();
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002546 }
2547
2548 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002549 public String getTypeAllocationCodeForSlot(int slotIndex) {
2550 Phone phone = PhoneFactory.getPhone(slotIndex);
2551 String tac = null;
2552 if (phone != null) {
2553 String imei = phone.getImei();
2554 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2555 }
2556 return tac;
2557 }
2558
2559 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002560 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002561 Phone phone = PhoneFactory.getPhone(slotIndex);
2562 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002563 return null;
2564 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002565
Jeff Davidson913390f2018-02-23 17:11:49 -08002566 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002567 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002568 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002569 return null;
2570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 return phone.getMeid();
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Jack Yu2af8d712017-03-15 17:14:14 -07002578 }
2579
2580 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002581 public String getManufacturerCodeForSlot(int slotIndex) {
2582 Phone phone = PhoneFactory.getPhone(slotIndex);
2583 String manufacturerCode = null;
2584 if (phone != null) {
2585 String meid = phone.getMeid();
2586 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2587 }
2588 return manufacturerCode;
2589 }
2590
2591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002592 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2593 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002594 Phone phone = PhoneFactory.getPhone(slotIndex);
2595 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002596 return null;
2597 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002598 int subId = phone.getSubId();
2599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002600 mApp, subId, callingPackage, callingFeatureId,
2601 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002602 return null;
2603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 return phone.getDeviceSvn();
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
2610 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002611 }
2612
fionaxu43304da2017-11-27 22:51:16 -08002613 @Override
2614 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 final Phone phone = getPhone(subId);
2618 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
fionaxu43304da2017-11-27 22:51:16 -08002622 }
2623
2624 @Override
2625 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 final Phone phone = getPhone(subId);
2629 return phone == null ? null : phone.getCarrierName();
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
2632 }
fionaxu43304da2017-11-27 22:51:16 -08002633 }
2634
calvinpanffe225e2018-11-01 19:43:06 +08002635 @Override
chen xu0026ca62019-03-06 15:28:50 -08002636 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002641 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
2645 }
2646
2647 @Override
chen xu0026ca62019-03-06 15:28:50 -08002648 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002652 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002653 } finally {
2654 Binder.restoreCallingIdentity(identity);
2655 }
2656 }
2657
chen xu651eec72018-11-11 19:03:44 -08002658 @Override
chen xu864e11c2018-12-06 22:10:03 -08002659 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2660 if (!isSubscriptionMccMnc) {
2661 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2662 }
chen xu651eec72018-11-11 19:03:44 -08002663 final Phone phone = PhoneFactory.getPhone(slotIndex);
2664 if (phone == null) {
2665 return TelephonyManager.UNKNOWN_CARRIER_ID;
2666 }
2667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
2672 }
2673 }
2674
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 //
2676 // Internal helper methods.
2677 //
2678
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002679 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2681 *
2682 * @throws SecurityException if the caller does not have the required permission
2683 */
2684 private void enforceModifyPermission() {
2685 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2686 }
2687
Shuo Qiancd19c462020-01-16 20:51:11 -08002688 /**
2689 * Make sure the caller is system.
2690 *
2691 * @throws SecurityException if the caller is not system.
2692 */
2693 private void enforceSystemCaller() {
2694 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2695 throw new SecurityException("Caller must be system");
2696 }
2697 }
2698
Shuo Qian3b6ee772019-11-13 17:43:31 -08002699 private void enforceActiveEmergencySessionPermission() {
2700 mApp.enforceCallingOrSelfPermission(
2701 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2702 }
2703
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 /**
2705 * Make sure the caller has the CALL_PHONE permission.
2706 *
2707 * @throws SecurityException if the caller does not have the required permission
2708 */
2709 private void enforceCallPermission() {
2710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2711 }
2712
paulhu5a773602019-08-23 19:17:33 +08002713 private void enforceSettingsPermission() {
2714 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002715 }
2716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 private String createTelUrl(String number) {
2718 if (TextUtils.isEmpty(number)) {
2719 return null;
2720 }
2721
Jake Hambye994d462014-02-03 13:10:13 -08002722 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
Ihab Awadf9e92732013-12-05 18:02:52 -08002725 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2727 }
2728
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002729 private static void logv(String msg) {
2730 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2731 }
2732
Ihab Awadf9e92732013-12-05 18:02:52 -08002733 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2735 }
2736
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002737 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002739 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002740 }
2741
Sanket Padawe356d7632015-06-22 14:03:32 -07002742 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002743 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 final Phone phone = PhoneFactory.getPhone(slotIndex);
2747 if (phone == null) {
2748 return PhoneConstants.PHONE_TYPE_NONE;
2749 } else {
2750 return phone.getPhoneType();
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 }
2756
2757 /**
2758 * Returns the CDMA ERI icon index to display
2759 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002761 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2762 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2763 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002764 }
2765
Sanket Padawe356d7632015-06-22 14:03:32 -07002766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002767 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2768 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002770 mApp, subId, callingPackage, callingFeatureId,
2771 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002772 return -1;
2773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774
2775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 final Phone phone = getPhone(subId);
2778 if (phone != null) {
2779 return phone.getCdmaEriIconIndex();
2780 } else {
2781 return -1;
2782 }
2783 } finally {
2784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002786 }
2787
2788 /**
2789 * Returns the CDMA ERI icon mode,
2790 * 0 - ON
2791 * 1 - FLASHING
2792 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002793 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002794 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2795 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2796 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002797 }
2798
Sanket Padawe356d7632015-06-22 14:03:32 -07002799 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002800 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2801 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002803 mApp, subId, callingPackage, callingFeatureId,
2804 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002805 return -1;
2806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807
2808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 final Phone phone = getPhone(subId);
2811 if (phone != null) {
2812 return phone.getCdmaEriIconMode();
2813 } else {
2814 return -1;
2815 }
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
2821 /**
2822 * Returns the CDMA ERI text,
2823 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002824 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002825 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2826 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2827 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002828 }
2829
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002831 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2832 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002834 mApp, subId, callingPackage, callingFeatureId,
2835 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002836 return null;
2837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 final Phone phone = getPhone(subId);
2842 if (phone != null) {
2843 return phone.getCdmaEriText();
2844 } else {
2845 return null;
2846 }
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851
2852 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002853 * Returns the CDMA MDN.
2854 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002855 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002856 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2858 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 return phone.getLine1Number();
2865 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002866 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 return null;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002871 }
2872 }
2873
2874 /**
2875 * Returns the CDMA MIN.
2876 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002877 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002878 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2880 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 final Phone phone = getPhone(subId);
2885 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2886 return phone.getCdmaMin();
2887 } else {
2888 return null;
2889 }
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002892 }
2893 }
2894
Hall Liud892bec2018-11-30 14:51:45 -08002895 @Override
2896 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2897 INumberVerificationCallback callback, String callingPackage) {
2898 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2899 != PERMISSION_GRANTED) {
2900 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2901 }
2902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2903
2904 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2905 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2906 throw new SecurityException("Calling package must be configured in the device config");
2907 }
2908
2909 if (range == null) {
2910 throw new NullPointerException("Range must be non-null");
2911 }
2912
2913 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002914 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002915
2916 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2917 }
2918
Junda Liuca05d5d2014-08-14 22:36:34 -07002919 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 * Returns true if CDMA provisioning needs to run.
2921 */
2922 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 final long identity = Binder.clearCallingIdentity();
2924 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002925 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 } finally {
2927 Binder.restoreCallingIdentity(identity);
2928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
2931 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002932 * Sets the voice mail number of a given subId.
2933 */
2934 @Override
2935 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002936 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2937 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2942 new Pair<String, String>(alphaTag, number), new Integer(subId));
2943 return success;
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002947 }
2948
Ta-wei Yen87c49842016-05-13 21:19:52 -07002949 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002950 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2951 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002952 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2953 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002954 if (!TextUtils.equals(callingPackage, systemDialer)) {
2955 throw new SecurityException("caller must be system dialer");
2956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002957
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2961 if (phoneAccountHandle == null) {
2962 return null;
2963 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002964 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002967 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002968 }
2969
2970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002971 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2972 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002975 mApp, subId, callingPackage, callingFeatureId,
2976 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002977 return null;
2978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002980 final long identity = Binder.clearCallingIdentity();
2981 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002982 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002986 }
2987
2988 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002989 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2990 VisualVoicemailSmsFilterSettings settings) {
2991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003000 }
3001
3002 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003003 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3004 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003009 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003010 } finally {
3011 Binder.restoreCallingIdentity(identity);
3012 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003013 }
3014
3015 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003016 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3017 String callingPackage, int subId) {
3018 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003023 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003027 }
3028
3029 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003030 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003040 }
3041
3042 @Override
3043 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3044 String number, int port, String text, PendingIntent sentIntent) {
3045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003046 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003047 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003048 SmsController smsController = PhoneFactory.getSmsController();
3049 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3050 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003051 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003052
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003053 /**
fionaxu0152e512016-11-14 13:36:14 -08003054 * Sets the voice activation state of a given subId.
3055 */
3056 @Override
3057 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3059 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 final Phone phone = getPhone(subId);
3064 if (phone != null) {
3065 phone.setVoiceActivationState(activationState);
3066 } else {
3067 loge("setVoiceActivationState fails with invalid subId: " + subId);
3068 }
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003071 }
3072 }
3073
3074 /**
3075 * Sets the data activation state of a given subId.
3076 */
3077 @Override
3078 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3080 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 final Phone phone = getPhone(subId);
3085 if (phone != null) {
3086 phone.setDataActivationState(activationState);
3087 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003088 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089 }
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003092 }
3093 }
3094
3095 /**
3096 * Returns the voice activation state of a given subId.
3097 */
3098 @Override
3099 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003100 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101
fionaxu0152e512016-11-14 13:36:14 -08003102 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 if (phone != null) {
3106 return phone.getVoiceActivationState();
3107 } else {
3108 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3109 }
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003112 }
3113 }
3114
3115 /**
3116 * Returns the data activation state of a given subId.
3117 */
3118 @Override
3119 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003120 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121
fionaxu0152e512016-11-14 13:36:14 -08003122 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 if (phone != null) {
3126 return phone.getDataActivationState();
3127 } else {
3128 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3129 }
3130 } finally {
3131 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003132 }
3133 }
3134
3135 /**
Wink Saville36469e72014-06-11 15:17:00 -07003136 * Returns the unread count of voicemails for a subId
3137 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003138 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003139 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3140 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003142 mApp, subId, callingPackage, callingFeatureId,
3143 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003144 return 0;
3145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 final Phone phone = getPhone(subId);
3149 if (phone != null) {
3150 return phone.getVoiceMessageCount();
3151 } else {
3152 return 0;
3153 }
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
3158
3159 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003160 * returns true, if the device is in a state where both voice and data
3161 * are supported simultaneously. This can change based on location or network condition.
3162 */
3163 @Override
3164 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 final Phone phone = getPhone(subId);
3168 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003172 }
3173
3174 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003175 * Send the dialer code if called from the current default dialer or the caller has
3176 * carrier privilege.
3177 * @param inputCode The dialer code to send
3178 */
3179 @Override
3180 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003181 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003182 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003183 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3184 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003185 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003186 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003187 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003188 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
3190 final long identity = Binder.clearCallingIdentity();
3191 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003192 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
fionaxu235cc5e2017-03-06 22:25:57 -08003196 }
3197
Pengquan Menga1bb6272018-09-06 09:59:22 -07003198 @Override
3199 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003200 TelephonyPermissions
3201 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3202 mApp, subId, "getNetworkSelectionMode");
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 if (!isActiveSubscription(subId)) {
3206 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3207 }
3208 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003211 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003212 }
3213
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003215 public boolean isInEmergencySmsMode() {
3216 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 for (Phone phone : PhoneFactory.getPhones()) {
3220 if (phone.isInEmergencySmsMode()) {
3221 return true;
3222 }
3223 }
3224 } finally {
3225 Binder.restoreCallingIdentity(identity);
3226 }
3227 return false;
3228 }
3229
shilu366312e2019-12-17 09:28:10 -08003230 /**
3231 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3232 * @param subId The subscription to use to check the configuration.
3233 * @param c The callback that will be used to send the result.
3234 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003235 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003236 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3237 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003238 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3239 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003240
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003241 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3242 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3243 "IMS not available on device.");
3244 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 final long token = Binder.clearCallingIdentity();
3246 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003247 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003248 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003249 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003250 } catch (ImsException e) {
3251 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003252 } finally {
3253 Binder.restoreCallingIdentity(token);
3254 }
3255 }
3256
shilu366312e2019-12-17 09:28:10 -08003257 /**
3258 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3259 * @param subId The subscription to use to check the configuration.
3260 * @param c The callback that will be used to send the result.
3261 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003262 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003263 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003264 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3265 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003266 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3267 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3268 }
Meng Wangafbc5852019-09-19 17:37:13 -07003269 final long token = Binder.clearCallingIdentity();
3270 try {
3271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3272 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3273 .removeRegistrationCallbackForSubscription(c, subId);
3274 } catch (ImsException e) {
3275 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3276 + "is inactive, ignoring unregister.");
3277 // If the subscription is no longer active, just return, since the callback
3278 // will already have been removed internally.
3279 } finally {
3280 Binder.restoreCallingIdentity(token);
3281 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 }
3283
Brad Ebingera34a6c22019-10-22 17:36:18 -07003284 /**
3285 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3286 */
3287 @Override
3288 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3289 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3290 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3291 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3292 "IMS not available on device.");
3293 }
3294 final long token = Binder.clearCallingIdentity();
3295 try {
3296 Phone phone = getPhone(subId);
3297 if (phone == null) {
3298 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3299 + subId + "'");
3300 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3301 }
3302 phone.getImsRegistrationState(regState -> {
3303 try {
3304 consumer.accept((regState == null)
3305 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3306 } catch (RemoteException e) {
3307 // Ignore if the remote process is no longer available to call back.
3308 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3309 }
3310 });
3311 } finally {
3312 Binder.restoreCallingIdentity(token);
3313 }
3314 }
3315
3316 /**
3317 * Get the transport type for the IMS service registration state.
3318 */
3319 @Override
3320 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003321 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3322 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003323 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3324 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3325 "IMS not available on device.");
3326 }
3327 final long token = Binder.clearCallingIdentity();
3328 try {
3329 Phone phone = getPhone(subId);
3330 if (phone == null) {
3331 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3332 + subId + "'");
3333 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3334 }
3335 phone.getImsRegistrationTech(regTech -> {
3336 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3337 int regTechConverted = (regTech == null)
3338 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3339 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3340 regTechConverted);
3341 try {
3342 consumer.accept(regTechConverted);
3343 } catch (RemoteException e) {
3344 // Ignore if the remote process is no longer available to call back.
3345 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3346 }
3347 });
3348 } finally {
3349 Binder.restoreCallingIdentity(token);
3350 }
3351 }
3352
shilu366312e2019-12-17 09:28:10 -08003353 /**
3354 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3355 * @param subId The subscription to use to check the configuration.
3356 * @param c The callback that will be used to send the result.
3357 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003358 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003359 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3360 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003361 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3362 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003363 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3364 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3365 "IMS not available on device.");
3366 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003367 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3368 final long token = Binder.clearCallingIdentity();
3369 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003370 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003371 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003372 } catch (ImsException e) {
3373 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003374 } finally {
3375 Binder.restoreCallingIdentity(token);
3376 }
3377 }
3378
shilu366312e2019-12-17 09:28:10 -08003379 /**
3380 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3381 * @param subId The subscription to use to check the configuration.
3382 * @param c The callback that will be used to send the result.
3383 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003385 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003386 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3387 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003388 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3389 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3390 }
Meng Wangafbc5852019-09-19 17:37:13 -07003391
3392 final long token = Binder.clearCallingIdentity();
3393 try {
3394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3395 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003396 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003397 } catch (ImsException e) {
3398 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3399 + "is inactive, ignoring unregister.");
3400 // If the subscription is no longer active, just return, since the callback
3401 // will already have been removed internally.
3402 } finally {
3403 Binder.restoreCallingIdentity(token);
3404 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003405 }
3406
3407 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003408 public boolean isCapable(int subId, int capability, int regTech) {
3409 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3411 final long token = Binder.clearCallingIdentity();
3412 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003413 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003414 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003415 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003416 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3417 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003418 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003419 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3420 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003421 } finally {
3422 Binder.restoreCallingIdentity(token);
3423 }
3424 }
3425
3426 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003427 public boolean isAvailable(int subId, int capability, int regTech) {
3428 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 final long token = Binder.clearCallingIdentity();
3430 try {
3431 Phone phone = getPhone(subId);
3432 if (phone == null) return false;
3433 return phone.isImsCapabilityAvailable(capability, regTech);
3434 } finally {
3435 Binder.restoreCallingIdentity(token);
3436 }
3437 }
3438
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003439 /**
3440 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3441 * subscription.
3442 * @param subId The subscription to use to check the configuration.
3443 * @param callback The callback that will be used to send the result.
3444 * @param capability The MmTelFeature capability that will be used to send the result.
3445 * @param transportType The transport type of the MmTelFeature capability.
3446 */
3447 @Override
3448 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3449 int transportType) {
3450 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3451 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3452 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3453 "IMS not available on device.");
3454 }
3455 final long token = Binder.clearCallingIdentity();
3456 try {
3457 int slotId = getSlotIndex(subId);
3458 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3459 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3460 + subId + "'");
3461 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3462 }
3463 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3464 transportType, aBoolean -> {
3465 try {
3466 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3467 } catch (RemoteException e) {
3468 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3469 + "running. Ignore");
3470 }
3471 });
3472 } finally {
3473 Binder.restoreCallingIdentity(token);
3474 }
3475 }
3476
shilu366312e2019-12-17 09:28:10 -08003477 /**
3478 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3479 * @param subId The subscription to use to check the configuration.
3480 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003481 @Override
3482 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003483 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3484 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003485
Brad Ebinger35c841c2018-10-01 10:40:55 -07003486 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3487 final long token = Binder.clearCallingIdentity();
3488 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003489 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003490 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003491 } catch (ImsException e) {
3492 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003493 } finally {
3494 Binder.restoreCallingIdentity(token);
3495 }
3496 }
3497
3498 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003499 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003501 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003505 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003507 } catch (ImsException e) {
3508 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003509 } finally {
3510 Binder.restoreCallingIdentity(identity);
3511 }
3512 }
3513
shilu366312e2019-12-17 09:28:10 -08003514 /**
3515 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3516 * @param subId The subscription to use to check the configuration.
3517 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003519 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003520 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3521 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003525 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3526 } catch (ImsException e) {
3527 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003528 } finally {
3529 Binder.restoreCallingIdentity(identity);
3530 }
3531 }
3532
3533 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003534 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003536 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003540 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003541 } catch (ImsException e) {
3542 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003543 } finally {
3544 Binder.restoreCallingIdentity(identity);
3545 }
3546 }
3547
shilu366312e2019-12-17 09:28:10 -08003548 /**
3549 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3550 * @param subId The subscription to use to check the configuration.
3551 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 @Override
3553 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003554 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3555 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003556 final long identity = Binder.clearCallingIdentity();
3557 try {
3558 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003559 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003560 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003561 } catch (ImsException e) {
3562 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 } finally {
3564 Binder.restoreCallingIdentity(identity);
3565 }
3566 }
3567
3568 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003569 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003571 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003575 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003576 } catch (ImsException e) {
3577 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
3581 }
3582
shilu366312e2019-12-17 09:28:10 -08003583 /**
3584 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3585 * @param subId The subscription to use to check the configuration.
3586 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 @Override
3588 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003589 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3590 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003594 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003596 } catch (ImsException e) {
3597 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 } finally {
3599 Binder.restoreCallingIdentity(identity);
3600 }
3601 }
3602
3603 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003604 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003606 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003610 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003611 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003612 } catch (ImsException e) {
3613 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
3617 }
3618
3619 @Override
3620 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3622 "setVoWiFiNonPersistent");
3623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003626 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003627 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003628 } catch (ImsException e) {
3629 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
3633 }
3634
shilu366312e2019-12-17 09:28:10 -08003635 /**
3636 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3637 * @param subId The subscription to use to check the configuration.
3638 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 @Override
3640 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003641 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3642 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003646 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003647 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003648 } catch (ImsException e) {
3649 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
3653 }
3654
3655 @Override
3656 public void setVoWiFiModeSetting(int subId, int mode) {
3657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3658 "setVoWiFiModeSetting");
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003662 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003663 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003664 } catch (ImsException e) {
3665 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
3669 }
3670
3671 @Override
3672 public int getVoWiFiRoamingModeSetting(int subId) {
3673 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003677 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003679 } catch (ImsException e) {
3680 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
3684 }
3685
3686 @Override
3687 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3689 "setVoWiFiRoamingModeSetting");
3690 final long identity = Binder.clearCallingIdentity();
3691 try {
3692 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003693 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003694 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003695 } catch (ImsException e) {
3696 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 } finally {
3698 Binder.restoreCallingIdentity(identity);
3699 }
3700 }
3701
3702 @Override
3703 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3705 "setRttCapabilityEnabled");
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003709 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3710 } catch (ImsException e) {
3711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
3715 }
3716
shilu366312e2019-12-17 09:28:10 -08003717 /**
3718 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3719 * @param subId The subscription to use to check the configuration.
3720 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 @Override
3722 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003723 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3724 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003728 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003730 } catch (ImsException e) {
3731 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003732 } finally {
3733 Binder.restoreCallingIdentity(identity);
3734 }
3735 }
3736
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003737 @Override
3738 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3739 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3740 final long identity = Binder.clearCallingIdentity();
3741 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003742 if (!isImsAvailableOnDevice()) {
3743 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3744 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003745 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003746 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003747 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003748 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003749 } catch (ImsException e) {
3750 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003751 } finally {
3752 Binder.restoreCallingIdentity(identity);
3753 }
3754 }
3755
3756 @Override
3757 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3758 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3759 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003760 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3761 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3762 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003763 try {
3764 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003765 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003766 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003767 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003768 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3769 + "is inactive, ignoring unregister.");
3770 // If the subscription is no longer active, just return, since the callback will already
3771 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003772 } finally {
3773 Binder.restoreCallingIdentity(identity);
3774 }
3775 }
3776
allenwtsu99c623b2020-01-03 18:24:23 +08003777
3778 private void checkModifyPhoneStatePermission(int subId, String message) {
3779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3780 message);
3781 }
3782
3783 private boolean isImsProvisioningRequired(int subId, int capability,
3784 boolean isMmtelCapability) {
3785 Phone phone = getPhone(subId);
3786 if (phone == null) {
3787 loge("phone instance null for subid " + subId);
3788 return false;
3789 }
3790 if (isMmtelCapability) {
3791 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3792 return false;
3793 }
3794 } else {
3795 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3796 return false;
3797 }
3798 }
3799 return true;
3800 }
3801
3802 @Override
3803 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3804 boolean isProvisioned) {
3805 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3806
3807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3810 if (!isImsProvisioningRequired(subId, capability, false)) {
3811 return;
3812 }
3813
3814 // this capability requires provisioning, route to the correct API.
3815 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3816 switch (capability) {
3817 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3818 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3819 ims.setEabProvisioned(isProvisioned);
3820 break;
3821 default: {
3822 throw new IllegalArgumentException("Tried to set provisioning for "
3823 + "rcs capability '" + capability + "', which does not require "
3824 + "provisioning.");
3825 }
3826 }
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
3829 }
3830
3831 }
3832
3833
3834 @Override
3835 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3836 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3840 if (!isImsProvisioningRequired(subId, capability, false)) {
3841 return true;
3842 }
3843
3844 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3845 switch (capability) {
3846 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3847 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3848 return ims.isEabProvisionedOnDevice();
3849
3850 default: {
3851 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3852 + "capability '" + capability + "', which does not require "
3853 + "provisioning.");
3854 }
3855 }
3856
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
3859 }
3860 }
3861
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003862 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003863 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3864 boolean isProvisioned) {
3865 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3866 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3867 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3868 }
allenwtsu99c623b2020-01-03 18:24:23 +08003869 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003873 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003874 return;
3875 }
3876
3877 // this capability requires provisioning, route to the correct API.
3878 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3879 switch (capability) {
3880 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3881 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3882 ims.setVolteProvisioned(isProvisioned);
3883 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3884 ims.setWfcProvisioned(isProvisioned);
3885 }
3886 break;
3887 }
3888 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3889 // There is currently no difference in VT provisioning type.
3890 ims.setVtProvisioned(isProvisioned);
3891 break;
3892 }
3893 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3894 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3895 // change the capability of the feature instead if needed.
3896 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3897 == isProvisioned) {
3898 // No change in provisioning.
3899 return;
3900 }
3901 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3902 try {
3903 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003904 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003905 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3906 + ", Exception" + e.getMessage());
3907 }
3908 break;
3909 }
3910 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003911 throw new IllegalArgumentException("Tried to set provisioning for "
3912 + "MmTel capability '" + capability + "', which does not require "
3913 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003914 }
3915 }
3916
3917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
3920 }
3921
3922 @Override
3923 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3924 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3925 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3926 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3927 }
3928 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003932 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003933 return true;
3934 }
3935
3936 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3937 switch (capability) {
3938 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3939 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3940 return ims.isVolteProvisionedOnDevice();
3941 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3942 return ims.isWfcProvisionedOnDevice();
3943 }
3944 // This should never happen, since we are checking tech above to make sure it
3945 // is either LTE or IWLAN.
3946 throw new IllegalArgumentException("Invalid radio technology for voice "
3947 + "capability.");
3948 }
3949 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3950 // There is currently no difference in VT provisioning type.
3951 return ims.isVtProvisionedOnDevice();
3952 }
3953 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3954 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3955 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3956 }
3957 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003958 throw new IllegalArgumentException(
3959 "Tried to get provisioning for MmTel capability '" + capability
3960 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003961 }
3962 }
3963
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
3967 }
3968
3969 @Override
3970 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3971 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3972 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3973 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3974 }
3975 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3976 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3977 return (provisionedBits & capability) > 0;
3978 }
3979
3980 @Override
3981 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3982 boolean isProvisioned) {
3983 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3984 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3985 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3986 }
3987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3988 "setProvisioningStatusForCapability");
3989 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3990 // If the current provisioning status for capability already matches isProvisioned,
3991 // do nothing.
3992 if (((provisionedBits & capability) > 0) == isProvisioned) {
3993 return;
3994 }
3995 if (isProvisioned) {
3996 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3997 } else {
3998 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3999 }
4000 }
4001
4002 /**
4003 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4004 * technology. The bitfield should mirror the bitfield defined by
4005 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4006 */
4007 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4008 String key = getMmTelProvisioningKey(subId, tech);
4009 // Default is no capabilities are provisioned.
4010 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4011 }
4012
4013 /**
4014 * Sets the MmTel capability provisioning bitfield (defined by
4015 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4016 * technology specified.
4017 *
4018 * Note: This is a synchronous command and should not be called on UI thread.
4019 */
4020 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4021 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4022 String key = getMmTelProvisioningKey(subId, tech);
4023 editor.putInt(key, newField);
4024 editor.commit();
4025 }
4026
4027 private static String getMmTelProvisioningKey(int subId, int tech) {
4028 // resulting key is provision_ims_mmtel_{subId}_{tech}
4029 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4030 }
4031
4032 /**
4033 * Query CarrierConfig to see if the specified capability requires provisioning for the
4034 * carrier associated with the subscription id.
4035 */
4036 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4037 int capability) {
4038 CarrierConfigManager configManager = new CarrierConfigManager(context);
4039 PersistableBundle c = configManager.getConfigForSubId(subId);
4040 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004041 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004042 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4043 false);
4044 boolean requireVoiceVtProvisioning = c.getBoolean(
4045 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4046
4047 // First check to make sure that the capability requires provisioning.
4048 switch (capability) {
4049 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4050 // intentional fallthrough
4051 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4052 if (requireVoiceVtProvisioning) {
4053 // Voice and Video requires provisioning
4054 return true;
4055 }
4056 break;
4057 }
4058 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4059 if (requireUtProvisioning) {
4060 // UT requires provisioning
4061 return true;
4062 }
4063 break;
4064 }
4065 }
4066 return false;
4067 }
4068
allenwtsu99c623b2020-01-03 18:24:23 +08004069 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4070 int capability) {
4071 CarrierConfigManager configManager = new CarrierConfigManager(context);
4072 PersistableBundle c = configManager.getConfigForSubId(subId);
4073
4074 boolean requireRcsProvisioning = c.getBoolean(
4075 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4076
4077 // First check to make sure that the capability requires provisioning.
4078 switch (capability) {
4079 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4080 // intentional fallthrough
4081 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4082 if (requireRcsProvisioning) {
4083 // OPTION or PRESENCE requires provisioning
4084 return true;
4085 }
4086 break;
4087 }
4088 }
4089 return false;
4090 }
4091
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004092 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004093 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004094 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4095 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4096 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004097 enforceReadPrivilegedPermission("getImsProvisioningInt");
4098 final long identity = Binder.clearCallingIdentity();
4099 try {
4100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004101 int slotId = getSlotIndex(subId);
4102 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4103 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4104 + subId + "' for key:" + key);
4105 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4106 }
4107 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004108 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004109 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4110 + subId + "' for key:" + key);
4111 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004112 } finally {
4113 Binder.restoreCallingIdentity(identity);
4114 }
4115 }
4116
4117 @Override
4118 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4120 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4121 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004122 enforceReadPrivilegedPermission("getImsProvisioningString");
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004126 int slotId = getSlotIndex(subId);
4127 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4128 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4129 + subId + "' for key:" + key);
4130 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4131 }
4132 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004133 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004134 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4135 + subId + "' for key:" + key);
4136 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
4140 }
4141
4142 @Override
4143 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004144 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4145 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4146 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4148 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004152 int slotId = getSlotIndex(subId);
4153 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4154 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4155 + subId + "' for key:" + key);
4156 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4157 }
4158 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004159 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004160 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4161 + "' for key:" + key);
4162 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
4166 }
4167
4168 @Override
4169 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004170 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4171 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4172 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4174 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004175 final long identity = Binder.clearCallingIdentity();
4176 try {
4177 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004178 int slotId = getSlotIndex(subId);
4179 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4180 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4181 + subId + "' for key:" + key);
4182 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4183 }
4184 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004185 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004186 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4187 + "' for key:" + key);
4188 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
4192 }
4193
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004194 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 int slotId = SubscriptionManager.getSlotIndex(subId);
4196 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004197 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4198 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 }
4200 return slotId;
4201 }
4202
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004203 private int getSlotIndex(int subId) {
4204 int slotId = SubscriptionManager.getSlotIndex(subId);
4205 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4206 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4207 }
4208 return slotId;
4209 }
4210
Wink Saville36469e72014-06-11 15:17:00 -07004211 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004212 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004213 */
4214 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004215 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4216 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004217 final int targetSdk = getTargetSdk(callingPackage);
4218 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004219 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004220 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004221 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004222 mApp, subId, callingPackage, callingFeatureId,
4223 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004224 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4225 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004227 final long identity = Binder.clearCallingIdentity();
4228 try {
4229 final Phone phone = getPhone(subId);
4230 if (phone != null) {
4231 return phone.getServiceState().getDataNetworkType();
4232 } else {
4233 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4234 }
4235 } finally {
4236 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004238 }
4239
4240 /**
4241 * Returns the data network type
4242 */
4243 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004244 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4245 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4246 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004247 }
4248
4249 /**
4250 * Returns the data network type for a subId
4251 */
4252 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004253 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4254 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004256 mApp, subId, callingPackage, callingFeatureId,
4257 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004258 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4259 }
4260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 final Phone phone = getPhone(subId);
4264 if (phone != null) {
4265 return phone.getServiceState().getDataNetworkType();
4266 } else {
4267 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4268 }
4269 } finally {
4270 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004272 }
4273
4274 /**
Wink Saville36469e72014-06-11 15:17:00 -07004275 * Returns the Voice network type for a subId
4276 */
4277 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004278 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4279 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004281 mApp, subId, callingPackage, callingFeatureId,
4282 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004283 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4284 }
4285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 final long identity = Binder.clearCallingIdentity();
4287 try {
4288 final Phone phone = getPhone(subId);
4289 if (phone != null) {
4290 return phone.getServiceState().getVoiceNetworkType();
4291 } else {
4292 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4293 }
4294 } finally {
4295 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004297 }
4298
4299 /**
4300 * @return true if a ICC card is present
4301 */
4302 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004303 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004304 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4305 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004306 }
4307
4308 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004309 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004310 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004311 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004312 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 final Phone phone = PhoneFactory.getPhone(slotIndex);
4316 if (phone != null) {
4317 return phone.getIccCard().hasIccCard();
4318 } else {
4319 return false;
4320 }
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004324 }
4325
4326 /**
4327 * Return if the current radio is LTE on CDMA. This
4328 * is a tri-state return value as for a period of time
4329 * the mode may be unknown.
4330 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004331 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004332 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004333 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004334 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004336 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4337 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4338 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004339 }
4340
Sanket Padawe356d7632015-06-22 14:03:32 -07004341 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004342 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4343 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004344 try {
4345 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4346 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004347 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4348 }
4349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 final Phone phone = getPhone(subId);
4353 if (phone == null) {
4354 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4355 } else {
4356 return phone.getLteOnCdmaMode();
4357 }
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004360 }
Wink Saville36469e72014-06-11 15:17:00 -07004361 }
4362
Wink Saville36469e72014-06-11 15:17:00 -07004363 /**
4364 * {@hide}
4365 * Returns Default subId, 0 in the case of single standby.
4366 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004367 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004368 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004369 }
4370
Shishir Agrawala9f32182016-04-12 12:00:16 -07004371 private int getSlotForDefaultSubscription() {
4372 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4373 }
4374
Wink Savilleb564aae2014-10-23 10:18:09 -07004375 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004376 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004377 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004378
Pengquan Menge92a50d2018-09-21 15:54:48 -07004379 private boolean isActiveSubscription(int subId) {
4380 return mSubscriptionController.isActiveSubId(subId);
4381 }
4382
Ihab Awadf2177b72013-11-25 13:33:23 -08004383 /**
4384 * @see android.telephony.TelephonyManager.WifiCallingChoices
4385 */
4386 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 final long identity = Binder.clearCallingIdentity();
4388 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004389 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004390 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4391 getWhenToMakeWifiCallsDefaultPreference());
4392 } finally {
4393 Binder.restoreCallingIdentity(identity);
4394 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004395 }
4396
4397 /**
4398 * @see android.telephony.TelephonyManager.WifiCallingChoices
4399 */
4400 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004404 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004409 }
4410
Sailesh Nepald1e68152013-12-12 19:08:02 -08004411 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004412 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004413 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004414 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004415
Jordan Liu4c733742019-02-28 12:03:40 -08004416 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4417 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4418 if (phoneId == -1) {
4419 throw new IllegalArgumentException("Given slot index: " + slotIndex
4420 + " does not correspond to an active phone");
4421 }
4422 return PhoneFactory.getPhone(phoneId);
4423 }
4424
Shishir Agrawal566b7612013-10-28 14:41:00 -07004425 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004426 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4427 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4429 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004430 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004431 if (DBG) {
4432 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4433 }
4434 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4435 p2);
4436 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004437
Jordan Liu4c733742019-02-28 12:03:40 -08004438
4439 @Override
4440 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4441 int slotIndex, String callingPackage, String aid, int p2) {
4442 enforceModifyPermission();
4443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4444 if (DBG) {
4445 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4446 }
4447 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4448 callingPackage, aid, p2);
4449 }
4450
4451 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4452 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004453 final long identity = Binder.clearCallingIdentity();
4454 try {
4455 if (TextUtils.equals(ISDR_AID, aid)) {
4456 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004457 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4458 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004459 if (bestComponent == null
4460 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4461 loge("The calling package is not allowed to access ISD-R.");
4462 throw new SecurityException(
4463 "The calling package is not allowed to access ISD-R.");
4464 }
Derek Tan740e1672017-06-27 14:56:27 -07004465 }
Derek Tan740e1672017-06-27 14:56:27 -07004466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004467 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004468 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4469 null /* workSource */);
4470 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471 return response;
4472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004475 }
4476
4477 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004478 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4480 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004481 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4482 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4483 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004484
Jordan Liu4c733742019-02-28 12:03:40 -08004485 @Override
4486 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4487 enforceModifyPermission();
4488 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4489 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4490 channel);
4491 }
4492
4493 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494 final long identity = Binder.clearCallingIdentity();
4495 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496 if (channel < 0) {
4497 return false;
4498 }
Jordan Liu4c733742019-02-28 12:03:40 -08004499 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4500 null /* workSource */);
4501 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502 return success;
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004505 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004506 }
4507
4508 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004509 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004510 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4512 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004513 if (DBG) {
4514 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4515 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4516 + p3 + " data=" + data);
4517 }
4518 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4519 command, p1, p2, p3, data);
4520 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004521
Jordan Liu4c733742019-02-28 12:03:40 -08004522 @Override
4523 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4524 int command, int p1, int p2, int p3, String data) {
4525 enforceModifyPermission();
4526 if (DBG) {
4527 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4528 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4529 + p3 + " data=" + data);
4530 }
4531 return iccTransmitApduLogicalChannelWithPermission(
4532 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4533 data);
4534 }
4535
4536 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4537 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 final long identity = Binder.clearCallingIdentity();
4539 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004540 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 return "";
4542 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004544 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004545 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4546 null /* workSource */);
4547 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549 // Append the returned status code to the end of the response payload.
4550 String s = Integer.toHexString(
4551 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4552 if (response.payload != null) {
4553 s = IccUtils.bytesToHexString(response.payload) + s;
4554 }
4555 return s;
4556 } finally {
4557 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004558 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004559 }
Jake Hambye994d462014-02-03 13:10:13 -08004560
Evan Charltonc66da362014-05-16 14:06:40 -07004561 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004562 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4563 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4565 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004567 if (DBG) {
4568 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4569 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4570 }
4571 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4572 cla, command, p1, p2, p3, data);
4573 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004574
Jordan Liu4c733742019-02-28 12:03:40 -08004575 @Override
4576 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4577 int command, int p1, int p2, int p3, String data) {
4578 enforceModifyPermission();
4579 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4580 if (DBG) {
4581 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4582 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4583 + " data=" + data);
4584 }
4585
4586 return iccTransmitApduBasicChannelWithPermission(
4587 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4588 p2, p3, data);
4589 }
4590
4591 // open APDU basic channel assuming the caller has sufficient permissions
4592 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4593 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 final long identity = Binder.clearCallingIdentity();
4595 try {
4596 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4597 && TextUtils.equals(ISDR_AID, data)) {
4598 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004599 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4600 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 if (bestComponent == null
4602 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4603 loge("The calling package is not allowed to select ISD-R.");
4604 throw new SecurityException(
4605 "The calling package is not allowed to select ISD-R.");
4606 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004607 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004609 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004610 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4611 null /* workSource */);
4612 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 // Append the returned status code to the end of the response payload.
4615 String s = Integer.toHexString(
4616 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4617 if (response.payload != null) {
4618 s = IccUtils.bytesToHexString(response.payload) + s;
4619 }
4620 return s;
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004623 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004624 }
4625
4626 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004627 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004628 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4630 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 final long identity = Binder.clearCallingIdentity();
4633 try {
4634 if (DBG) {
4635 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4636 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4637 }
4638
4639 IccIoResult response =
4640 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4641 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4642 subId);
4643
4644 if (DBG) {
4645 log("Exchange SIM_IO [R]" + response);
4646 }
4647
4648 byte[] result = null;
4649 int length = 2;
4650 if (response.payload != null) {
4651 length = 2 + response.payload.length;
4652 result = new byte[length];
4653 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4654 } else {
4655 result = new byte[length];
4656 }
4657
4658 result[length - 1] = (byte) response.sw2;
4659 result[length - 2] = (byte) response.sw1;
4660 return result;
4661 } finally {
4662 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004663 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004664 }
4665
Nathan Haroldb3014052017-01-25 15:57:32 -08004666 /**
4667 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4668 * on a particular subscription
4669 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004670 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4671 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004673 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004674 return null;
4675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004676
4677 final long identity = Binder.clearCallingIdentity();
4678 try {
4679 if (appType != TelephonyManager.APPTYPE_USIM
4680 && appType != TelephonyManager.APPTYPE_SIM) {
4681 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4682 return null;
4683 }
4684 Object response = sendRequest(
4685 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4686 if (response instanceof String[]) {
4687 return (String[]) response;
4688 }
yincheng zhao2737e882019-09-06 17:06:54 -07004689 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004691 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692 } finally {
4693 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004694 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004695 }
4696
yincheng zhao2737e882019-09-06 17:06:54 -07004697 /**
4698 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4699 * subscription.
4700 *
4701 * @param subId the id of the subscription.
4702 * @param appType the uicc app type, must be USIM or SIM.
4703 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4704 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004705 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004706 * @return number of fplmns that is successfully written to the SIM.
4707 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004708 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4709 String callingFeatureId) {
4710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4711 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004712 if (DBG) logv("no permissions for setForbiddenplmns");
4713 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4714 }
4715 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4716 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4717 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4718 }
4719 if (fplmns == null) {
4720 throw new IllegalArgumentException("Fplmn List provided is null");
4721 }
4722 for (String fplmn : fplmns) {
4723 if (!CellIdentity.isValidPlmn(fplmn)) {
4724 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4725 }
4726 }
4727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 Object response = sendRequest(
4730 CMD_SET_FORBIDDEN_PLMNS,
4731 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4732 subId);
4733 return (int) response;
4734 } finally {
4735 Binder.restoreCallingIdentity(identity);
4736 }
4737 }
4738
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004739 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004740 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4742 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
4746 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4747 if (response.payload == null) {
4748 return "";
4749 }
Evan Charltonc66da362014-05-16 14:06:40 -07004750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004751 // Append the returned status code to the end of the response payload.
4752 String s = Integer.toHexString(
4753 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4754 s = IccUtils.bytesToHexString(response.payload) + s;
4755 return s;
4756 } finally {
4757 Binder.restoreCallingIdentity(identity);
4758 }
Evan Charltonc66da362014-05-16 14:06:40 -07004759 }
4760
Jake Hambye994d462014-02-03 13:10:13 -08004761 /**
4762 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4763 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4764 *
4765 * @param itemID the ID of the item to read
4766 * @return the NV item as a String, or null on error.
4767 */
4768 @Override
4769 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004770 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4772 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773
4774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004777 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4779 return value;
4780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
Jake Hambye994d462014-02-03 13:10:13 -08004783 }
4784
4785 /**
4786 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4787 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4788 *
4789 * @param itemID the ID of the item to read
4790 * @param itemValue the value to write, as a String
4791 * @return true on success; false on any failure
4792 */
4793 @Override
4794 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4797 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798
4799 final long identity = Binder.clearCallingIdentity();
4800 try {
4801 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4802 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004803 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4805 return success;
4806 } finally {
4807 Binder.restoreCallingIdentity(identity);
4808 }
Jake Hambye994d462014-02-03 13:10:13 -08004809 }
4810
4811 /**
4812 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4813 * Used for device configuration by some CDMA operators.
4814 *
4815 * @param preferredRoamingList byte array containing the new PRL
4816 * @return true on success; false on any failure
4817 */
4818 @Override
4819 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4821 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822
4823 final long identity = Binder.clearCallingIdentity();
4824 try {
4825 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4826 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4827 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4828 return success;
4829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
Jake Hambye994d462014-02-03 13:10:13 -08004832 }
4833
4834 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004835 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004836 * Used for device configuration by some CDMA operators.
4837 *
chen xu6dac5ab2018-10-26 17:39:23 -07004838 * @param slotIndex - device slot.
4839 *
Jake Hambye994d462014-02-03 13:10:13 -08004840 * @return true on success; false on any failure
4841 */
4842 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004843 public boolean resetModemConfig(int slotIndex) {
4844 Phone phone = PhoneFactory.getPhone(slotIndex);
4845 if (phone != null) {
4846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4847 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848
chen xu6dac5ab2018-10-26 17:39:23 -07004849 final long identity = Binder.clearCallingIdentity();
4850 try {
4851 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4852 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4853 return success;
4854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 }
chen xu6dac5ab2018-10-26 17:39:23 -07004858 return false;
4859 }
4860
4861 /**
4862 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4863 *
4864 * @param slotIndex - device slot.
4865 *
4866 * @return true on success; false on any failure
4867 */
4868 @Override
4869 public boolean rebootModem(int slotIndex) {
4870 Phone phone = PhoneFactory.getPhone(slotIndex);
4871 if (phone != null) {
4872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4873 mApp, phone.getSubId(), "rebootModem");
4874
4875 final long identity = Binder.clearCallingIdentity();
4876 try {
4877 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4878 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4879 return success;
4880 } finally {
4881 Binder.restoreCallingIdentity(identity);
4882 }
4883 }
4884 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004885 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004886
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004887 public String[] getPcscfAddress(String apnType, String callingPackage,
4888 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004889 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4891 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004892 return new String[0];
4893 }
4894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895 final long identity = Binder.clearCallingIdentity();
4896 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004897 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898 } finally {
4899 Binder.restoreCallingIdentity(identity);
4900 }
Wink Saville36469e72014-06-11 15:17:00 -07004901 }
4902
Brad Ebinger51f743a2017-01-23 13:50:20 -08004903 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004904 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4905 * {@link #disableIms(int)}.
4906 * @param slotIndex device slot.
4907 */
4908 public void resetIms(int slotIndex) {
4909 enforceModifyPermission();
4910
4911 final long identity = Binder.clearCallingIdentity();
4912 try {
4913 if (mImsResolver == null) {
4914 // may happen if the does not support IMS.
4915 return;
4916 }
4917 mImsResolver.disableIms(slotIndex);
4918 mImsResolver.enableIms(slotIndex);
4919 } finally {
4920 Binder.restoreCallingIdentity(identity);
4921 }
4922 }
4923
4924 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004925 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4926 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004927 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004928 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004929 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930
4931 final long identity = Binder.clearCallingIdentity();
4932 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004933 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004934 // may happen if the device does not support IMS.
4935 return;
4936 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004937 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 } finally {
4939 Binder.restoreCallingIdentity(identity);
4940 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004941 }
4942
4943 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004944 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4945 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004946 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004947 public void disableIms(int slotId) {
4948 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949
4950 final long identity = Binder.clearCallingIdentity();
4951 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004952 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004953 // may happen if the device does not support IMS.
4954 return;
4955 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004956 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004960 }
4961
4962 /**
4963 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4964 * feature or {@link null} if the service is not available. If the feature is available, the
4965 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4966 */
4967 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004968 IImsServiceFeatureCallback callback) {
4969 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970
4971 final long identity = Binder.clearCallingIdentity();
4972 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004973 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004974 // may happen if the device does not support IMS.
4975 return null;
4976 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004977 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 } finally {
4979 Binder.restoreCallingIdentity(identity);
4980 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004981 }
4982
4983 /**
4984 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4985 * feature during emergency calling or {@link null} if the service is not available. If the
4986 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4987 * listener for feature updates.
4988 */
4989 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4990 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991
4992 final long identity = Binder.clearCallingIdentity();
4993 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004994 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004995 // may happen if the device does not support IMS.
4996 return null;
4997 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004998 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005002 }
5003
Brad Ebinger5f64b052017-12-14 14:26:15 -08005004 /**
5005 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005006 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005007 */
5008 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5009 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010
5011 final long identity = Binder.clearCallingIdentity();
5012 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005013 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005014 // may happen if the device does not support IMS.
5015 return null;
5016 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005017 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 } finally {
5019 Binder.restoreCallingIdentity(identity);
5020 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005021 }
5022
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005023 /**
5024 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005025 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005026 */
5027 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5028 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029
5030 final long identity = Binder.clearCallingIdentity();
5031 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005032 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005033 // may happen if the device does not support IMS.
5034 return null;
5035 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005036 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037 } finally {
5038 Binder.restoreCallingIdentity(identity);
5039 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005040 }
5041
Brad Ebinger884c07b2018-02-15 16:17:40 -08005042 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005043 * Sets the ImsService Package Name that Telephony will bind to.
5044 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005045 * @param slotIndex the slot ID that the ImsService should bind for.
5046 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005047 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005048 * @param featureTypes An integer array of feature types associated with a packageName.
5049 * @param packageName The name of the package that the current configuration will be replaced
5050 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005051 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005052 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005053 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5054 int[] featureTypes, String packageName) {
5055 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5058 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005059 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061 final long identity = Binder.clearCallingIdentity();
5062 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005063 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005064 // may happen if the device does not support IMS.
5065 return false;
5066 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005067 Map<Integer, String> featureConfig = new HashMap<>();
5068 for (int featureType : featureTypes) {
5069 featureConfig.put(featureType, packageName);
5070 }
5071 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5072 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 } finally {
5074 Binder.restoreCallingIdentity(identity);
5075 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005076 }
5077
5078 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005079 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005080 *
5081 * @param slotId The slot that the ImsService is associated with.
5082 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5083 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005084 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005085 * @return the package name of the ImsService configuration.
5086 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005087 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5088 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005089 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005090 TelephonyPermissions
5091 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5092 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5093 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005097 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005098 // may happen if the device does not support IMS.
5099 return "";
5100 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005101 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005102 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5103 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005107 }
5108
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005109 /**
5110 * Get the MmTelFeature state associated with the requested subscription id.
5111 * @param subId The subscription that the MmTelFeature is associated with.
5112 * @param callback A callback with an integer containing the
5113 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5114 */
5115 @Override
5116 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5117 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5118 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5119 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5120 "IMS not available on device.");
5121 }
5122 final long token = Binder.clearCallingIdentity();
5123 try {
5124 int slotId = getSlotIndex(subId);
5125 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5126 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5127 + subId + "'");
5128 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5129 }
5130 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5131 try {
5132 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5133 } catch (RemoteException e) {
5134 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5135 + "Ignore");
5136 }
5137 });
5138 } finally {
5139 Binder.restoreCallingIdentity(token);
5140 }
5141 }
5142
Wink Saville36469e72014-06-11 15:17:00 -07005143 public void setImsRegistrationState(boolean registered) {
5144 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145
5146 final long identity = Binder.clearCallingIdentity();
5147 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005148 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 } finally {
5150 Binder.restoreCallingIdentity(identity);
5151 }
Wink Saville36469e72014-06-11 15:17:00 -07005152 }
5153
5154 /**
Stuart Scott54788802015-03-30 13:18:01 -07005155 * Set the network selection mode to automatic.
5156 *
5157 */
5158 @Override
5159 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5161 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162
5163 final long identity = Binder.clearCallingIdentity();
5164 try {
shilufc958392020-01-20 11:36:01 -08005165 if (!isActiveSubscription(subId)) {
5166 return;
5167 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5169 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5170 } finally {
5171 Binder.restoreCallingIdentity(identity);
5172 }
Stuart Scott54788802015-03-30 13:18:01 -07005173 }
5174
Pengquan Mengea84e042018-09-20 14:57:26 -07005175 /**
5176 * Ask the radio to connect to the input network and change selection mode to manual.
5177 *
5178 * @param subId the id of the subscription.
5179 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5180 * the operator to attach to.
5181 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5182 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5183 * normal network selection next time.
5184 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005185 */
5186 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005187 public boolean setNetworkSelectionModeManual(
5188 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5190 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005191
5192 if (!isActiveSubscription(subId)) {
5193 return false;
5194 }
5195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 final long identity = Binder.clearCallingIdentity();
5197 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005198 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005200 if (DBG) {
5201 log("setNetworkSelectionModeManual: subId: " + subId
5202 + " operator: " + operatorInfo);
5203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005208 }
shilu84f6e8b2019-12-19 13:58:01 -08005209 /**
5210 * Get the manual network selection
5211 *
5212 * @param subId the id of the subscription.
5213 *
5214 * @return the previously saved user selected PLMN
5215 */
5216 @Override
5217 public String getManualNetworkSelectionPlmn(int subId) {
5218 TelephonyPermissions
5219 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5220 mApp, subId, "getManualNetworkSelectionPlmn");
5221
5222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 if (!isActiveSubscription(subId)) {
5225 return "";
5226 }
5227
5228 final Phone phone = getPhone(subId);
5229 if (phone == null) {
5230 return "";
5231 }
5232 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5233 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5234 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
5238 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005239
5240 /**
5241 * Scans for available networks.
5242 */
5243 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005244 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5245 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5247 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005248 LocationAccessPolicy.LocationPermissionResult locationResult =
5249 LocationAccessPolicy.checkLocationPermission(mApp,
5250 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5251 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005252 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005253 .setCallingPid(Binder.getCallingPid())
5254 .setCallingUid(Binder.getCallingUid())
5255 .setMethod("getCellNetworkScanResults")
5256 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5257 .build());
5258 switch (locationResult) {
5259 case DENIED_HARD:
5260 throw new SecurityException("Not allowed to access scan results -- location");
5261 case DENIED_SOFT:
5262 return null;
5263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264
Pengquan Menga1bb6272018-09-06 09:59:22 -07005265 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 try {
5267 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005268 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005273 }
5274
5275 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005276 * Get the call forwarding info, given the call forwarding reason.
5277 */
5278 @Override
5279 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5280 enforceReadPrivilegedPermission("getCallForwarding");
5281 long identity = Binder.clearCallingIdentity();
5282 try {
5283 if (DBG) {
5284 log("getCallForwarding: subId " + subId
5285 + " callForwardingReason" + callForwardingReason);
5286 }
5287 return (CallForwardingInfo) sendRequest(
5288 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
5292 }
5293
5294 /**
5295 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5296 * reason, the number to forward, and the timeout before the forwarding is attempted.
5297 */
5298 @Override
5299 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5300 enforceModifyPermission();
5301 long identity = Binder.clearCallingIdentity();
5302 try {
5303 if (DBG) {
5304 log("setCallForwarding: subId " + subId
5305 + " callForwardingInfo" + callForwardingInfo);
5306 }
5307 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
5311 }
5312
5313 /**
5314 * Get the call forwarding info, given the call forwarding reason.
5315 */
5316 @Override
5317 public int getCallWaitingStatus(int subId) {
5318 enforceReadPrivilegedPermission("getCallForwarding");
5319 long identity = Binder.clearCallingIdentity();
5320 try {
5321 if (DBG) log("getCallWaitingStatus: subId " + subId);
5322 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
5325 }
5326 }
5327
5328 /**
5329 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5330 * reason, the number to forward, and the timeout before the forwarding is attempted.
5331 */
5332 @Override
5333 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5334 enforceModifyPermission();
5335 long identity = Binder.clearCallingIdentity();
5336 try {
5337 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5338 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
5342 }
5343
5344 /**
yinxub1bed742017-04-17 11:45:04 -07005345 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005346 *
yinxub1bed742017-04-17 11:45:04 -07005347 * @param subId id of the subscription
5348 * @param request contains the radio access networks with bands/channels to scan
5349 * @param messenger callback messenger for scan results or errors
5350 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005351 * @return the id of the requested scan which can be used to stop the scan.
5352 */
5353 @Override
5354 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005355 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5357 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005358 LocationAccessPolicy.LocationPermissionResult locationResult =
5359 LocationAccessPolicy.checkLocationPermission(mApp,
5360 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5361 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005362 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005363 .setCallingPid(Binder.getCallingPid())
5364 .setCallingUid(Binder.getCallingUid())
5365 .setMethod("requestNetworkScan")
5366 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5367 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005368 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005369 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005370 if (e != null) {
5371 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5372 throw e;
5373 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005374 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005375 return TelephonyScanManager.INVALID_SCAN_ID;
5376 }
5377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 }
Hall Liu912dfd32019-04-25 14:02:26 -07005379 int callingUid = Binder.getCallingUid();
5380 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005381 final long identity = Binder.clearCallingIdentity();
5382 try {
5383 return mNetworkScanRequestTracker.startNetworkScan(
5384 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005385 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388 }
yinxu504e1392017-04-12 16:03:22 -07005389 }
5390
Hall Liub2ac8ef2019-02-28 15:56:23 -08005391 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005392 NetworkScanRequest request, int subId) {
5393 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5394 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5395 boolean hasNetworkScanPermission =
5396 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5397 == PERMISSION_GRANTED;
5398
5399 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5400 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5401 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005402 }
5403
5404 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5405 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005406 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5407 return new SecurityException("Specific channels must not be"
5408 + " scanned without location access.");
5409 }
5410 }
5411 }
5412
Hall Liub2ac8ef2019-02-28 15:56:23 -08005413 return null;
5414 }
5415
yinxu504e1392017-04-12 16:03:22 -07005416 /**
5417 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005418 *
5419 * @param subId id of the subscription
5420 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005421 */
5422 @Override
5423 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5425 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426
Hall Liu912dfd32019-04-25 14:02:26 -07005427 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 final long identity = Binder.clearCallingIdentity();
5429 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005430 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 } finally {
5432 Binder.restoreCallingIdentity(identity);
5433 }
yinxu504e1392017-04-12 16:03:22 -07005434 }
5435
5436 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005437 * Get the calculated preferred network type.
5438 * Used for debugging incorrect network type.
5439 *
5440 * @return the preferred network type, defined in RILConstants.java.
5441 */
5442 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005443 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005444 final Phone defaultPhone = getDefaultPhone();
5445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005446 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005447 return RILConstants.PREFERRED_NETWORK_MODE;
5448 }
5449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 final long identity = Binder.clearCallingIdentity();
5451 try {
5452 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005453 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 } finally {
5455 Binder.restoreCallingIdentity(identity);
5456 }
Junda Liu84d15a22014-07-02 11:21:04 -07005457 }
5458
5459 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005460 * Get the preferred network type.
5461 * Used for device configuration by some CDMA operators.
5462 *
5463 * @return the preferred network type, defined in RILConstants.java.
5464 */
5465 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005466 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005467 TelephonyPermissions
5468 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5469 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470
5471 final long identity = Binder.clearCallingIdentity();
5472 try {
5473 if (DBG) log("getPreferredNetworkType");
5474 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5475 int networkType = (result != null ? result[0] : -1);
5476 if (DBG) log("getPreferredNetworkType: " + networkType);
5477 return networkType;
5478 } finally {
5479 Binder.restoreCallingIdentity(identity);
5480 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005481 }
5482
5483 /**
5484 * Set the preferred network type.
5485 * Used for device configuration by some CDMA operators.
5486 *
5487 * @param networkType the preferred network type, defined in RILConstants.java.
5488 * @return true on success; false on any failure.
5489 */
5490 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005491 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5493 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494
5495 final long identity = Binder.clearCallingIdentity();
5496 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005497 Settings.Global.putInt(mApp.getContentResolver(),
5498 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5499 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 } finally {
5501 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005502 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005503 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005504
5505 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005506 * Get the allowed network types that store in the telephony provider.
5507 *
5508 * @param subId the id of the subscription.
5509 * @return allowedNetworkTypes the allowed network types.
5510 */
5511 @Override
5512 public long getAllowedNetworkTypes(int subId) {
5513 TelephonyPermissions
5514 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5515 mApp, subId, "getAllowedNetworkTypes");
5516
5517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 return SubscriptionManager.getLongSubscriptionProperty(
5520 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
5523 }
5524 }
5525
5526 /**
5527 * Set the allowed network types.
5528 *
5529 * @param subId the id of the subscription.
5530 * @param allowedNetworkTypes the allowed network types.
5531 * @return true on success; false on any failure.
5532 */
5533 @Override
5534 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5536 mApp, subId, "setAllowedNetworkTypes");
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
5539 SubscriptionManager.setSubscriptionProperty(subId,
5540 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5541 String.valueOf(allowedNetworkTypes));
5542 return setPreferredNetworkTypesInternal(subId);
5543 } finally {
5544 Binder.restoreCallingIdentity(identity);
5545 }
5546 }
5547
5548 private boolean setPreferredNetworkTypesInternal(int subId) {
5549 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5550 Settings.Global.getInt(mApp.getContentResolver(),
5551 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5552 RILConstants.PREFERRED_NETWORK_MODE));
5553 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5554 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5555 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5556 (int) (networkTypeBitMask & allowedNetworkTypes));
5557
5558 if (DBG) {
5559 log("setPreferredNetworkTypesInternal: subId " + subId
5560 + " networkTypes " + networkTypeBitMask
5561 + " allowedNetworkTypes " + allowedNetworkTypes
5562 + " networkMode " + networkMode);
5563 }
5564
5565 Boolean success = (Boolean) sendRequest(
5566 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5567 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5568 return success;
5569 }
5570
5571 /**
Miaoa84611c2019-03-15 09:21:10 +08005572 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005573 *
Miaoa84611c2019-03-15 09:21:10 +08005574 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005575 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005576 * @hide
5577 */
5578 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005579 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005580 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005582 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 try {
Miaoa84611c2019-03-15 09:21:10 +08005584 if (phone != null) {
5585 return phone.hasMatchedTetherApnSetting();
5586 } else {
5587 return false;
5588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 } finally {
5590 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005591 }
Junda Liu475951f2014-11-07 16:45:03 -08005592 }
5593
5594 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005595 * Set mobile data enabled
5596 * Used by the user through settings etc to turn on/off mobile data
5597 *
5598 * @param enable {@code true} turn turn data on, else {@code false}
5599 */
5600 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005601 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5603 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604
5605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 int phoneId = mSubscriptionController.getPhoneId(subId);
5608 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5609 Phone phone = PhoneFactory.getPhone(phoneId);
5610 if (phone != null) {
5611 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005612 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005614 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 }
5616 } finally {
5617 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005618 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005619 }
5620
5621 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005622 * Enable or disable always reporting signal strength changes from radio.
5623 *
5624 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5625 */
5626 @Override
5627 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5628 enforceModifyPermission();
5629 enforceSystemCaller();
5630
5631 final long identity = Binder.clearCallingIdentity();
5632 final Phone phone = getPhone(subId);
5633 try {
5634 if (phone != null) {
5635 if (DBG) {
5636 log("setAlwaysReportSignalStrength: subId=" + subId
5637 + " isEnable=" + isEnable);
5638 }
5639 phone.setAlwaysReportSignalStrength(isEnable);
5640 } else {
5641 loge("setAlwaysReportSignalStrength: no phone found for subId="
5642 + subId);
5643 }
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
5647 }
5648
5649 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005650 * Get the user enabled state of Mobile Data.
5651 *
5652 * TODO: remove and use isUserDataEnabled.
5653 * This can't be removed now because some vendor codes
5654 * calls through ITelephony directly while they should
5655 * use TelephonyManager.
5656 *
5657 * @return true on enabled
5658 */
5659 @Override
5660 public boolean getDataEnabled(int subId) {
5661 return isUserDataEnabled(subId);
5662 }
5663
5664 /**
5665 * Get whether mobile data is enabled per user setting.
5666 *
5667 * There are other factors deciding whether mobile data is actually enabled, but they are
5668 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005669 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005670 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005671 *
5672 * @return {@code true} if data is enabled else {@code false}
5673 */
5674 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005675 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005676 try {
5677 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5678 null);
5679 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5681 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683
5684 final long identity = Binder.clearCallingIdentity();
5685 try {
5686 int phoneId = mSubscriptionController.getPhoneId(subId);
5687 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5688 Phone phone = PhoneFactory.getPhone(phoneId);
5689 if (phone != null) {
5690 boolean retVal = phone.isUserDataEnabled();
5691 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5692 return retVal;
5693 } else {
5694 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5695 return false;
5696 }
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005699 }
5700 }
5701
5702 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005703 * Checks if the device is capable of mobile data by considering whether whether the
5704 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5705 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005706 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005707 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005708 */
5709 @Override
5710 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005711 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712
5713 final long identity = Binder.clearCallingIdentity();
5714 try {
5715 int phoneId = mSubscriptionController.getPhoneId(subId);
5716 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5717 Phone phone = PhoneFactory.getPhone(phoneId);
5718 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005719 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5721 return retVal;
5722 } else {
5723 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5724 return false;
5725 }
5726 } finally {
5727 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005728 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005729 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005730
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005731 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5732 Phone phone) {
5733 //load access rules from carrier configs, and check those as well: b/139133814
5734 SubscriptionController subController = SubscriptionController.getInstance();
5735 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5736 || subController == null) return privilegeFromSim;
5737
5738 int uid = Binder.getCallingUid();
5739 PackageManager pkgMgr = phone.getContext().getPackageManager();
5740 String[] packages = pkgMgr.getPackagesForUid(uid);
5741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
5744 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5745 SubscriptionManager subManager = (SubscriptionManager)
5746 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5747 for (String pkg : packages) {
5748 if (subManager.canManageSubscription(subInfo, pkg)) {
5749 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5750 }
5751 }
5752 return privilegeFromSim;
5753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
5756 }
5757
5758 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5759 String pkgName) {
5760 //load access rules from carrier configs, and check those as well: b/139133814
5761 SubscriptionController subController = SubscriptionController.getInstance();
5762 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5763 || subController == null) return privilegeFromSim;
5764
5765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5768 SubscriptionManager subManager = (SubscriptionManager)
5769 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5770 return subManager.canManageSubscription(subInfo, pkgName)
5771 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
5775 }
5776
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005777 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005778 public int getCarrierPrivilegeStatus(int subId) {
5779 final Phone phone = getPhone(subId);
5780 if (phone == null) {
5781 loge("getCarrierPrivilegeStatus: Invalid subId");
5782 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5783 }
5784 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005785 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005786 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005787 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5788 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005789
5790 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5791 card.getCarrierPrivilegeStatusForCurrentTransaction(
5792 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005793 }
Junda Liu29340342014-07-10 15:23:27 -07005794
5795 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005796 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005797 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005798 final Phone phone = getPhone(subId);
5799 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005800 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005801 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5802 }
5803 UiccProfile profile =
5804 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5805 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005806 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005807 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5808 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005809 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005810 profile.getCarrierPrivilegeStatusForUid(
5811 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005812 }
5813
5814 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005815 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5816 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005817 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005818 }
5819
5820 int phoneId = SubscriptionManager.getPhoneId(subId);
5821 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005822 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005823 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005824 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5825 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005826 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5827 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5828 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005829 }
5830
5831 @Override
5832 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005833 if (TextUtils.isEmpty(pkgName))
5834 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005835 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5836 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5837 UiccCard card = UiccController.getInstance().getUiccCard(i);
5838 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005839 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005840 continue;
5841 }
5842
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005843 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5844 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5845 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005846 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5847 break;
5848 }
5849 }
5850
5851 return result;
Junda Liu29340342014-07-10 15:23:27 -07005852 }
Derek Tan89e89d42014-07-08 17:00:10 -07005853
5854 @Override
Junda Liue64de782015-04-16 17:19:16 -07005855 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5856 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5857 loge("phoneId " + phoneId + " is not valid.");
5858 return null;
5859 }
5860 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005861 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005862 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005863 return null ;
5864 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005865 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005866 }
5867
Amith Yamasani6e118872016-02-19 12:53:51 -08005868 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005869 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005870 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005871 List<String> privilegedPackages = new ArrayList<>();
5872 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005873 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5874 // has UICC in that slot.
5875 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005876 if (card.hasCarrierPrivilegeRules()) {
5877 if (packages == null) {
5878 // Only check packages in user 0 for now
5879 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005880 PackageManager.MATCH_DISABLED_COMPONENTS
5881 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005882 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005883 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005884 }
5885 for (int p = packages.size() - 1; p >= 0; p--) {
5886 PackageInfo pkgInfo = packages.get(p);
5887 if (pkgInfo != null && pkgInfo.packageName != null
5888 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005889 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005890 privilegedPackages.add(pkgInfo.packageName);
5891 }
5892 }
5893 }
5894 }
5895 return privilegedPackages;
5896 }
5897
chen xuf7e9fe82019-05-09 19:31:02 -07005898 @Override
5899 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005900 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5901
5902 final long identity = Binder.clearCallingIdentity();
5903
chen xuf7e9fe82019-05-09 19:31:02 -07005904 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005905 try {
5906 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5907 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5908 }
5909 } finally {
5910 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005911 }
5912 return privilegedPackages;
5913 }
5914
Wink Savilleb564aae2014-10-23 10:18:09 -07005915 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005916 final Phone phone = getPhone(subId);
5917 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005918 if (card == null) {
5919 loge("getIccId: No UICC");
5920 return null;
5921 }
5922 String iccId = card.getIccId();
5923 if (TextUtils.isEmpty(iccId)) {
5924 loge("getIccId: ICC ID is null or empty.");
5925 return null;
5926 }
5927 return iccId;
5928 }
5929
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005930 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005931 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5932 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005933 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005934 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 final long identity = Binder.clearCallingIdentity();
5937 try {
5938 final String iccId = getIccId(subId);
5939 final Phone phone = getPhone(subId);
5940 if (phone == null) {
5941 return false;
5942 }
5943 final String subscriberId = phone.getSubscriberId();
5944
5945 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08005946 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 + subscriberId + " to " + number);
5948 }
5949
5950 if (TextUtils.isEmpty(iccId)) {
5951 return false;
5952 }
5953
5954 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5955
5956 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5957 if (alphaTag == null) {
5958 editor.remove(alphaTagPrefKey);
5959 } else {
5960 editor.putString(alphaTagPrefKey, alphaTag);
5961 }
5962
5963 // Record both the line number and IMSI for this ICCID, since we need to
5964 // track all merged IMSIs based on line number
5965 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5966 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5967 if (number == null) {
5968 editor.remove(numberPrefKey);
5969 editor.remove(subscriberPrefKey);
5970 } else {
5971 editor.putString(numberPrefKey, number);
5972 editor.putString(subscriberPrefKey, subscriberId);
5973 }
5974
5975 editor.commit();
5976 return true;
5977 } finally {
5978 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005979 }
Derek Tan7226c842014-07-02 17:42:23 -07005980 }
5981
5982 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005983 public String getLine1NumberForDisplay(int subId, String callingPackage,
5984 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005985 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005987 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005988 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005989 return null;
5990 }
Derek Tan97ebb422014-09-05 16:55:38 -07005991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 final long identity = Binder.clearCallingIdentity();
5993 try {
5994 String iccId = getIccId(subId);
5995 if (iccId != null) {
5996 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5997 if (DBG_MERGE) {
5998 log("getLine1NumberForDisplay returning "
5999 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6000 }
6001 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6004 return null;
6005 } finally {
6006 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006007 }
Derek Tan7226c842014-07-02 17:42:23 -07006008 }
6009
6010 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006011 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6012 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006014 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006015 return null;
6016 }
Derek Tan97ebb422014-09-05 16:55:38 -07006017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 final long identity = Binder.clearCallingIdentity();
6019 try {
6020 String iccId = getIccId(subId);
6021 if (iccId != null) {
6022 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6023 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6024 }
6025 return null;
6026 } finally {
6027 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006028 }
Derek Tan7226c842014-07-02 17:42:23 -07006029 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006030
6031 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006032 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6033 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006034 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6035 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006037 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006038 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006039 return null;
6040 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006041
Jordan Liub49b04b2019-05-06 14:45:15 -07006042 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6043 // the process, where TelephonyManager was instantiated.
6044 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006045 final long identity = Binder.clearCallingIdentity();
6046 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006047 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 final TelephonyManager tele = TelephonyManager.from(context);
6049 final SubscriptionManager sub = SubscriptionManager.from(context);
6050
6051 // Figure out what subscribers are currently active
6052 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053
Jordan Liub49b04b2019-05-06 14:45:15 -07006054 // Only consider subs which match the current subId
6055 // This logic can be simplified. See b/131189269 for progress.
6056 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006057 activeSubscriberIds.add(tele.getSubscriberId(subId));
6058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059
6060 // First pass, find a number override for an active subscriber
6061 String mergeNumber = null;
6062 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6063 for (String key : prefs.keySet()) {
6064 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6065 final String subscriberId = (String) prefs.get(key);
6066 if (activeSubscriberIds.contains(subscriberId)) {
6067 final String iccId = key.substring(
6068 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6069 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6070 mergeNumber = (String) prefs.get(numberKey);
6071 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006072 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 + " for active subscriber " + subscriberId);
6074 }
6075 if (!TextUtils.isEmpty(mergeNumber)) {
6076 break;
6077 }
6078 }
6079 }
6080 }
6081
6082 // Shortcut when no active merged subscribers
6083 if (TextUtils.isEmpty(mergeNumber)) {
6084 return null;
6085 }
6086
6087 // Second pass, find all subscribers under that line override
6088 final ArraySet<String> result = new ArraySet<>();
6089 for (String key : prefs.keySet()) {
6090 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6091 final String number = (String) prefs.get(key);
6092 if (mergeNumber.equals(number)) {
6093 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6094 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6095 final String subscriberId = (String) prefs.get(subscriberKey);
6096 if (!TextUtils.isEmpty(subscriberId)) {
6097 result.add(subscriberId);
6098 }
6099 }
6100 }
6101 }
6102
6103 final String[] resultArray = result.toArray(new String[result.size()]);
6104 Arrays.sort(resultArray);
6105 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006106 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6108 }
6109 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006110 } finally {
6111 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006112 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006113 }
6114
6115 @Override
zoey chen38003472019-12-13 17:16:31 +08006116 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6117 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006118
6119 final long identity = Binder.clearCallingIdentity();
6120 try {
6121 final TelephonyManager telephonyManager = mApp.getSystemService(
6122 TelephonyManager.class);
6123 String subscriberId = telephonyManager.getSubscriberId(subId);
6124 if (subscriberId == null) {
6125 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006126 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006127 + subId);
6128 }
6129 return null;
6130 }
6131
6132 final SubscriptionInfo info = SubscriptionController.getInstance()
6133 .getSubscriptionInfo(subId);
6134 final ParcelUuid groupUuid = info.getGroupUuid();
6135 // If it doesn't belong to any group, return just subscriberId of itself.
6136 if (groupUuid == null) {
6137 return new String[]{subscriberId};
6138 }
6139
6140 // Get all subscriberIds from the group.
6141 final List<String> mergedSubscriberIds = new ArrayList<>();
6142 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006143 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6144 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006145 for (SubscriptionInfo subInfo : groupInfos) {
6146 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6147 if (subscriberId != null) {
6148 mergedSubscriberIds.add(subscriberId);
6149 }
6150 }
6151
6152 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6153 } finally {
6154 Binder.restoreCallingIdentity(identity);
6155
6156 }
6157 }
6158
6159 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006160 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006161 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006162 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163
6164 final long identity = Binder.clearCallingIdentity();
6165 try {
6166 final Phone phone = getPhone(subId);
6167 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6168 } finally {
6169 Binder.restoreCallingIdentity(identity);
6170 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006171 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006172
6173 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006174 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006175 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6176 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006177 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6178 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179
6180 final long identity = Binder.clearCallingIdentity();
6181 try {
6182 final Phone phone = getPhone(subId);
6183 if (phone == null) {
6184 return false;
6185 }
6186 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6187 cdmaNonRoamingList);
6188 } finally {
6189 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006190 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006191 }
6192
6193 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006194 @Deprecated
6195 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6196 enforceModifyPermission();
6197
6198 int returnValue = 0;
6199 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006200 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006201 if(result.exception == null) {
6202 if (result.result != null) {
6203 byte[] responseData = (byte[])(result.result);
6204 if(responseData.length > oemResp.length) {
6205 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6206 responseData.length + "bytes. Buffer Size is " +
6207 oemResp.length + "bytes.");
6208 }
6209 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6210 returnValue = responseData.length;
6211 }
6212 } else {
6213 CommandException ex = (CommandException) result.exception;
6214 returnValue = ex.getCommandError().ordinal();
6215 if(returnValue > 0) returnValue *= -1;
6216 }
6217 } catch (RuntimeException e) {
6218 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6219 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6220 if(returnValue > 0) returnValue *= -1;
6221 }
6222
6223 return returnValue;
6224 }
6225
6226 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006227 public void setRadioCapability(RadioAccessFamily[] rafs) {
6228 try {
6229 ProxyController.getInstance().setRadioCapability(rafs);
6230 } catch (RuntimeException e) {
6231 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6232 }
6233 }
6234
6235 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006236 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006237 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006238 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006239 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006240 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 final long identity = Binder.clearCallingIdentity();
6243 try {
chen xub97461a2018-10-26 14:17:57 -07006244 TelephonyPermissions
6245 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6246 mApp, phone.getSubId(), "getRadioAccessFamily");
6247 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006248 } finally {
6249 Binder.restoreCallingIdentity(identity);
6250 }
chen xub97461a2018-10-26 14:17:57 -07006251 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006252 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006253
6254 @Override
6255 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006256 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006257 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258
6259 final long identity = Binder.clearCallingIdentity();
6260 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006261 ImsManager.getInstance(defaultPhone.getContext(),
6262 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006263 } finally {
6264 Binder.restoreCallingIdentity(identity);
6265 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006266 }
6267
6268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006269 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006270 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6272 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006273 return false;
6274 }
Svet Ganovb320e182015-04-16 12:30:10 -07006275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276 final long identity = Binder.clearCallingIdentity();
6277 try {
6278 // Check the user preference and the system-level IMS setting. Even if the user has
6279 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6280 // In the long run, we may instead need to check if there exists a connection service
6281 // which can support video calling.
6282 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006283 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 return imsManager.isVtEnabledByPlatform()
6285 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6286 && imsManager.isVtEnabledByUser();
6287 } finally {
6288 Binder.restoreCallingIdentity(identity);
6289 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006290 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006291
Andrew Leea1239f22015-03-02 17:44:07 -08006292 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006293 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6294 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006296 mApp, subId, callingPackage, callingFeatureId,
6297 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 return false;
6299 }
6300
6301 final long identity = Binder.clearCallingIdentity();
6302 try {
6303 CarrierConfigManager configManager =
6304 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006305 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6307 } finally {
6308 Binder.restoreCallingIdentity(identity);
6309 }
Andrew Leea1239f22015-03-02 17:44:07 -08006310 }
6311
6312 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006313 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006315 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 return false;
6317 }
6318
6319 final long identity = Binder.clearCallingIdentity();
6320 try {
6321 CarrierConfigManager configManager =
6322 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006323 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
Andrew Leea1239f22015-03-02 17:44:07 -08006328 }
6329
Andrew Lee9431b832015-03-09 18:46:45 -07006330 @Override
6331 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006332 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006333 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006334 }
6335
6336 @Override
6337 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 final long identity = Binder.clearCallingIdentity();
6339 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006340 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341 } finally {
6342 Binder.restoreCallingIdentity(identity);
6343 }
Andrew Lee9431b832015-03-09 18:46:45 -07006344 }
6345
Hall Liuf6668912018-10-31 17:05:23 -07006346 /**
6347 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6348 * support for the feature and device firmware support.
6349 *
6350 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6351 */
6352 @Override
6353 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006355 final Phone phone = getPhone(subscriptionId);
6356 if (phone == null) {
6357 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6358 return false;
6359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006361 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6363 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006364 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 return isCarrierSupported && isDeviceSupported;
6366 } finally {
6367 Binder.restoreCallingIdentity(identity);
6368 }
Hall Liu98187582018-01-22 19:15:32 -08006369 }
6370
Hall Liuf6668912018-10-31 17:05:23 -07006371 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006372 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6373 * RTT setting, will return true if the device and carrier both support RTT.
6374 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006375 */
6376 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 final long identity = Binder.clearCallingIdentity();
6378 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006379 boolean isRttSupported = isRttSupported(subscriptionId);
6380 boolean isUserRttSettingOn = Settings.Secure.getInt(
6381 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6382 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6383 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6384 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 } finally {
6386 Binder.restoreCallingIdentity(identity);
6387 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006388 }
6389
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006390 @Deprecated
6391 @Override
6392 public String getDeviceId(String callingPackage) {
6393 return getDeviceIdWithFeature(callingPackage, null);
6394 }
6395
Sanket Padawe7310cc72015-01-14 09:53:20 -08006396 /**
6397 * Returns the unique device ID of phone, for example, the IMEI for
6398 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6399 *
6400 * <p>Requires Permission:
6401 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6402 */
6403 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006404 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006405 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006406 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006407 return null;
6408 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006409 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006410 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006411 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006412 return null;
6413 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414
6415 final long identity = Binder.clearCallingIdentity();
6416 try {
6417 return phone.getDeviceId();
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006421 }
6422
Ping Sunc67b7c22016-03-02 19:16:45 +08006423 /**
6424 * {@hide}
6425 * Returns the IMS Registration Status on a particular subid
6426 *
6427 * @param subId
6428 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006429 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006430 Phone phone = getPhone(subId);
6431 if (phone != null) {
6432 return phone.isImsRegistered();
6433 } else {
6434 return false;
6435 }
6436 }
6437
Santos Cordon7a1885b2015-02-03 11:15:19 -08006438 @Override
6439 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 final long identity = Binder.clearCallingIdentity();
6441 try {
6442 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006446 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006447
Tyler Gunnf70ed162019-04-03 15:28:53 -07006448 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006449 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006450 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006452 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006453 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6454 }
6455 final long identity = Binder.clearCallingIdentity();
6456 try {
6457 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6458 } finally {
6459 Binder.restoreCallingIdentity(identity);
6460 }
6461 }
6462
6463 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006464 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6465 final long identity = Binder.clearCallingIdentity();
6466 try {
6467 Phone phone = getPhone(subscriptionId);
6468 if (phone == null) {
6469 return null;
6470 }
6471 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
6475 }
6476
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006477 /**
6478 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006479 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006480 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 final long identity = Binder.clearCallingIdentity();
6482 try {
6483 Phone phone = getPhone(subId);
6484 if (phone != null) {
6485 return phone.isWifiCallingEnabled();
6486 } else {
6487 return false;
6488 }
6489 } finally {
6490 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006491 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006492 }
6493
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006494 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006495 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006496 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006497 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006498 final long identity = Binder.clearCallingIdentity();
6499 try {
6500 Phone phone = getPhone(subId);
6501 if (phone != null) {
6502 return phone.isVideoEnabled();
6503 } else {
6504 return false;
6505 }
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006508 }
6509 }
6510
6511 /**
6512 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6513 * defined in {@link ImsRegistrationImplBase}.
6514 */
6515 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516 final long identity = Binder.clearCallingIdentity();
6517 try {
6518 Phone phone = getPhone(subId);
6519 if (phone != null) {
6520 return phone.getImsRegistrationTech();
6521 } else {
6522 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6523 }
6524 } finally {
6525 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006526 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006527 }
6528
Stuart Scott8eef64f2015-04-08 15:13:54 -07006529 @Override
6530 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006531 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006532 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6533 return;
6534 }
6535
Svet Ganovcc087f82015-05-12 20:35:54 -07006536 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006537
Svet Ganovcc087f82015-05-12 20:35:54 -07006538 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006539 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6540 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006541 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006542 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006543 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006544 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6545 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006546 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006547 // There has been issues when Sms raw table somehow stores orphan
6548 // fragments. They lead to garbled message when new fragments come
6549 // in and combined with those stale ones. In case this happens again,
6550 // user can reset all network settings which will clean up this table.
6551 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006552 // Clean up IMS settings as well here.
6553 int slotId = getSlotIndex(subId);
6554 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6555 ImsManager.getInstance(mApp, slotId).factoryReset();
6556 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006557
6558 // Erase modem config if erase modem on network setting is enabled.
6559 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6560 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6561 if (configValue != null && Boolean.parseBoolean(configValue)) {
6562 sendEraseModemConfig(getDefaultPhone());
6563 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006564 } finally {
6565 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006566 }
6567 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006568
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006569 private void cleanUpSmsRawTable(Context context) {
6570 ContentResolver resolver = context.getContentResolver();
6571 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6572 resolver.delete(uri, null, null);
6573 }
6574
Narayan Kamath1c496c22015-04-16 14:40:19 +01006575 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006576 public String getSimLocaleForSubscriber(int subId) {
6577 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6578 final Phone phone = getPhone(subId);
6579 if (phone == null) {
6580 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006581 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 final long identity = Binder.clearCallingIdentity();
6584 try {
chen xu5d3637b2019-01-21 23:31:38 -08006585 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006586 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006587 if (info == null) {
6588 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6589 return null;
6590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006591 // Try and fetch the locale from the carrier properties or from the SIM language
6592 // preferences (EF-PL and EF-LI)...
6593 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006595 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6596 if (localeFromDefaultSim != null) {
6597 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6598 if (DBG) log("Using locale from subId: " + subId + " locale: "
6599 + localeFromDefaultSim);
6600 return localeFromDefaultSim.toLanguageTag();
6601 } else {
6602 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603 }
6604 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606 // The SIM language preferences only store a language (e.g. fr = French), not an
6607 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6608 // the SIM and carrier preferences does not include a country we add the country
6609 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006610 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006612 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006613 return mccLocale.toLanguageTag();
6614 }
6615
6616 if (DBG) log("No locale found - returning null");
6617 return null;
6618 } finally {
6619 Binder.restoreCallingIdentity(identity);
6620 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006621 }
6622
6623 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006624 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6625 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006626 }
6627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 /**
6629 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6630 */
6631 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006632 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6633 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006634 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006635
Chenjie Yu1ba97252018-01-11 18:16:20 -08006636 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006637 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006638
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006639 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006640 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6641 * representing the state of the modem.
6642 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006643 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6644 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006645 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006646 */
6647 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006648 public void requestModemActivityInfo(ResultReceiver result) {
6649 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006650 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651
6652 final long identity = Binder.clearCallingIdentity();
6653 try {
6654 ModemActivityInfo ret = null;
6655 synchronized (mLastModemActivityInfo) {
6656 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6657 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006658 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006659 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006661 int[] txTimeMs = info.getTransmitTimeMillis();
6662 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006664 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 }
6666 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006667 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6668 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669 mLastModemActivityInfo.setIdleTimeMillis(
6670 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006671 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6672 mLastModemActivityInfo.setReceiveTimeMillis(
6673 info.getReceiveTimeMillis() + mLastModemActivityInfo
6674 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006675 }
Chen Xud78231e2019-09-10 18:49:52 -07006676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6678 mLastModemActivityInfo.getSleepTimeMillis(),
6679 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006680 mLastModemActivityInfo.getTransmitTimeMillis(),
6681 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006683 Bundle bundle = new Bundle();
6684 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6685 result.send(0, bundle);
6686 } finally {
6687 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006688 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006689 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006690
Siddharth Rayb8114062018-06-17 15:02:38 -07006691 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6692 // less than total activity duration.
6693 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6694 if (info == null) {
6695 return false;
6696 }
6697 int activityDurationMs =
6698 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6699 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006700 int[] txTimeMs = info.getTransmitTimeMillis();
6701 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6702 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006703 }
6704 return (info.isValid()
6705 && (info.getSleepTimeMillis() <= activityDurationMs)
6706 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006707 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006708 && (totalTxTimeMs <= activityDurationMs));
6709 }
6710
Jack Yu85bd38a2015-11-09 11:34:32 -08006711 /**
6712 * {@hide}
6713 * Returns the service state information on specified subscription.
6714 */
6715 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006716 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6717 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006719 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006720 return null;
6721 }
6722
Hall Liuf19c44f2018-11-27 14:38:17 -08006723 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6724 LocationAccessPolicy.checkLocationPermission(mApp,
6725 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6726 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006727 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006728 .setCallingPid(Binder.getCallingPid())
6729 .setCallingUid(Binder.getCallingUid())
6730 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006731 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006732 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6733 .build());
6734
6735 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6736 LocationAccessPolicy.checkLocationPermission(mApp,
6737 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6738 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006739 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006740 .setCallingPid(Binder.getCallingPid())
6741 .setCallingUid(Binder.getCallingUid())
6742 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006743 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006744 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6745 .build());
6746 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6747 boolean hasFinePermission =
6748 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6749 boolean hasCoarsePermission =
6750 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 final long identity = Binder.clearCallingIdentity();
6753 try {
6754 final Phone phone = getPhone(subId);
6755 if (phone == null) {
6756 return null;
6757 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006758
Hall Liuf19c44f2018-11-27 14:38:17 -08006759 ServiceState ss = phone.getServiceState();
6760
6761 // Scrub out the location info in ServiceState depending on what level of access
6762 // the caller has.
6763 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006764 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6765 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 } finally {
6767 Binder.restoreCallingIdentity(identity);
6768 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006769 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006770
6771 /**
6772 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6773 *
6774 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6775 * voicemail ringtone.
6776 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6777 * PhoneAccount.
6778 */
6779 @Override
6780 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 final long identity = Binder.clearCallingIdentity();
6782 try {
6783 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6784 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006785 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006786 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6789 } finally {
6790 Binder.restoreCallingIdentity(identity);
6791 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006792 }
6793
6794 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006795 * Sets the per-account voicemail ringtone.
6796 *
6797 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6798 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6799 *
6800 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6801 * voicemail ringtone.
6802 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6803 * PhoneAccount.
6804 */
6805 @Override
6806 public void setVoicemailRingtoneUri(String callingPackage,
6807 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006808 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006809 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006810 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6811 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6813 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6814 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816
6817 final long identity = Binder.clearCallingIdentity();
6818 try {
6819 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6820 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006821 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006822 }
6823 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6824 } finally {
6825 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006826 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006827 }
6828
6829 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006830 * Returns whether vibration is set for voicemail notification in Phone settings.
6831 *
6832 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6833 * voicemail vibration setting.
6834 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6835 */
6836 @Override
6837 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 final long identity = Binder.clearCallingIdentity();
6839 try {
6840 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6841 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006842 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006843 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006844
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6846 } finally {
6847 Binder.restoreCallingIdentity(identity);
6848 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006849 }
6850
Youhan Wange64578a2016-05-02 15:32:42 -07006851 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006852 * Sets the per-account voicemail vibration.
6853 *
6854 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6855 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6856 *
6857 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6858 * voicemail vibration setting.
6859 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6860 * specific PhoneAccount.
6861 */
6862 @Override
6863 public void setVoicemailVibrationEnabled(String callingPackage,
6864 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006865 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006866 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006867 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6868 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6870 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6871 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006872 }
6873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6877 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006878 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879 }
6880 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6881 } finally {
6882 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006883 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006884 }
6885
6886 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006887 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6888 *
6889 * @throws SecurityException if the caller does not have the required permission
6890 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006891 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006892 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006893 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006894 }
6895
6896 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006897 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6898 * permission.
6899 *
6900 * @throws SecurityException if the caller does not have the required permission
6901 */
6902 private void enforceSendSmsPermission() {
6903 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6904 }
6905
6906 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006907 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006908 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006909 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006910 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006911 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006912 final long identity = Binder.clearCallingIdentity();
6913 try {
6914 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006915 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 if (componentName == null) {
6917 throw new SecurityException(
6918 "Caller not current active visual voicemail package[null]");
6919 }
6920 String vvmPackage = componentName.getPackageName();
6921 if (!callingPackage.equals(vvmPackage)) {
6922 throw new SecurityException("Caller not current active visual voicemail package["
6923 + vvmPackage + "]");
6924 }
6925 } finally {
6926 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006927 }
6928 }
6929
6930 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006931 * Return the application ID for the app type.
6932 *
6933 * @param subId the subscription ID that this request applies to.
6934 * @param appType the uicc app type.
6935 * @return Application ID for specificied app type, or null if no uicc.
6936 */
6937 @Override
6938 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006939 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006940 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006941
6942 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006943 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944 if (phone == null) {
6945 return null;
6946 }
6947 String aid = null;
6948 try {
6949 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6950 .getApplicationByType(appType).getAid();
6951 } catch (Exception e) {
6952 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6953 }
6954 return aid;
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006957 }
Youhan Wange64578a2016-05-02 15:32:42 -07006958 }
6959
Youhan Wang4001d252016-05-11 10:29:41 -07006960 /**
6961 * Return the Electronic Serial Number.
6962 *
6963 * @param subId the subscription ID that this request applies to.
6964 * @return ESN or null if error.
6965 */
6966 @Override
6967 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006968 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006969 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970
6971 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006972 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 if (phone == null) {
6974 return null;
6975 }
6976 String esn = null;
6977 try {
6978 esn = phone.getEsn();
6979 } catch (Exception e) {
6980 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6981 }
6982 return esn;
6983 } finally {
6984 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006985 }
Youhan Wang4001d252016-05-11 10:29:41 -07006986 }
6987
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006988 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006989 * Return the Preferred Roaming List Version.
6990 *
6991 * @param subId the subscription ID that this request applies to.
6992 * @return PRLVersion or null if error.
6993 */
6994 @Override
6995 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006996 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006997 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998
6999 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007000 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 if (phone == null) {
7002 return null;
7003 }
7004 String cdmaPrlVersion = null;
7005 try {
7006 cdmaPrlVersion = phone.getCdmaPrlVersion();
7007 } catch (Exception e) {
7008 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7009 }
7010 return cdmaPrlVersion;
7011 } finally {
7012 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007013 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007014 }
7015
7016 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007017 * Get snapshot of Telephony histograms
7018 * @return List of Telephony histograms
7019 * @hide
7020 */
7021 @Override
7022 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7024 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
7028 return RIL.getTelephonyRILTimingHistograms();
7029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007032 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007033
7034 /**
7035 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007036 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7037 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007038 * Require system privileges. In the future we may add this to carrier APIs.
7039 *
Michele Berionne482f8202018-11-27 18:57:59 -08007040 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007041 */
7042 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007043 @TelephonyManager.SetCarrierRestrictionResult
7044 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007045 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007046 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007047
Michele Berionne482f8202018-11-27 18:57:59 -08007048 if (carrierRestrictionRules == null) {
7049 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007050 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 final long identity = Binder.clearCallingIdentity();
7053 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007054 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007055 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 } finally {
7057 Binder.restoreCallingIdentity(identity);
7058 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007059 }
7060
7061 /**
7062 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007063 * Get the allowed carrier list and the excluded carrier list, including the priority between
7064 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007065 * Require system privileges. In the future we may add this to carrier APIs.
7066 *
Michele Berionne482f8202018-11-27 18:57:59 -08007067 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007068 */
7069 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007070 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007071 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007072 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073
7074 final long identity = Binder.clearCallingIdentity();
7075 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007076 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7077 if (response instanceof CarrierRestrictionRules) {
7078 return (CarrierRestrictionRules) response;
7079 }
7080 // Response is an Exception of some kind,
7081 // which is signalled to the user as a NULL retval
7082 return null;
7083 } catch (Exception e) {
7084 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7085 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086 } finally {
7087 Binder.restoreCallingIdentity(identity);
7088 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007089 }
7090
fionaxu59545b42016-05-25 15:53:37 -07007091 /**
7092 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7093 * @param subId the subscription ID that this action applies to.
7094 * @param enabled control enable or disable metered apns.
7095 * {@hide}
7096 */
7097 @Override
7098 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7099 enforceModifyPermission();
7100 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101
7102 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007103 if (phone == null) {
7104 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7105 return;
7106 }
7107 try {
7108 phone.carrierActionSetMeteredApnsEnabled(enabled);
7109 } catch (Exception e) {
7110 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 } finally {
7112 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007113 }
7114 }
7115
7116 /**
7117 * Action set from carrier signalling broadcast receivers to enable/disable radio
7118 * @param subId the subscription ID that this action applies to.
7119 * @param enabled control enable or disable radio.
7120 * {@hide}
7121 */
7122 @Override
7123 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7124 enforceModifyPermission();
7125 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126
7127 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007128 if (phone == null) {
7129 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7130 return;
7131 }
7132 try {
7133 phone.carrierActionSetRadioEnabled(enabled);
7134 } catch (Exception e) {
7135 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 } finally {
7137 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007138 }
7139 }
7140
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007141 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007142 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7143 * network status based on which carrier apps could apply actions accordingly,
7144 * enable/disable default url handler for example.
7145 *
7146 * @param subId the subscription ID that this action applies to.
7147 * @param report control start/stop reporting the default network status.
7148 * {@hide}
7149 */
7150 @Override
7151 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7152 enforceModifyPermission();
7153 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154
7155 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007156 if (phone == null) {
7157 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7158 return;
7159 }
7160 try {
7161 phone.carrierActionReportDefaultNetworkStatus(report);
7162 } catch (Exception e) {
7163 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164 } finally {
7165 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007166 }
7167 }
7168
7169 /**
fionaxud9622282017-07-17 17:51:30 -07007170 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7171 * @param subId the subscription ID that this action applies to.
7172 * {@hide}
7173 */
7174 @Override
7175 public void carrierActionResetAll(int subId) {
7176 enforceModifyPermission();
7177 final Phone phone = getPhone(subId);
7178 if (phone == null) {
7179 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7180 return;
7181 }
7182 try {
7183 phone.carrierActionResetAll();
7184 } catch (Exception e) {
7185 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7186 }
7187 }
7188
7189 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007190 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7191 * bug report is being generated.
7192 */
7193 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007194 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007195 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7196 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007197 writer.println("Permission Denial: can't dump Phone from pid="
7198 + Binder.getCallingPid()
7199 + ", uid=" + Binder.getCallingUid()
7200 + "without permission "
7201 + android.Manifest.permission.DUMP);
7202 return;
7203 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007204 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007205 }
Jack Yueb89b242016-06-22 13:27:47 -07007206
Brad Ebingerdac2f002018-04-03 15:17:52 -07007207 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007208 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7209 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7210 @NonNull String[] args) {
7211 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7212 this, in.getFileDescriptor(), out.getFileDescriptor(),
7213 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007214 }
7215
Jack Yueb89b242016-06-22 13:27:47 -07007216 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007217 * Policy control of data connection. Usually used when data limit is passed.
7218 * @param enabled True if enabling the data, otherwise disabling.
7219 * @param subId Subscription index
7220 * {@hide}
7221 */
7222 @Override
7223 public void setPolicyDataEnabled(boolean enabled, int subId) {
7224 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225
7226 final long identity = Binder.clearCallingIdentity();
7227 try {
7228 Phone phone = getPhone(subId);
7229 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007230 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231 }
7232 } finally {
7233 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007234 }
7235 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007236
7237 /**
7238 * Get Client request stats
7239 * @return List of Client Request Stats
7240 * @hide
7241 */
7242 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007243 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7244 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007246 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007247 return null;
7248 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007249 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 if (phone != null) {
7254 return phone.getClientRequestStats();
7255 }
7256
7257 return null;
7258 } finally {
7259 Binder.restoreCallingIdentity(identity);
7260 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007261 }
7262
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007263 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007264 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007265 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007266 }
Jack Yueb4124c2017-02-16 15:32:43 -08007267
7268 /**
Grace Chen70990072017-03-24 17:21:30 -07007269 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007270 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007271 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007272 * @param state State of SIM (power down, power up, pass through)
7273 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7274 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7275 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007276 *
7277 **/
7278 @Override
Grace Chen70990072017-03-24 17:21:30 -07007279 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007280 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007281 Phone phone = PhoneFactory.getPhone(slotIndex);
7282
vagdeviaf9a5b92018-08-15 16:01:53 -07007283 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007285 final long identity = Binder.clearCallingIdentity();
7286 try {
7287 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007288 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007289 }
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007292 }
7293 }
Shuo Qiandd210312017-04-12 22:11:33 +00007294
Tyler Gunn65d45c22017-06-05 11:22:26 -07007295 private boolean isUssdApiAllowed(int subId) {
7296 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007297 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007298 if (configManager == null) {
7299 return false;
7300 }
7301 PersistableBundle pb = configManager.getConfigForSubId(subId);
7302 if (pb == null) {
7303 return false;
7304 }
7305 return pb.getBoolean(
7306 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7307 }
7308
Shuo Qiandd210312017-04-12 22:11:33 +00007309 /**
7310 * Check if phone is in emergency callback mode
7311 * @return true if phone is in emergency callback mode
7312 * @param subId sub id
7313 */
goneil9c5f4872017-12-05 14:07:56 -08007314 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007315 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007316 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007317 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 if (phone != null) {
7322 return phone.isInEcm();
7323 } else {
7324 return false;
7325 }
7326 } finally {
7327 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007328 }
7329 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007330
7331 /**
7332 * Get the current signal strength information for the given subscription.
7333 * Because this information is not updated when the device is in a low power state
7334 * it should not be relied-upon to be current.
7335 * @param subId Subscription index
7336 * @return the most recent cached signal strength info from the modem
7337 */
7338 @Override
7339 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340 final long identity = Binder.clearCallingIdentity();
7341 try {
7342 Phone p = getPhone(subId);
7343 if (p == null) {
7344 return null;
7345 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007347 return p.getSignalStrength();
7348 } finally {
7349 Binder.restoreCallingIdentity(identity);
7350 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007351 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007352
Pengquan Meng77b7f132018-08-22 14:49:57 -07007353 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007354 * Get the current modem radio state for the given slot.
7355 * @param slotIndex slot index.
7356 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007357 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007358 * @return the current radio power state from the modem
7359 */
7360 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007361 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007362 Phone phone = PhoneFactory.getPhone(slotIndex);
7363 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7365 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007366 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7367 }
7368
7369 final long identity = Binder.clearCallingIdentity();
7370 try {
7371 return phone.getRadioPowerState();
7372 } finally {
7373 Binder.restoreCallingIdentity(identity);
7374 }
7375 }
7376 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7377 }
7378
7379 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007380 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7381 *
7382 * <p>Requires one of the following permissions:
7383 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7384 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7385 * privileges.
7386 *
7387 * @param subId subscription id
7388 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7389 * {@code false}.
7390 */
7391 @Override
7392 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007393 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7394 null /* message */);
7395
Pengquan Menga1bb6272018-09-06 09:59:22 -07007396 boolean isEnabled = false;
7397 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007398 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007399 Phone phone = getPhone(subId);
7400 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007401 } catch (Exception e) {
7402 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7403 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007404 } finally {
7405 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007406 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007407 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007408 }
7409
7410
7411 /**
7412 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7413 *
7414 * <p> Requires permission:
7415 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7416 * privileges.
7417 *
7418 * @param subId subscription id
7419 * @param isEnabled {@code true} means enable, {@code false} means disable.
7420 */
7421 @Override
7422 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7424 mApp, subId, "setDataRoamingEnabled");
7425
Pengquan Menga1bb6272018-09-06 09:59:22 -07007426 final long identity = Binder.clearCallingIdentity();
7427 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007428 Phone phone = getPhone(subId);
7429 if (phone != null) {
7430 phone.setDataRoamingEnabled(isEnabled);
7431 }
7432 } finally {
7433 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007434 }
7435 }
7436
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007437 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007438 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007439 TelephonyPermissions
7440 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007441 mApp, subId, "isManualNetworkSelectionAllowed");
7442
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007443 boolean isAllowed = true;
7444 final long identity = Binder.clearCallingIdentity();
7445 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007446 Phone phone = getPhone(subId);
7447 if (phone != null) {
7448 isAllowed = phone.isCspPlmnEnabled();
7449 }
7450 } finally {
7451 Binder.restoreCallingIdentity(identity);
7452 }
7453 return isAllowed;
7454 }
7455
7456 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007457 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007458 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007459 try {
7460 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007461 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007462 } catch (SecurityException e) {
7463 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7464 // has carrier privileges on an active UICC
7465 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7466 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007467 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007468 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007469 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007470
7471 final long identity = Binder.clearCallingIdentity();
7472 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007473 UiccController uiccController = UiccController.getInstance();
7474 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007475 if (hasReadPermission) {
7476 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007477 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007478
7479 // Remove private info if the caller doesn't have access
7480 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7481 for (UiccCardInfo cardInfo : cardInfos) {
7482 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7483 // is available
7484 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7485 if (card == null || card.getUiccProfile() == null) {
7486 // assume no access if the card or profile is unavailable
7487 filteredInfos.add(cardInfo.getUnprivileged());
7488 continue;
7489 }
7490 UiccProfile profile = card.getUiccProfile();
7491 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7492 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7493 filteredInfos.add(cardInfo);
7494 } else {
7495 filteredInfos.add(cardInfo.getUnprivileged());
7496 }
7497 }
7498 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007499 } finally {
7500 Binder.restoreCallingIdentity(identity);
7501 }
7502 }
7503
7504 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007505 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007506 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 final long identity = Binder.clearCallingIdentity();
7509 try {
7510 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7511 if (slots == null) {
7512 Rlog.i(LOG_TAG, "slots is null.");
7513 return null;
7514 }
7515
7516 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7517 for (int i = 0; i < slots.length; i++) {
7518 UiccSlot slot = slots[i];
7519 if (slot == null) {
7520 continue;
7521 }
7522
Jordan Liu7be7e652019-05-06 18:55:02 +00007523 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 UiccCard card = slot.getUiccCard();
7525 if (card != null) {
7526 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007527 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007528 cardId = slot.getEid();
7529 if (TextUtils.isEmpty(cardId)) {
7530 cardId = slot.getIccId();
7531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 }
7533
Jordan Liu857451f2019-05-09 16:35:35 -07007534 if (cardId != null) {
7535 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7536 // if cardId is an EID, it's all digits so this is fine
7537 cardId = IccUtils.stripTrailingFs(cardId);
7538 }
7539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 int cardState = 0;
7541 switch (slot.getCardState()) {
7542 case CARDSTATE_ABSENT:
7543 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7544 break;
7545 case CARDSTATE_PRESENT:
7546 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7547 break;
7548 case CARDSTATE_ERROR:
7549 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7550 break;
7551 case CARDSTATE_RESTRICTED:
7552 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7553 break;
7554 default:
7555 break;
7556
7557 }
7558
7559 infos[i] = new UiccSlotInfo(
7560 slot.isActive(),
7561 slot.isEuicc(),
7562 cardId,
7563 cardState,
7564 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007565 slot.isExtendedApduSupported(),
7566 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567 }
7568 return infos;
7569 } finally {
7570 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007571 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007572 }
7573
7574 @Override
7575 public boolean switchSlots(int[] physicalSlots) {
7576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577
7578 final long identity = Binder.clearCallingIdentity();
7579 try {
7580 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7581 } finally {
7582 Binder.restoreCallingIdentity(identity);
7583 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007584 }
Jack Yu4c988042018-02-27 15:30:01 -08007585
7586 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007587 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007588 final long identity = Binder.clearCallingIdentity();
7589 try {
7590 return UiccController.getInstance().getCardIdForDefaultEuicc();
7591 } finally {
7592 Binder.restoreCallingIdentity(identity);
7593 }
7594 }
7595
Pengquan Meng85728fb2018-03-12 16:31:21 -07007596 /**
goneil47ffb6e2018-04-06 15:40:58 -07007597 * A test API to reload the UICC profile.
7598 *
7599 * <p>Requires that the calling app has permission
7600 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7601 * @hide
7602 */
7603 @Override
7604 public void refreshUiccProfile(int subId) {
7605 enforceModifyPermission();
7606
7607 final long identity = Binder.clearCallingIdentity();
7608 try {
7609 Phone phone = getPhone(subId);
7610 if (phone == null) {
7611 return;
7612 }
7613 UiccCard uiccCard = phone.getUiccCard();
7614 if (uiccCard == null) {
7615 return;
7616 }
7617 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7618 if (uiccProfile == null) {
7619 return;
7620 }
7621 uiccProfile.refresh();
7622 } finally {
7623 Binder.restoreCallingIdentity(identity);
7624 }
7625 }
7626
7627 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007628 * Returns false if the mobile data is disabled by default, otherwise return true.
7629 */
7630 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007631 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007632 }
7633
7634 /**
7635 * Returns true if the data roaming is enabled by default, i.e the system property
7636 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7637 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7638 */
7639 private boolean getDefaultDataRoamingEnabled(int subId) {
7640 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007641 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007642 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007643 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7644 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7645 return isDataRoamingEnabled;
7646 }
7647
7648 /**
7649 * Returns the default network type for the given {@code subId}, if the default network type is
7650 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7651 */
7652 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007653 List<Integer> list = TelephonyProperties.default_network();
7654 int phoneId = mSubscriptionController.getPhoneId(subId);
7655 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7656 return list.get(phoneId);
7657 }
7658 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007659 }
fionaxua13278b2018-03-21 00:08:13 -07007660
7661 @Override
7662 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007663 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665
7666 final long identity = Binder.clearCallingIdentity();
7667 try {
7668 final Phone phone = getPhone(subId);
7669 if (phone == null) {
7670 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7671 return;
7672 }
chen xueaba88a2019-03-15 13:15:10 -07007673 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7674 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 } finally {
7676 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007677 }
fionaxua13278b2018-03-21 00:08:13 -07007678 }
7679
7680 @Override
7681 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007682 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683
7684 final long identity = Binder.clearCallingIdentity();
7685 try {
7686 final Phone phone = getPhone(subId);
7687 if (phone == null) {
7688 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7689 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7690 }
7691 return phone.getCarrierIdListVersion();
7692 } finally {
7693 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007694 }
fionaxua13278b2018-03-21 00:08:13 -07007695 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007696
7697 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007698 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7699 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007701 mApp, subId, callingPackage, callingFeatureId,
7702 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007703 return -1;
7704 }
7705
7706 final long identity = Binder.clearCallingIdentity();
7707 try {
7708 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7709 } finally {
7710 Binder.restoreCallingIdentity(identity);
7711 }
7712 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007713
7714 @Override
7715 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007716 TelephonyPermissions
7717 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007718 mApp, subId, "getCdmaRoamingMode");
7719
7720 final long identity = Binder.clearCallingIdentity();
7721 try {
7722 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
7726 }
7727
7728 @Override
7729 public boolean setCdmaRoamingMode(int subId, int mode) {
7730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7731 mApp, subId, "setCdmaRoamingMode");
7732
7733 final long identity = Binder.clearCallingIdentity();
7734 try {
7735 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7736 } finally {
7737 Binder.restoreCallingIdentity(identity);
7738 }
7739 }
7740
7741 @Override
7742 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7744 mApp, subId, "setCdmaSubscriptionMode");
7745
7746 final long identity = Binder.clearCallingIdentity();
7747 try {
7748 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7749 } finally {
7750 Binder.restoreCallingIdentity(identity);
7751 }
7752 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007753
sqianc5eccab2018-10-19 18:46:41 -07007754 @Override
sqian8c685422019-02-22 15:55:18 -08007755 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007756 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007758 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7759 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007760 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7761 }
7762 final long identity = Binder.clearCallingIdentity();
7763 try {
sqian854d44b2018-12-12 16:48:18 -08007764 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7765 for (Phone phone: PhoneFactory.getPhones()) {
7766 if (phone.getEmergencyNumberTracker() != null
7767 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7768 emergencyNumberListInternal.put(
7769 phone.getSubId(),
7770 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7771 }
sqian11b7a0e2018-12-05 18:48:28 -08007772 }
sqian854d44b2018-12-12 16:48:18 -08007773 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007774 } finally {
7775 Binder.restoreCallingIdentity(identity);
7776 }
sqianc5eccab2018-10-19 18:46:41 -07007777 }
7778
7779 @Override
sqian8c685422019-02-22 15:55:18 -08007780 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007781 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007782 if (!exactMatch) {
7783 TelephonyPermissions
7784 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007785 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007786 }
7787 final long identity = Binder.clearCallingIdentity();
7788 try {
sqian854d44b2018-12-12 16:48:18 -08007789 for (Phone phone: PhoneFactory.getPhones()) {
7790 if (phone.getEmergencyNumberTracker() != null
7791 && phone.getEmergencyNumberTracker() != null) {
7792 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7793 number, exactMatch)) {
7794 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007795 }
7796 }
sqian11b7a0e2018-12-05 18:48:28 -08007797 }
7798 return false;
7799 } finally {
7800 Binder.restoreCallingIdentity(identity);
7801 }
7802 }
7803
sqianf4ca7ed2019-01-15 18:32:07 -08007804 /**
7805 * Update emergency number list for test mode.
7806 */
7807 @Override
7808 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7809 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7810 "updateEmergencyNumberListTestMode");
7811
7812 final long identity = Binder.clearCallingIdentity();
7813 try {
7814 for (Phone phone: PhoneFactory.getPhones()) {
7815 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7816 if (tracker != null) {
7817 tracker.executeEmergencyNumberTestModeCommand(action, num);
7818 }
7819 }
7820 } finally {
7821 Binder.restoreCallingIdentity(identity);
7822 }
7823 }
7824
7825 /**
7826 * Get the full emergency number list for test mode.
7827 */
7828 @Override
7829 public List<String> getEmergencyNumberListTestMode() {
7830 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7831 "getEmergencyNumberListTestMode");
7832
7833 final long identity = Binder.clearCallingIdentity();
7834 try {
7835 Set<String> emergencyNumbers = new HashSet<>();
7836 for (Phone phone: PhoneFactory.getPhones()) {
7837 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7838 if (tracker != null) {
7839 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7840 emergencyNumbers.add(num.getNumber());
7841 }
7842 }
7843 }
7844 return new ArrayList<>(emergencyNumbers);
7845 } finally {
7846 Binder.restoreCallingIdentity(identity);
7847 }
7848 }
7849
chen xud6b45bd2018-10-30 22:27:10 -07007850 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007851 public int getEmergencyNumberDbVersion(int subId) {
7852 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7853
7854 final long identity = Binder.clearCallingIdentity();
7855 try {
7856 final Phone phone = getPhone(subId);
7857 if (phone == null) {
7858 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7859 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7860 }
7861 return phone.getEmergencyNumberDbVersion();
7862 } finally {
7863 Binder.restoreCallingIdentity(identity);
7864 }
7865 }
7866
7867 @Override
7868 public void notifyOtaEmergencyNumberDbInstalled() {
7869 enforceModifyPermission();
7870
7871 final long identity = Binder.clearCallingIdentity();
7872 try {
7873 for (Phone phone: PhoneFactory.getPhones()) {
7874 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7875 if (tracker != null) {
7876 tracker.updateOtaEmergencyNumberDatabase();
7877 }
7878 }
7879 } finally {
7880 Binder.restoreCallingIdentity(identity);
7881 }
7882 }
7883
7884 @Override
7885 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7886 enforceActiveEmergencySessionPermission();
7887
7888 final long identity = Binder.clearCallingIdentity();
7889 try {
7890 for (Phone phone: PhoneFactory.getPhones()) {
7891 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7892 if (tracker != null) {
7893 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7894 }
7895 }
7896 } finally {
7897 Binder.restoreCallingIdentity(identity);
7898 }
7899 }
7900
7901 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007902 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7903 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7904 Phone phone = getPhone(subId);
7905 if (phone == null) {
7906 return null;
7907 }
7908 final long identity = Binder.clearCallingIdentity();
7909 try {
7910 UiccProfile profile = UiccController.getInstance()
7911 .getUiccProfileForPhone(phone.getPhoneId());
7912 if (profile != null) {
7913 return profile.getCertsFromCarrierPrivilegeAccessRules();
7914 }
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
7918 return null;
7919 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007920
7921 /**
7922 * Enable or disable a modem stack.
7923 */
7924 @Override
7925 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7926 enforceModifyPermission();
7927
7928 final long identity = Binder.clearCallingIdentity();
7929 try {
7930 Phone phone = PhoneFactory.getPhone(slotIndex);
7931 if (phone == null) {
7932 return false;
7933 } else {
7934 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7935 }
7936 } finally {
7937 Binder.restoreCallingIdentity(identity);
7938 }
7939 }
Michelecea4cf22018-12-21 15:00:11 -08007940
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007941 /**
7942 * Whether a modem stack is enabled or not.
7943 */
7944 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007945 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7946 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007947 Phone phone = PhoneFactory.getPhone(slotIndex);
7948 if (phone == null) return false;
7949
7950 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007951 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7952 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007953 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7954 }
7955
7956 final long identity = Binder.clearCallingIdentity();
7957 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007958 try {
7959 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7960 } catch (NoSuchElementException ex) {
7961 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7962 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007963 } finally {
7964 Binder.restoreCallingIdentity(identity);
7965 }
7966 }
7967
Michelecea4cf22018-12-21 15:00:11 -08007968 @Override
Michele0ea7d782019-03-19 14:58:42 -07007969 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007970 enforceModifyPermission();
7971
7972 final long identity = Binder.clearCallingIdentity();
7973 try {
7974 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007975 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007976 .commit();
7977 } finally {
7978 Binder.restoreCallingIdentity(identity);
7979 }
7980 }
7981
7982 @Override
Michele0ea7d782019-03-19 14:58:42 -07007983 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007984 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007986 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7987 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007988 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007989 }
Michelecea4cf22018-12-21 15:00:11 -08007990
7991 final long identity = Binder.clearCallingIdentity();
7992 try {
Michele0ea7d782019-03-19 14:58:42 -07007993 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007994 } finally {
7995 Binder.restoreCallingIdentity(identity);
7996 }
7997 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007998
Michele0ea7d782019-03-19 14:58:42 -07007999 @TelephonyManager.IsMultiSimSupportedResult
8000 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008001 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8002 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8003 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008004 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8005 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008006 }
8007 // Check if the hardware supports multisim functionality. If usage of multisim is not
8008 // supported by the modem, indicate that it is restricted.
8009 PhoneCapability staticCapability =
8010 mPhoneConfigurationManager.getStaticPhoneCapability();
8011 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008012 loge("isMultiSimSupportedInternal: no static configuration available");
8013 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008014 }
Sarah Chin7caee492020-02-18 20:49:02 +00008015 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008016 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8017 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008018 }
8019 // Check if support of multiple SIMs is restricted by carrier
8020 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008021 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008022 }
8023
Michele0ea7d782019-03-19 14:58:42 -07008024 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008025 }
8026
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008027 /**
8028 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008029 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8030 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8031 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008032 * @param numOfSims number of active sims we want to switch to
8033 */
8034 @Override
8035 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008036 if (numOfSims == 1) {
8037 enforceModifyPermission();
8038 } else {
8039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8040 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8041 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008042 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008043
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008044 try {
Michele30b57b22019-03-01 12:01:14 -08008045 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008046 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008047 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8048 return;
8049 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008050 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8051 } finally {
8052 Binder.restoreCallingIdentity(identity);
8053 }
8054 }
8055
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008056 @Override
8057 public boolean isApplicationOnUicc(int subId, int appType) {
8058 enforceReadPrivilegedPermission("isApplicationOnUicc");
8059 Phone phone = getPhone(subId);
8060 if (phone == null) {
8061 return false;
8062 }
8063 final long identity = Binder.clearCallingIdentity();
8064 try {
8065 UiccCard uiccCard = phone.getUiccCard();
8066 if (uiccCard == null) {
8067 return false;
8068 }
8069 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8070 if (uiccProfile == null) {
8071 return false;
8072 }
8073 if (TelephonyManager.APPTYPE_SIM <= appType
8074 && appType <= TelephonyManager.APPTYPE_ISIM) {
8075 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8076 }
8077 return false;
8078 } finally {
8079 Binder.restoreCallingIdentity(identity);
8080 }
8081 }
8082
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008083 /**
chen xub4baa772019-04-03 10:23:41 -07008084 * Get whether making changes to modem configurations will trigger reboot.
8085 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008086 */
8087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008088 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8089 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008091 mApp, subId, callingPackage, callingFeatureId,
8092 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008093 return false;
8094 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8098 } finally {
8099 Binder.restoreCallingIdentity(identity);
8100 }
8101 }
8102
Nathan Harold29f5f052019-02-15 13:41:57 -08008103 private void updateModemStateMetrics() {
8104 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8105 // TODO: check the state for each modem if the api is ready.
8106 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8107 }
8108
Pengquan Meng3889a572019-01-23 11:16:29 -08008109 @Override
8110 public int[] getSlotsMapping() {
8111 enforceReadPrivilegedPermission("getSlotsMapping");
8112
8113 final long identity = Binder.clearCallingIdentity();
8114 try {
8115 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8116 // All logical slots should have a mapping to a physical slot.
8117 int[] logicalSlotsMapping = new int[phoneCount];
8118 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8119 for (int i = 0; i < slotInfos.length; i++) {
8120 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8121 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8122 }
8123 }
8124 return logicalSlotsMapping;
8125 } finally {
8126 Binder.restoreCallingIdentity(identity);
8127 }
8128 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008129
8130 /**
8131 * Get the IRadio HAL Version
8132 */
8133 @Override
8134 public int getRadioHalVersion() {
8135 Phone phone = getDefaultPhone();
8136 if (phone == null) return -1;
8137 HalVersion hv = phone.getHalVersion();
8138 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8139 return hv.major * 100 + hv.minor;
8140 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008141
8142 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008143 * Get the current calling package name.
8144 * @return the current calling package name
8145 */
8146 @Override
8147 public String getCurrentPackageName() {
8148 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8149 }
8150
8151 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008152 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8153 * corresponding network requests on a subId.
8154 *
8155 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008156 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008157 * 2) APN is un-metered for this subscription, or
8158 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008159 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008160 *
8161 * @return whether data is allowed for a apn type.
8162 *
8163 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008164 */
8165 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008166 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008167 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8168 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008169
8170 // Now that all security checks passes, perform the operation as ourselves.
8171 final long identity = Binder.clearCallingIdentity();
8172 try {
8173 Phone phone = getPhone(subId);
8174 if (phone == null) return false;
8175
Jack Yu41407ee2019-05-13 16:54:09 -07008176 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008177 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8178 } finally {
8179 Binder.restoreCallingIdentity(identity);
8180 }
8181 }
8182
8183 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008184 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008185 enforceReadPrivilegedPermission("isApnMetered");
8186
8187 // Now that all security checks passes, perform the operation as ourselves.
8188 final long identity = Binder.clearCallingIdentity();
8189 try {
8190 Phone phone = getPhone(subId);
8191 if (phone == null) return true; // By default return true.
8192
Jack Yu41407ee2019-05-13 16:54:09 -07008193 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008194 } finally {
8195 Binder.restoreCallingIdentity(identity);
8196 }
8197 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008198
8199 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008200 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8201 int subscriptionId, IBooleanConsumer resultCallback) {
8202 enforceModifyPermission();
8203 long token = Binder.clearCallingIdentity();
8204 try {
8205 Phone phone = getPhone(subscriptionId);
8206 if (phone == null) {
8207 try {
8208 if (resultCallback != null) {
8209 resultCallback.accept(false);
8210 }
8211 } catch (RemoteException e) {
8212 // ignore
8213 }
8214 return;
8215 }
8216 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8217 Pair.create(specifiers, (x) -> {
8218 try {
8219 if (resultCallback != null) {
8220 resultCallback.accept(x);
8221 }
8222 } catch (RemoteException e) {
8223 // ignore
8224 }
8225 });
8226 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8227 } finally {
8228 Binder.restoreCallingIdentity(token);
8229 }
8230 }
8231
8232 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008233 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8234 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8235 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8236 if (iccRecords == null) {
8237 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8238 return false;
8239 }
8240 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8241 }
8242
8243 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008244 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008245 if (callingPackage == null) {
8246 callingPackage = getCurrentPackageName();
8247 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008248 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8249 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8250 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8251 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8252 }
8253 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8254 Intent intent = new Intent();
8255 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8256 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8257 // Bring up choose default SMS subscription dialog right now
8258 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8259 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8260 mApp.startActivity(intent);
8261 }
chen xud5ca2d52019-05-28 15:20:57 -07008262
8263 @Override
8264 public String getMmsUAProfUrl(int subId) {
8265 //TODO investigate if this API should require proper permission check in R b/133791609
8266 final long identity = Binder.clearCallingIdentity();
8267 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008268 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8269 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008270 } finally {
8271 Binder.restoreCallingIdentity(identity);
8272 }
8273 }
8274
8275 @Override
8276 public String getMmsUserAgent(int subId) {
8277 //TODO investigate if this API should require proper permission check in R b/133791609
8278 final long identity = Binder.clearCallingIdentity();
8279 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008280 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8281 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008282 } finally {
8283 Binder.restoreCallingIdentity(identity);
8284 }
8285 }
Jack Yub07d4972019-05-28 16:12:25 -07008286
8287 @Override
8288 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8289 enforceModifyPermission();
8290
8291 // Now that all security checks passes, perform the operation as ourselves.
8292 final long identity = Binder.clearCallingIdentity();
8293 try {
8294 Phone phone = getPhone(subId);
8295 if (phone == null) return false;
8296
8297 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8298 } finally {
8299 Binder.restoreCallingIdentity(identity);
8300 }
8301 }
8302
8303 @Override
8304 public boolean isDataAllowedInVoiceCall(int subId) {
8305 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8306
8307 // Now that all security checks passes, perform the operation as ourselves.
8308 final long identity = Binder.clearCallingIdentity();
8309 try {
8310 Phone phone = getPhone(subId);
8311 if (phone == null) return false;
8312
8313 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8314 } finally {
8315 Binder.restoreCallingIdentity(identity);
8316 }
8317 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008318
changbettyd5c246e2019-12-24 15:40:37 +08008319 @Override
8320 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8321 enforceModifyPermission();
8322
8323 // Now that all security checks passes, perform the operation as ourselves.
8324 final long identity = Binder.clearCallingIdentity();
8325 try {
8326 Phone phone = getPhone(subId);
8327 if (phone == null) return false;
8328
8329 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8330 } finally {
8331 Binder.restoreCallingIdentity(identity);
8332 }
8333 }
8334
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008335 /**
8336 * Updates whether conference event pacakge handling is enabled.
8337 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8338 * otherwise.
8339 */
8340 @Override
8341 public void setCepEnabled(boolean isCepEnabled) {
8342 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8343
8344 final long identity = Binder.clearCallingIdentity();
8345 try {
8346 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8347 for (Phone phone : PhoneFactory.getPhones()) {
8348 Phone defaultPhone = phone.getImsPhone();
8349 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8350 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8351 ImsPhoneCallTracker imsPhoneCallTracker =
8352 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8353 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8354 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8355 + imsPhone.getMsisdn());
8356 }
8357 }
8358 } finally {
8359 Binder.restoreCallingIdentity(identity);
8360 }
8361 }
allenwtsu46dcc572020-01-08 18:24:03 +08008362
8363 /**
8364 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8365 *
8366 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8367 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8368 * before being read.
8369 */
8370 @Override
8371 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8372 isCompressed) {
8373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8374 mApp, subId, "notifyRcsAutoConfigurationReceived");
8375 try {
8376 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8377 if (configBinder == null) {
8378 Rlog.e(LOG_TAG, "null result for getImsConfig");
8379 } else {
8380 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8381 }
8382 } catch (RemoteException e) {
8383 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8384 }
8385 }
zoey chene02881a2019-12-30 16:11:23 +08008386
8387 @Override
8388 public boolean isIccLockEnabled(int subId) {
8389 enforceReadPrivilegedPermission("isIccLockEnabled");
8390
8391 // Now that all security checks passes, perform the operation as ourselves.
8392 final long identity = Binder.clearCallingIdentity();
8393 try {
8394 Phone phone = getPhone(subId);
8395 if (phone != null && phone.getIccCard() != null) {
8396 return phone.getIccCard().getIccLockEnabled();
8397 } else {
8398 return false;
8399 }
8400 } finally {
8401 Binder.restoreCallingIdentity(identity);
8402 }
8403 }
8404
8405 /**
8406 * Set the ICC pin lock enabled or disabled.
8407 *
8408 * @return an integer representing the status of IccLock enabled or disabled in the following
8409 * three cases:
8410 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8411 * successfully.
8412 * - Positive number and zero for remaining password attempts.
8413 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8414 *
8415 */
8416 @Override
8417 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8418 enforceModifyPermission();
8419
8420 Phone phone = getPhone(subId);
8421 if (phone == null) {
8422 return 0;
8423 }
8424 // Now that all security checks passes, perform the operation as ourselves.
8425 final long identity = Binder.clearCallingIdentity();
8426 try {
8427 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8428 new Pair<Boolean, String>(enabled, password), phone, null);
8429 return attemptsRemaining;
8430
8431 } catch (Exception e) {
8432 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8433 } finally {
8434 Binder.restoreCallingIdentity(identity);
8435 }
8436 return 0;
8437 }
8438
8439 /**
8440 * Change the ICC password used in ICC pin lock.
8441 *
8442 * @return an integer representing the status of IccLock changed in the following three cases:
8443 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8444 * - Positive number and zero for remaining password attempts.
8445 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8446 *
8447 */
8448 @Override
8449 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8450 enforceModifyPermission();
8451
8452 Phone phone = getPhone(subId);
8453 if (phone == null) {
8454 return 0;
8455 }
8456 // Now that all security checks passes, perform the operation as ourselves.
8457 final long identity = Binder.clearCallingIdentity();
8458 try {
8459 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8460 new Pair<String, String>(oldPassword, newPassword), phone, null);
8461 return attemptsRemaining;
8462
8463 } catch (Exception e) {
8464 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
8467 }
8468 return 0;
8469 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008470
8471 /**
8472 * Request for receiving user activity notification
8473 */
8474 @Override
8475 public void requestUserActivityNotification() {
8476 if (!mNotifyUserActivity.get()
8477 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8478 mNotifyUserActivity.set(true);
8479 }
8480 }
8481
8482 /**
8483 * Called when userActivity is signalled in the power manager.
8484 * This is safe to call from any thread, with any window manager locks held or not.
8485 */
8486 @Override
8487 public void userActivity() {
8488 // ***************************************
8489 // * Inherited from PhoneWindowManager *
8490 // ***************************************
8491 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8492 // WITH ITS LOCKS HELD.
8493 //
8494 // This code must be VERY careful about the locks
8495 // it acquires.
8496 // In fact, the current code acquires way too many,
8497 // and probably has lurking deadlocks.
8498
8499 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8500 throw new SecurityException("Only the OS may call notifyUserActivity()");
8501 }
8502
8503 if (mNotifyUserActivity.getAndSet(false)) {
8504 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8505 USER_ACTIVITY_NOTIFICATION_DELAY);
8506 }
8507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008508}