blob: f9218f82d9fc0deb476cc88235d2ad07c866e9a5 [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;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
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;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070055import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070071import android.telephony.CellInfoGsm;
72import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070073import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070074import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070075import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070076import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080077import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070078import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080079import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070080import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080081import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080082import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070083import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080084import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070085import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080087import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080088import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080089import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070090import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080092import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080093import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000094import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070095import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070096import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -0700100import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.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 Ebinger77b832e2019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
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;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
160import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700162import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000166import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800167import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700168import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700171import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800172import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700174import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800175
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700176import java.io.FileDescriptor;
177import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800180import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800181import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800182import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100183import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700185import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188/**
189 * Implementation of the ITelephony interface.
190 */
Santos Cordon117fee72014-05-16 17:56:12 -0700191public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 private static final String LOG_TAG = "PhoneInterfaceManager";
193 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
194 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800195 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197 // Message codes used with mMainThreadHandler
198 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700199 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
200 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201 private static final int CMD_OPEN_CHANNEL = 9;
202 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
203 private static final int CMD_CLOSE_CHANNEL = 11;
204 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800205 private static final int CMD_NV_READ_ITEM = 13;
206 private static final int EVENT_NV_READ_ITEM_DONE = 14;
207 private static final int CMD_NV_WRITE_ITEM = 15;
208 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
209 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
210 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700211 private static final int CMD_RESET_MODEM_CONFIG = 19;
212 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800213 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
214 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
215 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
216 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800217 private static final int CMD_SEND_ENVELOPE = 25;
218 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000219 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
220 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700221 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
222 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
223 private static final int CMD_EXCHANGE_SIM_IO = 31;
224 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800225 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
226 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700227 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700229 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
230 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700231 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
232 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
233 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700235 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
236 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
237 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
238 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700239 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
241 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000242 private static final int CMD_SWITCH_SLOTS = 50;
243 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700244 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
245 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
246 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
247 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
248 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
249 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
250 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
251 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700252 private static final int CMD_GET_ALL_CELL_INFO = 60;
253 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
254 private static final int CMD_GET_CELL_LOCATION = 62;
255 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700256 private static final int CMD_MODEM_REBOOT = 64;
257 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700258 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
259 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800260 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
261 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262 private static final int CMD_GET_MODEM_STATUS = 70;
263 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700264 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
265 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700266 private static final int CMD_ERASE_MODEM_CONFIG = 74;
267 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800269 // Parameters of select command.
270 private static final int SELECT_COMMAND = 0xA4;
271 private static final int SELECT_P1 = 0x04;
272 private static final int SELECT_P2 = 0;
273 private static final int SELECT_P3 = 0x10;
274
Pengquan Meng85728fb2018-03-12 16:31:21 -0700275 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
276 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
277 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
278
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279 /** The singleton instance. */
280 private static PhoneInterfaceManager sInstance;
281
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800283 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700284 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private AppOpsManager mAppOps;
286 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800287 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800288 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700289 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
Derek Tan97ebb422014-09-05 16:55:38 -0700291 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
292 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800293 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800294 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700295
Michelecea4cf22018-12-21 15:00:11 -0800296 // String to store multi SIM allowed
297 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
298
Derek Tan740e1672017-06-27 14:56:27 -0700299 // The AID of ISD-R.
300 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
301
yinxub1bed742017-04-17 11:45:04 -0700302 private NetworkScanRequestTracker mNetworkScanRequestTracker;
303
David Kelly5e06a7f2018-03-12 14:10:59 +0000304 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
305 private static final int MANUFACTURER_CODE_LENGTH = 8;
306
Derek Tan89e89d42014-07-08 17:00:10 -0700307 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700308 * Experiment flag to enable erase modem config on reset network, default value is false
309 */
310 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
311 "reset_network_erase_modem_config_enabled";
312
313 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700314 * A request object to use for transmitting data to an ICC.
315 */
316 private static final class IccAPDUArgument {
317 public int channel, cla, command, p1, p2, p3;
318 public String data;
319
320 public IccAPDUArgument(int channel, int cla, int command,
321 int p1, int p2, int p3, String data) {
322 this.channel = channel;
323 this.cla = cla;
324 this.command = command;
325 this.p1 = p1;
326 this.p2 = p2;
327 this.p3 = p3;
328 this.data = data;
329 }
330 }
331
332 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700333 * A request object to use for transmitting data to an ICC.
334 */
335 private static final class ManualNetworkSelectionArgument {
336 public OperatorInfo operatorInfo;
337 public boolean persistSelection;
338
339 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
340 this.operatorInfo = operatorInfo;
341 this.persistSelection = persistSelection;
342 }
343 }
344
345 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
347 * request after sending. The main thread will notify the request when it is complete.
348 */
349 private static final class MainThreadRequest {
350 /** The argument to use for the request */
351 public Object argument;
352 /** The result of the request that is run on the main thread */
353 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800354 // The subscriber id that this request applies to. Defaults to
355 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
356 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Nathan Harold92bed182018-10-12 18:16:49 -0700358 // In cases where subId is unavailable, the caller needs to specify the phone.
359 public Phone phone;
360
vagdeviaf9a5b92018-08-15 16:01:53 -0700361 public WorkSource workSource;
362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 public MainThreadRequest(Object argument) {
364 this.argument = argument;
365 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800366
Nathan Harold92bed182018-10-12 18:16:49 -0700367 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
368 this.argument = argument;
369 if (phone != null) {
370 this.phone = phone;
371 }
372 this.workSource = workSource;
373 }
374
vagdeviaf9a5b92018-08-15 16:01:53 -0700375 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800376 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800377 if (subId != null) {
378 this.subId = subId;
379 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700380 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 }
383
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800384 private static final class IncomingThirdPartyCallArgs {
385 public final ComponentName component;
386 public final String callId;
387 public final String callerDisplayName;
388
389 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
390 String callerDisplayName) {
391 this.component = component;
392 this.callId = callId;
393 this.callerDisplayName = callerDisplayName;
394 }
395 }
396
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 /**
398 * A handler that processes messages on the main thread in the phone process. Since many
399 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
400 * inbound binder threads to the main thread in the phone process. The Binder thread
401 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
402 * on, which will be notified when the operation completes and will contain the result of the
403 * request.
404 *
405 * <p>If a MainThreadRequest object is provided in the msg.obj field,
406 * note that request.result must be set to something non-null for the calling thread to
407 * unblock.
408 */
409 private final class MainThreadHandler extends Handler {
410 @Override
411 public void handleMessage(Message msg) {
412 MainThreadRequest request;
413 Message onCompleted;
414 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800415 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800417 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
419 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 case CMD_HANDLE_USSD_REQUEST: {
421 request = (MainThreadRequest) msg.obj;
422 final Phone phone = getPhoneFromRequest(request);
423 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
424 String ussdRequest = ussdObject.first;
425 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700426
Pengquan Menga1bb6272018-09-06 09:59:22 -0700427 if (!isUssdApiAllowed(request.subId)) {
428 // Carrier does not support use of this API, return failure.
429 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
430 UssdResponse response = new UssdResponse(ussdRequest, null);
431 Bundle returnData = new Bundle();
432 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
433 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700434
Pengquan Menga1bb6272018-09-06 09:59:22 -0700435 request.result = true;
436 notifyRequester(request);
437 return;
438 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700439
Pengquan Menga1bb6272018-09-06 09:59:22 -0700440 try {
441 request.result = phone != null
442 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
443 } catch (CallStateException cse) {
444 request.result = false;
445 }
446 // Wake up the requesting thread
447 notifyRequester(request);
448 break;
pkanwar32d516d2016-10-14 19:37:38 -0700449 }
450
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700453 final Phone phone = getPhoneFromRequest(request);
454 request.result = phone != null ?
455 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
456 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800465 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 if (uiccCard == null) {
467 loge("iccTransmitApduLogicalChannel: No UICC");
468 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
472 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 iccArgument.channel, iccArgument.cla, iccArgument.command,
475 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700477 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 break;
479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 ar = (AsyncResult) msg.obj;
482 request = (MainThreadRequest) ar.userObj;
483 if (ar.exception == null && ar.result != null) {
484 request.result = ar.result;
485 } else {
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
487 if (ar.result == null) {
488 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800489 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800491 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 } else {
493 loge("iccTransmitApduLogicalChannel: Unknown exception");
494 }
495 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 break;
498
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
500 request = (MainThreadRequest) msg.obj;
501 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800502 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 if (uiccCard == null) {
504 loge("iccTransmitApduBasicChannel: No UICC");
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 } else {
508 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
509 request);
510 uiccCard.iccTransmitApduBasicChannel(
511 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
512 iccArgument.p3, iccArgument.data, onCompleted);
513 }
514 break;
515
516 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
517 ar = (AsyncResult) msg.obj;
518 request = (MainThreadRequest) ar.userObj;
519 if (ar.exception == null && ar.result != null) {
520 request.result = ar.result;
521 } else {
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
523 if (ar.result == null) {
524 loge("iccTransmitApduBasicChannel: Empty response");
525 } else if (ar.exception instanceof CommandException) {
526 loge("iccTransmitApduBasicChannel: CommandException: " +
527 ar.exception);
528 } else {
529 loge("iccTransmitApduBasicChannel: Unknown exception");
530 }
531 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 break;
534
535 case CMD_EXCHANGE_SIM_IO:
536 request = (MainThreadRequest) msg.obj;
537 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 if (uiccCard == null) {
540 loge("iccExchangeSimIO: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 } else {
544 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
545 request);
546 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
547 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
548 iccArgument.data, onCompleted);
549 }
550 break;
551
552 case EVENT_EXCHANGE_SIM_IO_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
557 } else {
558 request.result = new IccIoResult(0x6f, 0, (byte[])null);
559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 break;
562
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 case CMD_SEND_ENVELOPE:
564 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("sendEnvelopeWithStatus: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
572 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
573 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 break;
575
576 case EVENT_SEND_ENVELOPE_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800581 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
583 if (ar.result == null) {
584 loge("sendEnvelopeWithStatus: Empty response");
585 } else if (ar.exception instanceof CommandException) {
586 loge("sendEnvelopeWithStatus: CommandException: " +
587 ar.exception);
588 } else {
589 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
590 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800593 break;
594
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 case CMD_OPEN_CHANNEL:
596 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800597 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800598 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 if (uiccCard == null) {
600 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800601 request.result = new IccOpenLogicalChannelResponse(-1,
602 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 } else {
605 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800606 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
607 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700608 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
611 case EVENT_OPEN_CHANNEL_DONE:
612 ar = (AsyncResult) msg.obj;
613 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 int[] result = (int[]) ar.result;
617 int channelId = result[0];
618 byte[] selectResponse = null;
619 if (result.length > 1) {
620 selectResponse = new byte[result.length - 1];
621 for (int i = 1; i < result.length; ++i) {
622 selectResponse[i - 1] = (byte) result[i];
623 }
624 }
625 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 if (ar.result == null) {
629 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 if (ar.exception != null) {
632 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
633 }
634
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700635 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700636 if (ar.exception instanceof CommandException) {
637 CommandException.Error error =
638 ((CommandException) (ar.exception)).getCommandError();
639 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700640 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700641 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700642 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 }
644 }
645 openChannelResp = new IccOpenLogicalChannelResponse(
646 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700648 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case CMD_CLOSE_CHANNEL:
653 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800654 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 if (uiccCard == null) {
656 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900657 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 } else {
660 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
661 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
662 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
665 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800666 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
667 break;
668
669 case CMD_NV_READ_ITEM:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800672 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
673 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800674 break;
675
676 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800682 request.result = "";
683 if (ar.result == null) {
684 loge("nvReadItem: Empty response");
685 } else if (ar.exception instanceof CommandException) {
686 loge("nvReadItem: CommandException: " +
687 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800689 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 }
691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 break;
694
Jake Hambye994d462014-02-03 13:10:13 -0800695 case CMD_NV_WRITE_ITEM:
696 request = (MainThreadRequest) msg.obj;
697 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
698 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_WRITE_ITEM_DONE:
704 handleNullReturnEvent(msg, "nvWriteItem");
705 break;
706
707 case CMD_NV_WRITE_CDMA_PRL:
708 request = (MainThreadRequest) msg.obj;
709 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800710 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800711 break;
712
713 case EVENT_NV_WRITE_CDMA_PRL_DONE:
714 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
715 break;
716
chen xu6dac5ab2018-10-26 17:39:23 -0700717 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800718 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700719 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800720 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
chen xu6dac5ab2018-10-26 17:39:23 -0700723 case EVENT_RESET_MODEM_CONFIG_DONE:
724 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800725 break;
726
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 case CMD_GET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700730 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 break;
732
733 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
734 ar = (AsyncResult) msg.obj;
735 request = (MainThreadRequest) ar.userObj;
736 if (ar.exception == null && ar.result != null) {
737 request.result = ar.result; // Integer
738 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800739 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 if (ar.result == null) {
741 loge("getPreferredNetworkType: Empty response");
742 } else if (ar.exception instanceof CommandException) {
743 loge("getPreferredNetworkType: CommandException: " +
744 ar.exception);
745 } else {
746 loge("getPreferredNetworkType: Unknown exception");
747 }
748 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case CMD_SET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
755 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700756 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800757 break;
758
759 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
760 handleNullReturnEvent(msg, "setPreferredNetworkType");
761 break;
762
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
764 request = (MainThreadRequest)msg.obj;
765 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800766 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000767 break;
768
769 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
770 ar = (AsyncResult)msg.obj;
771 request = (MainThreadRequest)ar.userObj;
772 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000774 break;
775
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800776 case CMD_SET_VOICEMAIL_NUMBER:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
779 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800780 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
781 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800782 break;
783
784 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
785 handleNullReturnEvent(msg, "setVoicemailNumber");
786 break;
787
Stuart Scott54788802015-03-30 13:18:01 -0700788 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
791 request);
792 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
793 break;
794
795 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
796 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
797 break;
798
Shishir Agrawal302c8692015-06-19 13:49:39 -0700799 case CMD_PERFORM_NETWORK_SCAN:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
802 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
803 break;
804
805 case EVENT_PERFORM_NETWORK_SCAN_DONE:
806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 CellNetworkScanResult cellScanResult;
809 if (ar.exception == null && ar.result != null) {
810 cellScanResult = new CellNetworkScanResult(
811 CellNetworkScanResult.STATUS_SUCCESS,
812 (List<OperatorInfo>) ar.result);
813 } else {
814 if (ar.result == null) {
815 loge("getCellNetworkScanResults: Empty response");
816 }
817 if (ar.exception != null) {
818 loge("getCellNetworkScanResults: Exception: " + ar.exception);
819 }
820 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
821 if (ar.exception instanceof CommandException) {
822 CommandException.Error error =
823 ((CommandException) (ar.exception)).getCommandError();
824 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
825 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
826 } else if (error == CommandException.Error.GENERIC_FAILURE) {
827 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
828 }
829 }
830 cellScanResult = new CellNetworkScanResult(errorCode, null);
831 }
832 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700833 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700834 break;
835
836 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
837 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 ManualNetworkSelectionArgument selArg =
839 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
841 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700842 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
843 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
846 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null) {
850 request.result = true;
851 } else {
852 request.result = false;
853 loge("setNetworkSelectionModeManual " + ar.exception);
854 }
855 notifyRequester(request);
856 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700857 break;
858
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700859 case CMD_GET_MODEM_ACTIVITY_INFO:
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700862 if (defaultPhone != null) {
863 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
864 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700865 break;
866
867 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result;
872 } else {
873 if (ar.result == null) {
874 loge("queryModemActivityInfo: Empty response");
875 } else if (ar.exception instanceof CommandException) {
876 loge("queryModemActivityInfo: CommandException: " +
877 ar.exception);
878 } else {
879 loge("queryModemActivityInfo: Unknown exception");
880 }
881 }
Amit Mahajand4766222016-01-28 15:28:28 -0800882 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
883 if (request.result == null) {
884 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
885 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700886 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700887 break;
888
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 case CMD_SET_ALLOWED_CARRIERS:
890 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800891 CarrierRestrictionRules argument =
892 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800894 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 break;
896
897 case EVENT_SET_ALLOWED_CARRIERS_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800903 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
904 if (ar.exception instanceof CommandException) {
905 loge("setAllowedCarriers: CommandException: " + ar.exception);
906 CommandException.Error error =
907 ((CommandException) (ar.exception)).getCommandError();
908 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
909 request.result =
910 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
911 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700912 } else {
913 loge("setAllowedCarriers: Unknown exception");
914 }
915 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 break;
918
919 case CMD_GET_ALLOWED_CARRIERS:
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800922 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700923 break;
924
925 case EVENT_GET_ALLOWED_CARRIERS_DONE:
926 ar = (AsyncResult) msg.obj;
927 request = (MainThreadRequest) ar.userObj;
928 if (ar.exception == null && ar.result != null) {
929 request.result = ar.result;
930 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800931 request.result = new IllegalStateException(
932 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 if (ar.result == null) {
934 loge("getAllowedCarriers: Empty response");
935 } else if (ar.exception instanceof CommandException) {
936 loge("getAllowedCarriers: CommandException: " +
937 ar.exception);
938 } else {
939 loge("getAllowedCarriers: Unknown exception");
940 }
941 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700943 break;
944
Nathan Haroldb3014052017-01-25 15:57:32 -0800945 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
946 ar = (AsyncResult) msg.obj;
947 request = (MainThreadRequest) ar.userObj;
948 if (ar.exception == null && ar.result != null) {
949 request.result = ar.result;
950 } else {
951 request.result = new IllegalArgumentException(
952 "Failed to retrieve Forbidden Plmns");
953 if (ar.result == null) {
954 loge("getForbiddenPlmns: Empty response");
955 } else {
956 loge("getForbiddenPlmns: Unknown exception");
957 }
958 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700959 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800960 break;
961
962 case CMD_GET_FORBIDDEN_PLMNS:
963 request = (MainThreadRequest) msg.obj;
964 uiccCard = getUiccCardFromRequest(request);
965 if (uiccCard == null) {
966 loge("getForbiddenPlmns() UiccCard is null");
967 request.result = new IllegalArgumentException(
968 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800970 break;
971 }
972 Integer appType = (Integer) request.argument;
973 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
974 if (uiccApp == null) {
975 loge("getForbiddenPlmns() no app with specified type -- "
976 + appType);
977 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700978 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800979 break;
980 } else {
981 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
982 + " specified type -- " + appType);
983 }
984 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
985 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
986 onCompleted);
987 break;
988
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000989 case CMD_SWITCH_SLOTS:
990 request = (MainThreadRequest) msg.obj;
991 int[] physicalSlots = (int[]) request.argument;
992 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
993 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
994 break;
995
996 case EVENT_SWITCH_SLOTS_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001000 notifyRequester(request);
1001 break;
1002 case CMD_GET_NETWORK_SELECTION_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1005 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1006 break;
1007
1008 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 if (ar.exception != null) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1013 } else {
1014 int mode = ((int[]) ar.result)[0];
1015 if (mode == 0) {
1016 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1017 } else {
1018 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1019 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001020 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001021 notifyRequester(request);
1022 break;
1023 case CMD_GET_CDMA_ROAMING_MODE:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1026 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1027 break;
1028 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 if (ar.exception != null) {
1032 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1033 } else {
1034 request.result = ((int[]) ar.result)[0];
1035 }
1036 notifyRequester(request);
1037 break;
1038 case CMD_SET_CDMA_ROAMING_MODE:
1039 request = (MainThreadRequest) msg.obj;
1040 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1041 int mode = (int) request.argument;
1042 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1043 break;
1044 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
1047 request.result = ar.exception == null;
1048 notifyRequester(request);
1049 break;
1050 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1053 int subscriptionMode = (int) request.argument;
1054 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1055 break;
1056 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
1059 request.result = ar.exception == null;
1060 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001061 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 case CMD_GET_ALL_CELL_INFO:
1063 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001065 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 case EVENT_GET_ALL_CELL_INFO_DONE:
1068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001070 // If a timeout occurs, the response will be null
1071 request.result = (ar.exception == null && ar.result != null)
1072 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 synchronized (request) {
1074 request.notifyAll();
1075 }
1076 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 case CMD_REQUEST_CELL_INFO_UPDATE:
1078 request = (MainThreadRequest) msg.obj;
1079 request.phone.requestCellInfoUpdate(request.workSource,
1080 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1081 break;
1082 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
1085 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1086 try {
1087 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001088 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001089 cb.onError(
1090 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1091 ar.exception.getClass().getName(),
1092 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001095 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 } else {
1097 // use the result as returned
1098 cb.onCellInfo((List<CellInfo>) ar.result);
1099 }
1100 } catch (RemoteException re) {
1101 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1102 }
1103 break;
1104 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001105 request = (MainThreadRequest) msg.obj;
1106 WorkSource ws = (WorkSource) request.argument;
1107 Phone phone = getPhoneFromRequest(request);
1108 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1109 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001110 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001111 ar = (AsyncResult) msg.obj;
1112 request = (MainThreadRequest) ar.userObj;
1113 if (ar.exception == null) {
1114 request.result = ar.result;
1115 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001116 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001117 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1118 ? new CdmaCellLocation() : new GsmCellLocation();
1119 }
1120
1121 synchronized (request) {
1122 request.notifyAll();
1123 }
1124 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001125 case CMD_MODEM_REBOOT:
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001128 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001129 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001130 case EVENT_CMD_MODEM_REBOOT_DONE:
1131 handleNullReturnEvent(msg, "rebootModem");
1132 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001133 case CMD_REQUEST_ENABLE_MODEM:
1134 request = (MainThreadRequest) msg.obj;
1135 boolean enable = (boolean) request.argument;
1136 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001137 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001138 PhoneConfigurationManager.getInstance()
1139 .enablePhone(request.phone, enable, onCompleted);
1140 break;
1141 case EVENT_ENABLE_MODEM_DONE:
1142 ar = (AsyncResult) msg.obj;
1143 request = (MainThreadRequest) ar.userObj;
1144 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001145 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001146 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001147 if ((boolean) request.result) {
1148 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1149 updateModemStateMetrics();
1150 } else {
1151 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1152 + ar.exception);
1153 }
1154 notifyRequester(request);
1155 break;
1156 case CMD_GET_MODEM_STATUS:
1157 request = (MainThreadRequest) msg.obj;
1158 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1159 PhoneConfigurationManager.getInstance()
1160 .getPhoneStatusFromModem(request.phone, onCompleted);
1161 break;
1162 case EVENT_GET_MODEM_STATUS_DONE:
1163 ar = (AsyncResult) msg.obj;
1164 request = (MainThreadRequest) ar.userObj;
1165 int id = request.phone.getPhoneId();
1166 if (ar.exception == null && ar.result != null) {
1167 request.result = ar.result;
1168 //update the cache as modem status has changed
1169 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1170 (boolean) request.result);
1171 } else {
1172 // Return true if modem status cannot be retrieved. For most cases,
1173 // modem status is on. And for older version modems, GET_MODEM_STATUS
1174 // and disable modem are not supported. Modem is always on.
1175 // TODO: this should be fixed in R to support a third
1176 // status UNKNOWN b/131631629
1177 request.result = true;
1178 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1179 + ar.exception);
1180 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001181 notifyRequester(request);
1182 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001183 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
1186 if (ar.exception == null && ar.result != null) {
1187 request.result = ar.result;
1188 } else {
1189 request.result = -1;
1190 loge("Failed to set Forbidden Plmns");
1191 if (ar.result == null) {
1192 loge("setForbidenPlmns: Empty response");
1193 } else if (ar.exception != null) {
1194 loge("setForbiddenPlmns: Exception: " + ar.exception);
1195 request.result = -1;
1196 } else {
1197 loge("setForbiddenPlmns: Unknown exception");
1198 }
1199 }
1200 notifyRequester(request);
1201 break;
1202 case CMD_SET_FORBIDDEN_PLMNS:
1203 request = (MainThreadRequest) msg.obj;
1204 uiccCard = getUiccCardFromRequest(request);
1205 if (uiccCard == null) {
1206 loge("setForbiddenPlmns: UiccCard is null");
1207 request.result = -1;
1208 notifyRequester(request);
1209 break;
1210 }
1211 Pair<Integer, List<String>> setFplmnsArgs =
1212 (Pair<Integer, List<String>>) request.argument;
1213 appType = setFplmnsArgs.first;
1214 List<String> fplmns = setFplmnsArgs.second;
1215 uiccApp = uiccCard.getApplicationByType(appType);
1216 if (uiccApp == null) {
1217 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1218 request.result = -1;
1219 loge("Failed to get UICC App");
1220 notifyRequester(request);
1221 } else {
1222 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1223 ((SIMRecords) uiccApp.getIccRecords())
1224 .setForbiddenPlmns(onCompleted, fplmns);
1225 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001226 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001227 case CMD_ERASE_MODEM_CONFIG:
1228 request = (MainThreadRequest) msg.obj;
1229 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1230 defaultPhone.eraseModemConfig(onCompleted);
1231 break;
1232 case EVENT_ERASE_MODEM_CONFIG_DONE:
1233 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001234 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 default:
1236 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1237 break;
1238 }
1239 }
Jake Hambye994d462014-02-03 13:10:13 -08001240
Pengquan Menga1bb6272018-09-06 09:59:22 -07001241 private void notifyRequester(MainThreadRequest request) {
1242 synchronized (request) {
1243 request.notifyAll();
1244 }
1245 }
1246
Jake Hambye994d462014-02-03 13:10:13 -08001247 private void handleNullReturnEvent(Message msg, String command) {
1248 AsyncResult ar = (AsyncResult) msg.obj;
1249 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1250 if (ar.exception == null) {
1251 request.result = true;
1252 } else {
1253 request.result = false;
1254 if (ar.exception instanceof CommandException) {
1255 loge(command + ": CommandException: " + ar.exception);
1256 } else {
1257 loge(command + ": Unknown exception");
1258 }
1259 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001260 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 }
1263
1264 /**
1265 * Posts the specified command to be executed on the main thread,
1266 * waits for the request to complete, and returns the result.
1267 * @see #sendRequestAsync
1268 */
1269 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001270 return sendRequest(
1271 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001272 }
1273
1274 /**
1275 * Posts the specified command to be executed on the main thread,
1276 * waits for the request to complete, and returns the result.
1277 * @see #sendRequestAsync
1278 */
1279 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1280 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001281 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
1284 /**
1285 * Posts the specified command to be executed on the main thread,
1286 * waits for the request to complete, and returns the result.
1287 * @see #sendRequestAsync
1288 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001289 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001290 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001291 }
1292
1293 /**
1294 * Posts the specified command to be executed on the main thread,
1295 * waits for the request to complete, and returns the result.
1296 * @see #sendRequestAsync
1297 */
Nathan Harold92bed182018-10-12 18:16:49 -07001298 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1299 return sendRequest(command, argument, subId, null, workSource);
1300 }
1301
1302 /**
1303 * Posts the specified command to be executed on the main thread,
1304 * waits for the request to complete, and returns the result.
1305 * @see #sendRequestAsync
1306 */
1307 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1308 return sendRequest(
1309 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1310 }
1311
1312 /**
1313 * Posts the specified command to be executed on the main thread,
1314 * waits for the request to complete, and returns the result.
1315 * @see #sendRequestAsync
1316 */
1317 private Object sendRequest(
1318 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1320 throw new RuntimeException("This method will deadlock if called from the main thread.");
1321 }
1322
Nathan Harold92bed182018-10-12 18:16:49 -07001323 MainThreadRequest request = null;
1324 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1325 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1326 } else if (phone != null) {
1327 request = new MainThreadRequest(argument, phone, workSource);
1328 } else {
1329 request = new MainThreadRequest(argument, subId, workSource);
1330 }
1331
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 Message msg = mMainThreadHandler.obtainMessage(command, request);
1333 msg.sendToTarget();
1334
1335 // Wait for the request to complete
1336 synchronized (request) {
1337 while (request.result == null) {
1338 try {
1339 request.wait();
1340 } catch (InterruptedException e) {
1341 // Do nothing, go back and wait until the request is complete
1342 }
1343 }
1344 }
1345 return request.result;
1346 }
1347
1348 /**
1349 * Asynchronous ("fire and forget") version of sendRequest():
1350 * Posts the specified command to be executed on the main thread, and
1351 * returns immediately.
1352 * @see #sendRequest
1353 */
1354 private void sendRequestAsync(int command) {
1355 mMainThreadHandler.sendEmptyMessage(command);
1356 }
1357
1358 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001359 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001360 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001361 */
1362 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001363 sendRequestAsync(command, argument, null, null);
1364 }
1365
1366 /**
1367 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1368 * @see {@link #sendRequest(int,Object)}
1369 */
1370 private void sendRequestAsync(
1371 int command, Object argument, Phone phone, WorkSource workSource) {
1372 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001373 Message msg = mMainThreadHandler.obtainMessage(command, request);
1374 msg.sendToTarget();
1375 }
1376
1377 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 * Initialize the singleton PhoneInterfaceManager instance.
1379 * This is only done once, at startup, from PhoneApp.onCreate().
1380 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 synchronized (PhoneInterfaceManager.class) {
1383 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001384 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 } else {
1386 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1387 }
1388 return sInstance;
1389 }
1390 }
1391
1392 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001393 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001396 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1398 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001399 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001400 mTelephonySharedPreferences =
1401 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001402 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001403 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 publish();
1406 }
1407
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001408 private Phone getDefaultPhone() {
1409 Phone thePhone = getPhone(getDefaultSubscription());
1410 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1411 }
1412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 private void publish() {
1414 if (DBG) log("publish: " + this);
1415
1416 ServiceManager.addService("phone", this);
1417 }
1418
Stuart Scott584921c2015-01-15 17:10:34 -08001419 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001420 if (request.phone != null) {
1421 return request.phone;
1422 } else {
1423 return getPhoneFromSubId(request.subId);
1424 }
1425 }
1426
1427 private Phone getPhoneFromSubId(int subId) {
1428 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1429 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001430 }
1431
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001432 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1433 Phone phone = getPhoneFromRequest(request);
1434 return phone == null ? null :
1435 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1436 }
1437
Wink Saville36469e72014-06-11 15:17:00 -07001438 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001439 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001440 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001443 private void sendEraseModemConfig(Phone phone) {
1444 if (phone != null) {
1445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1446 mApp, phone.getSubId(), "eraseModemConfig");
1447 final long identity = Binder.clearCallingIdentity();
1448 try {
1449 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1450 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1451 } finally {
1452 Binder.restoreCallingIdentity(identity);
1453 }
1454 }
1455 }
1456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001458 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001459 }
1460
Wink Savilleb564aae2014-10-23 10:18:09 -07001461 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 if (DBG) log("dial: " + number);
1463 // No permission check needed here: This is just a wrapper around the
1464 // ACTION_DIAL intent, which is available to any app since it puts up
1465 // the UI before it does anything.
1466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001467 final long identity = Binder.clearCallingIdentity();
1468 try {
1469 String url = createTelUrl(number);
1470 if (url == null) {
1471 return;
1472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001474 // PENDING: should we just silently fail if phone is offhook or ringing?
1475 PhoneConstants.State state = mCM.getState(subId);
1476 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1477 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1478 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1479 mApp.startActivity(intent);
1480 }
1481 } finally {
1482 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484 }
1485
1486 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 if (DBG) log("call: " + number);
1492
1493 // This is just a wrapper around the ACTION_CALL intent, but we still
1494 // need to do a permission check since we're calling startActivity()
1495 // from the context of the phone app.
1496 enforceCallPermission();
1497
Jordan Liu1617b712019-07-10 15:06:26 -07001498 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 != AppOpsManager.MODE_ALLOWED) {
1500 return;
1501 }
1502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001503 final long identity = Binder.clearCallingIdentity();
1504 try {
1505 String url = createTelUrl(number);
1506 if (url == null) {
1507 return;
1508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001510 boolean isValid = false;
1511 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1512 if (slist != null) {
1513 for (SubscriptionInfo subInfoRecord : slist) {
1514 if (subInfoRecord.getSubscriptionId() == subId) {
1515 isValid = true;
1516 break;
1517 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001518 }
Wink Saville08874612014-08-31 19:19:58 -07001519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520 if (!isValid) {
1521 return;
1522 }
Wink Saville08874612014-08-31 19:19:58 -07001523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001524 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1525 intent.putExtra(SUBSCRIPTION_KEY, subId);
1526 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1527 mApp.startActivity(intent);
1528 } finally {
1529 Binder.restoreCallingIdentity(identity);
1530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 }
1532
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001534 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001535 }
1536
Wink Savilleb564aae2014-10-23 10:18:09 -07001537 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001539 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1540 }
1541
1542 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001543 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001544 }
1545
Wink Savilleb564aae2014-10-23 10:18:09 -07001546 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001547 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001548 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1549 }
1550
1551 /** {@hide} */
1552 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001553 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001554 }
1555
Wink Savilleb564aae2014-10-23 10:18:09 -07001556 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558
1559 final long identity = Binder.clearCallingIdentity();
1560 try {
1561 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1562 checkSimPin.start();
1563 return checkSimPin.unlockSim(null, pin);
1564 } finally {
1565 Binder.restoreCallingIdentity(identity);
1566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 }
1568
Wink Saville9de0f752013-10-22 19:04:03 -07001569 /** {@hide} */
1570 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001571 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001572 }
1573
Wink Savilleb564aae2014-10-23 10:18:09 -07001574 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001576
1577 final long identity = Binder.clearCallingIdentity();
1578 try {
1579 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1580 checkSimPuk.start();
1581 return checkSimPuk.unlockSim(puk, pin);
1582 } finally {
1583 Binder.restoreCallingIdentity(identity);
1584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 }
1586
1587 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001588 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 * a synchronous one.
1590 */
1591 private static class UnlockSim extends Thread {
1592
1593 private final IccCard mSimCard;
1594
1595 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001596 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1597 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598
1599 // For replies from SimCard interface
1600 private Handler mHandler;
1601
1602 // For async handler to identify request type
1603 private static final int SUPPLY_PIN_COMPLETE = 100;
1604
1605 public UnlockSim(IccCard simCard) {
1606 mSimCard = simCard;
1607 }
1608
1609 @Override
1610 public void run() {
1611 Looper.prepare();
1612 synchronized (UnlockSim.this) {
1613 mHandler = new Handler() {
1614 @Override
1615 public void handleMessage(Message msg) {
1616 AsyncResult ar = (AsyncResult) msg.obj;
1617 switch (msg.what) {
1618 case SUPPLY_PIN_COMPLETE:
1619 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1620 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001621 mRetryCount = msg.arg1;
1622 if (ar.exception != null) {
1623 if (ar.exception instanceof CommandException &&
1624 ((CommandException)(ar.exception)).getCommandError()
1625 == CommandException.Error.PASSWORD_INCORRECT) {
1626 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1627 } else {
1628 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1629 }
1630 } else {
1631 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001633 mDone = true;
1634 UnlockSim.this.notifyAll();
1635 }
1636 break;
1637 }
1638 }
1639 };
1640 UnlockSim.this.notifyAll();
1641 }
1642 Looper.loop();
1643 }
1644
1645 /*
1646 * Use PIN or PUK to unlock SIM card
1647 *
1648 * If PUK is null, unlock SIM card with PIN
1649 *
1650 * If PUK is not null, unlock SIM card with PUK and set PIN code
1651 */
Wink Saville9de0f752013-10-22 19:04:03 -07001652 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653
1654 while (mHandler == null) {
1655 try {
1656 wait();
1657 } catch (InterruptedException e) {
1658 Thread.currentThread().interrupt();
1659 }
1660 }
1661 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1662
1663 if (puk == null) {
1664 mSimCard.supplyPin(pin, callback);
1665 } else {
1666 mSimCard.supplyPuk(puk, pin, callback);
1667 }
1668
1669 while (!mDone) {
1670 try {
1671 Log.d(LOG_TAG, "wait for done");
1672 wait();
1673 } catch (InterruptedException e) {
1674 // Restore the interrupted status
1675 Thread.currentThread().interrupt();
1676 }
1677 }
1678 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001679 int[] resultArray = new int[2];
1680 resultArray[0] = mResult;
1681 resultArray[1] = mRetryCount;
1682 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 }
1684 }
1685
1686 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001687 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001688
1689 }
1690
Wink Savilleb564aae2014-10-23 10:18:09 -07001691 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 // No permission check needed here: this call is harmless, and it's
1693 // needed for the ServiceState.requestStateUpdate() call (which is
1694 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001695 final long identity = Binder.clearCallingIdentity();
1696 try {
1697 final Phone phone = getPhone(subId);
1698 if (phone != null) {
1699 phone.updateServiceLocation();
1700 }
1701 } finally {
1702 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 }
1705
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001706 @Override
1707 public boolean isRadioOn(String callingPackage) {
1708 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001709 }
1710
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001711 @Override
1712 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001714 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001715 return false;
1716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 return isRadioOnForSubscriber(subId);
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
1723 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001724 }
1725
1726 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001727 final long identity = Binder.clearCallingIdentity();
1728 try {
1729 final Phone phone = getPhone(subId);
1730 if (phone != null) {
1731 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1732 } else {
1733 return false;
1734 }
1735 } finally {
1736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
1739
1740 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001741 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 }
Wink Saville36469e72014-06-11 15:17:00 -07001743
Wink Savilleb564aae2014-10-23 10:18:09 -07001744 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001746
1747 final long identity = Binder.clearCallingIdentity();
1748 try {
1749 final Phone phone = getPhone(subId);
1750 if (phone != null) {
1751 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1752 }
1753 } finally {
1754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001755 }
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
1758 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001759 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001760 }
1761
Wink Savilleb564aae2014-10-23 10:18:09 -07001762 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001764
1765 final long identity = Binder.clearCallingIdentity();
1766 try {
1767 final Phone phone = getPhone(subId);
1768 if (phone == null) {
1769 return false;
1770 }
1771 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1772 toggleRadioOnOffForSubscriber(subId);
1773 }
1774 return true;
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
Wink Saville36469e72014-06-11 15:17:00 -07001779
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001780 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001781 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001782 /*
1783 * If any of the Radios are available, it will need to be
1784 * shutdown. So return true if any Radio is available.
1785 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 final long identity = Binder.clearCallingIdentity();
1787 try {
1788 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1789 Phone phone = PhoneFactory.getPhone(i);
1790 if (phone != null && phone.isRadioAvailable()) return true;
1791 }
1792 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1793 return false;
1794 } finally {
1795 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001796 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001797 }
1798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001800 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 enforceModifyPermission();
1802
1803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1806 logv("Shutting down Phone " + i);
1807 shutdownRadioUsingPhoneId(i);
1808 }
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 }
1812 }
1813
1814 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001815 Phone phone = PhoneFactory.getPhone(phoneId);
1816 if (phone != null && phone.isRadioAvailable()) {
1817 phone.shutdownRadio();
1818 }
1819 }
1820
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001823
1824 final long identity = Binder.clearCallingIdentity();
1825 try {
1826 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1827 if (defaultPhone != null) {
1828 defaultPhone.setRadioPower(turnOn);
1829 return true;
1830 } else {
1831 loge("There's no default phone.");
1832 return false;
1833 }
1834 } finally {
1835 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001836 }
Wink Saville36469e72014-06-11 15:17:00 -07001837 }
1838
Wink Savilleb564aae2014-10-23 10:18:09 -07001839 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001841
1842 final long identity = Binder.clearCallingIdentity();
1843 try {
1844 final Phone phone = getPhone(subId);
1845 if (phone != null) {
1846 phone.setRadioPower(turnOn);
1847 return true;
1848 } else {
1849 return false;
1850 }
1851 } finally {
1852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 }
1855
Wink Saville36469e72014-06-11 15:17:00 -07001856 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 public boolean enableDataConnectivity() {
1859 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001860
1861 final long identity = Binder.clearCallingIdentity();
1862 try {
1863 int subId = mSubscriptionController.getDefaultDataSubId();
1864 final Phone phone = getPhone(subId);
1865 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001866 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001867 return true;
1868 } else {
1869 return false;
1870 }
1871 } finally {
1872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 }
1875
Wink Saville36469e72014-06-11 15:17:00 -07001876 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001877 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 public boolean disableDataConnectivity() {
1879 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880
1881 final long identity = Binder.clearCallingIdentity();
1882 try {
1883 int subId = mSubscriptionController.getDefaultDataSubId();
1884 final Phone phone = getPhone(subId);
1885 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001886 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001887 return true;
1888 } else {
1889 return false;
1890 }
1891 } finally {
1892 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 }
1895
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001897 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898 final long identity = Binder.clearCallingIdentity();
1899 try {
1900 final Phone phone = getPhone(subId);
1901 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001902 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001903 } else {
1904 return false;
1905 }
1906 } finally {
1907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 }
1910
1911 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001912 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001913 }
1914
pkanwarae03a6b2016-11-06 20:37:09 -08001915 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001916 enforceCallPermission();
1917
1918 final long identity = Binder.clearCallingIdentity();
1919 try {
1920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1921 return;
1922 }
1923 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1924 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1925 } finally {
1926 Binder.restoreCallingIdentity(identity);
1927 }
pkanwar32d516d2016-10-14 19:37:38 -07001928 };
1929
Wink Savilleb564aae2014-10-23 10:18:09 -07001930 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001932
1933 final long identity = Binder.clearCallingIdentity();
1934 try {
1935 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1936 return false;
1937 }
1938 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001945 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001946 }
1947
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001948 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 Phone phone = PhoneFactory.getPhone(slotIndex);
1952 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1953 PhoneConstantConversions.convertCallState(phone.getState());
1954 } finally {
1955 Binder.restoreCallingIdentity(identity);
1956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 }
1958
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001960 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001961 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1962 }
1963
1964 @Override
1965 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 final long identity = Binder.clearCallingIdentity();
1967 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001968 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001969 if (phone != null) {
1970 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1971 } else {
1972 return PhoneConstantConversions.convertDataState(
1973 PhoneConstants.DataState.DISCONNECTED);
1974 }
1975 } finally {
1976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979
Sanket Padawe356d7632015-06-22 14:03:32 -07001980 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001981 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001982 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1983 }
1984
1985 @Override
1986 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987 final long identity = Binder.clearCallingIdentity();
1988 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001989 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001990 if (phone != null) {
1991 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1992 } else {
1993 return TelephonyManager.DATA_ACTIVITY_NONE;
1994 }
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 }
1999
2000 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002001 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002002 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002003 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002004
2005 LocationAccessPolicy.LocationPermissionResult locationResult =
2006 LocationAccessPolicy.checkLocationPermission(mApp,
2007 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2008 .setCallingPackage(callingPackage)
2009 .setCallingPid(Binder.getCallingPid())
2010 .setCallingUid(Binder.getCallingUid())
2011 .setMethod("getCellLocation")
2012 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2013 .build());
2014 switch (locationResult) {
2015 case DENIED_HARD:
2016 throw new SecurityException("Not allowed to access cell location");
2017 case DENIED_SOFT:
2018 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 }
2020
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002021 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 if (DBG_LOC) log("getCellLocation: is active user");
2025 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002026 int subId = mSubscriptionController.getDefaultDataSubId();
2027 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2028 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002029 return data;
2030 } finally {
2031 Binder.restoreCallingIdentity(identity);
2032 }
Svetoslav64fad262015-04-14 14:35:21 -07002033 }
2034
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002035 @Override
Jack Yu7c5d91a2019-09-26 11:48:33 -07002036 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2037 if (!TextUtils.isEmpty(callingPackage)) {
2038 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2040 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2041 return "";
2042 }
2043 }
2044
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002045 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2046 // registered cell info, so return a NULL country instead.
2047 final long identity = Binder.clearCallingIdentity();
2048 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002049 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2050 // Get default phone in this case.
2051 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2052 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002053 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002054 // Todo: fix this when we can get the actual cellular network info when the device
2055 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002056 if (TelephonyManager.NETWORK_TYPE_IWLAN
2057 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2058 return "";
2059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002060 Phone phone = PhoneFactory.getPhone(phoneId);
2061 if (phone != null) {
2062 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002063 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002064 if (sst != null) {
2065 LocaleTracker lt = sst.getLocaleTracker();
2066 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002067 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2068 return lt.getCurrentCountry();
2069 } else if (emergencyNumberTracker != null) {
2070 return emergencyNumberTracker.getEmergencyCountryIso();
2071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 }
2073 }
2074 }
2075 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002076 } finally {
2077 Binder.restoreCallingIdentity(identity);
2078 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002079 }
2080
2081 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002083 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002084 }
2085
Sanket Padawe356d7632015-06-22 14:03:32 -07002086 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002087 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 mApp.enforceCallingOrSelfPermission(
2089 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002090
2091 final long identity = Binder.clearCallingIdentity();
2092 try {
2093 final Phone phone = getPhone(subId);
2094 if (phone != null) {
2095 phone.enableLocationUpdates();
2096 }
2097 } finally {
2098 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 }
2101
2102 @Override
2103 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002104 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002105 }
2106
Sanket Padawe356d7632015-06-22 14:03:32 -07002107 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002108 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 mApp.enforceCallingOrSelfPermission(
2110 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002111
2112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 final Phone phone = getPhone(subId);
2115 if (phone != null) {
2116 phone.disableLocationUpdates();
2117 }
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 }
2122
Nathan Harold31d7ff32018-10-15 20:20:30 -07002123 /**
2124 * Returns the target SDK version number for a given package name.
2125 *
Nathan Haroldec184742019-07-10 17:04:16 -07002126 * This call MUST be invoked before clearing the calling UID.
2127 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002128 * @return target SDK if the package is found or INT_MAX.
2129 */
2130 private int getTargetSdk(String packageName) {
2131 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002132 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002133 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002134 if (ai != null) return ai.targetSdkVersion;
2135 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002136 loge("Failed to get package info for pkg="
2137 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002138 }
2139 return Integer.MAX_VALUE;
2140 }
2141
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 @Override
2143 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002144 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2145 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002146 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2147 throw new SecurityException(
2148 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2149 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002150
Jordan Liu1617b712019-07-10 15:06:26 -07002151 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2153 return null;
2154 }
Svetoslav64fad262015-04-14 14:35:21 -07002155
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002156 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157
Nathan Haroldf180aac2018-06-01 18:43:55 -07002158 List<CellInfo> info = getAllCellInfo(callingPackage);
2159 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160
Nathan Haroldf180aac2018-06-01 18:43:55 -07002161 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2162 for (CellInfo ci : info) {
2163 if (ci instanceof CellInfoGsm) {
2164 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2165 } else if (ci instanceof CellInfoWcdma) {
2166 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002169 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 }
2171
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002172 private List<CellInfo> getCachedCellInfo() {
2173 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2174 for (Phone phone : PhoneFactory.getPhones()) {
2175 List<CellInfo> info = phone.getAllCellInfo();
2176 if (info != null) cellInfos.addAll(info);
2177 }
2178 return cellInfos;
2179 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180
2181 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002182 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002183 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002184 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002185
2186 LocationAccessPolicy.LocationPermissionResult locationResult =
2187 LocationAccessPolicy.checkLocationPermission(mApp,
2188 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2189 .setCallingPackage(callingPackage)
2190 .setCallingPid(Binder.getCallingPid())
2191 .setCallingUid(Binder.getCallingUid())
2192 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002193 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002194 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2195 .build());
2196 switch (locationResult) {
2197 case DENIED_HARD:
2198 throw new SecurityException("Not allowed to access cell info");
2199 case DENIED_SOFT:
2200 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 }
2202
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002203 final int targetSdk = getTargetSdk(callingPackage);
2204 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2205 return getCachedCellInfo();
2206 }
2207
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002208 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002210 final long identity = Binder.clearCallingIdentity();
2211 try {
2212 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2213 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002214 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002215 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002216 if (info != null) cellInfos.addAll(info);
2217 }
2218 return cellInfos;
2219 } finally {
2220 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 }
2222 }
2223
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002224 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2226 requestCellInfoUpdateInternal(
2227 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2228 }
2229
2230 @Override
2231 public void requestCellInfoUpdateWithWorkSource(
2232 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2233 enforceModifyPermission();
2234 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2235 }
2236
2237 private void requestCellInfoUpdateInternal(
2238 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002239 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002240 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002241
2242 LocationAccessPolicy.LocationPermissionResult locationResult =
2243 LocationAccessPolicy.checkLocationPermission(mApp,
2244 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2245 .setCallingPackage(callingPackage)
2246 .setCallingPid(Binder.getCallingPid())
2247 .setCallingUid(Binder.getCallingUid())
2248 .setMethod("requestCellInfoUpdate")
2249 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2250 .build());
2251 switch (locationResult) {
2252 case DENIED_HARD:
2253 throw new SecurityException("Not allowed to access cell info");
2254 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002255 try {
2256 cb.onCellInfo(new ArrayList<CellInfo>());
2257 } catch (RemoteException re) {
2258 // Drop without consequences
2259 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002260 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002261 }
2262
Nathan Harolda939a962019-05-09 10:13:47 -07002263
2264 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002265 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2266
2267 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2268 }
2269
2270 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002272 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002273 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002274
2275 final long identity = Binder.clearCallingIdentity();
2276 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002277 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002278 } finally {
2279 Binder.restoreCallingIdentity(identity);
2280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 }
2282
Shishir Agrawala9f32182016-04-12 12:00:16 -07002283 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002284 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002285 Phone phone = PhoneFactory.getPhone(slotIndex);
2286 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002287 return null;
2288 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002289 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002290 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2291 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002292 return null;
2293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294
2295 final long identity = Binder.clearCallingIdentity();
2296 try {
2297 return phone.getImei();
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
2300 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002301 }
2302
2303 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002304 public String getTypeAllocationCodeForSlot(int slotIndex) {
2305 Phone phone = PhoneFactory.getPhone(slotIndex);
2306 String tac = null;
2307 if (phone != null) {
2308 String imei = phone.getImei();
2309 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2310 }
2311 return tac;
2312 }
2313
2314 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002315 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002316 Phone phone = PhoneFactory.getPhone(slotIndex);
2317 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002318 return null;
2319 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002320
Jeff Davidson913390f2018-02-23 17:11:49 -08002321 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002322 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2323 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002324 return null;
2325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 return phone.getMeid();
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
Jack Yu2af8d712017-03-15 17:14:14 -07002333 }
2334
2335 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002336 public String getManufacturerCodeForSlot(int slotIndex) {
2337 Phone phone = PhoneFactory.getPhone(slotIndex);
2338 String manufacturerCode = null;
2339 if (phone != null) {
2340 String meid = phone.getMeid();
2341 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2342 }
2343 return manufacturerCode;
2344 }
2345
2346 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002347 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002348 Phone phone = PhoneFactory.getPhone(slotIndex);
2349 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002350 return null;
2351 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002352 int subId = phone.getSubId();
2353 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2354 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2355 return null;
2356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002357
2358 final long identity = Binder.clearCallingIdentity();
2359 try {
2360 return phone.getDeviceSvn();
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
2363 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002364 }
2365
fionaxu43304da2017-11-27 22:51:16 -08002366 @Override
2367 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002368 final long identity = Binder.clearCallingIdentity();
2369 try {
2370 final Phone phone = getPhone(subId);
2371 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
2374 }
fionaxu43304da2017-11-27 22:51:16 -08002375 }
2376
2377 @Override
2378 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 final Phone phone = getPhone(subId);
2382 return phone == null ? null : phone.getCarrierName();
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
2385 }
fionaxu43304da2017-11-27 22:51:16 -08002386 }
2387
calvinpanffe225e2018-11-01 19:43:06 +08002388 @Override
chen xu0026ca62019-03-06 15:28:50 -08002389 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002390 final long identity = Binder.clearCallingIdentity();
2391 try {
2392 final Phone phone = getPhone(subId);
2393 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002394 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002395 } finally {
2396 Binder.restoreCallingIdentity(identity);
2397 }
2398 }
2399
2400 @Override
chen xu0026ca62019-03-06 15:28:50 -08002401 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002402 final long identity = Binder.clearCallingIdentity();
2403 try {
2404 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002405 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002406 } finally {
2407 Binder.restoreCallingIdentity(identity);
2408 }
2409 }
2410
chen xu651eec72018-11-11 19:03:44 -08002411 @Override
chen xu864e11c2018-12-06 22:10:03 -08002412 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2413 if (!isSubscriptionMccMnc) {
2414 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2415 }
chen xu651eec72018-11-11 19:03:44 -08002416 final Phone phone = PhoneFactory.getPhone(slotIndex);
2417 if (phone == null) {
2418 return TelephonyManager.UNKNOWN_CARRIER_ID;
2419 }
2420 final long identity = Binder.clearCallingIdentity();
2421 try {
2422 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
2426 }
2427
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 //
2429 // Internal helper methods.
2430 //
2431
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002432 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2434 *
2435 * @throws SecurityException if the caller does not have the required permission
2436 */
2437 private void enforceModifyPermission() {
2438 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2439 }
2440
Shuo Qianf2b2df42019-11-13 17:43:31 -08002441 private void enforceActiveEmergencySessionPermission() {
2442 mApp.enforceCallingOrSelfPermission(
2443 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2444 }
2445
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 /**
2447 * Make sure the caller has the CALL_PHONE permission.
2448 *
2449 * @throws SecurityException if the caller does not have the required permission
2450 */
2451 private void enforceCallPermission() {
2452 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2453 }
2454
paulhu423b5f22019-08-23 19:17:33 +08002455 private void enforceSettingsPermission() {
2456 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002457 }
2458
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 private String createTelUrl(String number) {
2460 if (TextUtils.isEmpty(number)) {
2461 return null;
2462 }
2463
Jake Hambye994d462014-02-03 13:10:13 -08002464 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 }
2466
Ihab Awadf9e92732013-12-05 18:02:52 -08002467 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2469 }
2470
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002471 private static void logv(String msg) {
2472 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2473 }
2474
Ihab Awadf9e92732013-12-05 18:02:52 -08002475 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2477 }
2478
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002479 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002481 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002482 }
2483
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002485 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 final Phone phone = PhoneFactory.getPhone(slotIndex);
2489 if (phone == null) {
2490 return PhoneConstants.PHONE_TYPE_NONE;
2491 } else {
2492 return phone.getPhoneType();
2493 }
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
2499 /**
2500 * Returns the CDMA ERI icon index to display
2501 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002502 @Override
2503 public int getCdmaEriIconIndex(String callingPackage) {
2504 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002505 }
2506
Sanket Padawe356d7632015-06-22 14:03:32 -07002507 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002508 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002509 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002510 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002511 return -1;
2512 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513
2514 final long identity = Binder.clearCallingIdentity();
2515 try {
2516 final Phone phone = getPhone(subId);
2517 if (phone != null) {
2518 return phone.getCdmaEriIconIndex();
2519 } else {
2520 return -1;
2521 }
2522 } finally {
2523 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 }
2526
2527 /**
2528 * Returns the CDMA ERI icon mode,
2529 * 0 - ON
2530 * 1 - FLASHING
2531 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002532 @Override
2533 public int getCdmaEriIconMode(String callingPackage) {
2534 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002535 }
2536
Sanket Padawe356d7632015-06-22 14:03:32 -07002537 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002538 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002540 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002541 return -1;
2542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 final Phone phone = getPhone(subId);
2547 if (phone != null) {
2548 return phone.getCdmaEriIconMode();
2549 } else {
2550 return -1;
2551 }
2552 } finally {
2553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 }
2556
2557 /**
2558 * Returns the CDMA ERI text,
2559 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002560 @Override
2561 public String getCdmaEriText(String callingPackage) {
2562 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002563 }
2564
Sanket Padawe356d7632015-06-22 14:03:32 -07002565 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002566 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002568 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002569 return null;
2570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 final Phone phone = getPhone(subId);
2575 if (phone != null) {
2576 return phone.getCdmaEriText();
2577 } else {
2578 return null;
2579 }
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 }
2584
2585 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002586 * Returns the CDMA MDN.
2587 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002588 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002589 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2591 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592
2593 final long identity = Binder.clearCallingIdentity();
2594 try {
2595 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002596 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597 return phone.getLine1Number();
2598 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002599 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 return null;
2601 }
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002604 }
2605 }
2606
2607 /**
2608 * Returns the CDMA MIN.
2609 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002610 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002611 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2613 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614
2615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 final Phone phone = getPhone(subId);
2618 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2619 return phone.getCdmaMin();
2620 } else {
2621 return null;
2622 }
2623 } finally {
2624 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002625 }
2626 }
2627
Hall Liud892bec2018-11-30 14:51:45 -08002628 @Override
2629 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2630 INumberVerificationCallback callback, String callingPackage) {
2631 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2632 != PERMISSION_GRANTED) {
2633 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2634 }
2635 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2636
2637 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2638 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2639 throw new SecurityException("Calling package must be configured in the device config");
2640 }
2641
2642 if (range == null) {
2643 throw new NullPointerException("Range must be non-null");
2644 }
2645
2646 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002647 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002648
2649 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2650 }
2651
Junda Liuca05d5d2014-08-14 22:36:34 -07002652 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 * Returns true if CDMA provisioning needs to run.
2654 */
2655 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 final long identity = Binder.clearCallingIdentity();
2657 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002658 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 }
2663
2664 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002665 * Sets the voice mail number of a given subId.
2666 */
2667 @Override
2668 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002669 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002670
2671 final long identity = Binder.clearCallingIdentity();
2672 try {
2673 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2674 new Pair<String, String>(alphaTag, number), new Integer(subId));
2675 return success;
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
2678 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002679 }
2680
Ta-wei Yen87c49842016-05-13 21:19:52 -07002681 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002682 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002684 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2685 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002686 if (!TextUtils.equals(callingPackage, systemDialer)) {
2687 throw new SecurityException("caller must be system dialer");
2688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689
2690 final long identity = Binder.clearCallingIdentity();
2691 try {
2692 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2693 if (phoneAccountHandle == null) {
2694 return null;
2695 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002696 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 } finally {
2698 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002699 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002700 }
2701
2702 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002703 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002706 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002707 return null;
2708 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002710 final long identity = Binder.clearCallingIdentity();
2711 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002712 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002713 } finally {
2714 Binder.restoreCallingIdentity(identity);
2715 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002716 }
2717
2718 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002719 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2720 VisualVoicemailSmsFilterSettings settings) {
2721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722
2723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002726 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 } finally {
2728 Binder.restoreCallingIdentity(identity);
2729 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002730 }
2731
2732 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002733 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735
2736 final long identity = Binder.clearCallingIdentity();
2737 try {
2738 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002739 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740 } finally {
2741 Binder.restoreCallingIdentity(identity);
2742 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002743 }
2744
2745 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002746 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2747 String callingPackage, int subId) {
2748 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002753 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754 } finally {
2755 Binder.restoreCallingIdentity(identity);
2756 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002757 }
2758
2759 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002760 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002761 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002766 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767 } finally {
2768 Binder.restoreCallingIdentity(identity);
2769 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002770 }
2771
2772 @Override
2773 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2774 String number, int port, String text, PendingIntent sentIntent) {
2775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002776 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002777 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002778 SmsController smsController = PhoneFactory.getSmsController();
2779 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2780 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002781 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002782
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002783 /**
fionaxu0152e512016-11-14 13:36:14 -08002784 * Sets the voice activation state of a given subId.
2785 */
2786 @Override
2787 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2789 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790
2791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 final Phone phone = getPhone(subId);
2794 if (phone != null) {
2795 phone.setVoiceActivationState(activationState);
2796 } else {
2797 loge("setVoiceActivationState fails with invalid subId: " + subId);
2798 }
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002801 }
2802 }
2803
2804 /**
2805 * Sets the data activation state of a given subId.
2806 */
2807 @Override
2808 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2810 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811
2812 final long identity = Binder.clearCallingIdentity();
2813 try {
2814 final Phone phone = getPhone(subId);
2815 if (phone != null) {
2816 phone.setDataActivationState(activationState);
2817 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002818 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819 }
2820 } finally {
2821 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002822 }
2823 }
2824
2825 /**
2826 * Returns the voice activation state of a given subId.
2827 */
2828 @Override
2829 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002830 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831
fionaxu0152e512016-11-14 13:36:14 -08002832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 if (phone != null) {
2836 return phone.getVoiceActivationState();
2837 } else {
2838 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2839 }
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002842 }
2843 }
2844
2845 /**
2846 * Returns the data activation state of a given subId.
2847 */
2848 @Override
2849 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002850 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851
fionaxu0152e512016-11-14 13:36:14 -08002852 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 if (phone != null) {
2856 return phone.getDataActivationState();
2857 } else {
2858 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2859 }
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002862 }
2863 }
2864
2865 /**
Wink Saville36469e72014-06-11 15:17:00 -07002866 * Returns the unread count of voicemails for a subId
2867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002868 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002869 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2870 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2871 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2872 return 0;
2873 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 final Phone phone = getPhone(subId);
2877 if (phone != null) {
2878 return phone.getVoiceMessageCount();
2879 } else {
2880 return 0;
2881 }
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002885 }
2886
2887 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002888 * returns true, if the device is in a state where both voice and data
2889 * are supported simultaneously. This can change based on location or network condition.
2890 */
2891 @Override
2892 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 final Phone phone = getPhone(subId);
2896 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2897 } finally {
2898 Binder.restoreCallingIdentity(identity);
2899 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002900 }
2901
2902 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002903 * Send the dialer code if called from the current default dialer or the caller has
2904 * carrier privilege.
2905 * @param inputCode The dialer code to send
2906 */
2907 @Override
2908 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002909 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002911 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2912 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002913 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002914 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2915 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002920 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 } finally {
2922 Binder.restoreCallingIdentity(identity);
2923 }
fionaxu235cc5e2017-03-06 22:25:57 -08002924 }
2925
Pengquan Menga1bb6272018-09-06 09:59:22 -07002926 @Override
2927 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002928 if (!isActiveSubscription(subId)) {
2929 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2930 }
2931
Pengquan Menga1bb6272018-09-06 09:59:22 -07002932 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2933 }
2934
Brad Ebinger35c841c2018-10-01 10:40:55 -07002935 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002936 public boolean isInEmergencySmsMode() {
2937 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 for (Phone phone : PhoneFactory.getPhones()) {
2941 if (phone.isInEmergencySmsMode()) {
2942 return true;
2943 }
2944 }
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
2947 }
2948 return false;
2949 }
2950
2951 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002952 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2953 throws RemoteException {
2954 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002955 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2956 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2957 "IMS not available on device.");
2958 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002959 final long token = Binder.clearCallingIdentity();
2960 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002962 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002963 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002964 } catch (ImsException e) {
2965 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002966 } finally {
2967 Binder.restoreCallingIdentity(token);
2968 }
2969 }
2970
2971 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002972 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2973 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002974 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2975 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2976 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002977 final long token = Binder.clearCallingIdentity();
2978 try {
2979 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2980 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2981 .removeRegistrationCallbackForSubscription(c, subId);
2982 } catch (ImsException e) {
2983 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2984 + "is inactive, ignoring unregister.");
2985 // If the subscription is no longer active, just return, since the callback
2986 // will already have been removed internally.
2987 } finally {
2988 Binder.restoreCallingIdentity(token);
2989 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 }
2991
Brad Ebinger774ba362019-10-22 17:36:18 -07002992 /**
2993 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2994 */
2995 @Override
2996 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2997 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2998 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2999 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3000 "IMS not available on device.");
3001 }
3002 final long token = Binder.clearCallingIdentity();
3003 try {
3004 Phone phone = getPhone(subId);
3005 if (phone == null) {
3006 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3007 + subId + "'");
3008 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3009 }
3010 phone.getImsRegistrationState(regState -> {
3011 try {
3012 consumer.accept((regState == null)
3013 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3014 } catch (RemoteException e) {
3015 // Ignore if the remote process is no longer available to call back.
3016 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3017 }
3018 });
3019 } finally {
3020 Binder.restoreCallingIdentity(token);
3021 }
3022 }
3023
3024 /**
3025 * Get the transport type for the IMS service registration state.
3026 */
3027 @Override
3028 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3029 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3030 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3031 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3032 "IMS not available on device.");
3033 }
3034 final long token = Binder.clearCallingIdentity();
3035 try {
3036 Phone phone = getPhone(subId);
3037 if (phone == null) {
3038 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3039 + subId + "'");
3040 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3041 }
3042 phone.getImsRegistrationTech(regTech -> {
3043 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3044 int regTechConverted = (regTech == null)
3045 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3046 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3047 regTechConverted);
3048 try {
3049 consumer.accept(regTechConverted);
3050 } catch (RemoteException e) {
3051 // Ignore if the remote process is no longer available to call back.
3052 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3053 }
3054 });
3055 } finally {
3056 Binder.restoreCallingIdentity(token);
3057 }
3058 }
3059
Brad Ebinger35c841c2018-10-01 10:40:55 -07003060 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003061 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3062 throws RemoteException {
3063 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003064 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3065 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3066 "IMS not available on device.");
3067 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003068 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3069 final long token = Binder.clearCallingIdentity();
3070 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003071 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003072 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003073 } catch (ImsException e) {
3074 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003075 } finally {
3076 Binder.restoreCallingIdentity(token);
3077 }
3078 }
3079
3080 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003081 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3082 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003083 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3084 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3085 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003086
3087 final long token = Binder.clearCallingIdentity();
3088 try {
3089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3090 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003091 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003092 } catch (ImsException e) {
3093 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3094 + "is inactive, ignoring unregister.");
3095 // If the subscription is no longer active, just return, since the callback
3096 // will already have been removed internally.
3097 } finally {
3098 Binder.restoreCallingIdentity(token);
3099 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003100 }
3101
3102 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003103 public boolean isCapable(int subId, int capability, int regTech) {
3104 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003105 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3106 final long token = Binder.clearCallingIdentity();
3107 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003108 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003110 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003111 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3112 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003113 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003114 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3115 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003116 } finally {
3117 Binder.restoreCallingIdentity(token);
3118 }
3119 }
3120
3121 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003122 public boolean isAvailable(int subId, int capability, int regTech) {
3123 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003124 final long token = Binder.clearCallingIdentity();
3125 try {
3126 Phone phone = getPhone(subId);
3127 if (phone == null) return false;
3128 return phone.isImsCapabilityAvailable(capability, regTech);
3129 } finally {
3130 Binder.restoreCallingIdentity(token);
3131 }
3132 }
3133
Brad Ebinger77b832e2019-10-17 17:03:22 -07003134 /**
3135 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3136 * subscription.
3137 * @param subId The subscription to use to check the configuration.
3138 * @param callback The callback that will be used to send the result.
3139 * @param capability The MmTelFeature capability that will be used to send the result.
3140 * @param transportType The transport type of the MmTelFeature capability.
3141 */
3142 @Override
3143 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3144 int transportType) {
3145 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3146 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3147 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3148 "IMS not available on device.");
3149 }
3150 final long token = Binder.clearCallingIdentity();
3151 try {
3152 int slotId = getSlotIndex(subId);
3153 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3154 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3155 + subId + "'");
3156 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3157 }
3158 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3159 transportType, aBoolean -> {
3160 try {
3161 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3162 } catch (RemoteException e) {
3163 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3164 + "running. Ignore");
3165 }
3166 });
3167 } finally {
3168 Binder.restoreCallingIdentity(token);
3169 }
3170 }
3171
Brad Ebinger35c841c2018-10-01 10:40:55 -07003172 @Override
3173 public boolean isAdvancedCallingSettingEnabled(int subId) {
3174 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3175 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3176 final long token = Binder.clearCallingIdentity();
3177 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003178 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003179 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003180 } catch (ImsException e) {
3181 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003182 } finally {
3183 Binder.restoreCallingIdentity(token);
3184 }
3185 }
3186
3187 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003188 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003190 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003191 final long identity = Binder.clearCallingIdentity();
3192 try {
3193 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003194 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003195 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003196 } catch (ImsException e) {
3197 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
3201 }
3202
3203 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003204 public boolean isVtSettingEnabled(int subId) {
3205 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003209 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3210 } catch (ImsException e) {
3211 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
3215 }
3216
3217 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003218 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003220 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003224 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003225 } catch (ImsException e) {
3226 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003227 } finally {
3228 Binder.restoreCallingIdentity(identity);
3229 }
3230 }
3231
3232 @Override
3233 public boolean isVoWiFiSettingEnabled(int subId) {
3234 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003238 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003240 } catch (ImsException e) {
3241 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003242 } finally {
3243 Binder.restoreCallingIdentity(identity);
3244 }
3245 }
3246
3247 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003248 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003250 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003251 final long identity = Binder.clearCallingIdentity();
3252 try {
3253 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003254 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003255 } catch (ImsException e) {
3256 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 } finally {
3258 Binder.restoreCallingIdentity(identity);
3259 }
3260 }
3261
3262 @Override
3263 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3264 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3265 final long identity = Binder.clearCallingIdentity();
3266 try {
3267 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003268 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003270 } catch (ImsException e) {
3271 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
3275 }
3276
3277 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003278 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003280 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003284 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003286 } catch (ImsException e) {
3287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
3291 }
3292
3293 @Override
3294 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3296 "setVoWiFiNonPersistent");
3297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003300 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003301 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003302 } catch (ImsException e) {
3303 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003304 } finally {
3305 Binder.restoreCallingIdentity(identity);
3306 }
3307 }
3308
3309 @Override
3310 public int getVoWiFiModeSetting(int subId) {
3311 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003315 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003316 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003317 } catch (ImsException e) {
3318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
3322 }
3323
3324 @Override
3325 public void setVoWiFiModeSetting(int subId, int mode) {
3326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3327 "setVoWiFiModeSetting");
3328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003331 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003332 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003333 } catch (ImsException e) {
3334 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
3338 }
3339
3340 @Override
3341 public int getVoWiFiRoamingModeSetting(int subId) {
3342 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003346 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003347 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003348 } catch (ImsException e) {
3349 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 } finally {
3351 Binder.restoreCallingIdentity(identity);
3352 }
3353 }
3354
3355 @Override
3356 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3358 "setVoWiFiRoamingModeSetting");
3359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003362 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003364 } catch (ImsException e) {
3365 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
3369 }
3370
3371 @Override
3372 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3374 "setRttCapabilityEnabled");
3375 final long identity = Binder.clearCallingIdentity();
3376 try {
3377 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003378 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3379 } catch (ImsException e) {
3380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
3384 }
3385
3386 @Override
3387 public boolean isTtyOverVolteEnabled(int subId) {
3388 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003392 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003393 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003394 } catch (ImsException e) {
3395 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 } finally {
3397 Binder.restoreCallingIdentity(identity);
3398 }
3399 }
3400
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003401 @Override
3402 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3403 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3404 final long identity = Binder.clearCallingIdentity();
3405 try {
3406 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003407 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003408 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003409 } catch (ImsException e) {
3410 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003411 } finally {
3412 Binder.restoreCallingIdentity(identity);
3413 }
3414 }
3415
3416 @Override
3417 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3418 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3419 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003420 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3421 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3422 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003423 try {
3424 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003425 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003426 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003427 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003428 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3429 + "is inactive, ignoring unregister.");
3430 // If the subscription is no longer active, just return, since the callback will already
3431 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003432 } finally {
3433 Binder.restoreCallingIdentity(identity);
3434 }
3435 }
3436
3437 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003438 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3439 boolean isProvisioned) {
3440 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3441 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3442 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3443 }
3444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3445 "setProvisioningStatusForCapability");
3446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3449 Phone phone = getPhone(subId);
3450 if (phone == null) {
3451 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3452 + subId);
3453 return;
3454 }
3455 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3456 return;
3457 }
3458
3459 // this capability requires provisioning, route to the correct API.
3460 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3461 switch (capability) {
3462 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3463 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3464 ims.setVolteProvisioned(isProvisioned);
3465 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3466 ims.setWfcProvisioned(isProvisioned);
3467 }
3468 break;
3469 }
3470 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3471 // There is currently no difference in VT provisioning type.
3472 ims.setVtProvisioned(isProvisioned);
3473 break;
3474 }
3475 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3476 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3477 // change the capability of the feature instead if needed.
3478 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3479 == isProvisioned) {
3480 // No change in provisioning.
3481 return;
3482 }
3483 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3484 try {
3485 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003486 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003487 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3488 + ", Exception" + e.getMessage());
3489 }
3490 break;
3491 }
3492 default: {
3493 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3494 + capability + "', which does not require provisioning.");
3495 }
3496 }
3497
3498 } finally {
3499 Binder.restoreCallingIdentity(identity);
3500 }
3501 }
3502
3503 @Override
3504 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3505 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3506 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3507 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3508 }
3509 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3510 final long identity = Binder.clearCallingIdentity();
3511 try {
3512 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3513 Phone phone = getPhone(subId);
3514 if (phone == null) {
3515 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3516 + subId);
3517 // We will fail with "true" as the provisioning status because this is the default
3518 // if we do not require provisioning.
3519 return true;
3520 }
3521
3522 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3523 return true;
3524 }
3525
3526 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3527 switch (capability) {
3528 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3529 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3530 return ims.isVolteProvisionedOnDevice();
3531 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3532 return ims.isWfcProvisionedOnDevice();
3533 }
3534 // This should never happen, since we are checking tech above to make sure it
3535 // is either LTE or IWLAN.
3536 throw new IllegalArgumentException("Invalid radio technology for voice "
3537 + "capability.");
3538 }
3539 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3540 // There is currently no difference in VT provisioning type.
3541 return ims.isVtProvisionedOnDevice();
3542 }
3543 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3544 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3545 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3546 }
3547 default: {
3548 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3549 + capability + "', which does not require provisioning.");
3550 }
3551 }
3552
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
3556 }
3557
3558 @Override
3559 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3560 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3561 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3562 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3563 }
3564 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3565 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3566 return (provisionedBits & capability) > 0;
3567 }
3568
3569 @Override
3570 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3571 boolean isProvisioned) {
3572 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3573 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3574 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3575 }
3576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3577 "setProvisioningStatusForCapability");
3578 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3579 // If the current provisioning status for capability already matches isProvisioned,
3580 // do nothing.
3581 if (((provisionedBits & capability) > 0) == isProvisioned) {
3582 return;
3583 }
3584 if (isProvisioned) {
3585 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3586 } else {
3587 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3588 }
3589 }
3590
3591 /**
3592 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3593 * technology. The bitfield should mirror the bitfield defined by
3594 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3595 */
3596 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3597 String key = getMmTelProvisioningKey(subId, tech);
3598 // Default is no capabilities are provisioned.
3599 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3600 }
3601
3602 /**
3603 * Sets the MmTel capability provisioning bitfield (defined by
3604 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3605 * technology specified.
3606 *
3607 * Note: This is a synchronous command and should not be called on UI thread.
3608 */
3609 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3610 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3611 String key = getMmTelProvisioningKey(subId, tech);
3612 editor.putInt(key, newField);
3613 editor.commit();
3614 }
3615
3616 private static String getMmTelProvisioningKey(int subId, int tech) {
3617 // resulting key is provision_ims_mmtel_{subId}_{tech}
3618 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3619 }
3620
3621 /**
3622 * Query CarrierConfig to see if the specified capability requires provisioning for the
3623 * carrier associated with the subscription id.
3624 */
3625 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3626 int capability) {
3627 CarrierConfigManager configManager = new CarrierConfigManager(context);
3628 PersistableBundle c = configManager.getConfigForSubId(subId);
3629 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003630 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003631 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3632 false);
3633 boolean requireVoiceVtProvisioning = c.getBoolean(
3634 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3635
3636 // First check to make sure that the capability requires provisioning.
3637 switch (capability) {
3638 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3639 // intentional fallthrough
3640 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3641 if (requireVoiceVtProvisioning) {
3642 // Voice and Video requires provisioning
3643 return true;
3644 }
3645 break;
3646 }
3647 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3648 if (requireUtProvisioning) {
3649 // UT requires provisioning
3650 return true;
3651 }
3652 break;
3653 }
3654 }
3655 return false;
3656 }
3657
3658 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003659 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003660 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3661 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3662 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003663 enforceReadPrivilegedPermission("getImsProvisioningInt");
3664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003667 int slotId = getSlotIndex(subId);
3668 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3669 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3670 + subId + "' for key:" + key);
3671 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3672 }
3673 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003674 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003675 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3676 + subId + "' for key:" + key);
3677 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
3681 }
3682
3683 @Override
3684 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003685 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3686 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3687 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003688 enforceReadPrivilegedPermission("getImsProvisioningString");
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003692 int slotId = getSlotIndex(subId);
3693 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3694 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3695 + subId + "' for key:" + key);
3696 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3697 }
3698 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003699 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003700 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3701 + subId + "' for key:" + key);
3702 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003703 } finally {
3704 Binder.restoreCallingIdentity(identity);
3705 }
3706 }
3707
3708 @Override
3709 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003710 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3711 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3712 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3714 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003715 final long identity = Binder.clearCallingIdentity();
3716 try {
3717 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003718 int slotId = getSlotIndex(subId);
3719 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3720 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3721 + subId + "' for key:" + key);
3722 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3723 }
3724 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003725 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003726 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3727 + "' for key:" + key);
3728 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
3732 }
3733
3734 @Override
3735 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3737 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3738 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3740 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003741 final long identity = Binder.clearCallingIdentity();
3742 try {
3743 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003744 int slotId = getSlotIndex(subId);
3745 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3746 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3747 + subId + "' for key:" + key);
3748 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3749 }
3750 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003751 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003752 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3753 + "' for key:" + key);
3754 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003755 } finally {
3756 Binder.restoreCallingIdentity(identity);
3757 }
3758 }
3759
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003760 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 int slotId = SubscriptionManager.getSlotIndex(subId);
3762 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003763 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3764 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003765 }
3766 return slotId;
3767 }
3768
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003769 private int getSlotIndex(int subId) {
3770 int slotId = SubscriptionManager.getSlotIndex(subId);
3771 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3772 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3773 }
3774 return slotId;
3775 }
3776
Wink Saville36469e72014-06-11 15:17:00 -07003777 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003778 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003779 */
3780 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003781 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003782 final int targetSdk = getTargetSdk(callingPackage);
3783 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3784 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3785 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003786 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3787 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003788 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3789 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 final Phone phone = getPhone(subId);
3794 if (phone != null) {
3795 return phone.getServiceState().getDataNetworkType();
3796 } else {
3797 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3798 }
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003802 }
3803
3804 /**
3805 * Returns the data network type
3806 */
3807 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003808 public int getDataNetworkType(String callingPackage) {
3809 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003810 }
3811
3812 /**
3813 * Returns the data network type for a subId
3814 */
3815 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003816 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003817 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003818 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003819 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3820 }
3821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003822 final long identity = Binder.clearCallingIdentity();
3823 try {
3824 final Phone phone = getPhone(subId);
3825 if (phone != null) {
3826 return phone.getServiceState().getDataNetworkType();
3827 } else {
3828 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3829 }
3830 } finally {
3831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003833 }
3834
3835 /**
Wink Saville36469e72014-06-11 15:17:00 -07003836 * Returns the Voice network type for a subId
3837 */
3838 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003839 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003841 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003842 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3843 }
3844
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003845 final long identity = Binder.clearCallingIdentity();
3846 try {
3847 final Phone phone = getPhone(subId);
3848 if (phone != null) {
3849 return phone.getServiceState().getVoiceNetworkType();
3850 } else {
3851 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3852 }
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003856 }
3857
3858 /**
3859 * @return true if a ICC card is present
3860 */
3861 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003862 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003863 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3864 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003865 }
3866
3867 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003868 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003869 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003870 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003871 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 final Phone phone = PhoneFactory.getPhone(slotIndex);
3875 if (phone != null) {
3876 return phone.getIccCard().hasIccCard();
3877 } else {
3878 return false;
3879 }
3880 } finally {
3881 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003883 }
3884
3885 /**
3886 * Return if the current radio is LTE on CDMA. This
3887 * is a tri-state return value as for a period of time
3888 * the mode may be unknown.
3889 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003890 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003891 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003892 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003893 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003894 @Override
3895 public int getLteOnCdmaMode(String callingPackage) {
3896 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003897 }
3898
Sanket Padawe356d7632015-06-22 14:03:32 -07003899 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003900 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003901 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003902 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003903 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3904 }
3905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003906 final long identity = Binder.clearCallingIdentity();
3907 try {
3908 final Phone phone = getPhone(subId);
3909 if (phone == null) {
3910 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3911 } else {
3912 return phone.getLteOnCdmaMode();
3913 }
3914 } finally {
3915 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003916 }
Wink Saville36469e72014-06-11 15:17:00 -07003917 }
3918
Wink Saville36469e72014-06-11 15:17:00 -07003919 /**
3920 * {@hide}
3921 * Returns Default subId, 0 in the case of single standby.
3922 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003923 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003924 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003925 }
3926
Shishir Agrawala9f32182016-04-12 12:00:16 -07003927 private int getSlotForDefaultSubscription() {
3928 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3929 }
3930
Wink Savilleb564aae2014-10-23 10:18:09 -07003931 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003932 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003933 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003934
Pengquan Menge92a50d2018-09-21 15:54:48 -07003935 private boolean isActiveSubscription(int subId) {
3936 return mSubscriptionController.isActiveSubId(subId);
3937 }
3938
Ihab Awadf2177b72013-11-25 13:33:23 -08003939 /**
3940 * @see android.telephony.TelephonyManager.WifiCallingChoices
3941 */
3942 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943 final long identity = Binder.clearCallingIdentity();
3944 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003945 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003946 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3947 getWhenToMakeWifiCallsDefaultPreference());
3948 } finally {
3949 Binder.restoreCallingIdentity(identity);
3950 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003951 }
3952
3953 /**
3954 * @see android.telephony.TelephonyManager.WifiCallingChoices
3955 */
3956 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957 final long identity = Binder.clearCallingIdentity();
3958 try {
3959 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003960 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003961 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3962 } finally {
3963 Binder.restoreCallingIdentity(identity);
3964 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003965 }
3966
Sailesh Nepald1e68152013-12-12 19:08:02 -08003967 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003968 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003969 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003970 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003971
Jordan Liu4c733742019-02-28 12:03:40 -08003972 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3973 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3974 if (phoneId == -1) {
3975 throw new IllegalArgumentException("Given slot index: " + slotIndex
3976 + " does not correspond to an active phone");
3977 }
3978 return PhoneFactory.getPhone(phoneId);
3979 }
3980
Shishir Agrawal566b7612013-10-28 14:41:00 -07003981 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003982 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3983 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3985 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003987 if (DBG) {
3988 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3989 }
3990 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3991 p2);
3992 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003993
Jordan Liu4c733742019-02-28 12:03:40 -08003994
3995 @Override
3996 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3997 int slotIndex, String callingPackage, String aid, int p2) {
3998 enforceModifyPermission();
3999 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4000 if (DBG) {
4001 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4002 }
4003 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4004 callingPackage, aid, p2);
4005 }
4006
4007 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4008 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 if (TextUtils.equals(ISDR_AID, aid)) {
4012 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004013 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4014 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015 if (bestComponent == null
4016 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4017 loge("The calling package is not allowed to access ISD-R.");
4018 throw new SecurityException(
4019 "The calling package is not allowed to access ISD-R.");
4020 }
Derek Tan740e1672017-06-27 14:56:27 -07004021 }
Derek Tan740e1672017-06-27 14:56:27 -07004022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004024 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4025 null /* workSource */);
4026 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027 return response;
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004031 }
4032
4033 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004034 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4036 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004037 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4038 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4039 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004040
Jordan Liu4c733742019-02-28 12:03:40 -08004041 @Override
4042 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4043 enforceModifyPermission();
4044 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4045 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4046 channel);
4047 }
4048
4049 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 final long identity = Binder.clearCallingIdentity();
4051 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 if (channel < 0) {
4053 return false;
4054 }
Jordan Liu4c733742019-02-28 12:03:40 -08004055 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4056 null /* workSource */);
4057 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 return success;
4059 } finally {
4060 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004061 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004062 }
4063
4064 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004065 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004066 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4068 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004069 if (DBG) {
4070 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4071 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4072 + p3 + " data=" + data);
4073 }
4074 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4075 command, p1, p2, p3, data);
4076 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004077
Jordan Liu4c733742019-02-28 12:03:40 -08004078 @Override
4079 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4080 int command, int p1, int p2, int p3, String data) {
4081 enforceModifyPermission();
4082 if (DBG) {
4083 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4084 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4085 + p3 + " data=" + data);
4086 }
4087 return iccTransmitApduLogicalChannelWithPermission(
4088 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4089 data);
4090 }
4091
4092 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4093 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 final long identity = Binder.clearCallingIdentity();
4095 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004096 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 return "";
4098 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004101 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4102 null /* workSource */);
4103 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004104
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105 // Append the returned status code to the end of the response payload.
4106 String s = Integer.toHexString(
4107 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4108 if (response.payload != null) {
4109 s = IccUtils.bytesToHexString(response.payload) + s;
4110 }
4111 return s;
4112 } finally {
4113 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004114 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004115 }
Jake Hambye994d462014-02-03 13:10:13 -08004116
Evan Charltonc66da362014-05-16 14:06:40 -07004117 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004118 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4119 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4121 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004122 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004123 if (DBG) {
4124 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4125 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4126 }
4127 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4128 cla, command, p1, p2, p3, data);
4129 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004130
Jordan Liu4c733742019-02-28 12:03:40 -08004131 @Override
4132 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4133 int command, int p1, int p2, int p3, String data) {
4134 enforceModifyPermission();
4135 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4136 if (DBG) {
4137 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4138 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4139 + " data=" + data);
4140 }
4141
4142 return iccTransmitApduBasicChannelWithPermission(
4143 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4144 p2, p3, data);
4145 }
4146
4147 // open APDU basic channel assuming the caller has sufficient permissions
4148 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4149 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4153 && TextUtils.equals(ISDR_AID, data)) {
4154 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004155 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4156 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157 if (bestComponent == null
4158 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4159 loge("The calling package is not allowed to select ISD-R.");
4160 throw new SecurityException(
4161 "The calling package is not allowed to select ISD-R.");
4162 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004163 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004166 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4167 null /* workSource */);
4168 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004170 // Append the returned status code to the end of the response payload.
4171 String s = Integer.toHexString(
4172 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4173 if (response.payload != null) {
4174 s = IccUtils.bytesToHexString(response.payload) + s;
4175 }
4176 return s;
4177 } finally {
4178 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004179 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004180 }
4181
4182 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004183 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004184 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4186 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004188 final long identity = Binder.clearCallingIdentity();
4189 try {
4190 if (DBG) {
4191 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4192 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4193 }
4194
4195 IccIoResult response =
4196 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4197 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4198 subId);
4199
4200 if (DBG) {
4201 log("Exchange SIM_IO [R]" + response);
4202 }
4203
4204 byte[] result = null;
4205 int length = 2;
4206 if (response.payload != null) {
4207 length = 2 + response.payload.length;
4208 result = new byte[length];
4209 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4210 } else {
4211 result = new byte[length];
4212 }
4213
4214 result[length - 1] = (byte) response.sw2;
4215 result[length - 2] = (byte) response.sw1;
4216 return result;
4217 } finally {
4218 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004219 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004220 }
4221
Nathan Haroldb3014052017-01-25 15:57:32 -08004222 /**
4223 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4224 * on a particular subscription
4225 */
sqianb6e41952018-03-12 14:54:01 -07004226 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4227 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4228 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4229 return null;
4230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231
4232 final long identity = Binder.clearCallingIdentity();
4233 try {
4234 if (appType != TelephonyManager.APPTYPE_USIM
4235 && appType != TelephonyManager.APPTYPE_SIM) {
4236 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4237 return null;
4238 }
4239 Object response = sendRequest(
4240 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4241 if (response instanceof String[]) {
4242 return (String[]) response;
4243 }
yincheng zhaod698b842019-09-06 17:06:54 -07004244 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004246 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247 } finally {
4248 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004249 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004250 }
4251
yincheng zhaod698b842019-09-06 17:06:54 -07004252 /**
4253 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4254 * subscription.
4255 *
4256 * @param subId the id of the subscription.
4257 * @param appType the uicc app type, must be USIM or SIM.
4258 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4259 * @param callingPackage the op Package name.
4260 * @return number of fplmns that is successfully written to the SIM.
4261 */
4262 public int setForbiddenPlmns(
4263 int subId, int appType, List<String> fplmns, String callingPackage) {
4264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4265 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4266 if (DBG) logv("no permissions for setForbiddenplmns");
4267 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4268 }
4269 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4270 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4271 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4272 }
4273 if (fplmns == null) {
4274 throw new IllegalArgumentException("Fplmn List provided is null");
4275 }
4276 for (String fplmn : fplmns) {
4277 if (!CellIdentity.isValidPlmn(fplmn)) {
4278 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4279 }
4280 }
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
4283 Object response = sendRequest(
4284 CMD_SET_FORBIDDEN_PLMNS,
4285 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4286 subId);
4287 return (int) response;
4288 } finally {
4289 Binder.restoreCallingIdentity(identity);
4290 }
4291 }
4292
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004293 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004294 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4296 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004298 final long identity = Binder.clearCallingIdentity();
4299 try {
4300 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4301 if (response.payload == null) {
4302 return "";
4303 }
Evan Charltonc66da362014-05-16 14:06:40 -07004304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 // Append the returned status code to the end of the response payload.
4306 String s = Integer.toHexString(
4307 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4308 s = IccUtils.bytesToHexString(response.payload) + s;
4309 return s;
4310 } finally {
4311 Binder.restoreCallingIdentity(identity);
4312 }
Evan Charltonc66da362014-05-16 14:06:40 -07004313 }
4314
Jake Hambye994d462014-02-03 13:10:13 -08004315 /**
4316 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4317 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4318 *
4319 * @param itemID the ID of the item to read
4320 * @return the NV item as a String, or null on error.
4321 */
4322 @Override
4323 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004324 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4326 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327
4328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004331 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4333 return value;
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
Jake Hambye994d462014-02-03 13:10:13 -08004337 }
4338
4339 /**
4340 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4341 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4342 *
4343 * @param itemID the ID of the item to read
4344 * @param itemValue the value to write, as a String
4345 * @return true on success; false on any failure
4346 */
4347 @Override
4348 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004349 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4351 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004352
4353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4356 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004357 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4359 return success;
4360 } finally {
4361 Binder.restoreCallingIdentity(identity);
4362 }
Jake Hambye994d462014-02-03 13:10:13 -08004363 }
4364
4365 /**
4366 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4367 * Used for device configuration by some CDMA operators.
4368 *
4369 * @param preferredRoamingList byte array containing the new PRL
4370 * @return true on success; false on any failure
4371 */
4372 @Override
4373 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4375 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376
4377 final long identity = Binder.clearCallingIdentity();
4378 try {
4379 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4380 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4381 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4382 return success;
4383 } finally {
4384 Binder.restoreCallingIdentity(identity);
4385 }
Jake Hambye994d462014-02-03 13:10:13 -08004386 }
4387
4388 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004389 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004390 * Used for device configuration by some CDMA operators.
4391 *
chen xu6dac5ab2018-10-26 17:39:23 -07004392 * @param slotIndex - device slot.
4393 *
Jake Hambye994d462014-02-03 13:10:13 -08004394 * @return true on success; false on any failure
4395 */
4396 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004397 public boolean resetModemConfig(int slotIndex) {
4398 Phone phone = PhoneFactory.getPhone(slotIndex);
4399 if (phone != null) {
4400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4401 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402
chen xu6dac5ab2018-10-26 17:39:23 -07004403 final long identity = Binder.clearCallingIdentity();
4404 try {
4405 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4406 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4407 return success;
4408 } finally {
4409 Binder.restoreCallingIdentity(identity);
4410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004411 }
chen xu6dac5ab2018-10-26 17:39:23 -07004412 return false;
4413 }
4414
4415 /**
4416 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4417 *
4418 * @param slotIndex - device slot.
4419 *
4420 * @return true on success; false on any failure
4421 */
4422 @Override
4423 public boolean rebootModem(int slotIndex) {
4424 Phone phone = PhoneFactory.getPhone(slotIndex);
4425 if (phone != null) {
4426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4427 mApp, phone.getSubId(), "rebootModem");
4428
4429 final long identity = Binder.clearCallingIdentity();
4430 try {
4431 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4432 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4433 return success;
4434 } finally {
4435 Binder.restoreCallingIdentity(identity);
4436 }
4437 }
4438 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004439 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004440
Svet Ganovb320e182015-04-16 12:30:10 -07004441 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004442 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004444 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004445 return new String[0];
4446 }
4447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448 final long identity = Binder.clearCallingIdentity();
4449 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004450 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004451 } finally {
4452 Binder.restoreCallingIdentity(identity);
4453 }
Wink Saville36469e72014-06-11 15:17:00 -07004454 }
4455
Brad Ebinger51f743a2017-01-23 13:50:20 -08004456 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004457 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4458 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004459 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004460 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004461 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004462
4463 final long identity = Binder.clearCallingIdentity();
4464 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004465 ImsResolver resolver = PhoneFactory.getImsResolver();
4466 if (resolver == null) {
4467 // may happen if the device does not support IMS.
4468 return;
4469 }
4470 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004474 }
4475
4476 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004477 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4478 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004479 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004480 public void disableIms(int slotId) {
4481 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482
4483 final long identity = Binder.clearCallingIdentity();
4484 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004485 ImsResolver resolver = PhoneFactory.getImsResolver();
4486 if (resolver == null) {
4487 // may happen if the device does not support IMS.
4488 return;
4489 }
4490 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004494 }
4495
4496 /**
4497 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4498 * feature or {@link null} if the service is not available. If the feature is available, the
4499 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4500 */
4501 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004502 IImsServiceFeatureCallback callback) {
4503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004504
4505 final long identity = Binder.clearCallingIdentity();
4506 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004507 ImsResolver resolver = PhoneFactory.getImsResolver();
4508 if (resolver == null) {
4509 // may happen if the device does not support IMS.
4510 return null;
4511 }
4512 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004516 }
4517
4518 /**
4519 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4520 * feature during emergency calling or {@link null} if the service is not available. If the
4521 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4522 * listener for feature updates.
4523 */
4524 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526
4527 final long identity = Binder.clearCallingIdentity();
4528 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004529 ImsResolver resolver = PhoneFactory.getImsResolver();
4530 if (resolver == null) {
4531 // may happen if the device does not support IMS.
4532 return null;
4533 }
4534 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004538 }
4539
Brad Ebinger5f64b052017-12-14 14:26:15 -08004540 /**
4541 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004542 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004543 */
4544 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4545 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004546
4547 final long identity = Binder.clearCallingIdentity();
4548 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004549 ImsResolver resolver = PhoneFactory.getImsResolver();
4550 if (resolver == null) {
4551 // may happen if the device does not support IMS.
4552 return null;
4553 }
4554 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004555 } finally {
4556 Binder.restoreCallingIdentity(identity);
4557 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004558 }
4559
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004560 /**
4561 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004562 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004563 */
4564 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4565 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566
4567 final long identity = Binder.clearCallingIdentity();
4568 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004569 ImsResolver resolver = PhoneFactory.getImsResolver();
4570 if (resolver == null) {
4571 // may happen if the device does not support IMS.
4572 return null;
4573 }
4574 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004578 }
4579
Brad Ebinger884c07b2018-02-15 16:17:40 -08004580 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004581 * Sets the ImsService Package Name that Telephony will bind to.
4582 *
4583 * @param slotId the slot ID that the ImsService should bind for.
4584 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4585 * ImsService is the device default ImsService.
4586 * @param packageName The package name of the application that contains the ImsService to bind
4587 * to.
4588 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4589 * @hide
4590 */
4591 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004592 int[] subIds = SubscriptionManager.getSubId(slotId);
4593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4594 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4595 "setImsService");
4596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 final long identity = Binder.clearCallingIdentity();
4598 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004599 ImsResolver resolver = PhoneFactory.getImsResolver();
4600 if (resolver == null) {
4601 // may happen if the device does not support IMS.
4602 return false;
4603 }
4604 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4605 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606 } finally {
4607 Binder.restoreCallingIdentity(identity);
4608 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004609 }
4610
4611 /**
4612 * Return the ImsService configuration.
4613 *
4614 * @param slotId The slot that the ImsService is associated with.
4615 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4616 * the device default.
4617 * @return the package name of the ImsService configuration.
4618 */
4619 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004620 int[] subIds = SubscriptionManager.getSubId(slotId);
4621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4622 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4623 "getImsService");
4624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 final long identity = Binder.clearCallingIdentity();
4626 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004627 ImsResolver resolver = PhoneFactory.getImsResolver();
4628 if (resolver == null) {
4629 // may happen if the device does not support IMS.
4630 return "";
4631 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004632 // TODO: change API to query RCS separately.
4633 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4634 ImsFeature.FEATURE_MMTEL);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004638 }
4639
Brad Ebinger77b832e2019-10-17 17:03:22 -07004640 /**
4641 * Get the MmTelFeature state associated with the requested subscription id.
4642 * @param subId The subscription that the MmTelFeature is associated with.
4643 * @param callback A callback with an integer containing the
4644 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4645 */
4646 @Override
4647 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4648 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4649 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4650 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4651 "IMS not available on device.");
4652 }
4653 final long token = Binder.clearCallingIdentity();
4654 try {
4655 int slotId = getSlotIndex(subId);
4656 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4657 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4658 + subId + "'");
4659 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4660 }
4661 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4662 try {
4663 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4664 } catch (RemoteException e) {
4665 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4666 + "Ignore");
4667 }
4668 });
4669 } finally {
4670 Binder.restoreCallingIdentity(token);
4671 }
4672 }
4673
Wink Saville36469e72014-06-11 15:17:00 -07004674 public void setImsRegistrationState(boolean registered) {
4675 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004676
4677 final long identity = Binder.clearCallingIdentity();
4678 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004679 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
Wink Saville36469e72014-06-11 15:17:00 -07004683 }
4684
4685 /**
Stuart Scott54788802015-03-30 13:18:01 -07004686 * Set the network selection mode to automatic.
4687 *
4688 */
4689 @Override
4690 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4692 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693
Pengquan Menge92a50d2018-09-21 15:54:48 -07004694 if (!isActiveSubscription(subId)) {
4695 return;
4696 }
4697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 final long identity = Binder.clearCallingIdentity();
4699 try {
4700 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4701 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4702 } finally {
4703 Binder.restoreCallingIdentity(identity);
4704 }
Stuart Scott54788802015-03-30 13:18:01 -07004705 }
4706
Pengquan Mengea84e042018-09-20 14:57:26 -07004707 /**
4708 * Ask the radio to connect to the input network and change selection mode to manual.
4709 *
4710 * @param subId the id of the subscription.
4711 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4712 * the operator to attach to.
4713 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4714 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4715 * normal network selection next time.
4716 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004717 */
4718 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004719 public boolean setNetworkSelectionModeManual(
4720 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4722 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004723
4724 if (!isActiveSubscription(subId)) {
4725 return false;
4726 }
4727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728 final long identity = Binder.clearCallingIdentity();
4729 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004730 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004732 if (DBG) {
4733 log("setNetworkSelectionModeManual: subId: " + subId
4734 + " operator: " + operatorInfo);
4735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4737 } finally {
4738 Binder.restoreCallingIdentity(identity);
4739 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004740 }
4741
4742 /**
4743 * Scans for available networks.
4744 */
4745 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004746 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4748 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004749 LocationAccessPolicy.LocationPermissionResult locationResult =
4750 LocationAccessPolicy.checkLocationPermission(mApp,
4751 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4752 .setCallingPackage(callingPackage)
4753 .setCallingPid(Binder.getCallingPid())
4754 .setCallingUid(Binder.getCallingUid())
4755 .setMethod("getCellNetworkScanResults")
4756 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4757 .build());
4758 switch (locationResult) {
4759 case DENIED_HARD:
4760 throw new SecurityException("Not allowed to access scan results -- location");
4761 case DENIED_SOFT:
4762 return null;
4763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764
Pengquan Menga1bb6272018-09-06 09:59:22 -07004765 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 try {
4767 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004768 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004770 } finally {
4771 Binder.restoreCallingIdentity(identity);
4772 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004773 }
4774
4775 /**
yinxub1bed742017-04-17 11:45:04 -07004776 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004777 *
yinxub1bed742017-04-17 11:45:04 -07004778 * @param subId id of the subscription
4779 * @param request contains the radio access networks with bands/channels to scan
4780 * @param messenger callback messenger for scan results or errors
4781 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004782 * @return the id of the requested scan which can be used to stop the scan.
4783 */
4784 @Override
4785 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004786 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4788 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004789 LocationAccessPolicy.LocationPermissionResult locationResult =
4790 LocationAccessPolicy.checkLocationPermission(mApp,
4791 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4792 .setCallingPackage(callingPackage)
4793 .setCallingPid(Binder.getCallingPid())
4794 .setCallingUid(Binder.getCallingUid())
4795 .setMethod("requestNetworkScan")
4796 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4797 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004798 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004799 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004800 if (e != null) {
4801 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4802 throw e;
4803 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004804 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004805 return TelephonyScanManager.INVALID_SCAN_ID;
4806 }
4807 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004808 }
Hall Liu912dfd32019-04-25 14:02:26 -07004809 int callingUid = Binder.getCallingUid();
4810 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004811 final long identity = Binder.clearCallingIdentity();
4812 try {
4813 return mNetworkScanRequestTracker.startNetworkScan(
4814 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004815 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004816 } finally {
4817 Binder.restoreCallingIdentity(identity);
4818 }
yinxu504e1392017-04-12 16:03:22 -07004819 }
4820
Hall Liub2ac8ef2019-02-28 15:56:23 -08004821 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004822 NetworkScanRequest request, int subId) {
4823 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4824 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4825 boolean hasNetworkScanPermission =
4826 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4827 == PERMISSION_GRANTED;
4828
4829 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4830 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4831 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004832 }
4833
4834 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4835 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004836 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4837 return new SecurityException("Specific channels must not be"
4838 + " scanned without location access.");
4839 }
4840 }
4841 }
4842
Hall Liub2ac8ef2019-02-28 15:56:23 -08004843 return null;
4844 }
4845
yinxu504e1392017-04-12 16:03:22 -07004846 /**
4847 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004848 *
4849 * @param subId id of the subscription
4850 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004851 */
4852 @Override
4853 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4855 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856
Hall Liu912dfd32019-04-25 14:02:26 -07004857 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858 final long identity = Binder.clearCallingIdentity();
4859 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004860 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
yinxu504e1392017-04-12 16:03:22 -07004864 }
4865
4866 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004867 * Get the calculated preferred network type.
4868 * Used for debugging incorrect network type.
4869 *
4870 * @return the preferred network type, defined in RILConstants.java.
4871 */
4872 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004873 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004874 final Phone defaultPhone = getDefaultPhone();
4875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4876 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004877 return RILConstants.PREFERRED_NETWORK_MODE;
4878 }
4879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 final long identity = Binder.clearCallingIdentity();
4881 try {
4882 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004883 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 } finally {
4885 Binder.restoreCallingIdentity(identity);
4886 }
Junda Liu84d15a22014-07-02 11:21:04 -07004887 }
4888
4889 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004890 * Get the preferred network type.
4891 * Used for device configuration by some CDMA operators.
4892 *
4893 * @return the preferred network type, defined in RILConstants.java.
4894 */
4895 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004896 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004897 TelephonyPermissions
4898 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4899 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900
4901 final long identity = Binder.clearCallingIdentity();
4902 try {
4903 if (DBG) log("getPreferredNetworkType");
4904 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4905 int networkType = (result != null ? result[0] : -1);
4906 if (DBG) log("getPreferredNetworkType: " + networkType);
4907 return networkType;
4908 } finally {
4909 Binder.restoreCallingIdentity(identity);
4910 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004911 }
4912
4913 /**
4914 * Set the preferred network type.
4915 * Used for device configuration by some CDMA operators.
4916 *
4917 * @param networkType the preferred network type, defined in RILConstants.java.
4918 * @return true on success; false on any failure.
4919 */
4920 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004921 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4923 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924
4925 final long identity = Binder.clearCallingIdentity();
4926 try {
4927 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4928 Boolean success = (Boolean) sendRequest(
4929 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4930 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4931 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004932 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4934 }
4935 return success;
4936 } finally {
4937 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004938 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004939 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004940
4941 /**
Miaoa84611c2019-03-15 09:21:10 +08004942 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004943 *
Miaoa84611c2019-03-15 09:21:10 +08004944 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004945 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004946 * @hide
4947 */
4948 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004949 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004950 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004952 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 try {
Miaoa84611c2019-03-15 09:21:10 +08004954 if (phone != null) {
4955 return phone.hasMatchedTetherApnSetting();
4956 } else {
4957 return false;
4958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 } finally {
4960 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004961 }
Junda Liu475951f2014-11-07 16:45:03 -08004962 }
4963
4964 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004965 * Set mobile data enabled
4966 * Used by the user through settings etc to turn on/off mobile data
4967 *
4968 * @param enable {@code true} turn turn data on, else {@code false}
4969 */
4970 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004971 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4973 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974
4975 final long identity = Binder.clearCallingIdentity();
4976 try {
4977 int phoneId = mSubscriptionController.getPhoneId(subId);
4978 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4979 Phone phone = PhoneFactory.getPhone(phoneId);
4980 if (phone != null) {
4981 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004982 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004984 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 }
4986 } finally {
4987 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004988 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004989 }
4990
4991 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004992 * Get the user enabled state of Mobile Data.
4993 *
4994 * TODO: remove and use isUserDataEnabled.
4995 * This can't be removed now because some vendor codes
4996 * calls through ITelephony directly while they should
4997 * use TelephonyManager.
4998 *
4999 * @return true on enabled
5000 */
5001 @Override
5002 public boolean getDataEnabled(int subId) {
5003 return isUserDataEnabled(subId);
5004 }
5005
5006 /**
5007 * Get whether mobile data is enabled per user setting.
5008 *
5009 * There are other factors deciding whether mobile data is actually enabled, but they are
5010 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005011 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005012 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005013 *
5014 * @return {@code true} if data is enabled else {@code false}
5015 */
5016 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005017 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005018 try {
5019 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5020 null);
5021 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5023 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005024 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025
5026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 int phoneId = mSubscriptionController.getPhoneId(subId);
5029 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5030 Phone phone = PhoneFactory.getPhone(phoneId);
5031 if (phone != null) {
5032 boolean retVal = phone.isUserDataEnabled();
5033 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5034 return retVal;
5035 } else {
5036 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5037 return false;
5038 }
5039 } finally {
5040 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005041 }
5042 }
5043
5044 /**
5045 * Get whether mobile data is enabled.
5046 *
5047 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5048 * whether mobile data is actually enabled.
5049 *
5050 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5051 *
5052 * @return {@code true} if data is enabled else {@code false}
5053 */
5054 @Override
5055 public boolean isDataEnabled(int subId) {
5056 try {
5057 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5058 null);
5059 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5061 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063
5064 final long identity = Binder.clearCallingIdentity();
5065 try {
5066 int phoneId = mSubscriptionController.getPhoneId(subId);
5067 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5068 Phone phone = PhoneFactory.getPhone(phoneId);
5069 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005070 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5072 return retVal;
5073 } else {
5074 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5075 return false;
5076 }
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005079 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005080 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005081
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005082 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5083 Phone phone) {
5084 //load access rules from carrier configs, and check those as well: b/139133814
5085 SubscriptionController subController = SubscriptionController.getInstance();
5086 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5087 || subController == null) return privilegeFromSim;
5088
5089 int uid = Binder.getCallingUid();
5090 PackageManager pkgMgr = phone.getContext().getPackageManager();
5091 String[] packages = pkgMgr.getPackagesForUid(uid);
5092
5093 final long identity = Binder.clearCallingIdentity();
5094 try {
5095 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5096 SubscriptionManager subManager = (SubscriptionManager)
5097 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5098 for (String pkg : packages) {
5099 if (subManager.canManageSubscription(subInfo, pkg)) {
5100 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5101 }
5102 }
5103 return privilegeFromSim;
5104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
5107 }
5108
5109 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5110 String pkgName) {
5111 //load access rules from carrier configs, and check those as well: b/139133814
5112 SubscriptionController subController = SubscriptionController.getInstance();
5113 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5114 || subController == null) return privilegeFromSim;
5115
5116 final long identity = Binder.clearCallingIdentity();
5117 try {
5118 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5119 SubscriptionManager subManager = (SubscriptionManager)
5120 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5121 return subManager.canManageSubscription(subInfo, pkgName)
5122 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
5125 }
5126 }
5127
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005128 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005129 public int getCarrierPrivilegeStatus(int subId) {
5130 final Phone phone = getPhone(subId);
5131 if (phone == null) {
5132 loge("getCarrierPrivilegeStatus: Invalid subId");
5133 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5134 }
5135 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005136 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005137 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005138 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5139 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005140
5141 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5142 card.getCarrierPrivilegeStatusForCurrentTransaction(
5143 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005144 }
Junda Liu29340342014-07-10 15:23:27 -07005145
5146 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005147 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5148 final Phone phone = getPhone(subId);
5149 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005150 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005151 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5152 }
5153 UiccProfile profile =
5154 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5155 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005156 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005157 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5158 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005159 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5160 profile.getCarrierPrivilegeStatusForUid(
5161 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005162 }
5163
5164 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005165 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5166 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005167 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005168 }
5169
5170 int phoneId = SubscriptionManager.getPhoneId(subId);
5171 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005172 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005173 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005174 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5175 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005176 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5177 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5178 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005179 }
5180
5181 @Override
5182 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005183 if (TextUtils.isEmpty(pkgName))
5184 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005185 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5186 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5187 UiccCard card = UiccController.getInstance().getUiccCard(i);
5188 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005189 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005190 continue;
5191 }
5192
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005193 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5194 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5195 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005196 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5197 break;
5198 }
5199 }
5200
5201 return result;
Junda Liu29340342014-07-10 15:23:27 -07005202 }
Derek Tan89e89d42014-07-08 17:00:10 -07005203
5204 @Override
Junda Liue64de782015-04-16 17:19:16 -07005205 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5206 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5207 loge("phoneId " + phoneId + " is not valid.");
5208 return null;
5209 }
5210 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005211 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005212 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005213 return null ;
5214 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005215 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005216 }
5217
Amith Yamasani6e118872016-02-19 12:53:51 -08005218 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005219 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005220 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005221 List<String> privilegedPackages = new ArrayList<>();
5222 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005223 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5224 // has UICC in that slot.
5225 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005226 if (card.hasCarrierPrivilegeRules()) {
5227 if (packages == null) {
5228 // Only check packages in user 0 for now
5229 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005230 PackageManager.MATCH_DISABLED_COMPONENTS
5231 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005232 | PackageManager.GET_SIGNING_CERTIFICATES,
5233 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005234 }
5235 for (int p = packages.size() - 1; p >= 0; p--) {
5236 PackageInfo pkgInfo = packages.get(p);
5237 if (pkgInfo != null && pkgInfo.packageName != null
5238 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005239 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005240 privilegedPackages.add(pkgInfo.packageName);
5241 }
5242 }
5243 }
5244 }
5245 return privilegedPackages;
5246 }
5247
chen xuf7e9fe82019-05-09 19:31:02 -07005248 @Override
5249 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005250 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5251
5252 final long identity = Binder.clearCallingIdentity();
5253
chen xuf7e9fe82019-05-09 19:31:02 -07005254 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005255 try {
5256 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5257 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5258 }
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005261 }
5262 return privilegedPackages;
5263 }
5264
Wink Savilleb564aae2014-10-23 10:18:09 -07005265 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005266 final Phone phone = getPhone(subId);
5267 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005268 if (card == null) {
5269 loge("getIccId: No UICC");
5270 return null;
5271 }
5272 String iccId = card.getIccId();
5273 if (TextUtils.isEmpty(iccId)) {
5274 loge("getIccId: ICC ID is null or empty.");
5275 return null;
5276 }
5277 return iccId;
5278 }
5279
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005280 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005281 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5282 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005283 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5284 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 final long identity = Binder.clearCallingIdentity();
5287 try {
5288 final String iccId = getIccId(subId);
5289 final Phone phone = getPhone(subId);
5290 if (phone == null) {
5291 return false;
5292 }
5293 final String subscriberId = phone.getSubscriberId();
5294
5295 if (DBG_MERGE) {
5296 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5297 + subscriberId + " to " + number);
5298 }
5299
5300 if (TextUtils.isEmpty(iccId)) {
5301 return false;
5302 }
5303
5304 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5305
5306 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5307 if (alphaTag == null) {
5308 editor.remove(alphaTagPrefKey);
5309 } else {
5310 editor.putString(alphaTagPrefKey, alphaTag);
5311 }
5312
5313 // Record both the line number and IMSI for this ICCID, since we need to
5314 // track all merged IMSIs based on line number
5315 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5316 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5317 if (number == null) {
5318 editor.remove(numberPrefKey);
5319 editor.remove(subscriberPrefKey);
5320 } else {
5321 editor.putString(numberPrefKey, number);
5322 editor.putString(subscriberPrefKey, subscriberId);
5323 }
5324
5325 editor.commit();
5326 return true;
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005329 }
Derek Tan7226c842014-07-02 17:42:23 -07005330 }
5331
5332 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005333 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005334 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005336 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005337 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005338 return null;
5339 }
Derek Tan97ebb422014-09-05 16:55:38 -07005340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 final long identity = Binder.clearCallingIdentity();
5342 try {
5343 String iccId = getIccId(subId);
5344 if (iccId != null) {
5345 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5346 if (DBG_MERGE) {
5347 log("getLine1NumberForDisplay returning "
5348 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5349 }
5350 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5353 return null;
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005356 }
Derek Tan7226c842014-07-02 17:42:23 -07005357 }
5358
5359 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005360 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005362 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005363 return null;
5364 }
Derek Tan97ebb422014-09-05 16:55:38 -07005365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 final long identity = Binder.clearCallingIdentity();
5367 try {
5368 String iccId = getIccId(subId);
5369 if (iccId != null) {
5370 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5371 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5372 }
5373 return null;
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005376 }
Derek Tan7226c842014-07-02 17:42:23 -07005377 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005378
5379 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005380 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005381 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5382 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005384 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5385 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005386 return null;
5387 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005388
Jordan Liub49b04b2019-05-06 14:45:15 -07005389 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5390 // the process, where TelephonyManager was instantiated.
5391 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005392 final long identity = Binder.clearCallingIdentity();
5393 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005394 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 final TelephonyManager tele = TelephonyManager.from(context);
5396 final SubscriptionManager sub = SubscriptionManager.from(context);
5397
5398 // Figure out what subscribers are currently active
5399 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400
Jordan Liub49b04b2019-05-06 14:45:15 -07005401 // Only consider subs which match the current subId
5402 // This logic can be simplified. See b/131189269 for progress.
5403 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005404 activeSubscriberIds.add(tele.getSubscriberId(subId));
5405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406
5407 // First pass, find a number override for an active subscriber
5408 String mergeNumber = null;
5409 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5410 for (String key : prefs.keySet()) {
5411 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5412 final String subscriberId = (String) prefs.get(key);
5413 if (activeSubscriberIds.contains(subscriberId)) {
5414 final String iccId = key.substring(
5415 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5416 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5417 mergeNumber = (String) prefs.get(numberKey);
5418 if (DBG_MERGE) {
5419 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5420 + " for active subscriber " + subscriberId);
5421 }
5422 if (!TextUtils.isEmpty(mergeNumber)) {
5423 break;
5424 }
5425 }
5426 }
5427 }
5428
5429 // Shortcut when no active merged subscribers
5430 if (TextUtils.isEmpty(mergeNumber)) {
5431 return null;
5432 }
5433
5434 // Second pass, find all subscribers under that line override
5435 final ArraySet<String> result = new ArraySet<>();
5436 for (String key : prefs.keySet()) {
5437 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5438 final String number = (String) prefs.get(key);
5439 if (mergeNumber.equals(number)) {
5440 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5441 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5442 final String subscriberId = (String) prefs.get(subscriberKey);
5443 if (!TextUtils.isEmpty(subscriberId)) {
5444 result.add(subscriberId);
5445 }
5446 }
5447 }
5448 }
5449
5450 final String[] resultArray = result.toArray(new String[result.size()]);
5451 Arrays.sort(resultArray);
5452 if (DBG_MERGE) {
5453 Slog.d(LOG_TAG,
5454 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5455 }
5456 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005459 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005460 }
5461
5462 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005463 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5464 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5465
5466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 final TelephonyManager telephonyManager = mApp.getSystemService(
5469 TelephonyManager.class);
5470 String subscriberId = telephonyManager.getSubscriberId(subId);
5471 if (subscriberId == null) {
5472 if (DBG) {
5473 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5474 + subId);
5475 }
5476 return null;
5477 }
5478
5479 final SubscriptionInfo info = SubscriptionController.getInstance()
5480 .getSubscriptionInfo(subId);
5481 final ParcelUuid groupUuid = info.getGroupUuid();
5482 // If it doesn't belong to any group, return just subscriberId of itself.
5483 if (groupUuid == null) {
5484 return new String[]{subscriberId};
5485 }
5486
5487 // Get all subscriberIds from the group.
5488 final List<String> mergedSubscriberIds = new ArrayList<>();
5489 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5490 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5491 for (SubscriptionInfo subInfo : groupInfos) {
5492 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5493 if (subscriberId != null) {
5494 mergedSubscriberIds.add(subscriberId);
5495 }
5496 }
5497
5498 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501
5502 }
5503 }
5504
5505 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005506 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005507 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5508 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509
5510 final long identity = Binder.clearCallingIdentity();
5511 try {
5512 final Phone phone = getPhone(subId);
5513 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005517 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005518
5519 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005520 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005521 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5522 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005523 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524
5525 final long identity = Binder.clearCallingIdentity();
5526 try {
5527 final Phone phone = getPhone(subId);
5528 if (phone == null) {
5529 return false;
5530 }
5531 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5532 cdmaNonRoamingList);
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005535 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005536 }
5537
5538 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005539 @Deprecated
5540 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5541 enforceModifyPermission();
5542
5543 int returnValue = 0;
5544 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005545 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005546 if(result.exception == null) {
5547 if (result.result != null) {
5548 byte[] responseData = (byte[])(result.result);
5549 if(responseData.length > oemResp.length) {
5550 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5551 responseData.length + "bytes. Buffer Size is " +
5552 oemResp.length + "bytes.");
5553 }
5554 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5555 returnValue = responseData.length;
5556 }
5557 } else {
5558 CommandException ex = (CommandException) result.exception;
5559 returnValue = ex.getCommandError().ordinal();
5560 if(returnValue > 0) returnValue *= -1;
5561 }
5562 } catch (RuntimeException e) {
5563 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5564 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5565 if(returnValue > 0) returnValue *= -1;
5566 }
5567
5568 return returnValue;
5569 }
5570
5571 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005572 public void setRadioCapability(RadioAccessFamily[] rafs) {
5573 try {
5574 ProxyController.getInstance().setRadioCapability(rafs);
5575 } catch (RuntimeException e) {
5576 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5577 }
5578 }
5579
5580 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005581 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005582 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005583 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005584 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005585 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 final long identity = Binder.clearCallingIdentity();
5588 try {
chen xub97461a2018-10-26 14:17:57 -07005589 TelephonyPermissions
5590 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5591 mApp, phone.getSubId(), "getRadioAccessFamily");
5592 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
chen xub97461a2018-10-26 14:17:57 -07005596 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005597 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005598
5599 @Override
5600 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005601 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005602 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603
5604 final long identity = Binder.clearCallingIdentity();
5605 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005606 ImsManager.getInstance(defaultPhone.getContext(),
5607 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005611 }
5612
5613 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005614 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005615 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005617 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005618 return false;
5619 }
Svet Ganovb320e182015-04-16 12:30:10 -07005620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 final long identity = Binder.clearCallingIdentity();
5622 try {
5623 // Check the user preference and the system-level IMS setting. Even if the user has
5624 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5625 // In the long run, we may instead need to check if there exists a connection service
5626 // which can support video calling.
5627 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005628 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 return imsManager.isVtEnabledByPlatform()
5630 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5631 && imsManager.isVtEnabledByUser();
5632 } finally {
5633 Binder.restoreCallingIdentity(identity);
5634 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005635 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005636
Andrew Leea1239f22015-03-02 17:44:07 -08005637 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5639 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5640 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5641 return false;
5642 }
5643
5644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 CarrierConfigManager configManager =
5647 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005648 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5650 } finally {
5651 Binder.restoreCallingIdentity(identity);
5652 }
Andrew Leea1239f22015-03-02 17:44:07 -08005653 }
5654
5655 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 public boolean isWorldPhone(int subId, String callingPackage) {
5657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5658 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5659 return false;
5660 }
5661
5662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 CarrierConfigManager configManager =
5665 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005666 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
Andrew Leea1239f22015-03-02 17:44:07 -08005671 }
5672
Andrew Lee9431b832015-03-09 18:46:45 -07005673 @Override
5674 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005675 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005676 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005677 }
5678
5679 @Override
5680 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 final long identity = Binder.clearCallingIdentity();
5682 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005683 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
Andrew Lee9431b832015-03-09 18:46:45 -07005687 }
5688
Hall Liuf6668912018-10-31 17:05:23 -07005689 /**
5690 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5691 * support for the feature and device firmware support.
5692 *
5693 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5694 */
5695 @Override
5696 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005698 final Phone phone = getPhone(subscriptionId);
5699 if (phone == null) {
5700 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5701 return false;
5702 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005704 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5706 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005707 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 return isCarrierSupported && isDeviceSupported;
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Hall Liu98187582018-01-22 19:15:32 -08005712 }
5713
Hall Liuf6668912018-10-31 17:05:23 -07005714 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005715 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5716 * RTT setting, will return true if the device and carrier both support RTT.
5717 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005718 */
5719 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 final long identity = Binder.clearCallingIdentity();
5721 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005722 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005726 }
5727
Sanket Padawe7310cc72015-01-14 09:53:20 -08005728 /**
5729 * Returns the unique device ID of phone, for example, the IMEI for
5730 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5731 *
5732 * <p>Requires Permission:
5733 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5734 */
5735 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005736 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005737 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005738 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005739 return null;
5740 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005741 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005742 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5743 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005744 return null;
5745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746
5747 final long identity = Binder.clearCallingIdentity();
5748 try {
5749 return phone.getDeviceId();
5750 } finally {
5751 Binder.restoreCallingIdentity(identity);
5752 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005753 }
5754
Ping Sunc67b7c22016-03-02 19:16:45 +08005755 /**
5756 * {@hide}
5757 * Returns the IMS Registration Status on a particular subid
5758 *
5759 * @param subId
5760 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005761 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005762 Phone phone = getPhone(subId);
5763 if (phone != null) {
5764 return phone.isImsRegistered();
5765 } else {
5766 return false;
5767 }
5768 }
5769
Santos Cordon7a1885b2015-02-03 11:15:19 -08005770 @Override
5771 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005778 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005779
Tyler Gunnf70ed162019-04-03 15:28:53 -07005780 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005781 public int getSubIdForPhoneAccountHandle(
5782 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5784 callingPackage, "getSubIdForPhoneAccountHandle")) {
5785 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5786 }
5787 final long identity = Binder.clearCallingIdentity();
5788 try {
5789 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
5792 }
5793 }
5794
5795 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005796 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 Phone phone = getPhone(subscriptionId);
5800 if (phone == null) {
5801 return null;
5802 }
5803 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5804 } finally {
5805 Binder.restoreCallingIdentity(identity);
5806 }
5807 }
5808
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005809 /**
5810 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005811 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005812 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 final long identity = Binder.clearCallingIdentity();
5814 try {
5815 Phone phone = getPhone(subId);
5816 if (phone != null) {
5817 return phone.isWifiCallingEnabled();
5818 } else {
5819 return false;
5820 }
5821 } finally {
5822 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005823 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005824 }
5825
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005826 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005827 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005828 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005829 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 final long identity = Binder.clearCallingIdentity();
5831 try {
5832 Phone phone = getPhone(subId);
5833 if (phone != null) {
5834 return phone.isVideoEnabled();
5835 } else {
5836 return false;
5837 }
5838 } finally {
5839 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005840 }
5841 }
5842
5843 /**
5844 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5845 * defined in {@link ImsRegistrationImplBase}.
5846 */
5847 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 final long identity = Binder.clearCallingIdentity();
5849 try {
5850 Phone phone = getPhone(subId);
5851 if (phone != null) {
5852 return phone.getImsRegistrationTech();
5853 } else {
5854 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5855 }
5856 } finally {
5857 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005858 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005859 }
5860
Stuart Scott8eef64f2015-04-08 15:13:54 -07005861 @Override
5862 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005863 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005864 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5865 return;
5866 }
5867
Svet Ganovcc087f82015-05-12 20:35:54 -07005868 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005869
Svet Ganovcc087f82015-05-12 20:35:54 -07005870 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005871 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5872 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005873 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005874 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005875 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005876 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5877 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005878 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005879 // There has been issues when Sms raw table somehow stores orphan
5880 // fragments. They lead to garbled message when new fragments come
5881 // in and combined with those stale ones. In case this happens again,
5882 // user can reset all network settings which will clean up this table.
5883 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005884 // Clean up IMS settings as well here.
5885 int slotId = getSlotIndex(subId);
5886 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5887 ImsManager.getInstance(mApp, slotId).factoryReset();
5888 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005889
5890 // Erase modem config if erase modem on network setting is enabled.
5891 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5892 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5893 if (configValue != null && Boolean.parseBoolean(configValue)) {
5894 sendEraseModemConfig(getDefaultPhone());
5895 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005896 } finally {
5897 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005898 }
5899 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005900
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005901 private void cleanUpSmsRawTable(Context context) {
5902 ContentResolver resolver = context.getContentResolver();
5903 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5904 resolver.delete(uri, null, null);
5905 }
5906
Narayan Kamath1c496c22015-04-16 14:40:19 +01005907 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005908 public String getSimLocaleForSubscriber(int subId) {
5909 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5910 final Phone phone = getPhone(subId);
5911 if (phone == null) {
5912 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005913 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 final long identity = Binder.clearCallingIdentity();
5916 try {
chen xu5d3637b2019-01-21 23:31:38 -08005917 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5918 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005919 if (info == null) {
5920 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5921 return null;
5922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923 // Try and fetch the locale from the carrier properties or from the SIM language
5924 // preferences (EF-PL and EF-LI)...
5925 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005927 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5928 if (localeFromDefaultSim != null) {
5929 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5930 if (DBG) log("Using locale from subId: " + subId + " locale: "
5931 + localeFromDefaultSim);
5932 return localeFromDefaultSim.toLanguageTag();
5933 } else {
5934 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 }
5936 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938 // The SIM language preferences only store a language (e.g. fr = French), not an
5939 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5940 // the SIM and carrier preferences does not include a country we add the country
5941 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08005942 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005944 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 return mccLocale.toLanguageTag();
5946 }
5947
5948 if (DBG) log("No locale found - returning null");
5949 return null;
5950 } finally {
5951 Binder.restoreCallingIdentity(identity);
5952 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005953 }
5954
5955 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005956 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005957 }
5958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959 /**
5960 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5961 */
5962 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005963 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005964 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005965
Chenjie Yu1ba97252018-01-11 18:16:20 -08005966 private final ModemActivityInfo mLastModemActivityInfo =
5967 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5968
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005969 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005970 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5971 * representing the state of the modem.
5972 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005973 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5974 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005975 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005976 */
5977 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005978 public void requestModemActivityInfo(ResultReceiver result) {
5979 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005980 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981
5982 final long identity = Binder.clearCallingIdentity();
5983 try {
5984 ModemActivityInfo ret = null;
5985 synchronized (mLastModemActivityInfo) {
5986 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5987 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005988 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005989 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5991 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005992 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5993 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 }
5995 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005996 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5997 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 mLastModemActivityInfo.setIdleTimeMillis(
5999 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
6000 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
6001 mLastModemActivityInfo.setRxTimeMillis(
6002 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
6003 mLastModemActivityInfo.setEnergyUsed(
6004 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6007 mLastModemActivityInfo.getSleepTimeMillis(),
6008 mLastModemActivityInfo.getIdleTimeMillis(),
6009 mLastModemActivityInfo.getTxTimeMillis(),
6010 mLastModemActivityInfo.getRxTimeMillis(),
6011 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 Bundle bundle = new Bundle();
6014 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6015 result.send(0, bundle);
6016 } finally {
6017 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006018 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006019 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006020
Siddharth Rayb8114062018-06-17 15:02:38 -07006021 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6022 // less than total activity duration.
6023 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6024 if (info == null) {
6025 return false;
6026 }
6027 int activityDurationMs =
6028 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6029 int totalTxTimeMs = 0;
6030 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
6031 totalTxTimeMs += info.getTxTimeMillis()[i];
6032 }
6033 return (info.isValid()
6034 && (info.getSleepTimeMillis() <= activityDurationMs)
6035 && (info.getIdleTimeMillis() <= activityDurationMs)
6036 && (info.getRxTimeMillis() <= activityDurationMs)
6037 && (totalTxTimeMs <= activityDurationMs));
6038 }
6039
Jack Yu85bd38a2015-11-09 11:34:32 -08006040 /**
6041 * {@hide}
6042 * Returns the service state information on specified subscription.
6043 */
6044 @Override
6045 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006047 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006048 return null;
6049 }
6050
Hall Liuf19c44f2018-11-27 14:38:17 -08006051 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6052 LocationAccessPolicy.checkLocationPermission(mApp,
6053 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6054 .setCallingPackage(callingPackage)
6055 .setCallingPid(Binder.getCallingPid())
6056 .setCallingUid(Binder.getCallingUid())
6057 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006058 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006059 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6060 .build());
6061
6062 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6063 LocationAccessPolicy.checkLocationPermission(mApp,
6064 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6065 .setCallingPackage(callingPackage)
6066 .setCallingPid(Binder.getCallingPid())
6067 .setCallingUid(Binder.getCallingUid())
6068 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006069 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006070 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6071 .build());
6072 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6073 boolean hasFinePermission =
6074 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6075 boolean hasCoarsePermission =
6076 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 final long identity = Binder.clearCallingIdentity();
6079 try {
6080 final Phone phone = getPhone(subId);
6081 if (phone == null) {
6082 return null;
6083 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006084
Hall Liuf19c44f2018-11-27 14:38:17 -08006085 ServiceState ss = phone.getServiceState();
6086
6087 // Scrub out the location info in ServiceState depending on what level of access
6088 // the caller has.
6089 if (hasFinePermission) return ss;
6090 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6091 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 } finally {
6093 Binder.restoreCallingIdentity(identity);
6094 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006095 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006096
6097 /**
6098 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6099 *
6100 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6101 * voicemail ringtone.
6102 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6103 * PhoneAccount.
6104 */
6105 @Override
6106 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6110 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006111 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006118 }
6119
6120 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006121 * Sets the per-account voicemail ringtone.
6122 *
6123 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6124 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6125 *
6126 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6127 * voicemail ringtone.
6128 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6129 * PhoneAccount.
6130 */
6131 @Override
6132 public void setVoicemailRingtoneUri(String callingPackage,
6133 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006134 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006135 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006136 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6137 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6139 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6140 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142
6143 final long identity = Binder.clearCallingIdentity();
6144 try {
6145 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6146 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006147 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 }
6149 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6150 } finally {
6151 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006152 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006153 }
6154
6155 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006156 * Returns whether vibration is set for voicemail notification in Phone settings.
6157 *
6158 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6159 * voicemail vibration setting.
6160 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6161 */
6162 @Override
6163 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 final long identity = Binder.clearCallingIdentity();
6165 try {
6166 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6167 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006168 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006175 }
6176
Youhan Wange64578a2016-05-02 15:32:42 -07006177 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006178 * Sets the per-account voicemail vibration.
6179 *
6180 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6181 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6182 *
6183 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6184 * voicemail vibration setting.
6185 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6186 * specific PhoneAccount.
6187 */
6188 @Override
6189 public void setVoicemailVibrationEnabled(String callingPackage,
6190 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006191 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006192 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006193 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6194 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6196 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6197 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006198 }
6199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006200 final long identity = Binder.clearCallingIdentity();
6201 try {
6202 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6203 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006204 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205 }
6206 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6207 } finally {
6208 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006209 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006210 }
6211
6212 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006213 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6214 *
6215 * @throws SecurityException if the caller does not have the required permission
6216 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006217 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006218 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006219 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006220 }
6221
6222 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006223 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6224 * permission.
6225 *
6226 * @throws SecurityException if the caller does not have the required permission
6227 */
6228 private void enforceSendSmsPermission() {
6229 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6230 }
6231
6232 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006233 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006234 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006235 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006236 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006237 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 final long identity = Binder.clearCallingIdentity();
6239 try {
6240 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006241 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 if (componentName == null) {
6243 throw new SecurityException(
6244 "Caller not current active visual voicemail package[null]");
6245 }
6246 String vvmPackage = componentName.getPackageName();
6247 if (!callingPackage.equals(vvmPackage)) {
6248 throw new SecurityException("Caller not current active visual voicemail package["
6249 + vvmPackage + "]");
6250 }
6251 } finally {
6252 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006253 }
6254 }
6255
6256 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006257 * Return the application ID for the app type.
6258 *
6259 * @param subId the subscription ID that this request applies to.
6260 * @param appType the uicc app type.
6261 * @return Application ID for specificied app type, or null if no uicc.
6262 */
6263 @Override
6264 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006265 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006266 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267
6268 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006269 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 if (phone == null) {
6271 return null;
6272 }
6273 String aid = null;
6274 try {
6275 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6276 .getApplicationByType(appType).getAid();
6277 } catch (Exception e) {
6278 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6279 }
6280 return aid;
6281 } finally {
6282 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006283 }
Youhan Wange64578a2016-05-02 15:32:42 -07006284 }
6285
Youhan Wang4001d252016-05-11 10:29:41 -07006286 /**
6287 * Return the Electronic Serial Number.
6288 *
6289 * @param subId the subscription ID that this request applies to.
6290 * @return ESN or null if error.
6291 */
6292 @Override
6293 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006294 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006295 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296
6297 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006298 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 if (phone == null) {
6300 return null;
6301 }
6302 String esn = null;
6303 try {
6304 esn = phone.getEsn();
6305 } catch (Exception e) {
6306 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6307 }
6308 return esn;
6309 } finally {
6310 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006311 }
Youhan Wang4001d252016-05-11 10:29:41 -07006312 }
6313
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006314 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006315 * Return the Preferred Roaming List Version.
6316 *
6317 * @param subId the subscription ID that this request applies to.
6318 * @return PRLVersion or null if error.
6319 */
6320 @Override
6321 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006322 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006323 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324
6325 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006326 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327 if (phone == null) {
6328 return null;
6329 }
6330 String cdmaPrlVersion = null;
6331 try {
6332 cdmaPrlVersion = phone.getCdmaPrlVersion();
6333 } catch (Exception e) {
6334 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6335 }
6336 return cdmaPrlVersion;
6337 } finally {
6338 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006339 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006340 }
6341
6342 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006343 * Get snapshot of Telephony histograms
6344 * @return List of Telephony histograms
6345 * @hide
6346 */
6347 @Override
6348 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6350 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006351
6352 final long identity = Binder.clearCallingIdentity();
6353 try {
6354 return RIL.getTelephonyRILTimingHistograms();
6355 } finally {
6356 Binder.restoreCallingIdentity(identity);
6357 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006358 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006359
6360 /**
6361 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006362 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6363 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006364 * Require system privileges. In the future we may add this to carrier APIs.
6365 *
Michele Berionne482f8202018-11-27 18:57:59 -08006366 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006367 */
6368 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006369 @TelephonyManager.SetCarrierRestrictionResult
6370 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006371 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006372 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006373
Michele Berionne482f8202018-11-27 18:57:59 -08006374 if (carrierRestrictionRules == null) {
6375 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006376 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378 final long identity = Binder.clearCallingIdentity();
6379 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006380 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006381 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006385 }
6386
6387 /**
6388 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006389 * Get the allowed carrier list and the excluded carrier list, including the priority between
6390 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006391 * Require system privileges. In the future we may add this to carrier APIs.
6392 *
Michele Berionne482f8202018-11-27 18:57:59 -08006393 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006394 */
6395 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006396 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006397 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006398 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006402 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6403 if (response instanceof CarrierRestrictionRules) {
6404 return (CarrierRestrictionRules) response;
6405 }
6406 // Response is an Exception of some kind,
6407 // which is signalled to the user as a NULL retval
6408 return null;
6409 } catch (Exception e) {
6410 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6411 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006415 }
6416
fionaxu59545b42016-05-25 15:53:37 -07006417 /**
6418 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6419 * @param subId the subscription ID that this action applies to.
6420 * @param enabled control enable or disable metered apns.
6421 * {@hide}
6422 */
6423 @Override
6424 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6425 enforceModifyPermission();
6426 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427
6428 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006429 if (phone == null) {
6430 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6431 return;
6432 }
6433 try {
6434 phone.carrierActionSetMeteredApnsEnabled(enabled);
6435 } catch (Exception e) {
6436 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006439 }
6440 }
6441
6442 /**
6443 * Action set from carrier signalling broadcast receivers to enable/disable radio
6444 * @param subId the subscription ID that this action applies to.
6445 * @param enabled control enable or disable radio.
6446 * {@hide}
6447 */
6448 @Override
6449 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6450 enforceModifyPermission();
6451 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452
6453 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006454 if (phone == null) {
6455 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6456 return;
6457 }
6458 try {
6459 phone.carrierActionSetRadioEnabled(enabled);
6460 } catch (Exception e) {
6461 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462 } finally {
6463 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006464 }
6465 }
6466
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006467 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006468 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6469 * network status based on which carrier apps could apply actions accordingly,
6470 * enable/disable default url handler for example.
6471 *
6472 * @param subId the subscription ID that this action applies to.
6473 * @param report control start/stop reporting the default network status.
6474 * {@hide}
6475 */
6476 @Override
6477 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6478 enforceModifyPermission();
6479 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480
6481 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006482 if (phone == null) {
6483 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6484 return;
6485 }
6486 try {
6487 phone.carrierActionReportDefaultNetworkStatus(report);
6488 } catch (Exception e) {
6489 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 } finally {
6491 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006492 }
6493 }
6494
6495 /**
fionaxud9622282017-07-17 17:51:30 -07006496 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6497 * @param subId the subscription ID that this action applies to.
6498 * {@hide}
6499 */
6500 @Override
6501 public void carrierActionResetAll(int subId) {
6502 enforceModifyPermission();
6503 final Phone phone = getPhone(subId);
6504 if (phone == null) {
6505 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6506 return;
6507 }
6508 try {
6509 phone.carrierActionResetAll();
6510 } catch (Exception e) {
6511 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6512 }
6513 }
6514
6515 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006516 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6517 * bug report is being generated.
6518 */
6519 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006520 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006521 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6522 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006523 writer.println("Permission Denial: can't dump Phone from pid="
6524 + Binder.getCallingPid()
6525 + ", uid=" + Binder.getCallingUid()
6526 + "without permission "
6527 + android.Manifest.permission.DUMP);
6528 return;
6529 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006530 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006531 }
Jack Yueb89b242016-06-22 13:27:47 -07006532
Brad Ebingerdac2f002018-04-03 15:17:52 -07006533 @Override
6534 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6535 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6536 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006537 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6538 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006539 }
6540
Jack Yueb89b242016-06-22 13:27:47 -07006541 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006542 * Get aggregated video call data usage since boot.
6543 *
6544 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6545 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006546 * {@hide}
6547 */
6548 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006549 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006550 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6551 null);
6552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553 final long identity = Binder.clearCallingIdentity();
6554 try {
6555 // NetworkStatsService keeps tracking the active network interface and identity. It
6556 // records the delta with the corresponding network identity.
6557 // We just return the total video call data usage snapshot since boot.
6558 Phone phone = getPhone(subId);
6559 if (phone != null) {
6560 return phone.getVtDataUsage(perUidStats);
6561 }
6562 return null;
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006565 }
Jack Yueb89b242016-06-22 13:27:47 -07006566 }
Jack Yu75ab2952016-07-08 14:29:33 -07006567
6568 /**
6569 * Policy control of data connection. Usually used when data limit is passed.
6570 * @param enabled True if enabling the data, otherwise disabling.
6571 * @param subId Subscription index
6572 * {@hide}
6573 */
6574 @Override
6575 public void setPolicyDataEnabled(boolean enabled, int subId) {
6576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577
6578 final long identity = Binder.clearCallingIdentity();
6579 try {
6580 Phone phone = getPhone(subId);
6581 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006582 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 }
6584 } finally {
6585 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006586 }
6587 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006588
6589 /**
6590 * Get Client request stats
6591 * @return List of Client Request Stats
6592 * @hide
6593 */
6594 @Override
6595 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006597 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006598 return null;
6599 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006600 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 if (phone != null) {
6605 return phone.getClientRequestStats();
6606 }
6607
6608 return null;
6609 } finally {
6610 Binder.restoreCallingIdentity(identity);
6611 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006612 }
6613
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006614 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006615 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006616 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006617 }
Jack Yueb4124c2017-02-16 15:32:43 -08006618
6619 /**
Grace Chen70990072017-03-24 17:21:30 -07006620 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006621 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006622 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006623 * @param state State of SIM (power down, power up, pass through)
6624 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6625 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6626 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006627 *
6628 **/
6629 @Override
Grace Chen70990072017-03-24 17:21:30 -07006630 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006631 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006632 Phone phone = PhoneFactory.getPhone(slotIndex);
6633
vagdeviaf9a5b92018-08-15 16:01:53 -07006634 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636 final long identity = Binder.clearCallingIdentity();
6637 try {
6638 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006639 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006640 }
6641 } finally {
6642 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006643 }
6644 }
Shuo Qiandd210312017-04-12 22:11:33 +00006645
Tyler Gunn65d45c22017-06-05 11:22:26 -07006646 private boolean isUssdApiAllowed(int subId) {
6647 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006648 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006649 if (configManager == null) {
6650 return false;
6651 }
6652 PersistableBundle pb = configManager.getConfigForSubId(subId);
6653 if (pb == null) {
6654 return false;
6655 }
6656 return pb.getBoolean(
6657 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6658 }
6659
Shuo Qiandd210312017-04-12 22:11:33 +00006660 /**
6661 * Check if phone is in emergency callback mode
6662 * @return true if phone is in emergency callback mode
6663 * @param subId sub id
6664 */
goneil9c5f4872017-12-05 14:07:56 -08006665 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006666 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006667 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006668 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669
6670 final long identity = Binder.clearCallingIdentity();
6671 try {
6672 if (phone != null) {
6673 return phone.isInEcm();
6674 } else {
6675 return false;
6676 }
6677 } finally {
6678 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006679 }
6680 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006681
6682 /**
6683 * Get the current signal strength information for the given subscription.
6684 * Because this information is not updated when the device is in a low power state
6685 * it should not be relied-upon to be current.
6686 * @param subId Subscription index
6687 * @return the most recent cached signal strength info from the modem
6688 */
6689 @Override
6690 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006691 final long identity = Binder.clearCallingIdentity();
6692 try {
6693 Phone p = getPhone(subId);
6694 if (p == null) {
6695 return null;
6696 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698 return p.getSignalStrength();
6699 } finally {
6700 Binder.restoreCallingIdentity(identity);
6701 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006702 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006703
Pengquan Meng77b7f132018-08-22 14:49:57 -07006704 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006705 * Get the current modem radio state for the given slot.
6706 * @param slotIndex slot index.
6707 * @param callingPackage the name of the package making the call.
6708 * @return the current radio power state from the modem
6709 */
6710 @Override
6711 public int getRadioPowerState(int slotIndex, String callingPackage) {
6712 Phone phone = PhoneFactory.getPhone(slotIndex);
6713 if (phone != null) {
6714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6715 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6716 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6717 }
6718
6719 final long identity = Binder.clearCallingIdentity();
6720 try {
6721 return phone.getRadioPowerState();
6722 } finally {
6723 Binder.restoreCallingIdentity(identity);
6724 }
6725 }
6726 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6727 }
6728
6729 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006730 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6731 *
6732 * <p>Requires one of the following permissions:
6733 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6734 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6735 * privileges.
6736 *
6737 * @param subId subscription id
6738 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6739 * {@code false}.
6740 */
6741 @Override
6742 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006743 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6744 null /* message */);
6745
Pengquan Menga1bb6272018-09-06 09:59:22 -07006746 boolean isEnabled = false;
6747 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006748 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006749 Phone phone = getPhone(subId);
6750 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006751 } catch (Exception e) {
6752 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6753 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006754 } finally {
6755 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006756 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006757 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006758 }
6759
6760
6761 /**
6762 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6763 *
6764 * <p> Requires permission:
6765 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6766 * privileges.
6767 *
6768 * @param subId subscription id
6769 * @param isEnabled {@code true} means enable, {@code false} means disable.
6770 */
6771 @Override
6772 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6774 mApp, subId, "setDataRoamingEnabled");
6775
Pengquan Menga1bb6272018-09-06 09:59:22 -07006776 final long identity = Binder.clearCallingIdentity();
6777 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006778 Phone phone = getPhone(subId);
6779 if (phone != null) {
6780 phone.setDataRoamingEnabled(isEnabled);
6781 }
6782 } finally {
6783 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006784 }
6785 }
6786
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006787 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006788 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006789 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6790 mApp, subId, "isManualNetworkSelectionAllowed");
6791
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006792 boolean isAllowed = true;
6793 final long identity = Binder.clearCallingIdentity();
6794 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006795 Phone phone = getPhone(subId);
6796 if (phone != null) {
6797 isAllowed = phone.isCspPlmnEnabled();
6798 }
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
6802 return isAllowed;
6803 }
6804
6805 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006806 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006807 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006808 try {
6809 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006810 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006811 } catch (SecurityException e) {
6812 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6813 // has carrier privileges on an active UICC
6814 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6815 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006816 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006817 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006818 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006819
6820 final long identity = Binder.clearCallingIdentity();
6821 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006822 UiccController uiccController = UiccController.getInstance();
6823 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006824 if (hasReadPermission) {
6825 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006826 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006827
6828 // Remove private info if the caller doesn't have access
6829 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6830 for (UiccCardInfo cardInfo : cardInfos) {
6831 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6832 // is available
6833 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6834 if (card == null || card.getUiccProfile() == null) {
6835 // assume no access if the card or profile is unavailable
6836 filteredInfos.add(cardInfo.getUnprivileged());
6837 continue;
6838 }
6839 UiccProfile profile = card.getUiccProfile();
6840 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6841 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6842 filteredInfos.add(cardInfo);
6843 } else {
6844 filteredInfos.add(cardInfo.getUnprivileged());
6845 }
6846 }
6847 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006848 } finally {
6849 Binder.restoreCallingIdentity(identity);
6850 }
6851 }
6852
6853 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006854 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006855 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 final long identity = Binder.clearCallingIdentity();
6858 try {
6859 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6860 if (slots == null) {
6861 Rlog.i(LOG_TAG, "slots is null.");
6862 return null;
6863 }
6864
6865 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6866 for (int i = 0; i < slots.length; i++) {
6867 UiccSlot slot = slots[i];
6868 if (slot == null) {
6869 continue;
6870 }
6871
Jordan Liu7be7e652019-05-06 18:55:02 +00006872 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 UiccCard card = slot.getUiccCard();
6874 if (card != null) {
6875 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006876 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006877 cardId = slot.getEid();
6878 if (TextUtils.isEmpty(cardId)) {
6879 cardId = slot.getIccId();
6880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 }
6882
Jordan Liu857451f2019-05-09 16:35:35 -07006883 if (cardId != null) {
6884 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6885 // if cardId is an EID, it's all digits so this is fine
6886 cardId = IccUtils.stripTrailingFs(cardId);
6887 }
6888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889 int cardState = 0;
6890 switch (slot.getCardState()) {
6891 case CARDSTATE_ABSENT:
6892 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6893 break;
6894 case CARDSTATE_PRESENT:
6895 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6896 break;
6897 case CARDSTATE_ERROR:
6898 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6899 break;
6900 case CARDSTATE_RESTRICTED:
6901 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6902 break;
6903 default:
6904 break;
6905
6906 }
6907
6908 infos[i] = new UiccSlotInfo(
6909 slot.isActive(),
6910 slot.isEuicc(),
6911 cardId,
6912 cardState,
6913 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006914 slot.isExtendedApduSupported(),
6915 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006916 }
6917 return infos;
6918 } finally {
6919 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006920 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006921 }
6922
6923 @Override
6924 public boolean switchSlots(int[] physicalSlots) {
6925 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006926
6927 final long identity = Binder.clearCallingIdentity();
6928 try {
6929 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6930 } finally {
6931 Binder.restoreCallingIdentity(identity);
6932 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006933 }
Jack Yu4c988042018-02-27 15:30:01 -08006934
6935 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006936 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006937 final long identity = Binder.clearCallingIdentity();
6938 try {
6939 return UiccController.getInstance().getCardIdForDefaultEuicc();
6940 } finally {
6941 Binder.restoreCallingIdentity(identity);
6942 }
6943 }
6944
6945 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006946 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6947 enforceModifyPermission();
6948 final Phone phone = getPhone(subId);
6949 if (phone == null) {
6950 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6951 return;
6952 }
6953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954 final long identity = Binder.clearCallingIdentity();
6955 try {
6956 phone.setRadioIndicationUpdateMode(filters, mode);
6957 } finally {
6958 Binder.restoreCallingIdentity(identity);
6959 }
Jack Yu4c988042018-02-27 15:30:01 -08006960 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006961
6962 /**
goneil47ffb6e2018-04-06 15:40:58 -07006963 * A test API to reload the UICC profile.
6964 *
6965 * <p>Requires that the calling app has permission
6966 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6967 * @hide
6968 */
6969 @Override
6970 public void refreshUiccProfile(int subId) {
6971 enforceModifyPermission();
6972
6973 final long identity = Binder.clearCallingIdentity();
6974 try {
6975 Phone phone = getPhone(subId);
6976 if (phone == null) {
6977 return;
6978 }
6979 UiccCard uiccCard = phone.getUiccCard();
6980 if (uiccCard == null) {
6981 return;
6982 }
6983 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6984 if (uiccProfile == null) {
6985 return;
6986 }
6987 uiccProfile.refresh();
6988 } finally {
6989 Binder.restoreCallingIdentity(identity);
6990 }
6991 }
6992
6993 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006994 * Returns false if the mobile data is disabled by default, otherwise return true.
6995 */
6996 private boolean getDefaultDataEnabled() {
6997 return "true".equalsIgnoreCase(
6998 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6999 }
7000
7001 /**
7002 * Returns true if the data roaming is enabled by default, i.e the system property
7003 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7004 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7005 */
7006 private boolean getDefaultDataRoamingEnabled(int subId) {
7007 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007008 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007009 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
7010 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
7011 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7012 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7013 return isDataRoamingEnabled;
7014 }
7015
7016 /**
7017 * Returns the default network type for the given {@code subId}, if the default network type is
7018 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7019 */
7020 private int getDefaultNetworkType(int subId) {
7021 return Integer.parseInt(
7022 TelephonyManager.getTelephonyProperty(
7023 mSubscriptionController.getPhoneId(subId),
7024 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
7025 String.valueOf(Phone.PREFERRED_NT_MODE)));
7026 }
fionaxua13278b2018-03-21 00:08:13 -07007027
7028 @Override
7029 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007030 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007031 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032
7033 final long identity = Binder.clearCallingIdentity();
7034 try {
7035 final Phone phone = getPhone(subId);
7036 if (phone == null) {
7037 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7038 return;
7039 }
chen xueaba88a2019-03-15 13:15:10 -07007040 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7041 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 } finally {
7043 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007044 }
fionaxua13278b2018-03-21 00:08:13 -07007045 }
7046
7047 @Override
7048 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007049 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050
7051 final long identity = Binder.clearCallingIdentity();
7052 try {
7053 final Phone phone = getPhone(subId);
7054 if (phone == null) {
7055 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7056 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7057 }
7058 return phone.getCarrierIdListVersion();
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007061 }
fionaxua13278b2018-03-21 00:08:13 -07007062 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007063
7064 @Override
7065 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7067 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7068 return -1;
7069 }
7070
7071 final long identity = Binder.clearCallingIdentity();
7072 try {
7073 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7074 } finally {
7075 Binder.restoreCallingIdentity(identity);
7076 }
7077 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007078
7079 @Override
7080 public int getCdmaRoamingMode(int subId) {
7081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7082 mApp, subId, "getCdmaRoamingMode");
7083
7084 final long identity = Binder.clearCallingIdentity();
7085 try {
7086 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7087 } finally {
7088 Binder.restoreCallingIdentity(identity);
7089 }
7090 }
7091
7092 @Override
7093 public boolean setCdmaRoamingMode(int subId, int mode) {
7094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7095 mApp, subId, "setCdmaRoamingMode");
7096
7097 final long identity = Binder.clearCallingIdentity();
7098 try {
7099 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7100 } finally {
7101 Binder.restoreCallingIdentity(identity);
7102 }
7103 }
7104
7105 @Override
7106 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7108 mApp, subId, "setCdmaSubscriptionMode");
7109
7110 final long identity = Binder.clearCallingIdentity();
7111 try {
7112 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
7115 }
7116 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007117
sqianc5eccab2018-10-19 18:46:41 -07007118 @Override
sqian8c685422019-02-22 15:55:18 -08007119 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007120 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007122 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007123 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7124 }
7125 final long identity = Binder.clearCallingIdentity();
7126 try {
sqian854d44b2018-12-12 16:48:18 -08007127 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7128 for (Phone phone: PhoneFactory.getPhones()) {
7129 if (phone.getEmergencyNumberTracker() != null
7130 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7131 emergencyNumberListInternal.put(
7132 phone.getSubId(),
7133 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7134 }
sqian11b7a0e2018-12-05 18:48:28 -08007135 }
sqian854d44b2018-12-12 16:48:18 -08007136 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
sqianc5eccab2018-10-19 18:46:41 -07007140 }
7141
7142 @Override
sqian8c685422019-02-22 15:55:18 -08007143 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007144 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007145 if (!exactMatch) {
7146 TelephonyPermissions
7147 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007148 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007149 }
7150 final long identity = Binder.clearCallingIdentity();
7151 try {
sqian854d44b2018-12-12 16:48:18 -08007152 for (Phone phone: PhoneFactory.getPhones()) {
7153 if (phone.getEmergencyNumberTracker() != null
7154 && phone.getEmergencyNumberTracker() != null) {
7155 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7156 number, exactMatch)) {
7157 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007158 }
7159 }
sqian11b7a0e2018-12-05 18:48:28 -08007160 }
7161 return false;
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
7165 }
7166
sqianf4ca7ed2019-01-15 18:32:07 -08007167 /**
7168 * Update emergency number list for test mode.
7169 */
7170 @Override
7171 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7172 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7173 "updateEmergencyNumberListTestMode");
7174
7175 final long identity = Binder.clearCallingIdentity();
7176 try {
7177 for (Phone phone: PhoneFactory.getPhones()) {
7178 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7179 if (tracker != null) {
7180 tracker.executeEmergencyNumberTestModeCommand(action, num);
7181 }
7182 }
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
7185 }
7186 }
7187
7188 /**
7189 * Get the full emergency number list for test mode.
7190 */
7191 @Override
7192 public List<String> getEmergencyNumberListTestMode() {
7193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7194 "getEmergencyNumberListTestMode");
7195
7196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 Set<String> emergencyNumbers = new HashSet<>();
7199 for (Phone phone: PhoneFactory.getPhones()) {
7200 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7201 if (tracker != null) {
7202 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7203 emergencyNumbers.add(num.getNumber());
7204 }
7205 }
7206 }
7207 return new ArrayList<>(emergencyNumbers);
7208 } finally {
7209 Binder.restoreCallingIdentity(identity);
7210 }
7211 }
7212
chen xud6b45bd2018-10-30 22:27:10 -07007213 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007214 public int getEmergencyNumberDbVersion(int subId) {
7215 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7216
7217 final long identity = Binder.clearCallingIdentity();
7218 try {
7219 final Phone phone = getPhone(subId);
7220 if (phone == null) {
7221 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7222 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7223 }
7224 return phone.getEmergencyNumberDbVersion();
7225 } finally {
7226 Binder.restoreCallingIdentity(identity);
7227 }
7228 }
7229
7230 @Override
7231 public void notifyOtaEmergencyNumberDbInstalled() {
7232 enforceModifyPermission();
7233
7234 final long identity = Binder.clearCallingIdentity();
7235 try {
7236 for (Phone phone: PhoneFactory.getPhones()) {
7237 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7238 if (tracker != null) {
7239 tracker.updateOtaEmergencyNumberDatabase();
7240 }
7241 }
7242 } finally {
7243 Binder.restoreCallingIdentity(identity);
7244 }
7245 }
7246
7247 @Override
7248 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7249 enforceActiveEmergencySessionPermission();
7250
7251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 for (Phone phone: PhoneFactory.getPhones()) {
7254 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7255 if (tracker != null) {
7256 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7257 }
7258 }
7259 } finally {
7260 Binder.restoreCallingIdentity(identity);
7261 }
7262 }
7263
7264 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007265 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7266 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7267 Phone phone = getPhone(subId);
7268 if (phone == null) {
7269 return null;
7270 }
7271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 UiccProfile profile = UiccController.getInstance()
7274 .getUiccProfileForPhone(phone.getPhoneId());
7275 if (profile != null) {
7276 return profile.getCertsFromCarrierPrivilegeAccessRules();
7277 }
7278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
7281 return null;
7282 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007283
7284 /**
7285 * Enable or disable a modem stack.
7286 */
7287 @Override
7288 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7289 enforceModifyPermission();
7290
7291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 Phone phone = PhoneFactory.getPhone(slotIndex);
7294 if (phone == null) {
7295 return false;
7296 } else {
7297 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7298 }
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301 }
7302 }
Michelecea4cf22018-12-21 15:00:11 -08007303
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007304 /**
7305 * Whether a modem stack is enabled or not.
7306 */
7307 @Override
7308 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7309 Phone phone = PhoneFactory.getPhone(slotIndex);
7310 if (phone == null) return false;
7311
7312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7313 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7314 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7315 }
7316
7317 final long identity = Binder.clearCallingIdentity();
7318 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007319 try {
7320 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7321 } catch (NoSuchElementException ex) {
7322 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7323 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007324 } finally {
7325 Binder.restoreCallingIdentity(identity);
7326 }
7327 }
7328
Michelecea4cf22018-12-21 15:00:11 -08007329 @Override
Michele0ea7d782019-03-19 14:58:42 -07007330 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007331 enforceModifyPermission();
7332
7333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007336 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007337 .commit();
7338 } finally {
7339 Binder.restoreCallingIdentity(identity);
7340 }
7341 }
7342
7343 @Override
Michele0ea7d782019-03-19 14:58:42 -07007344 @TelephonyManager.IsMultiSimSupportedResult
7345 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007346 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007347 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7348 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007349 }
Michelecea4cf22018-12-21 15:00:11 -08007350
7351 final long identity = Binder.clearCallingIdentity();
7352 try {
Michele0ea7d782019-03-19 14:58:42 -07007353 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007354 } finally {
7355 Binder.restoreCallingIdentity(identity);
7356 }
7357 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007358
Michele0ea7d782019-03-19 14:58:42 -07007359 @TelephonyManager.IsMultiSimSupportedResult
7360 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007361 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7362 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7363 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007364 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7365 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007366 }
7367 // Check if the hardware supports multisim functionality. If usage of multisim is not
7368 // supported by the modem, indicate that it is restricted.
7369 PhoneCapability staticCapability =
7370 mPhoneConfigurationManager.getStaticPhoneCapability();
7371 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007372 loge("isMultiSimSupportedInternal: no static configuration available");
7373 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007374 }
7375 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007376 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7377 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007378 }
7379 // Check if support of multiple SIMs is restricted by carrier
7380 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007381 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007382 }
7383
Michele0ea7d782019-03-19 14:58:42 -07007384 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007385 }
7386
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007387 /**
7388 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007389 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7390 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7391 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007392 * @param numOfSims number of active sims we want to switch to
7393 */
7394 @Override
7395 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007396 if (numOfSims == 1) {
7397 enforceModifyPermission();
7398 } else {
7399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7400 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7401 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007402 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007403
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007404 try {
Michele30b57b22019-03-01 12:01:14 -08007405 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007406 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007407 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7408 return;
7409 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007410 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
7414 }
7415
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007416 @Override
7417 public boolean isApplicationOnUicc(int subId, int appType) {
7418 enforceReadPrivilegedPermission("isApplicationOnUicc");
7419 Phone phone = getPhone(subId);
7420 if (phone == null) {
7421 return false;
7422 }
7423 final long identity = Binder.clearCallingIdentity();
7424 try {
7425 UiccCard uiccCard = phone.getUiccCard();
7426 if (uiccCard == null) {
7427 return false;
7428 }
7429 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7430 if (uiccProfile == null) {
7431 return false;
7432 }
7433 if (TelephonyManager.APPTYPE_SIM <= appType
7434 && appType <= TelephonyManager.APPTYPE_ISIM) {
7435 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7436 }
7437 return false;
7438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
7441 }
7442
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007443 /**
chen xub4baa772019-04-03 10:23:41 -07007444 * Get whether making changes to modem configurations will trigger reboot.
7445 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007446 */
7447 @Override
chen xub4baa772019-04-03 10:23:41 -07007448 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7449 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7450 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7451 return false;
7452 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007453 final long identity = Binder.clearCallingIdentity();
7454 try {
7455 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7456 } finally {
7457 Binder.restoreCallingIdentity(identity);
7458 }
7459 }
7460
Nathan Harold29f5f052019-02-15 13:41:57 -08007461 private void updateModemStateMetrics() {
7462 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7463 // TODO: check the state for each modem if the api is ready.
7464 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7465 }
7466
Pengquan Meng3889a572019-01-23 11:16:29 -08007467 @Override
7468 public int[] getSlotsMapping() {
7469 enforceReadPrivilegedPermission("getSlotsMapping");
7470
7471 final long identity = Binder.clearCallingIdentity();
7472 try {
7473 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7474 // All logical slots should have a mapping to a physical slot.
7475 int[] logicalSlotsMapping = new int[phoneCount];
7476 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7477 for (int i = 0; i < slotInfos.length; i++) {
7478 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7479 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7480 }
7481 }
7482 return logicalSlotsMapping;
7483 } finally {
7484 Binder.restoreCallingIdentity(identity);
7485 }
7486 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007487
7488 /**
7489 * Get the IRadio HAL Version
7490 */
7491 @Override
7492 public int getRadioHalVersion() {
7493 Phone phone = getDefaultPhone();
7494 if (phone == null) return -1;
7495 HalVersion hv = phone.getHalVersion();
7496 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7497 return hv.major * 100 + hv.minor;
7498 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007499
7500 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007501 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7502 * corresponding network requests on a subId.
7503 *
7504 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007505 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007506 * 2) APN is un-metered for this subscription, or
7507 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7508 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7509 *
7510 * @return whether data is allowed for a apn type.
7511 *
7512 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007513 */
7514 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007515 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007516 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7517 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007518
7519 // Now that all security checks passes, perform the operation as ourselves.
7520 final long identity = Binder.clearCallingIdentity();
7521 try {
7522 Phone phone = getPhone(subId);
7523 if (phone == null) return false;
7524
Jack Yu41407ee2019-05-13 16:54:09 -07007525 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007526 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7527 } finally {
7528 Binder.restoreCallingIdentity(identity);
7529 }
7530 }
7531
7532 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007533 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007534 enforceReadPrivilegedPermission("isApnMetered");
7535
7536 // Now that all security checks passes, perform the operation as ourselves.
7537 final long identity = Binder.clearCallingIdentity();
7538 try {
7539 Phone phone = getPhone(subId);
7540 if (phone == null) return true; // By default return true.
7541
Jack Yu41407ee2019-05-13 16:54:09 -07007542 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007543 } finally {
7544 Binder.restoreCallingIdentity(identity);
7545 }
7546 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007547
7548 @Override
7549 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7550 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7551 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7552 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7553 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7554 }
7555 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7556 Intent intent = new Intent();
7557 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7558 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7559 // Bring up choose default SMS subscription dialog right now
7560 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7561 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7562 mApp.startActivity(intent);
7563 }
chen xud5ca2d52019-05-28 15:20:57 -07007564
7565 @Override
7566 public String getMmsUAProfUrl(int subId) {
7567 //TODO investigate if this API should require proper permission check in R b/133791609
7568 final long identity = Binder.clearCallingIdentity();
7569 try {
7570 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7571 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
7574 }
7575 }
7576
7577 @Override
7578 public String getMmsUserAgent(int subId) {
7579 //TODO investigate if this API should require proper permission check in R b/133791609
7580 final long identity = Binder.clearCallingIdentity();
7581 try {
7582 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7583 .getString(com.android.internal.R.string.config_mms_user_agent);
7584 } finally {
7585 Binder.restoreCallingIdentity(identity);
7586 }
7587 }
Jack Yub07d4972019-05-28 16:12:25 -07007588
7589 @Override
7590 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7591 enforceModifyPermission();
7592
7593 // Now that all security checks passes, perform the operation as ourselves.
7594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 Phone phone = getPhone(subId);
7597 if (phone == null) return false;
7598
7599 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7600 } finally {
7601 Binder.restoreCallingIdentity(identity);
7602 }
7603 }
7604
7605 @Override
7606 public boolean isDataAllowedInVoiceCall(int subId) {
7607 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7608
7609 // Now that all security checks passes, perform the operation as ourselves.
7610 final long identity = Binder.clearCallingIdentity();
7611 try {
7612 Phone phone = getPhone(subId);
7613 if (phone == null) return false;
7614
7615 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7616 } finally {
7617 Binder.restoreCallingIdentity(identity);
7618 }
7619 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007620
7621 /**
7622 * Updates whether conference event pacakge handling is enabled.
7623 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7624 * otherwise.
7625 */
7626 @Override
7627 public void setCepEnabled(boolean isCepEnabled) {
7628 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7629
7630 final long identity = Binder.clearCallingIdentity();
7631 try {
7632 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7633 for (Phone phone : PhoneFactory.getPhones()) {
7634 Phone defaultPhone = phone.getImsPhone();
7635 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7636 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7637 ImsPhoneCallTracker imsPhoneCallTracker =
7638 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7639 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7640 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7641 + imsPhone.getMsisdn());
7642 }
7643 }
7644 } finally {
7645 Binder.restoreCallingIdentity(identity);
7646 }
7647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007648}