blob: 3ecd6b42efe8f5d83db7624956838fe19811b38b [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;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070065import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080066import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070067import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070069import android.telephony.CellInfoGsm;
70import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070071import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070073import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070074import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080075import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070076import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080077import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070078import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080079import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080080import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070081import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080082import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080085import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080086import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080087import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070088import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070089import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080091import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000092import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070093import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080096import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070097import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070099import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700102import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700105import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsMmTelFeature;
107import android.telephony.ims.aidl.IImsRcsFeature;
108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800117import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700123import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700124import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800125import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700126import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700127import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800129import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700130import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800131import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800133import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700134import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100135import com.android.internal.telephony.MccTable;
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;
fionaxu7ed723d2017-05-30 18:58:54 -0700167import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700170import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800171import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700173import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800174
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700175import java.io.FileDescriptor;
176import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800179import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800180import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800181import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100182import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700184import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187/**
188 * Implementation of the ITelephony interface.
189 */
Santos Cordon117fee72014-05-16 17:56:12 -0700190public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 private static final String LOG_TAG = "PhoneInterfaceManager";
192 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
193 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800194 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196 // Message codes used with mMainThreadHandler
197 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700198 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
199 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200 private static final int CMD_OPEN_CHANNEL = 9;
201 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
202 private static final int CMD_CLOSE_CHANNEL = 11;
203 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800204 private static final int CMD_NV_READ_ITEM = 13;
205 private static final int EVENT_NV_READ_ITEM_DONE = 14;
206 private static final int CMD_NV_WRITE_ITEM = 15;
207 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
208 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
209 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700210 private static final int CMD_RESET_MODEM_CONFIG = 19;
211 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800212 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
213 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
214 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
215 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800216 private static final int CMD_SEND_ENVELOPE = 25;
217 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000218 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
219 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700220 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
221 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
222 private static final int CMD_EXCHANGE_SIM_IO = 31;
223 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800224 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
225 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700226 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
227 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700228 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
229 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700230 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
231 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
232 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
233 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700234 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
235 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
236 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
237 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700238 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
240 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000241 private static final int CMD_SWITCH_SLOTS = 50;
242 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700243 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
244 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
245 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
246 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
247 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
248 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
249 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
250 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700251 private static final int CMD_GET_ALL_CELL_INFO = 60;
252 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
253 private static final int CMD_GET_CELL_LOCATION = 62;
254 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700255 private static final int CMD_MODEM_REBOOT = 64;
256 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700257 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
258 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800259 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
260 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700261 private static final int CMD_GET_MODEM_STATUS = 70;
262 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700263 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
264 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800266 // Parameters of select command.
267 private static final int SELECT_COMMAND = 0xA4;
268 private static final int SELECT_P1 = 0x04;
269 private static final int SELECT_P2 = 0;
270 private static final int SELECT_P3 = 0x10;
271
Pengquan Meng85728fb2018-03-12 16:31:21 -0700272 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
273 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
274 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
275
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 /** The singleton instance. */
277 private static PhoneInterfaceManager sInstance;
278
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700281 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private AppOpsManager mAppOps;
283 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800284 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700286 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
Derek Tan97ebb422014-09-05 16:55:38 -0700288 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
289 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800290 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800291 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700292
Michelecea4cf22018-12-21 15:00:11 -0800293 // String to store multi SIM allowed
294 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
295
Derek Tan740e1672017-06-27 14:56:27 -0700296 // The AID of ISD-R.
297 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
298
yinxub1bed742017-04-17 11:45:04 -0700299 private NetworkScanRequestTracker mNetworkScanRequestTracker;
300
David Kelly5e06a7f2018-03-12 14:10:59 +0000301 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
302 private static final int MANUFACTURER_CODE_LENGTH = 8;
303
Derek Tan89e89d42014-07-08 17:00:10 -0700304 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700305 * A request object to use for transmitting data to an ICC.
306 */
307 private static final class IccAPDUArgument {
308 public int channel, cla, command, p1, p2, p3;
309 public String data;
310
311 public IccAPDUArgument(int channel, int cla, int command,
312 int p1, int p2, int p3, String data) {
313 this.channel = channel;
314 this.cla = cla;
315 this.command = command;
316 this.p1 = p1;
317 this.p2 = p2;
318 this.p3 = p3;
319 this.data = data;
320 }
321 }
322
323 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700324 * A request object to use for transmitting data to an ICC.
325 */
326 private static final class ManualNetworkSelectionArgument {
327 public OperatorInfo operatorInfo;
328 public boolean persistSelection;
329
330 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
331 this.operatorInfo = operatorInfo;
332 this.persistSelection = persistSelection;
333 }
334 }
335
336 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
338 * request after sending. The main thread will notify the request when it is complete.
339 */
340 private static final class MainThreadRequest {
341 /** The argument to use for the request */
342 public Object argument;
343 /** The result of the request that is run on the main thread */
344 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800345 // The subscriber id that this request applies to. Defaults to
346 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
347 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Nathan Harold92bed182018-10-12 18:16:49 -0700349 // In cases where subId is unavailable, the caller needs to specify the phone.
350 public Phone phone;
351
vagdeviaf9a5b92018-08-15 16:01:53 -0700352 public WorkSource workSource;
353
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 public MainThreadRequest(Object argument) {
355 this.argument = argument;
356 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800357
Nathan Harold92bed182018-10-12 18:16:49 -0700358 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
359 this.argument = argument;
360 if (phone != null) {
361 this.phone = phone;
362 }
363 this.workSource = workSource;
364 }
365
vagdeviaf9a5b92018-08-15 16:01:53 -0700366 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800367 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800368 if (subId != null) {
369 this.subId = subId;
370 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700371 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 }
374
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800375 private static final class IncomingThirdPartyCallArgs {
376 public final ComponentName component;
377 public final String callId;
378 public final String callerDisplayName;
379
380 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
381 String callerDisplayName) {
382 this.component = component;
383 this.callId = callId;
384 this.callerDisplayName = callerDisplayName;
385 }
386 }
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 /**
389 * A handler that processes messages on the main thread in the phone process. Since many
390 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
391 * inbound binder threads to the main thread in the phone process. The Binder thread
392 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
393 * on, which will be notified when the operation completes and will contain the result of the
394 * request.
395 *
396 * <p>If a MainThreadRequest object is provided in the msg.obj field,
397 * note that request.result must be set to something non-null for the calling thread to
398 * unblock.
399 */
400 private final class MainThreadHandler extends Handler {
401 @Override
402 public void handleMessage(Message msg) {
403 MainThreadRequest request;
404 Message onCompleted;
405 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800406 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700407 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800408 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
410 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700411 case CMD_HANDLE_USSD_REQUEST: {
412 request = (MainThreadRequest) msg.obj;
413 final Phone phone = getPhoneFromRequest(request);
414 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
415 String ussdRequest = ussdObject.first;
416 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700417
Pengquan Menga1bb6272018-09-06 09:59:22 -0700418 if (!isUssdApiAllowed(request.subId)) {
419 // Carrier does not support use of this API, return failure.
420 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
421 UssdResponse response = new UssdResponse(ussdRequest, null);
422 Bundle returnData = new Bundle();
423 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
424 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700425
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 request.result = true;
427 notifyRequester(request);
428 return;
429 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700430
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 try {
432 request.result = phone != null
433 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
434 } catch (CallStateException cse) {
435 request.result = false;
436 }
437 // Wake up the requesting thread
438 notifyRequester(request);
439 break;
pkanwar32d516d2016-10-14 19:37:38 -0700440 }
441
Yorke Lee716f67e2015-06-17 15:39:16 -0700442 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700444 final Phone phone = getPhoneFromRequest(request);
445 request.result = phone != null ?
446 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
447 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700449 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800456 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 if (uiccCard == null) {
458 loge("iccTransmitApduLogicalChannel: No UICC");
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700461 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
463 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 iccArgument.channel, iccArgument.cla, iccArgument.command,
466 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700468 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700469 break;
470
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 ar = (AsyncResult) msg.obj;
473 request = (MainThreadRequest) ar.userObj;
474 if (ar.exception == null && ar.result != null) {
475 request.result = ar.result;
476 } else {
477 request.result = new IccIoResult(0x6F, 0, (byte[])null);
478 if (ar.result == null) {
479 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800480 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800482 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700483 } else {
484 loge("iccTransmitApduLogicalChannel: Unknown exception");
485 }
486 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 break;
489
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
491 request = (MainThreadRequest) msg.obj;
492 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800493 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 if (uiccCard == null) {
495 loge("iccTransmitApduBasicChannel: No UICC");
496 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 } else {
499 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
500 request);
501 uiccCard.iccTransmitApduBasicChannel(
502 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
503 iccArgument.p3, iccArgument.data, onCompleted);
504 }
505 break;
506
507 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
508 ar = (AsyncResult) msg.obj;
509 request = (MainThreadRequest) ar.userObj;
510 if (ar.exception == null && ar.result != null) {
511 request.result = ar.result;
512 } else {
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 if (ar.result == null) {
515 loge("iccTransmitApduBasicChannel: Empty response");
516 } else if (ar.exception instanceof CommandException) {
517 loge("iccTransmitApduBasicChannel: CommandException: " +
518 ar.exception);
519 } else {
520 loge("iccTransmitApduBasicChannel: Unknown exception");
521 }
522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 break;
525
526 case CMD_EXCHANGE_SIM_IO:
527 request = (MainThreadRequest) msg.obj;
528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 if (uiccCard == null) {
531 loge("iccExchangeSimIO: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 } else {
535 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
536 request);
537 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
538 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
539 iccArgument.data, onCompleted);
540 }
541 break;
542
543 case EVENT_EXCHANGE_SIM_IO_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6f, 0, (byte[])null);
550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 break;
553
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 case CMD_SEND_ENVELOPE:
555 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 if (uiccCard == null) {
558 loge("sendEnvelopeWithStatus: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 } else {
562 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
563 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
564 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 break;
566
567 case EVENT_SEND_ENVELOPE_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700570 if (ar.exception == null && ar.result != null) {
571 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800572 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
574 if (ar.result == null) {
575 loge("sendEnvelopeWithStatus: Empty response");
576 } else if (ar.exception instanceof CommandException) {
577 loge("sendEnvelopeWithStatus: CommandException: " +
578 ar.exception);
579 } else {
580 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
581 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800584 break;
585
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 case CMD_OPEN_CHANNEL:
587 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800588 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800589 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 if (uiccCard == null) {
591 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800592 request.result = new IccOpenLogicalChannelResponse(-1,
593 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800597 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
598 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 break;
601
602 case EVENT_OPEN_CHANNEL_DONE:
603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 int[] result = (int[]) ar.result;
608 int channelId = result[0];
609 byte[] selectResponse = null;
610 if (result.length > 1) {
611 selectResponse = new byte[result.length - 1];
612 for (int i = 1; i < result.length; ++i) {
613 selectResponse[i - 1] = (byte) result[i];
614 }
615 }
616 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700617 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 if (ar.result == null) {
620 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 if (ar.exception != null) {
623 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
624 }
625
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700627 if (ar.exception instanceof CommandException) {
628 CommandException.Error error =
629 ((CommandException) (ar.exception)).getCommandError();
630 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700632 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700633 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 }
635 }
636 openChannelResp = new IccOpenLogicalChannelResponse(
637 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700639 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 break;
642
643 case CMD_CLOSE_CHANNEL:
644 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800645 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700646 if (uiccCard == null) {
647 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900648 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 } else {
651 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
652 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 break;
655
656 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800657 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
658 break;
659
660 case CMD_NV_READ_ITEM:
661 request = (MainThreadRequest) msg.obj;
662 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800663 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
664 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800665 break;
666
667 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 ar = (AsyncResult) msg.obj;
669 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800670 if (ar.exception == null && ar.result != null) {
671 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800673 request.result = "";
674 if (ar.result == null) {
675 loge("nvReadItem: Empty response");
676 } else if (ar.exception instanceof CommandException) {
677 loge("nvReadItem: CommandException: " +
678 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800680 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 }
682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 break;
685
Jake Hambye994d462014-02-03 13:10:13 -0800686 case CMD_NV_WRITE_ITEM:
687 request = (MainThreadRequest) msg.obj;
688 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
689 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800690 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700691 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800692 break;
693
694 case EVENT_NV_WRITE_ITEM_DONE:
695 handleNullReturnEvent(msg, "nvWriteItem");
696 break;
697
698 case CMD_NV_WRITE_CDMA_PRL:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800701 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800702 break;
703
704 case EVENT_NV_WRITE_CDMA_PRL_DONE:
705 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
706 break;
707
chen xu6dac5ab2018-10-26 17:39:23 -0700708 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800709 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700710 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800711 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800712 break;
713
chen xu6dac5ab2018-10-26 17:39:23 -0700714 case EVENT_RESET_MODEM_CONFIG_DONE:
715 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800716 break;
717
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 case CMD_GET_PREFERRED_NETWORK_TYPE:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700721 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800722 break;
723
724 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
727 if (ar.exception == null && ar.result != null) {
728 request.result = ar.result; // Integer
729 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800730 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 if (ar.result == null) {
732 loge("getPreferredNetworkType: Empty response");
733 } else if (ar.exception instanceof CommandException) {
734 loge("getPreferredNetworkType: CommandException: " +
735 ar.exception);
736 } else {
737 loge("getPreferredNetworkType: Unknown exception");
738 }
739 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case CMD_SET_PREFERRED_NETWORK_TYPE:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
746 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700747 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800748 break;
749
750 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
751 handleNullReturnEvent(msg, "setPreferredNetworkType");
752 break;
753
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000754 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
755 request = (MainThreadRequest)msg.obj;
756 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800757 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000758 break;
759
760 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
761 ar = (AsyncResult)msg.obj;
762 request = (MainThreadRequest)ar.userObj;
763 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000765 break;
766
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800767 case CMD_SET_VOICEMAIL_NUMBER:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
770 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800771 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
772 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800773 break;
774
775 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
776 handleNullReturnEvent(msg, "setVoicemailNumber");
777 break;
778
Stuart Scott54788802015-03-30 13:18:01 -0700779 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
782 request);
783 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
784 break;
785
786 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
787 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
788 break;
789
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 case CMD_PERFORM_NETWORK_SCAN:
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
793 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
794 break;
795
796 case EVENT_PERFORM_NETWORK_SCAN_DONE:
797 ar = (AsyncResult) msg.obj;
798 request = (MainThreadRequest) ar.userObj;
799 CellNetworkScanResult cellScanResult;
800 if (ar.exception == null && ar.result != null) {
801 cellScanResult = new CellNetworkScanResult(
802 CellNetworkScanResult.STATUS_SUCCESS,
803 (List<OperatorInfo>) ar.result);
804 } else {
805 if (ar.result == null) {
806 loge("getCellNetworkScanResults: Empty response");
807 }
808 if (ar.exception != null) {
809 loge("getCellNetworkScanResults: Exception: " + ar.exception);
810 }
811 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
812 if (ar.exception instanceof CommandException) {
813 CommandException.Error error =
814 ((CommandException) (ar.exception)).getCommandError();
815 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
816 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
817 } else if (error == CommandException.Error.GENERIC_FAILURE) {
818 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
819 }
820 }
821 cellScanResult = new CellNetworkScanResult(errorCode, null);
822 }
823 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700824 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700825 break;
826
827 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
828 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700829 ManualNetworkSelectionArgument selArg =
830 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
832 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700833 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
834 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700835 break;
836
837 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null) {
841 request.result = true;
842 } else {
843 request.result = false;
844 loge("setNetworkSelectionModeManual " + ar.exception);
845 }
846 notifyRequester(request);
847 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700848 break;
849
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700850 case CMD_GET_MODEM_ACTIVITY_INFO:
851 request = (MainThreadRequest) msg.obj;
852 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700853 if (defaultPhone != null) {
854 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
855 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700856 break;
857
858 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
859 ar = (AsyncResult) msg.obj;
860 request = (MainThreadRequest) ar.userObj;
861 if (ar.exception == null && ar.result != null) {
862 request.result = ar.result;
863 } else {
864 if (ar.result == null) {
865 loge("queryModemActivityInfo: Empty response");
866 } else if (ar.exception instanceof CommandException) {
867 loge("queryModemActivityInfo: CommandException: " +
868 ar.exception);
869 } else {
870 loge("queryModemActivityInfo: Unknown exception");
871 }
872 }
Amit Mahajand4766222016-01-28 15:28:28 -0800873 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
874 if (request.result == null) {
875 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
876 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700877 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700878 break;
879
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 case CMD_SET_ALLOWED_CARRIERS:
881 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800882 CarrierRestrictionRules argument =
883 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700884 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800885 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 break;
887
888 case EVENT_SET_ALLOWED_CARRIERS_DONE:
889 ar = (AsyncResult) msg.obj;
890 request = (MainThreadRequest) ar.userObj;
891 if (ar.exception == null && ar.result != null) {
892 request.result = ar.result;
893 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800894 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
895 if (ar.exception instanceof CommandException) {
896 loge("setAllowedCarriers: CommandException: " + ar.exception);
897 CommandException.Error error =
898 ((CommandException) (ar.exception)).getCommandError();
899 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
900 request.result =
901 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
902 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700903 } else {
904 loge("setAllowedCarriers: Unknown exception");
905 }
906 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700907 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 break;
909
910 case CMD_GET_ALLOWED_CARRIERS:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800913 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 break;
915
916 case EVENT_GET_ALLOWED_CARRIERS_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null && ar.result != null) {
920 request.result = ar.result;
921 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800922 request.result = new IllegalStateException(
923 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700924 if (ar.result == null) {
925 loge("getAllowedCarriers: Empty response");
926 } else if (ar.exception instanceof CommandException) {
927 loge("getAllowedCarriers: CommandException: " +
928 ar.exception);
929 } else {
930 loge("getAllowedCarriers: Unknown exception");
931 }
932 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700933 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700934 break;
935
Nathan Haroldb3014052017-01-25 15:57:32 -0800936 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
937 ar = (AsyncResult) msg.obj;
938 request = (MainThreadRequest) ar.userObj;
939 if (ar.exception == null && ar.result != null) {
940 request.result = ar.result;
941 } else {
942 request.result = new IllegalArgumentException(
943 "Failed to retrieve Forbidden Plmns");
944 if (ar.result == null) {
945 loge("getForbiddenPlmns: Empty response");
946 } else {
947 loge("getForbiddenPlmns: Unknown exception");
948 }
949 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700950 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800951 break;
952
953 case CMD_GET_FORBIDDEN_PLMNS:
954 request = (MainThreadRequest) msg.obj;
955 uiccCard = getUiccCardFromRequest(request);
956 if (uiccCard == null) {
957 loge("getForbiddenPlmns() UiccCard is null");
958 request.result = new IllegalArgumentException(
959 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700960 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800961 break;
962 }
963 Integer appType = (Integer) request.argument;
964 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
965 if (uiccApp == null) {
966 loge("getForbiddenPlmns() no app with specified type -- "
967 + appType);
968 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800970 break;
971 } else {
972 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
973 + " specified type -- " + appType);
974 }
975 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
976 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
977 onCompleted);
978 break;
979
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000980 case CMD_SWITCH_SLOTS:
981 request = (MainThreadRequest) msg.obj;
982 int[] physicalSlots = (int[]) request.argument;
983 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
984 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
985 break;
986
987 case EVENT_SWITCH_SLOTS_DONE:
988 ar = (AsyncResult) msg.obj;
989 request = (MainThreadRequest) ar.userObj;
990 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700991 notifyRequester(request);
992 break;
993 case CMD_GET_NETWORK_SELECTION_MODE:
994 request = (MainThreadRequest) msg.obj;
995 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
996 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
997 break;
998
999 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 if (ar.exception != null) {
1003 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1004 } else {
1005 int mode = ((int[]) ar.result)[0];
1006 if (mode == 0) {
1007 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1008 } else {
1009 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1010 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001011 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001012 notifyRequester(request);
1013 break;
1014 case CMD_GET_CDMA_ROAMING_MODE:
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1017 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1018 break;
1019 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
1022 if (ar.exception != null) {
1023 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1024 } else {
1025 request.result = ((int[]) ar.result)[0];
1026 }
1027 notifyRequester(request);
1028 break;
1029 case CMD_SET_CDMA_ROAMING_MODE:
1030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1032 int mode = (int) request.argument;
1033 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1034 break;
1035 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1036 ar = (AsyncResult) msg.obj;
1037 request = (MainThreadRequest) ar.userObj;
1038 request.result = ar.exception == null;
1039 notifyRequester(request);
1040 break;
1041 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1042 request = (MainThreadRequest) msg.obj;
1043 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1044 int subscriptionMode = (int) request.argument;
1045 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1046 break;
1047 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
1050 request.result = ar.exception == null;
1051 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001052 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 case CMD_GET_ALL_CELL_INFO:
1054 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001056 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 case EVENT_GET_ALL_CELL_INFO_DONE:
1059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001061 // If a timeout occurs, the response will be null
1062 request.result = (ar.exception == null && ar.result != null)
1063 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 synchronized (request) {
1065 request.notifyAll();
1066 }
1067 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 case CMD_REQUEST_CELL_INFO_UPDATE:
1069 request = (MainThreadRequest) msg.obj;
1070 request.phone.requestCellInfoUpdate(request.workSource,
1071 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1072 break;
1073 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1074 ar = (AsyncResult) msg.obj;
1075 request = (MainThreadRequest) ar.userObj;
1076 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1077 try {
1078 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001080 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1081 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001082 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001083 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001084 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 } else {
1086 // use the result as returned
1087 cb.onCellInfo((List<CellInfo>) ar.result);
1088 }
1089 } catch (RemoteException re) {
1090 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1091 }
1092 break;
1093 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001094 request = (MainThreadRequest) msg.obj;
1095 WorkSource ws = (WorkSource) request.argument;
1096 Phone phone = getPhoneFromRequest(request);
1097 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1098 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001099 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001100 ar = (AsyncResult) msg.obj;
1101 request = (MainThreadRequest) ar.userObj;
1102 if (ar.exception == null) {
1103 request.result = ar.result;
1104 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001105 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001106 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1107 ? new CdmaCellLocation() : new GsmCellLocation();
1108 }
1109
1110 synchronized (request) {
1111 request.notifyAll();
1112 }
1113 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001114 case CMD_MODEM_REBOOT:
1115 request = (MainThreadRequest) msg.obj;
1116 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001117 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001118 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001119 case EVENT_CMD_MODEM_REBOOT_DONE:
1120 handleNullReturnEvent(msg, "rebootModem");
1121 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001122 case CMD_REQUEST_ENABLE_MODEM:
1123 request = (MainThreadRequest) msg.obj;
1124 boolean enable = (boolean) request.argument;
1125 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001126 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001127 PhoneConfigurationManager.getInstance()
1128 .enablePhone(request.phone, enable, onCompleted);
1129 break;
1130 case EVENT_ENABLE_MODEM_DONE:
1131 ar = (AsyncResult) msg.obj;
1132 request = (MainThreadRequest) ar.userObj;
1133 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001134 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001135 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001136 if ((boolean) request.result) {
1137 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1138 updateModemStateMetrics();
1139 } else {
1140 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1141 + ar.exception);
1142 }
1143 notifyRequester(request);
1144 break;
1145 case CMD_GET_MODEM_STATUS:
1146 request = (MainThreadRequest) msg.obj;
1147 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1148 PhoneConfigurationManager.getInstance()
1149 .getPhoneStatusFromModem(request.phone, onCompleted);
1150 break;
1151 case EVENT_GET_MODEM_STATUS_DONE:
1152 ar = (AsyncResult) msg.obj;
1153 request = (MainThreadRequest) ar.userObj;
1154 int id = request.phone.getPhoneId();
1155 if (ar.exception == null && ar.result != null) {
1156 request.result = ar.result;
1157 //update the cache as modem status has changed
1158 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1159 (boolean) request.result);
1160 } else {
1161 // Return true if modem status cannot be retrieved. For most cases,
1162 // modem status is on. And for older version modems, GET_MODEM_STATUS
1163 // and disable modem are not supported. Modem is always on.
1164 // TODO: this should be fixed in R to support a third
1165 // status UNKNOWN b/131631629
1166 request.result = true;
1167 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1168 + ar.exception);
1169 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001170 notifyRequester(request);
1171 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001172 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1173 ar = (AsyncResult) msg.obj;
1174 request = (MainThreadRequest) ar.userObj;
1175 if (ar.exception == null && ar.result != null) {
1176 request.result = ar.result;
1177 } else {
1178 request.result = -1;
1179 loge("Failed to set Forbidden Plmns");
1180 if (ar.result == null) {
1181 loge("setForbidenPlmns: Empty response");
1182 } else if (ar.exception != null) {
1183 loge("setForbiddenPlmns: Exception: " + ar.exception);
1184 request.result = -1;
1185 } else {
1186 loge("setForbiddenPlmns: Unknown exception");
1187 }
1188 }
1189 notifyRequester(request);
1190 break;
1191 case CMD_SET_FORBIDDEN_PLMNS:
1192 request = (MainThreadRequest) msg.obj;
1193 uiccCard = getUiccCardFromRequest(request);
1194 if (uiccCard == null) {
1195 loge("setForbiddenPlmns: UiccCard is null");
1196 request.result = -1;
1197 notifyRequester(request);
1198 break;
1199 }
1200 Pair<Integer, List<String>> setFplmnsArgs =
1201 (Pair<Integer, List<String>>) request.argument;
1202 appType = setFplmnsArgs.first;
1203 List<String> fplmns = setFplmnsArgs.second;
1204 uiccApp = uiccCard.getApplicationByType(appType);
1205 if (uiccApp == null) {
1206 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1207 request.result = -1;
1208 loge("Failed to get UICC App");
1209 notifyRequester(request);
1210 } else {
1211 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1212 ((SIMRecords) uiccApp.getIccRecords())
1213 .setForbiddenPlmns(onCompleted, fplmns);
1214 }
1215 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 default:
1217 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1218 break;
1219 }
1220 }
Jake Hambye994d462014-02-03 13:10:13 -08001221
Pengquan Menga1bb6272018-09-06 09:59:22 -07001222 private void notifyRequester(MainThreadRequest request) {
1223 synchronized (request) {
1224 request.notifyAll();
1225 }
1226 }
1227
Jake Hambye994d462014-02-03 13:10:13 -08001228 private void handleNullReturnEvent(Message msg, String command) {
1229 AsyncResult ar = (AsyncResult) msg.obj;
1230 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1231 if (ar.exception == null) {
1232 request.result = true;
1233 } else {
1234 request.result = false;
1235 if (ar.exception instanceof CommandException) {
1236 loge(command + ": CommandException: " + ar.exception);
1237 } else {
1238 loge(command + ": Unknown exception");
1239 }
1240 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001241 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001242 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 }
1244
1245 /**
1246 * Posts the specified command to be executed on the main thread,
1247 * waits for the request to complete, and returns the result.
1248 * @see #sendRequestAsync
1249 */
1250 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001251 return sendRequest(
1252 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001253 }
1254
1255 /**
1256 * Posts the specified command to be executed on the main thread,
1257 * waits for the request to complete, and returns the result.
1258 * @see #sendRequestAsync
1259 */
1260 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1261 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001262 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001263 }
1264
1265 /**
1266 * Posts the specified command to be executed on the main thread,
1267 * waits for the request to complete, and returns the result.
1268 * @see #sendRequestAsync
1269 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001270 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001271 return sendRequest(command, argument, subId, 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 */
Nathan Harold92bed182018-10-12 18:16:49 -07001279 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1280 return sendRequest(command, argument, subId, null, workSource);
1281 }
1282
1283 /**
1284 * Posts the specified command to be executed on the main thread,
1285 * waits for the request to complete, and returns the result.
1286 * @see #sendRequestAsync
1287 */
1288 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1289 return sendRequest(
1290 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1291 }
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 */
1298 private Object sendRequest(
1299 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1301 throw new RuntimeException("This method will deadlock if called from the main thread.");
1302 }
1303
Nathan Harold92bed182018-10-12 18:16:49 -07001304 MainThreadRequest request = null;
1305 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1306 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1307 } else if (phone != null) {
1308 request = new MainThreadRequest(argument, phone, workSource);
1309 } else {
1310 request = new MainThreadRequest(argument, subId, workSource);
1311 }
1312
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 Message msg = mMainThreadHandler.obtainMessage(command, request);
1314 msg.sendToTarget();
1315
1316 // Wait for the request to complete
1317 synchronized (request) {
1318 while (request.result == null) {
1319 try {
1320 request.wait();
1321 } catch (InterruptedException e) {
1322 // Do nothing, go back and wait until the request is complete
1323 }
1324 }
1325 }
1326 return request.result;
1327 }
1328
1329 /**
1330 * Asynchronous ("fire and forget") version of sendRequest():
1331 * Posts the specified command to be executed on the main thread, and
1332 * returns immediately.
1333 * @see #sendRequest
1334 */
1335 private void sendRequestAsync(int command) {
1336 mMainThreadHandler.sendEmptyMessage(command);
1337 }
1338
1339 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001340 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001341 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001342 */
1343 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001344 sendRequestAsync(command, argument, null, null);
1345 }
1346
1347 /**
1348 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1349 * @see {@link #sendRequest(int,Object)}
1350 */
1351 private void sendRequestAsync(
1352 int command, Object argument, Phone phone, WorkSource workSource) {
1353 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001354 Message msg = mMainThreadHandler.obtainMessage(command, request);
1355 msg.sendToTarget();
1356 }
1357
1358 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 * Initialize the singleton PhoneInterfaceManager instance.
1360 * This is only done once, at startup, from PhoneApp.onCreate().
1361 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001362 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 synchronized (PhoneInterfaceManager.class) {
1364 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001365 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001366 } else {
1367 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1368 }
1369 return sInstance;
1370 }
1371 }
1372
1373 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001374 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001377 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1379 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001380 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 mTelephonySharedPreferences =
1382 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001383 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001384 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 publish();
1387 }
1388
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001389 private Phone getDefaultPhone() {
1390 Phone thePhone = getPhone(getDefaultSubscription());
1391 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1392 }
1393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 private void publish() {
1395 if (DBG) log("publish: " + this);
1396
1397 ServiceManager.addService("phone", this);
1398 }
1399
Stuart Scott584921c2015-01-15 17:10:34 -08001400 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001401 if (request.phone != null) {
1402 return request.phone;
1403 } else {
1404 return getPhoneFromSubId(request.subId);
1405 }
1406 }
1407
1408 private Phone getPhoneFromSubId(int subId) {
1409 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1410 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001411 }
1412
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001413 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1414 Phone phone = getPhoneFromRequest(request);
1415 return phone == null ? null :
1416 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1417 }
1418
Wink Saville36469e72014-06-11 15:17:00 -07001419 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001420 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001421 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001423
1424 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001425 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001426 }
1427
Wink Savilleb564aae2014-10-23 10:18:09 -07001428 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429 if (DBG) log("dial: " + number);
1430 // No permission check needed here: This is just a wrapper around the
1431 // ACTION_DIAL intent, which is available to any app since it puts up
1432 // the UI before it does anything.
1433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001434 final long identity = Binder.clearCallingIdentity();
1435 try {
1436 String url = createTelUrl(number);
1437 if (url == null) {
1438 return;
1439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001441 // PENDING: should we just silently fail if phone is offhook or ringing?
1442 PhoneConstants.State state = mCM.getState(subId);
1443 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1444 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1445 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1446 mApp.startActivity(intent);
1447 }
1448 } finally {
1449 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 }
1451 }
1452
1453 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001455 }
1456
Wink Savilleb564aae2014-10-23 10:18:09 -07001457 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 if (DBG) log("call: " + number);
1459
1460 // This is just a wrapper around the ACTION_CALL intent, but we still
1461 // need to do a permission check since we're calling startActivity()
1462 // from the context of the phone app.
1463 enforceCallPermission();
1464
Jordan Liu1617b712019-07-10 15:06:26 -07001465 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 != AppOpsManager.MODE_ALLOWED) {
1467 return;
1468 }
1469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001470 final long identity = Binder.clearCallingIdentity();
1471 try {
1472 String url = createTelUrl(number);
1473 if (url == null) {
1474 return;
1475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001477 boolean isValid = false;
1478 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1479 if (slist != null) {
1480 for (SubscriptionInfo subInfoRecord : slist) {
1481 if (subInfoRecord.getSubscriptionId() == subId) {
1482 isValid = true;
1483 break;
1484 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001485 }
Wink Saville08874612014-08-31 19:19:58 -07001486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001487 if (!isValid) {
1488 return;
1489 }
Wink Saville08874612014-08-31 19:19:58 -07001490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001491 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1492 intent.putExtra(SUBSCRIPTION_KEY, subId);
1493 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1494 mApp.startActivity(intent);
1495 } finally {
1496 Binder.restoreCallingIdentity(identity);
1497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 }
1499
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001501 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001502 }
1503
Wink Savilleb564aae2014-10-23 10:18:09 -07001504 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001505 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001506 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1507 }
1508
1509 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001510 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001511 }
1512
Wink Savilleb564aae2014-10-23 10:18:09 -07001513 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001514 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001515 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1516 }
1517
1518 /** {@hide} */
1519 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001520 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001521 }
1522
Wink Savilleb564aae2014-10-23 10:18:09 -07001523 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001525
1526 final long identity = Binder.clearCallingIdentity();
1527 try {
1528 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1529 checkSimPin.start();
1530 return checkSimPin.unlockSim(null, pin);
1531 } finally {
1532 Binder.restoreCallingIdentity(identity);
1533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 }
1535
Wink Saville9de0f752013-10-22 19:04:03 -07001536 /** {@hide} */
1537 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001539 }
1540
Wink Savilleb564aae2014-10-23 10:18:09 -07001541 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001543
1544 final long identity = Binder.clearCallingIdentity();
1545 try {
1546 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1547 checkSimPuk.start();
1548 return checkSimPuk.unlockSim(puk, pin);
1549 } finally {
1550 Binder.restoreCallingIdentity(identity);
1551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 }
1553
1554 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001555 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 * a synchronous one.
1557 */
1558 private static class UnlockSim extends Thread {
1559
1560 private final IccCard mSimCard;
1561
1562 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001563 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1564 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565
1566 // For replies from SimCard interface
1567 private Handler mHandler;
1568
1569 // For async handler to identify request type
1570 private static final int SUPPLY_PIN_COMPLETE = 100;
1571
1572 public UnlockSim(IccCard simCard) {
1573 mSimCard = simCard;
1574 }
1575
1576 @Override
1577 public void run() {
1578 Looper.prepare();
1579 synchronized (UnlockSim.this) {
1580 mHandler = new Handler() {
1581 @Override
1582 public void handleMessage(Message msg) {
1583 AsyncResult ar = (AsyncResult) msg.obj;
1584 switch (msg.what) {
1585 case SUPPLY_PIN_COMPLETE:
1586 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1587 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001588 mRetryCount = msg.arg1;
1589 if (ar.exception != null) {
1590 if (ar.exception instanceof CommandException &&
1591 ((CommandException)(ar.exception)).getCommandError()
1592 == CommandException.Error.PASSWORD_INCORRECT) {
1593 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1594 } else {
1595 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1596 }
1597 } else {
1598 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 mDone = true;
1601 UnlockSim.this.notifyAll();
1602 }
1603 break;
1604 }
1605 }
1606 };
1607 UnlockSim.this.notifyAll();
1608 }
1609 Looper.loop();
1610 }
1611
1612 /*
1613 * Use PIN or PUK to unlock SIM card
1614 *
1615 * If PUK is null, unlock SIM card with PIN
1616 *
1617 * If PUK is not null, unlock SIM card with PUK and set PIN code
1618 */
Wink Saville9de0f752013-10-22 19:04:03 -07001619 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620
1621 while (mHandler == null) {
1622 try {
1623 wait();
1624 } catch (InterruptedException e) {
1625 Thread.currentThread().interrupt();
1626 }
1627 }
1628 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1629
1630 if (puk == null) {
1631 mSimCard.supplyPin(pin, callback);
1632 } else {
1633 mSimCard.supplyPuk(puk, pin, callback);
1634 }
1635
1636 while (!mDone) {
1637 try {
1638 Log.d(LOG_TAG, "wait for done");
1639 wait();
1640 } catch (InterruptedException e) {
1641 // Restore the interrupted status
1642 Thread.currentThread().interrupt();
1643 }
1644 }
1645 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001646 int[] resultArray = new int[2];
1647 resultArray[0] = mResult;
1648 resultArray[1] = mRetryCount;
1649 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
1651 }
1652
1653 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001654 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001655
1656 }
1657
Wink Savilleb564aae2014-10-23 10:18:09 -07001658 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 // No permission check needed here: this call is harmless, and it's
1660 // needed for the ServiceState.requestStateUpdate() call (which is
1661 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 final Phone phone = getPhone(subId);
1665 if (phone != null) {
1666 phone.updateServiceLocation();
1667 }
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 }
1672
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001673 @Override
1674 public boolean isRadioOn(String callingPackage) {
1675 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001676 }
1677
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001678 @Override
1679 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001680 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001681 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001682 return false;
1683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001684
1685 final long identity = Binder.clearCallingIdentity();
1686 try {
1687 return isRadioOnForSubscriber(subId);
1688 } finally {
1689 Binder.restoreCallingIdentity(identity);
1690 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001691 }
1692
1693 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone phone = getPhone(subId);
1697 if (phone != null) {
1698 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1699 } else {
1700 return false;
1701 }
1702 } finally {
1703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
1707 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001708 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 }
Wink Saville36469e72014-06-11 15:17:00 -07001710
Wink Savilleb564aae2014-10-23 10:18:09 -07001711 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1719 }
1720 } finally {
1721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 }
Wink Saville36469e72014-06-11 15:17:00 -07001723 }
1724
1725 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001726 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001727 }
1728
Wink Savilleb564aae2014-10-23 10:18:09 -07001729 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001730 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001731
1732 final long identity = Binder.clearCallingIdentity();
1733 try {
1734 final Phone phone = getPhone(subId);
1735 if (phone == null) {
1736 return false;
1737 }
1738 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1739 toggleRadioOnOffForSubscriber(subId);
1740 }
1741 return true;
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
Wink Saville36469e72014-06-11 15:17:00 -07001746
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001747 public boolean needMobileRadioShutdown() {
1748 /*
1749 * If any of the Radios are available, it will need to be
1750 * shutdown. So return true if any Radio is available.
1751 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752 final long identity = Binder.clearCallingIdentity();
1753 try {
1754 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1755 Phone phone = PhoneFactory.getPhone(i);
1756 if (phone != null && phone.isRadioAvailable()) return true;
1757 }
1758 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1759 return false;
1760 } finally {
1761 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001762 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001763 }
1764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001765 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001766 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 enforceModifyPermission();
1768
1769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1772 logv("Shutting down Phone " + i);
1773 shutdownRadioUsingPhoneId(i);
1774 }
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001777 }
1778 }
1779
1780 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001781 Phone phone = PhoneFactory.getPhone(phoneId);
1782 if (phone != null && phone.isRadioAvailable()) {
1783 phone.shutdownRadio();
1784 }
1785 }
1786
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001788 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001789
1790 final long identity = Binder.clearCallingIdentity();
1791 try {
1792 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1793 if (defaultPhone != null) {
1794 defaultPhone.setRadioPower(turnOn);
1795 return true;
1796 } else {
1797 loge("There's no default phone.");
1798 return false;
1799 }
1800 } finally {
1801 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001802 }
Wink Saville36469e72014-06-11 15:17:00 -07001803 }
1804
Wink Savilleb564aae2014-10-23 10:18:09 -07001805 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001807
1808 final long identity = Binder.clearCallingIdentity();
1809 try {
1810 final Phone phone = getPhone(subId);
1811 if (phone != null) {
1812 phone.setRadioPower(turnOn);
1813 return true;
1814 } else {
1815 return false;
1816 }
1817 } finally {
1818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 }
1821
Wink Saville36469e72014-06-11 15:17:00 -07001822 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 public boolean enableDataConnectivity() {
1825 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001826
1827 final long identity = Binder.clearCallingIdentity();
1828 try {
1829 int subId = mSubscriptionController.getDefaultDataSubId();
1830 final Phone phone = getPhone(subId);
1831 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001832 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833 return true;
1834 } else {
1835 return false;
1836 }
1837 } finally {
1838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 }
1841
Wink Saville36469e72014-06-11 15:17:00 -07001842 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001843 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 public boolean disableDataConnectivity() {
1845 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001846
1847 final long identity = Binder.clearCallingIdentity();
1848 try {
1849 int subId = mSubscriptionController.getDefaultDataSubId();
1850 final Phone phone = getPhone(subId);
1851 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001852 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001853 return true;
1854 } else {
1855 return false;
1856 }
1857 } finally {
1858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 }
1861
Sanket Padawe356d7632015-06-22 14:03:32 -07001862 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001863 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001864 final long identity = Binder.clearCallingIdentity();
1865 try {
1866 final Phone phone = getPhone(subId);
1867 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001868 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001869 } else {
1870 return false;
1871 }
1872 } finally {
1873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 }
1876
1877 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001878 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001879 }
1880
pkanwarae03a6b2016-11-06 20:37:09 -08001881 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001882 enforceCallPermission();
1883
1884 final long identity = Binder.clearCallingIdentity();
1885 try {
1886 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1887 return;
1888 }
1889 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1890 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1891 } finally {
1892 Binder.restoreCallingIdentity(identity);
1893 }
pkanwar32d516d2016-10-14 19:37:38 -07001894 };
1895
Wink Savilleb564aae2014-10-23 10:18:09 -07001896 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898
1899 final long identity = Binder.clearCallingIdentity();
1900 try {
1901 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1902 return false;
1903 }
1904 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1905 } finally {
1906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001911 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001912 }
1913
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001914 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001915 final long identity = Binder.clearCallingIdentity();
1916 try {
1917 Phone phone = PhoneFactory.getPhone(slotIndex);
1918 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1919 PhoneConstantConversions.convertCallState(phone.getState());
1920 } finally {
1921 Binder.restoreCallingIdentity(identity);
1922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 }
1924
Sanket Padawe356d7632015-06-22 14:03:32 -07001925 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001926 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001927 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1928 }
1929
1930 @Override
1931 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001932 final long identity = Binder.clearCallingIdentity();
1933 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001934 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001935 if (phone != null) {
1936 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1937 } else {
1938 return PhoneConstantConversions.convertDataState(
1939 PhoneConstants.DataState.DISCONNECTED);
1940 }
1941 } finally {
1942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 }
1945
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001947 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001948 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1949 }
1950
1951 @Override
1952 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001953 final long identity = Binder.clearCallingIdentity();
1954 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001955 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001956 if (phone != null) {
1957 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1958 } else {
1959 return TelephonyManager.DATA_ACTIVITY_NONE;
1960 }
1961 } finally {
1962 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964 }
1965
1966 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001967 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001968 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001969 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001970
1971 LocationAccessPolicy.LocationPermissionResult locationResult =
1972 LocationAccessPolicy.checkLocationPermission(mApp,
1973 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1974 .setCallingPackage(callingPackage)
1975 .setCallingPid(Binder.getCallingPid())
1976 .setCallingUid(Binder.getCallingUid())
1977 .setMethod("getCellLocation")
1978 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1979 .build());
1980 switch (locationResult) {
1981 case DENIED_HARD:
1982 throw new SecurityException("Not allowed to access cell location");
1983 case DENIED_SOFT:
1984 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 }
1986
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001987 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988 final long identity = Binder.clearCallingIdentity();
1989 try {
1990 if (DBG_LOC) log("getCellLocation: is active user");
1991 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001992 int subId = mSubscriptionController.getDefaultDataSubId();
1993 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1994 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001995 return data;
1996 } finally {
1997 Binder.restoreCallingIdentity(identity);
1998 }
Svetoslav64fad262015-04-14 14:35:21 -07001999 }
2000
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002002 public String getNetworkCountryIsoForPhone(int phoneId) {
2003 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2004 // registered cell info, so return a NULL country instead.
2005 final long identity = Binder.clearCallingIdentity();
2006 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002007 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2008 // Get default phone in this case.
2009 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2010 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002011 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002012 // Todo: fix this when we can get the actual cellular network info when the device
2013 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002014 if (TelephonyManager.NETWORK_TYPE_IWLAN
2015 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2016 return "";
2017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002018 Phone phone = PhoneFactory.getPhone(phoneId);
2019 if (phone != null) {
2020 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002021 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022 if (sst != null) {
2023 LocaleTracker lt = sst.getLocaleTracker();
2024 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002025 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2026 return lt.getCurrentCountry();
2027 } else if (emergencyNumberTracker != null) {
2028 return emergencyNumberTracker.getEmergencyCountryIso();
2029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030 }
2031 }
2032 }
2033 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002034 } finally {
2035 Binder.restoreCallingIdentity(identity);
2036 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002037 }
2038
2039 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002041 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002042 }
2043
Sanket Padawe356d7632015-06-22 14:03:32 -07002044 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002045 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 mApp.enforceCallingOrSelfPermission(
2047 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002048
2049 final long identity = Binder.clearCallingIdentity();
2050 try {
2051 final Phone phone = getPhone(subId);
2052 if (phone != null) {
2053 phone.enableLocationUpdates();
2054 }
2055 } finally {
2056 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 }
2059
2060 @Override
2061 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002062 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002063 }
2064
Sanket Padawe356d7632015-06-22 14:03:32 -07002065 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002066 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 mApp.enforceCallingOrSelfPermission(
2068 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002069
2070 final long identity = Binder.clearCallingIdentity();
2071 try {
2072 final Phone phone = getPhone(subId);
2073 if (phone != null) {
2074 phone.disableLocationUpdates();
2075 }
2076 } finally {
2077 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 }
2080
Nathan Harold31d7ff32018-10-15 20:20:30 -07002081 /**
2082 * Returns the target SDK version number for a given package name.
2083 *
Nathan Haroldec184742019-07-10 17:04:16 -07002084 * This call MUST be invoked before clearing the calling UID.
2085 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002086 * @return target SDK if the package is found or INT_MAX.
2087 */
2088 private int getTargetSdk(String packageName) {
2089 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002090 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002091 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002092 if (ai != null) return ai.targetSdkVersion;
2093 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002094 loge("Failed to get package info for pkg="
2095 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002096 }
2097 return Integer.MAX_VALUE;
2098 }
2099
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 @Override
2101 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002102 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2103 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002104 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2105 throw new SecurityException(
2106 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2107 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002108
Jordan Liu1617b712019-07-10 15:06:26 -07002109 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2111 return null;
2112 }
Svetoslav64fad262015-04-14 14:35:21 -07002113
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002114 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115
Nathan Haroldf180aac2018-06-01 18:43:55 -07002116 List<CellInfo> info = getAllCellInfo(callingPackage);
2117 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118
Nathan Haroldf180aac2018-06-01 18:43:55 -07002119 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2120 for (CellInfo ci : info) {
2121 if (ci instanceof CellInfoGsm) {
2122 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2123 } else if (ci instanceof CellInfoWcdma) {
2124 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002127 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
2129
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002130 private List<CellInfo> getCachedCellInfo() {
2131 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2132 for (Phone phone : PhoneFactory.getPhones()) {
2133 List<CellInfo> info = phone.getAllCellInfo();
2134 if (info != null) cellInfos.addAll(info);
2135 }
2136 return cellInfos;
2137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138
2139 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002140 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002141 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002142 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002143
2144 LocationAccessPolicy.LocationPermissionResult locationResult =
2145 LocationAccessPolicy.checkLocationPermission(mApp,
2146 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2147 .setCallingPackage(callingPackage)
2148 .setCallingPid(Binder.getCallingPid())
2149 .setCallingUid(Binder.getCallingUid())
2150 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002151 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002152 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2153 .build());
2154 switch (locationResult) {
2155 case DENIED_HARD:
2156 throw new SecurityException("Not allowed to access cell info");
2157 case DENIED_SOFT:
2158 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
2160
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002161 final int targetSdk = getTargetSdk(callingPackage);
2162 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2163 return getCachedCellInfo();
2164 }
2165
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002166 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002167 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002168 final long identity = Binder.clearCallingIdentity();
2169 try {
2170 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2171 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002172 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002173 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174 if (info != null) cellInfos.addAll(info);
2175 }
2176 return cellInfos;
2177 } finally {
2178 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 }
2180 }
2181
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002182 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002183 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2184 requestCellInfoUpdateInternal(
2185 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2186 }
2187
2188 @Override
2189 public void requestCellInfoUpdateWithWorkSource(
2190 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2191 enforceModifyPermission();
2192 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2193 }
2194
2195 private void requestCellInfoUpdateInternal(
2196 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002197 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002198 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002199
2200 LocationAccessPolicy.LocationPermissionResult locationResult =
2201 LocationAccessPolicy.checkLocationPermission(mApp,
2202 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2203 .setCallingPackage(callingPackage)
2204 .setCallingPid(Binder.getCallingPid())
2205 .setCallingUid(Binder.getCallingUid())
2206 .setMethod("requestCellInfoUpdate")
2207 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2208 .build());
2209 switch (locationResult) {
2210 case DENIED_HARD:
2211 throw new SecurityException("Not allowed to access cell info");
2212 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002213 try {
2214 cb.onCellInfo(new ArrayList<CellInfo>());
2215 } catch (RemoteException re) {
2216 // Drop without consequences
2217 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002218 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002219 }
2220
Nathan Harolda939a962019-05-09 10:13:47 -07002221
2222 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002223 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2224
2225 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2226 }
2227
2228 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002230 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002231 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232
2233 final long identity = Binder.clearCallingIdentity();
2234 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002235 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002236 } finally {
2237 Binder.restoreCallingIdentity(identity);
2238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
Shishir Agrawala9f32182016-04-12 12:00:16 -07002241 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002242 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002243 Phone phone = PhoneFactory.getPhone(slotIndex);
2244 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002245 return null;
2246 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002247 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002248 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2249 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002250 return null;
2251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002252
2253 final long identity = Binder.clearCallingIdentity();
2254 try {
2255 return phone.getImei();
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
2258 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002259 }
2260
2261 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002262 public String getTypeAllocationCodeForSlot(int slotIndex) {
2263 Phone phone = PhoneFactory.getPhone(slotIndex);
2264 String tac = null;
2265 if (phone != null) {
2266 String imei = phone.getImei();
2267 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2268 }
2269 return tac;
2270 }
2271
2272 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002273 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002274 Phone phone = PhoneFactory.getPhone(slotIndex);
2275 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002276 return null;
2277 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002278
Jeff Davidson913390f2018-02-23 17:11:49 -08002279 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002280 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2281 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002282 return null;
2283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284
2285 final long identity = Binder.clearCallingIdentity();
2286 try {
2287 return phone.getMeid();
2288 } finally {
2289 Binder.restoreCallingIdentity(identity);
2290 }
Jack Yu2af8d712017-03-15 17:14:14 -07002291 }
2292
2293 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002294 public String getManufacturerCodeForSlot(int slotIndex) {
2295 Phone phone = PhoneFactory.getPhone(slotIndex);
2296 String manufacturerCode = null;
2297 if (phone != null) {
2298 String meid = phone.getMeid();
2299 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2300 }
2301 return manufacturerCode;
2302 }
2303
2304 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002305 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002306 Phone phone = PhoneFactory.getPhone(slotIndex);
2307 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002308 return null;
2309 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002310 int subId = phone.getSubId();
2311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2312 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2313 return null;
2314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002315
2316 final long identity = Binder.clearCallingIdentity();
2317 try {
2318 return phone.getDeviceSvn();
2319 } finally {
2320 Binder.restoreCallingIdentity(identity);
2321 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002322 }
2323
fionaxu43304da2017-11-27 22:51:16 -08002324 @Override
2325 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326 final long identity = Binder.clearCallingIdentity();
2327 try {
2328 final Phone phone = getPhone(subId);
2329 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
fionaxu43304da2017-11-27 22:51:16 -08002333 }
2334
2335 @Override
2336 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002337 final long identity = Binder.clearCallingIdentity();
2338 try {
2339 final Phone phone = getPhone(subId);
2340 return phone == null ? null : phone.getCarrierName();
2341 } finally {
2342 Binder.restoreCallingIdentity(identity);
2343 }
fionaxu43304da2017-11-27 22:51:16 -08002344 }
2345
calvinpanffe225e2018-11-01 19:43:06 +08002346 @Override
chen xu0026ca62019-03-06 15:28:50 -08002347 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 final Phone phone = getPhone(subId);
2351 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002352 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002353 } finally {
2354 Binder.restoreCallingIdentity(identity);
2355 }
2356 }
2357
2358 @Override
chen xu0026ca62019-03-06 15:28:50 -08002359 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002363 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002364 } finally {
2365 Binder.restoreCallingIdentity(identity);
2366 }
2367 }
2368
chen xu651eec72018-11-11 19:03:44 -08002369 @Override
chen xu864e11c2018-12-06 22:10:03 -08002370 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2371 if (!isSubscriptionMccMnc) {
2372 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2373 }
chen xu651eec72018-11-11 19:03:44 -08002374 final Phone phone = PhoneFactory.getPhone(slotIndex);
2375 if (phone == null) {
2376 return TelephonyManager.UNKNOWN_CARRIER_ID;
2377 }
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
2383 }
2384 }
2385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 //
2387 // Internal helper methods.
2388 //
2389
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002390 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2392 *
2393 * @throws SecurityException if the caller does not have the required permission
2394 */
2395 private void enforceModifyPermission() {
2396 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2397 }
2398
2399 /**
2400 * Make sure the caller has the CALL_PHONE permission.
2401 *
2402 * @throws SecurityException if the caller does not have the required permission
2403 */
2404 private void enforceCallPermission() {
2405 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2406 }
2407
Stuart Scott8eef64f2015-04-08 15:13:54 -07002408 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002409 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002410 "ConnectivityService");
2411 }
2412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 private String createTelUrl(String number) {
2414 if (TextUtils.isEmpty(number)) {
2415 return null;
2416 }
2417
Jake Hambye994d462014-02-03 13:10:13 -08002418 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
2420
Ihab Awadf9e92732013-12-05 18:02:52 -08002421 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2423 }
2424
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002425 private static void logv(String msg) {
2426 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2427 }
2428
Ihab Awadf9e92732013-12-05 18:02:52 -08002429 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2431 }
2432
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002433 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002435 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002436 }
2437
Sanket Padawe356d7632015-06-22 14:03:32 -07002438 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002439 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 final Phone phone = PhoneFactory.getPhone(slotIndex);
2443 if (phone == null) {
2444 return PhoneConstants.PHONE_TYPE_NONE;
2445 } else {
2446 return phone.getPhoneType();
2447 }
2448 } finally {
2449 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 }
2452
2453 /**
2454 * Returns the CDMA ERI icon index to display
2455 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002456 @Override
2457 public int getCdmaEriIconIndex(String callingPackage) {
2458 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002459 }
2460
Sanket Padawe356d7632015-06-22 14:03:32 -07002461 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002462 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002464 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002465 return -1;
2466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467
2468 final long identity = Binder.clearCallingIdentity();
2469 try {
2470 final Phone phone = getPhone(subId);
2471 if (phone != null) {
2472 return phone.getCdmaEriIconIndex();
2473 } else {
2474 return -1;
2475 }
2476 } finally {
2477 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 }
2480
2481 /**
2482 * Returns the CDMA ERI icon mode,
2483 * 0 - ON
2484 * 1 - FLASHING
2485 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002486 @Override
2487 public int getCdmaEriIconMode(String callingPackage) {
2488 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002489 }
2490
Sanket Padawe356d7632015-06-22 14:03:32 -07002491 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002492 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002494 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002495 return -1;
2496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497
2498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 final Phone phone = getPhone(subId);
2501 if (phone != null) {
2502 return phone.getCdmaEriIconMode();
2503 } else {
2504 return -1;
2505 }
2506 } finally {
2507 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 }
2510
2511 /**
2512 * Returns the CDMA ERI text,
2513 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002514 @Override
2515 public String getCdmaEriText(String callingPackage) {
2516 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002517 }
2518
Sanket Padawe356d7632015-06-22 14:03:32 -07002519 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002520 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002521 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002522 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002523 return null;
2524 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002525
2526 final long identity = Binder.clearCallingIdentity();
2527 try {
2528 final Phone phone = getPhone(subId);
2529 if (phone != null) {
2530 return phone.getCdmaEriText();
2531 } else {
2532 return null;
2533 }
2534 } finally {
2535 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 }
2538
2539 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002540 * Returns the CDMA MDN.
2541 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002542 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002543 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2545 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002546
2547 final long identity = Binder.clearCallingIdentity();
2548 try {
2549 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002550 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002551 return phone.getLine1Number();
2552 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002553 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554 return null;
2555 }
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002558 }
2559 }
2560
2561 /**
2562 * Returns the CDMA MIN.
2563 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002564 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002565 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2567 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 final Phone phone = getPhone(subId);
2572 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2573 return phone.getCdmaMin();
2574 } else {
2575 return null;
2576 }
2577 } finally {
2578 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002579 }
2580 }
2581
Hall Liud892bec2018-11-30 14:51:45 -08002582 @Override
2583 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2584 INumberVerificationCallback callback, String callingPackage) {
2585 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2586 != PERMISSION_GRANTED) {
2587 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2588 }
2589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2590
2591 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2592 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2593 throw new SecurityException("Calling package must be configured in the device config");
2594 }
2595
2596 if (range == null) {
2597 throw new NullPointerException("Range must be non-null");
2598 }
2599
2600 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002601 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002602
2603 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2604 }
2605
Junda Liuca05d5d2014-08-14 22:36:34 -07002606 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002607 * Returns true if CDMA provisioning needs to run.
2608 */
2609 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 final long identity = Binder.clearCallingIdentity();
2611 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002612 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 } finally {
2614 Binder.restoreCallingIdentity(identity);
2615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 }
2617
2618 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002619 * Sets the voice mail number of a given subId.
2620 */
2621 @Override
2622 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002623 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624
2625 final long identity = Binder.clearCallingIdentity();
2626 try {
2627 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2628 new Pair<String, String>(alphaTag, number), new Integer(subId));
2629 return success;
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
2632 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002633 }
2634
Ta-wei Yen87c49842016-05-13 21:19:52 -07002635 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002636 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2637 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002638 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002639 if (!TextUtils.equals(callingPackage, systemDialer)) {
2640 throw new SecurityException("caller must be system dialer");
2641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642
2643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2646 if (phoneAccountHandle == null) {
2647 return null;
2648 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002649 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 } finally {
2651 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002652 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002653 }
2654
2655 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002656 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002658 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002659 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002660 return null;
2661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002663 final long identity = Binder.clearCallingIdentity();
2664 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002665 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002669 }
2670
2671 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002672 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2673 VisualVoicemailSmsFilterSettings settings) {
2674 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675
2676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002679 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680 } finally {
2681 Binder.restoreCallingIdentity(identity);
2682 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002683 }
2684
2685 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002686 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2687 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002692 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 } finally {
2694 Binder.restoreCallingIdentity(identity);
2695 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002696 }
2697
2698 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002699 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2700 String callingPackage, int subId) {
2701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002706 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707 } finally {
2708 Binder.restoreCallingIdentity(identity);
2709 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002710 }
2711
2712 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002713 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002714 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715
2716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002719 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 } finally {
2721 Binder.restoreCallingIdentity(identity);
2722 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002723 }
2724
2725 @Override
2726 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2727 String number, int port, String text, PendingIntent sentIntent) {
2728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002729 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002730 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002731 SmsController smsController = PhoneFactory.getSmsController();
2732 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2733 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002734 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002735
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002736 /**
fionaxu0152e512016-11-14 13:36:14 -08002737 * Sets the voice activation state of a given subId.
2738 */
2739 @Override
2740 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2742 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743
2744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 final Phone phone = getPhone(subId);
2747 if (phone != null) {
2748 phone.setVoiceActivationState(activationState);
2749 } else {
2750 loge("setVoiceActivationState fails with invalid subId: " + subId);
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002754 }
2755 }
2756
2757 /**
2758 * Sets the data activation state of a given subId.
2759 */
2760 @Override
2761 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2763 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 final Phone phone = getPhone(subId);
2768 if (phone != null) {
2769 phone.setDataActivationState(activationState);
2770 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002771 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 }
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002775 }
2776 }
2777
2778 /**
2779 * Returns the voice activation state of a given subId.
2780 */
2781 @Override
2782 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002783 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784
fionaxu0152e512016-11-14 13:36:14 -08002785 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 if (phone != null) {
2789 return phone.getVoiceActivationState();
2790 } else {
2791 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2792 }
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002795 }
2796 }
2797
2798 /**
2799 * Returns the data activation state of a given subId.
2800 */
2801 @Override
2802 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002803 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804
fionaxu0152e512016-11-14 13:36:14 -08002805 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 if (phone != null) {
2809 return phone.getDataActivationState();
2810 } else {
2811 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2812 }
2813 } finally {
2814 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002815 }
2816 }
2817
2818 /**
Wink Saville36469e72014-06-11 15:17:00 -07002819 * Returns the unread count of voicemails for a subId
2820 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002822 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2824 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2825 return 0;
2826 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
2830 if (phone != null) {
2831 return phone.getVoiceMessageCount();
2832 } else {
2833 return 0;
2834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 }
2839
2840 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002841 * returns true, if the device is in a state where both voice and data
2842 * are supported simultaneously. This can change based on location or network condition.
2843 */
2844 @Override
2845 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 final Phone phone = getPhone(subId);
2849 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
2852 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002853 }
2854
2855 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002856 * Send the dialer code if called from the current default dialer or the caller has
2857 * carrier privilege.
2858 * @param inputCode The dialer code to send
2859 */
2860 @Override
2861 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002862 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002863 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2865 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002866 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002867 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2868 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002873 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874 } finally {
2875 Binder.restoreCallingIdentity(identity);
2876 }
fionaxu235cc5e2017-03-06 22:25:57 -08002877 }
2878
Pengquan Menga1bb6272018-09-06 09:59:22 -07002879 @Override
2880 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002881 if (!isActiveSubscription(subId)) {
2882 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2883 }
2884
Pengquan Menga1bb6272018-09-06 09:59:22 -07002885 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2886 }
2887
Brad Ebinger35c841c2018-10-01 10:40:55 -07002888 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002889 public boolean isInEmergencySmsMode() {
2890 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 for (Phone phone : PhoneFactory.getPhones()) {
2894 if (phone.isInEmergencySmsMode()) {
2895 return true;
2896 }
2897 }
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
2900 }
2901 return false;
2902 }
2903
2904 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002905 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2906 throws RemoteException {
2907 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002908 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2909 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2910 "IMS not available on device.");
2911 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002912 final long token = Binder.clearCallingIdentity();
2913 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002915 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002916 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002917 } catch (ImsException e) {
2918 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002919 } finally {
2920 Binder.restoreCallingIdentity(token);
2921 }
2922 }
2923
2924 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002925 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2926 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2928 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2929 }
2930 Binder.withCleanCallingIdentity(() -> {
2931 try {
2932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002933 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002934 .removeRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002935 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002936 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2937 + "is inactive, ignoring unregister.");
2938 // If the subscription is no longer active, just return, since the callback
2939 // will already have been removed internally.
2940 }
2941 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002942 }
2943
Brad Ebinger774ba362019-10-22 17:36:18 -07002944 /**
2945 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2946 */
2947 @Override
2948 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2949 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2950 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2951 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2952 "IMS not available on device.");
2953 }
2954 final long token = Binder.clearCallingIdentity();
2955 try {
2956 Phone phone = getPhone(subId);
2957 if (phone == null) {
2958 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2959 + subId + "'");
2960 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2961 }
2962 phone.getImsRegistrationState(regState -> {
2963 try {
2964 consumer.accept((regState == null)
2965 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
2966 } catch (RemoteException e) {
2967 // Ignore if the remote process is no longer available to call back.
2968 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
2969 }
2970 });
2971 } finally {
2972 Binder.restoreCallingIdentity(token);
2973 }
2974 }
2975
2976 /**
2977 * Get the transport type for the IMS service registration state.
2978 */
2979 @Override
2980 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
2981 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
2982 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2983 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2984 "IMS not available on device.");
2985 }
2986 final long token = Binder.clearCallingIdentity();
2987 try {
2988 Phone phone = getPhone(subId);
2989 if (phone == null) {
2990 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2991 + subId + "'");
2992 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2993 }
2994 phone.getImsRegistrationTech(regTech -> {
2995 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
2996 int regTechConverted = (regTech == null)
2997 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
2998 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
2999 regTechConverted);
3000 try {
3001 consumer.accept(regTechConverted);
3002 } catch (RemoteException e) {
3003 // Ignore if the remote process is no longer available to call back.
3004 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3005 }
3006 });
3007 } finally {
3008 Binder.restoreCallingIdentity(token);
3009 }
3010 }
3011
Brad Ebinger35c841c2018-10-01 10:40:55 -07003012 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003013 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3014 throws RemoteException {
3015 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003016 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3017 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3018 "IMS not available on device.");
3019 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003020 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3021 final long token = Binder.clearCallingIdentity();
3022 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003023 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003025 } catch (ImsException e) {
3026 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003027 } finally {
3028 Binder.restoreCallingIdentity(token);
3029 }
3030 }
3031
3032 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003033 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3034 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003035
3036 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3037 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3038 }
3039 Binder.withCleanCallingIdentity(() -> {
3040 try {
3041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003042 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003043 .removeCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003044 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003045 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3046 + "is inactive, ignoring unregister.");
3047 // If the subscription is no longer active, just return, since the callback
3048 // will already have been removed internally.
3049 }
3050 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07003051 }
3052
3053 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003054 public boolean isCapable(int subId, int capability, int regTech) {
3055 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003056 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3057 final long token = Binder.clearCallingIdentity();
3058 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003059 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003060 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003061 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3063 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003064 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003065 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3066 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003067 } finally {
3068 Binder.restoreCallingIdentity(token);
3069 }
3070 }
3071
3072 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003073 public boolean isAvailable(int subId, int capability, int regTech) {
3074 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003075 final long token = Binder.clearCallingIdentity();
3076 try {
3077 Phone phone = getPhone(subId);
3078 if (phone == null) return false;
3079 return phone.isImsCapabilityAvailable(capability, regTech);
3080 } finally {
3081 Binder.restoreCallingIdentity(token);
3082 }
3083 }
3084
Brad Ebinger77b832e2019-10-17 17:03:22 -07003085 /**
3086 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3087 * subscription.
3088 * @param subId The subscription to use to check the configuration.
3089 * @param callback The callback that will be used to send the result.
3090 * @param capability The MmTelFeature capability that will be used to send the result.
3091 * @param transportType The transport type of the MmTelFeature capability.
3092 */
3093 @Override
3094 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3095 int transportType) {
3096 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3097 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3098 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3099 "IMS not available on device.");
3100 }
3101 final long token = Binder.clearCallingIdentity();
3102 try {
3103 int slotId = getSlotIndex(subId);
3104 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3105 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3106 + subId + "'");
3107 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3108 }
3109 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3110 transportType, aBoolean -> {
3111 try {
3112 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3113 } catch (RemoteException e) {
3114 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3115 + "running. Ignore");
3116 }
3117 });
3118 } finally {
3119 Binder.restoreCallingIdentity(token);
3120 }
3121 }
3122
Brad Ebinger35c841c2018-10-01 10:40:55 -07003123 @Override
3124 public boolean isAdvancedCallingSettingEnabled(int subId) {
3125 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3126 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3127 final long token = Binder.clearCallingIdentity();
3128 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003129 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003130 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003131 } catch (ImsException e) {
3132 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 } finally {
3134 Binder.restoreCallingIdentity(token);
3135 }
3136 }
3137
3138 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003139 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003141 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 final long identity = Binder.clearCallingIdentity();
3143 try {
3144 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003145 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003146 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003147 } catch (ImsException e) {
3148 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003149 } finally {
3150 Binder.restoreCallingIdentity(identity);
3151 }
3152 }
3153
3154 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003155 public boolean isVtSettingEnabled(int subId) {
3156 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003160 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3161 } catch (ImsException e) {
3162 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
3166 }
3167
3168 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003169 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003171 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003172 final long identity = Binder.clearCallingIdentity();
3173 try {
3174 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003175 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003176 } catch (ImsException e) {
3177 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003178 } finally {
3179 Binder.restoreCallingIdentity(identity);
3180 }
3181 }
3182
3183 @Override
3184 public boolean isVoWiFiSettingEnabled(int subId) {
3185 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003189 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003190 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003191 } catch (ImsException e) {
3192 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
3196 }
3197
3198 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003199 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003201 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003205 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003206 } catch (ImsException e) {
3207 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003208 } finally {
3209 Binder.restoreCallingIdentity(identity);
3210 }
3211 }
3212
3213 @Override
3214 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3215 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003219 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003220 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003221 } catch (ImsException e) {
3222 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003223 } finally {
3224 Binder.restoreCallingIdentity(identity);
3225 }
3226 }
3227
3228 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003229 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003231 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003235 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003237 } catch (ImsException e) {
3238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
3242 }
3243
3244 @Override
3245 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3247 "setVoWiFiNonPersistent");
3248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003251 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003252 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003253 } catch (ImsException e) {
3254 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 } finally {
3256 Binder.restoreCallingIdentity(identity);
3257 }
3258 }
3259
3260 @Override
3261 public int getVoWiFiModeSetting(int subId) {
3262 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003266 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003268 } catch (ImsException e) {
3269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 } finally {
3271 Binder.restoreCallingIdentity(identity);
3272 }
3273 }
3274
3275 @Override
3276 public void setVoWiFiModeSetting(int subId, int mode) {
3277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3278 "setVoWiFiModeSetting");
3279 final long identity = Binder.clearCallingIdentity();
3280 try {
3281 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003282 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003284 } catch (ImsException e) {
3285 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
3289 }
3290
3291 @Override
3292 public int getVoWiFiRoamingModeSetting(int subId) {
3293 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003297 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003299 } catch (ImsException e) {
3300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
3304 }
3305
3306 @Override
3307 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3309 "setVoWiFiRoamingModeSetting");
3310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003313 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003314 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003315 } catch (ImsException e) {
3316 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
3320 }
3321
3322 @Override
3323 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3325 "setRttCapabilityEnabled");
3326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003329 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3330 } catch (ImsException e) {
3331 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003332 } finally {
3333 Binder.restoreCallingIdentity(identity);
3334 }
3335 }
3336
3337 @Override
3338 public boolean isTtyOverVolteEnabled(int subId) {
3339 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003343 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003344 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003345 } catch (ImsException e) {
3346 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
3350 }
3351
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003352 @Override
3353 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3354 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003358 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003359 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003360 } catch (ImsException e) {
3361 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
3365 }
3366
3367 @Override
3368 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3369 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3370 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003371 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3372 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3373 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003374 try {
3375 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003376 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003377 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003378 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003379 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3380 + "is inactive, ignoring unregister.");
3381 // If the subscription is no longer active, just return, since the callback will already
3382 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
3386 }
3387
3388 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003389 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3390 boolean isProvisioned) {
3391 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3392 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3393 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3394 }
3395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3396 "setProvisioningStatusForCapability");
3397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3400 Phone phone = getPhone(subId);
3401 if (phone == null) {
3402 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3403 + subId);
3404 return;
3405 }
3406 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3407 return;
3408 }
3409
3410 // this capability requires provisioning, route to the correct API.
3411 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3412 switch (capability) {
3413 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3414 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3415 ims.setVolteProvisioned(isProvisioned);
3416 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3417 ims.setWfcProvisioned(isProvisioned);
3418 }
3419 break;
3420 }
3421 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3422 // There is currently no difference in VT provisioning type.
3423 ims.setVtProvisioned(isProvisioned);
3424 break;
3425 }
3426 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3427 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3428 // change the capability of the feature instead if needed.
3429 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3430 == isProvisioned) {
3431 // No change in provisioning.
3432 return;
3433 }
3434 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3435 try {
3436 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003437 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003438 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3439 + ", Exception" + e.getMessage());
3440 }
3441 break;
3442 }
3443 default: {
3444 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3445 + capability + "', which does not require provisioning.");
3446 }
3447 }
3448
3449 } finally {
3450 Binder.restoreCallingIdentity(identity);
3451 }
3452 }
3453
3454 @Override
3455 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3456 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3457 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3458 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3459 }
3460 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3464 Phone phone = getPhone(subId);
3465 if (phone == null) {
3466 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3467 + subId);
3468 // We will fail with "true" as the provisioning status because this is the default
3469 // if we do not require provisioning.
3470 return true;
3471 }
3472
3473 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3474 return true;
3475 }
3476
3477 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3478 switch (capability) {
3479 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3480 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3481 return ims.isVolteProvisionedOnDevice();
3482 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3483 return ims.isWfcProvisionedOnDevice();
3484 }
3485 // This should never happen, since we are checking tech above to make sure it
3486 // is either LTE or IWLAN.
3487 throw new IllegalArgumentException("Invalid radio technology for voice "
3488 + "capability.");
3489 }
3490 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3491 // There is currently no difference in VT provisioning type.
3492 return ims.isVtProvisionedOnDevice();
3493 }
3494 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3495 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3496 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3497 }
3498 default: {
3499 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3500 + capability + "', which does not require provisioning.");
3501 }
3502 }
3503
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
3506 }
3507 }
3508
3509 @Override
3510 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3511 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3512 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3513 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3514 }
3515 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3516 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3517 return (provisionedBits & capability) > 0;
3518 }
3519
3520 @Override
3521 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3522 boolean isProvisioned) {
3523 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3524 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3525 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3526 }
3527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3528 "setProvisioningStatusForCapability");
3529 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3530 // If the current provisioning status for capability already matches isProvisioned,
3531 // do nothing.
3532 if (((provisionedBits & capability) > 0) == isProvisioned) {
3533 return;
3534 }
3535 if (isProvisioned) {
3536 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3537 } else {
3538 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3539 }
3540 }
3541
3542 /**
3543 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3544 * technology. The bitfield should mirror the bitfield defined by
3545 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3546 */
3547 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3548 String key = getMmTelProvisioningKey(subId, tech);
3549 // Default is no capabilities are provisioned.
3550 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3551 }
3552
3553 /**
3554 * Sets the MmTel capability provisioning bitfield (defined by
3555 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3556 * technology specified.
3557 *
3558 * Note: This is a synchronous command and should not be called on UI thread.
3559 */
3560 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3561 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3562 String key = getMmTelProvisioningKey(subId, tech);
3563 editor.putInt(key, newField);
3564 editor.commit();
3565 }
3566
3567 private static String getMmTelProvisioningKey(int subId, int tech) {
3568 // resulting key is provision_ims_mmtel_{subId}_{tech}
3569 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3570 }
3571
3572 /**
3573 * Query CarrierConfig to see if the specified capability requires provisioning for the
3574 * carrier associated with the subscription id.
3575 */
3576 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3577 int capability) {
3578 CarrierConfigManager configManager = new CarrierConfigManager(context);
3579 PersistableBundle c = configManager.getConfigForSubId(subId);
3580 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003581 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003582 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3583 false);
3584 boolean requireVoiceVtProvisioning = c.getBoolean(
3585 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3586
3587 // First check to make sure that the capability requires provisioning.
3588 switch (capability) {
3589 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3590 // intentional fallthrough
3591 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3592 if (requireVoiceVtProvisioning) {
3593 // Voice and Video requires provisioning
3594 return true;
3595 }
3596 break;
3597 }
3598 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3599 if (requireUtProvisioning) {
3600 // UT requires provisioning
3601 return true;
3602 }
3603 break;
3604 }
3605 }
3606 return false;
3607 }
3608
3609 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003610 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003611 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3612 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3613 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003614 enforceReadPrivilegedPermission("getImsProvisioningInt");
3615 final long identity = Binder.clearCallingIdentity();
3616 try {
3617 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003618 int slotId = getSlotIndex(subId);
3619 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3620 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3621 + subId + "' for key:" + key);
3622 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3623 }
3624 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003625 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003626 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3627 + subId + "' for key:" + key);
3628 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
3632 }
3633
3634 @Override
3635 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003636 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3637 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3638 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003639 enforceReadPrivilegedPermission("getImsProvisioningString");
3640 final long identity = Binder.clearCallingIdentity();
3641 try {
3642 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003643 int slotId = getSlotIndex(subId);
3644 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3645 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3646 + subId + "' for key:" + key);
3647 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3648 }
3649 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003650 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003651 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3652 + subId + "' for key:" + key);
3653 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
3657 }
3658
3659 @Override
3660 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003661 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3662 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3663 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3665 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003669 int slotId = getSlotIndex(subId);
3670 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3671 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3672 + subId + "' for key:" + key);
3673 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3674 }
3675 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003676 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003677 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3678 + "' for key:" + key);
3679 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
3684
3685 @Override
3686 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003687 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3688 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3689 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3691 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003692 final long identity = Binder.clearCallingIdentity();
3693 try {
3694 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003695 int slotId = getSlotIndex(subId);
3696 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3697 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3698 + subId + "' for key:" + key);
3699 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3700 }
3701 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003702 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003703 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3704 + "' for key:" + key);
3705 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
3709 }
3710
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003711 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 int slotId = SubscriptionManager.getSlotIndex(subId);
3713 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003714 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3715 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003716 }
3717 return slotId;
3718 }
3719
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003720 private int getSlotIndex(int subId) {
3721 int slotId = SubscriptionManager.getSlotIndex(subId);
3722 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3723 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3724 }
3725 return slotId;
3726 }
3727
Wink Saville36469e72014-06-11 15:17:00 -07003728 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003729 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003730 */
3731 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003732 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003733 final int targetSdk = getTargetSdk(callingPackage);
3734 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3735 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3736 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003737 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3738 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003739 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3740 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 final Phone phone = getPhone(subId);
3745 if (phone != null) {
3746 return phone.getServiceState().getDataNetworkType();
3747 } else {
3748 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3749 }
3750 } finally {
3751 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003752 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003753 }
3754
3755 /**
3756 * Returns the data network type
3757 */
3758 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003759 public int getDataNetworkType(String callingPackage) {
3760 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003761 }
3762
3763 /**
3764 * Returns the data network type for a subId
3765 */
3766 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003767 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003769 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003770 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3771 }
3772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003773 final long identity = Binder.clearCallingIdentity();
3774 try {
3775 final Phone phone = getPhone(subId);
3776 if (phone != null) {
3777 return phone.getServiceState().getDataNetworkType();
3778 } else {
3779 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3780 }
3781 } finally {
3782 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003784 }
3785
3786 /**
Wink Saville36469e72014-06-11 15:17:00 -07003787 * Returns the Voice network type for a subId
3788 */
3789 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003790 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003791 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003792 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003793 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3794 }
3795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 final Phone phone = getPhone(subId);
3799 if (phone != null) {
3800 return phone.getServiceState().getVoiceNetworkType();
3801 } else {
3802 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3803 }
3804 } finally {
3805 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003807 }
3808
3809 /**
3810 * @return true if a ICC card is present
3811 */
3812 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003813 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003814 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3815 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003816 }
3817
3818 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003819 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003820 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003821 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003822 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 final Phone phone = PhoneFactory.getPhone(slotIndex);
3826 if (phone != null) {
3827 return phone.getIccCard().hasIccCard();
3828 } else {
3829 return false;
3830 }
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003834 }
3835
3836 /**
3837 * Return if the current radio is LTE on CDMA. This
3838 * is a tri-state return value as for a period of time
3839 * the mode may be unknown.
3840 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003841 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003842 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003843 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003844 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003845 @Override
3846 public int getLteOnCdmaMode(String callingPackage) {
3847 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003848 }
3849
Sanket Padawe356d7632015-06-22 14:03:32 -07003850 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003851 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003853 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003854 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3855 }
3856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 final Phone phone = getPhone(subId);
3860 if (phone == null) {
3861 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3862 } else {
3863 return phone.getLteOnCdmaMode();
3864 }
3865 } finally {
3866 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003867 }
Wink Saville36469e72014-06-11 15:17:00 -07003868 }
3869
Wink Saville36469e72014-06-11 15:17:00 -07003870 /**
3871 * {@hide}
3872 * Returns Default subId, 0 in the case of single standby.
3873 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003874 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003875 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003876 }
3877
Shishir Agrawala9f32182016-04-12 12:00:16 -07003878 private int getSlotForDefaultSubscription() {
3879 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3880 }
3881
Wink Savilleb564aae2014-10-23 10:18:09 -07003882 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003883 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003884 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003885
Pengquan Menge92a50d2018-09-21 15:54:48 -07003886 private boolean isActiveSubscription(int subId) {
3887 return mSubscriptionController.isActiveSubId(subId);
3888 }
3889
Ihab Awadf2177b72013-11-25 13:33:23 -08003890 /**
3891 * @see android.telephony.TelephonyManager.WifiCallingChoices
3892 */
3893 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894 final long identity = Binder.clearCallingIdentity();
3895 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003896 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3898 getWhenToMakeWifiCallsDefaultPreference());
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
3901 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003902 }
3903
3904 /**
3905 * @see android.telephony.TelephonyManager.WifiCallingChoices
3906 */
3907 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003911 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003916 }
3917
Sailesh Nepald1e68152013-12-12 19:08:02 -08003918 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003919 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003920 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003921 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003922
Jordan Liu4c733742019-02-28 12:03:40 -08003923 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3924 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3925 if (phoneId == -1) {
3926 throw new IllegalArgumentException("Given slot index: " + slotIndex
3927 + " does not correspond to an active phone");
3928 }
3929 return PhoneFactory.getPhone(phoneId);
3930 }
3931
Shishir Agrawal566b7612013-10-28 14:41:00 -07003932 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003933 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3934 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3936 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003938 if (DBG) {
3939 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3940 }
3941 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3942 p2);
3943 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003944
Jordan Liu4c733742019-02-28 12:03:40 -08003945
3946 @Override
3947 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3948 int slotIndex, String callingPackage, String aid, int p2) {
3949 enforceModifyPermission();
3950 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3951 if (DBG) {
3952 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3953 }
3954 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3955 callingPackage, aid, p2);
3956 }
3957
3958 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3959 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960 final long identity = Binder.clearCallingIdentity();
3961 try {
3962 if (TextUtils.equals(ISDR_AID, aid)) {
3963 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003964 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3965 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003966 if (bestComponent == null
3967 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3968 loge("The calling package is not allowed to access ISD-R.");
3969 throw new SecurityException(
3970 "The calling package is not allowed to access ISD-R.");
3971 }
Derek Tan740e1672017-06-27 14:56:27 -07003972 }
Derek Tan740e1672017-06-27 14:56:27 -07003973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003974 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003975 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3976 null /* workSource */);
3977 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978 return response;
3979 } finally {
3980 Binder.restoreCallingIdentity(identity);
3981 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003982 }
3983
3984 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003985 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3987 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003988 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3989 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3990 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003991
Jordan Liu4c733742019-02-28 12:03:40 -08003992 @Override
3993 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3994 enforceModifyPermission();
3995 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3996 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3997 channel);
3998 }
3999
4000 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004001 final long identity = Binder.clearCallingIdentity();
4002 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004003 if (channel < 0) {
4004 return false;
4005 }
Jordan Liu4c733742019-02-28 12:03:40 -08004006 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4007 null /* workSource */);
4008 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009 return success;
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004012 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004013 }
4014
4015 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004016 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004017 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4019 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004020 if (DBG) {
4021 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4022 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4023 + p3 + " data=" + data);
4024 }
4025 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4026 command, p1, p2, p3, data);
4027 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004028
Jordan Liu4c733742019-02-28 12:03:40 -08004029 @Override
4030 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4031 int command, int p1, int p2, int p3, String data) {
4032 enforceModifyPermission();
4033 if (DBG) {
4034 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4035 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4036 + p3 + " data=" + data);
4037 }
4038 return iccTransmitApduLogicalChannelWithPermission(
4039 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4040 data);
4041 }
4042
4043 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4044 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 final long identity = Binder.clearCallingIdentity();
4046 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004047 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048 return "";
4049 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004052 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4053 null /* workSource */);
4054 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 // Append the returned status code to the end of the response payload.
4057 String s = Integer.toHexString(
4058 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4059 if (response.payload != null) {
4060 s = IccUtils.bytesToHexString(response.payload) + s;
4061 }
4062 return s;
4063 } finally {
4064 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004065 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004066 }
Jake Hambye994d462014-02-03 13:10:13 -08004067
Evan Charltonc66da362014-05-16 14:06:40 -07004068 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004069 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4070 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4072 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004074 if (DBG) {
4075 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4076 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4077 }
4078 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4079 cla, command, p1, p2, p3, data);
4080 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004081
Jordan Liu4c733742019-02-28 12:03:40 -08004082 @Override
4083 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4084 int command, int p1, int p2, int p3, String data) {
4085 enforceModifyPermission();
4086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4087 if (DBG) {
4088 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4089 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4090 + " data=" + data);
4091 }
4092
4093 return iccTransmitApduBasicChannelWithPermission(
4094 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4095 p2, p3, data);
4096 }
4097
4098 // open APDU basic channel assuming the caller has sufficient permissions
4099 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4100 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4104 && TextUtils.equals(ISDR_AID, data)) {
4105 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004106 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4107 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004108 if (bestComponent == null
4109 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4110 loge("The calling package is not allowed to select ISD-R.");
4111 throw new SecurityException(
4112 "The calling package is not allowed to select ISD-R.");
4113 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004114 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004117 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4118 null /* workSource */);
4119 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 // Append the returned status code to the end of the response payload.
4122 String s = Integer.toHexString(
4123 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4124 if (response.payload != null) {
4125 s = IccUtils.bytesToHexString(response.payload) + s;
4126 }
4127 return s;
4128 } finally {
4129 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004130 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004131 }
4132
4133 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004134 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004135 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4137 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004139 final long identity = Binder.clearCallingIdentity();
4140 try {
4141 if (DBG) {
4142 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4143 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4144 }
4145
4146 IccIoResult response =
4147 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4148 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4149 subId);
4150
4151 if (DBG) {
4152 log("Exchange SIM_IO [R]" + response);
4153 }
4154
4155 byte[] result = null;
4156 int length = 2;
4157 if (response.payload != null) {
4158 length = 2 + response.payload.length;
4159 result = new byte[length];
4160 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4161 } else {
4162 result = new byte[length];
4163 }
4164
4165 result[length - 1] = (byte) response.sw2;
4166 result[length - 2] = (byte) response.sw1;
4167 return result;
4168 } finally {
4169 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004170 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004171 }
4172
Nathan Haroldb3014052017-01-25 15:57:32 -08004173 /**
4174 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4175 * on a particular subscription
4176 */
sqianb6e41952018-03-12 14:54:01 -07004177 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4178 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4179 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4180 return null;
4181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004182
4183 final long identity = Binder.clearCallingIdentity();
4184 try {
4185 if (appType != TelephonyManager.APPTYPE_USIM
4186 && appType != TelephonyManager.APPTYPE_SIM) {
4187 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4188 return null;
4189 }
4190 Object response = sendRequest(
4191 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4192 if (response instanceof String[]) {
4193 return (String[]) response;
4194 }
yincheng zhaod698b842019-09-06 17:06:54 -07004195 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004197 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198 } finally {
4199 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004200 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004201 }
4202
yincheng zhaod698b842019-09-06 17:06:54 -07004203 /**
4204 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4205 * subscription.
4206 *
4207 * @param subId the id of the subscription.
4208 * @param appType the uicc app type, must be USIM or SIM.
4209 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4210 * @param callingPackage the op Package name.
4211 * @return number of fplmns that is successfully written to the SIM.
4212 */
4213 public int setForbiddenPlmns(
4214 int subId, int appType, List<String> fplmns, String callingPackage) {
4215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4216 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4217 if (DBG) logv("no permissions for setForbiddenplmns");
4218 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4219 }
4220 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4221 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4222 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4223 }
4224 if (fplmns == null) {
4225 throw new IllegalArgumentException("Fplmn List provided is null");
4226 }
4227 for (String fplmn : fplmns) {
4228 if (!CellIdentity.isValidPlmn(fplmn)) {
4229 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4230 }
4231 }
4232 final long identity = Binder.clearCallingIdentity();
4233 try {
4234 Object response = sendRequest(
4235 CMD_SET_FORBIDDEN_PLMNS,
4236 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4237 subId);
4238 return (int) response;
4239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
4242 }
4243
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004244 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004245 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4247 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249 final long identity = Binder.clearCallingIdentity();
4250 try {
4251 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4252 if (response.payload == null) {
4253 return "";
4254 }
Evan Charltonc66da362014-05-16 14:06:40 -07004255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 // Append the returned status code to the end of the response payload.
4257 String s = Integer.toHexString(
4258 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4259 s = IccUtils.bytesToHexString(response.payload) + s;
4260 return s;
4261 } finally {
4262 Binder.restoreCallingIdentity(identity);
4263 }
Evan Charltonc66da362014-05-16 14:06:40 -07004264 }
4265
Jake Hambye994d462014-02-03 13:10:13 -08004266 /**
4267 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4268 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4269 *
4270 * @param itemID the ID of the item to read
4271 * @return the NV item as a String, or null on error.
4272 */
4273 @Override
4274 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4277 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004282 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4284 return value;
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
4287 }
Jake Hambye994d462014-02-03 13:10:13 -08004288 }
4289
4290 /**
4291 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4292 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4293 *
4294 * @param itemID the ID of the item to read
4295 * @param itemValue the value to write, as a String
4296 * @return true on success; false on any failure
4297 */
4298 @Override
4299 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004300 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4302 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303
4304 final long identity = Binder.clearCallingIdentity();
4305 try {
4306 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4307 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004308 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4310 return success;
4311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
Jake Hambye994d462014-02-03 13:10:13 -08004314 }
4315
4316 /**
4317 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4318 * Used for device configuration by some CDMA operators.
4319 *
4320 * @param preferredRoamingList byte array containing the new PRL
4321 * @return true on success; false on any failure
4322 */
4323 @Override
4324 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4326 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327
4328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4331 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4332 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4333 return success;
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
Jake Hambye994d462014-02-03 13:10:13 -08004337 }
4338
4339 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004340 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004341 * Used for device configuration by some CDMA operators.
4342 *
chen xu6dac5ab2018-10-26 17:39:23 -07004343 * @param slotIndex - device slot.
4344 *
Jake Hambye994d462014-02-03 13:10:13 -08004345 * @return true on success; false on any failure
4346 */
4347 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004348 public boolean resetModemConfig(int slotIndex) {
4349 Phone phone = PhoneFactory.getPhone(slotIndex);
4350 if (phone != null) {
4351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4352 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353
chen xu6dac5ab2018-10-26 17:39:23 -07004354 final long identity = Binder.clearCallingIdentity();
4355 try {
4356 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4357 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4358 return success;
4359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004362 }
chen xu6dac5ab2018-10-26 17:39:23 -07004363 return false;
4364 }
4365
4366 /**
4367 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4368 *
4369 * @param slotIndex - device slot.
4370 *
4371 * @return true on success; false on any failure
4372 */
4373 @Override
4374 public boolean rebootModem(int slotIndex) {
4375 Phone phone = PhoneFactory.getPhone(slotIndex);
4376 if (phone != null) {
4377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4378 mApp, phone.getSubId(), "rebootModem");
4379
4380 final long identity = Binder.clearCallingIdentity();
4381 try {
4382 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4383 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4384 return success;
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
4388 }
4389 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004390 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004391
Svet Ganovb320e182015-04-16 12:30:10 -07004392 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004393 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004395 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004396 return new String[0];
4397 }
4398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004399 final long identity = Binder.clearCallingIdentity();
4400 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004401 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
Wink Saville36469e72014-06-11 15:17:00 -07004405 }
4406
Brad Ebinger51f743a2017-01-23 13:50:20 -08004407 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004408 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4409 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004410 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004411 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004412 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413
4414 final long identity = Binder.clearCallingIdentity();
4415 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004416 ImsResolver resolver = PhoneFactory.getImsResolver();
4417 if (resolver == null) {
4418 // may happen if the device does not support IMS.
4419 return;
4420 }
4421 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 } finally {
4423 Binder.restoreCallingIdentity(identity);
4424 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004425 }
4426
4427 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004428 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4429 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004430 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004431 public void disableIms(int slotId) {
4432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433
4434 final long identity = Binder.clearCallingIdentity();
4435 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004436 ImsResolver resolver = PhoneFactory.getImsResolver();
4437 if (resolver == null) {
4438 // may happen if the device does not support IMS.
4439 return;
4440 }
4441 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 } finally {
4443 Binder.restoreCallingIdentity(identity);
4444 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004445 }
4446
4447 /**
4448 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4449 * feature or {@link null} if the service is not available. If the feature is available, the
4450 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4451 */
4452 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004453 IImsServiceFeatureCallback callback) {
4454 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455
4456 final long identity = Binder.clearCallingIdentity();
4457 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004458 ImsResolver resolver = PhoneFactory.getImsResolver();
4459 if (resolver == null) {
4460 // may happen if the device does not support IMS.
4461 return null;
4462 }
4463 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004467 }
4468
4469 /**
4470 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4471 * feature during emergency calling or {@link null} if the service is not available. If the
4472 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4473 * listener for feature updates.
4474 */
4475 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4476 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477
4478 final long identity = Binder.clearCallingIdentity();
4479 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004480 ImsResolver resolver = PhoneFactory.getImsResolver();
4481 if (resolver == null) {
4482 // may happen if the device does not support IMS.
4483 return null;
4484 }
4485 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004489 }
4490
Brad Ebinger5f64b052017-12-14 14:26:15 -08004491 /**
4492 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004493 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004494 */
4495 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4496 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497
4498 final long identity = Binder.clearCallingIdentity();
4499 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004500 ImsResolver resolver = PhoneFactory.getImsResolver();
4501 if (resolver == null) {
4502 // may happen if the device does not support IMS.
4503 return null;
4504 }
4505 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004509 }
4510
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004511 /**
4512 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004513 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004514 */
4515 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4516 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517
4518 final long identity = Binder.clearCallingIdentity();
4519 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004520 ImsResolver resolver = PhoneFactory.getImsResolver();
4521 if (resolver == null) {
4522 // may happen if the device does not support IMS.
4523 return null;
4524 }
4525 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004529 }
4530
Brad Ebinger884c07b2018-02-15 16:17:40 -08004531 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004532 * Sets the ImsService Package Name that Telephony will bind to.
4533 *
4534 * @param slotId the slot ID that the ImsService should bind for.
4535 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4536 * ImsService is the device default ImsService.
4537 * @param packageName The package name of the application that contains the ImsService to bind
4538 * to.
4539 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4540 * @hide
4541 */
4542 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004543 int[] subIds = SubscriptionManager.getSubId(slotId);
4544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4545 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4546 "setImsService");
4547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004548 final long identity = Binder.clearCallingIdentity();
4549 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004550 ImsResolver resolver = PhoneFactory.getImsResolver();
4551 if (resolver == null) {
4552 // may happen if the device does not support IMS.
4553 return false;
4554 }
4555 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4556 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004560 }
4561
4562 /**
4563 * Return the ImsService configuration.
4564 *
4565 * @param slotId The slot that the ImsService is associated with.
4566 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4567 * the device default.
4568 * @return the package name of the ImsService configuration.
4569 */
4570 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004571 int[] subIds = SubscriptionManager.getSubId(slotId);
4572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4573 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4574 "getImsService");
4575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576 final long identity = Binder.clearCallingIdentity();
4577 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004578 ImsResolver resolver = PhoneFactory.getImsResolver();
4579 if (resolver == null) {
4580 // may happen if the device does not support IMS.
4581 return "";
4582 }
4583 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004584 } finally {
4585 Binder.restoreCallingIdentity(identity);
4586 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004587 }
4588
Brad Ebinger77b832e2019-10-17 17:03:22 -07004589 /**
4590 * Get the MmTelFeature state associated with the requested subscription id.
4591 * @param subId The subscription that the MmTelFeature is associated with.
4592 * @param callback A callback with an integer containing the
4593 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4594 */
4595 @Override
4596 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4597 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4598 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4599 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4600 "IMS not available on device.");
4601 }
4602 final long token = Binder.clearCallingIdentity();
4603 try {
4604 int slotId = getSlotIndex(subId);
4605 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4606 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4607 + subId + "'");
4608 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4609 }
4610 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4611 try {
4612 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4613 } catch (RemoteException e) {
4614 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4615 + "Ignore");
4616 }
4617 });
4618 } finally {
4619 Binder.restoreCallingIdentity(token);
4620 }
4621 }
4622
Wink Saville36469e72014-06-11 15:17:00 -07004623 public void setImsRegistrationState(boolean registered) {
4624 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625
4626 final long identity = Binder.clearCallingIdentity();
4627 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004628 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 } finally {
4630 Binder.restoreCallingIdentity(identity);
4631 }
Wink Saville36469e72014-06-11 15:17:00 -07004632 }
4633
4634 /**
Stuart Scott54788802015-03-30 13:18:01 -07004635 * Set the network selection mode to automatic.
4636 *
4637 */
4638 @Override
4639 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4641 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642
Pengquan Menge92a50d2018-09-21 15:54:48 -07004643 if (!isActiveSubscription(subId)) {
4644 return;
4645 }
4646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004647 final long identity = Binder.clearCallingIdentity();
4648 try {
4649 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4650 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4651 } finally {
4652 Binder.restoreCallingIdentity(identity);
4653 }
Stuart Scott54788802015-03-30 13:18:01 -07004654 }
4655
Pengquan Mengea84e042018-09-20 14:57:26 -07004656 /**
4657 * Ask the radio to connect to the input network and change selection mode to manual.
4658 *
4659 * @param subId the id of the subscription.
4660 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4661 * the operator to attach to.
4662 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4663 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4664 * normal network selection next time.
4665 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004666 */
4667 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004668 public boolean setNetworkSelectionModeManual(
4669 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4671 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004672
4673 if (!isActiveSubscription(subId)) {
4674 return false;
4675 }
4676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004677 final long identity = Binder.clearCallingIdentity();
4678 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004679 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004680 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004681 if (DBG) {
4682 log("setNetworkSelectionModeManual: subId: " + subId
4683 + " operator: " + operatorInfo);
4684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
4688 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004689 }
4690
4691 /**
4692 * Scans for available networks.
4693 */
4694 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004695 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4697 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004698 LocationAccessPolicy.LocationPermissionResult locationResult =
4699 LocationAccessPolicy.checkLocationPermission(mApp,
4700 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4701 .setCallingPackage(callingPackage)
4702 .setCallingPid(Binder.getCallingPid())
4703 .setCallingUid(Binder.getCallingUid())
4704 .setMethod("getCellNetworkScanResults")
4705 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4706 .build());
4707 switch (locationResult) {
4708 case DENIED_HARD:
4709 throw new SecurityException("Not allowed to access scan results -- location");
4710 case DENIED_SOFT:
4711 return null;
4712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004713
Pengquan Menga1bb6272018-09-06 09:59:22 -07004714 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004715 try {
4716 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004717 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 } finally {
4720 Binder.restoreCallingIdentity(identity);
4721 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004722 }
4723
4724 /**
yinxub1bed742017-04-17 11:45:04 -07004725 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004726 *
yinxub1bed742017-04-17 11:45:04 -07004727 * @param subId id of the subscription
4728 * @param request contains the radio access networks with bands/channels to scan
4729 * @param messenger callback messenger for scan results or errors
4730 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004731 * @return the id of the requested scan which can be used to stop the scan.
4732 */
4733 @Override
4734 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004735 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4737 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004738 LocationAccessPolicy.LocationPermissionResult locationResult =
4739 LocationAccessPolicy.checkLocationPermission(mApp,
4740 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4741 .setCallingPackage(callingPackage)
4742 .setCallingPid(Binder.getCallingPid())
4743 .setCallingUid(Binder.getCallingUid())
4744 .setMethod("requestNetworkScan")
4745 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4746 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004747 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004748 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004749 if (e != null) {
4750 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4751 throw e;
4752 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004753 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004754 return TelephonyScanManager.INVALID_SCAN_ID;
4755 }
4756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757 }
Hall Liu912dfd32019-04-25 14:02:26 -07004758 int callingUid = Binder.getCallingUid();
4759 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004760 final long identity = Binder.clearCallingIdentity();
4761 try {
4762 return mNetworkScanRequestTracker.startNetworkScan(
4763 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004764 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004765 } finally {
4766 Binder.restoreCallingIdentity(identity);
4767 }
yinxu504e1392017-04-12 16:03:22 -07004768 }
4769
Hall Liub2ac8ef2019-02-28 15:56:23 -08004770 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004771 NetworkScanRequest request, int subId) {
4772 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4773 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4774 boolean hasNetworkScanPermission =
4775 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4776 == PERMISSION_GRANTED;
4777
4778 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4779 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4780 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004781 }
4782
4783 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4784 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004785 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4786 return new SecurityException("Specific channels must not be"
4787 + " scanned without location access.");
4788 }
4789 }
4790 }
4791
Hall Liub2ac8ef2019-02-28 15:56:23 -08004792 return null;
4793 }
4794
yinxu504e1392017-04-12 16:03:22 -07004795 /**
4796 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004797 *
4798 * @param subId id of the subscription
4799 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004800 */
4801 @Override
4802 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4804 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805
Hall Liu912dfd32019-04-25 14:02:26 -07004806 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807 final long identity = Binder.clearCallingIdentity();
4808 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004809 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810 } finally {
4811 Binder.restoreCallingIdentity(identity);
4812 }
yinxu504e1392017-04-12 16:03:22 -07004813 }
4814
4815 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004816 * Get the calculated preferred network type.
4817 * Used for debugging incorrect network type.
4818 *
4819 * @return the preferred network type, defined in RILConstants.java.
4820 */
4821 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004822 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004823 final Phone defaultPhone = getDefaultPhone();
4824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4825 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004826 return RILConstants.PREFERRED_NETWORK_MODE;
4827 }
4828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 final long identity = Binder.clearCallingIdentity();
4830 try {
4831 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004832 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 } finally {
4834 Binder.restoreCallingIdentity(identity);
4835 }
Junda Liu84d15a22014-07-02 11:21:04 -07004836 }
4837
4838 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004839 * Get the preferred network type.
4840 * Used for device configuration by some CDMA operators.
4841 *
4842 * @return the preferred network type, defined in RILConstants.java.
4843 */
4844 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004845 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004846 TelephonyPermissions
4847 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4848 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849
4850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 if (DBG) log("getPreferredNetworkType");
4853 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4854 int networkType = (result != null ? result[0] : -1);
4855 if (DBG) log("getPreferredNetworkType: " + networkType);
4856 return networkType;
4857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004860 }
4861
4862 /**
4863 * Set the preferred network type.
4864 * Used for device configuration by some CDMA operators.
4865 *
4866 * @param networkType the preferred network type, defined in RILConstants.java.
4867 * @return true on success; false on any failure.
4868 */
4869 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004870 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4872 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873
4874 final long identity = Binder.clearCallingIdentity();
4875 try {
4876 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4877 Boolean success = (Boolean) sendRequest(
4878 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4879 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4880 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004881 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004882 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4883 }
4884 return success;
4885 } finally {
4886 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004887 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004888 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004889
4890 /**
Miaoa84611c2019-03-15 09:21:10 +08004891 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004892 *
Miaoa84611c2019-03-15 09:21:10 +08004893 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004894 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004895 * @hide
4896 */
4897 @Override
Miaoa84611c2019-03-15 09:21:10 +08004898 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004899 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004901 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 try {
Miaoa84611c2019-03-15 09:21:10 +08004903 if (phone != null) {
4904 return phone.hasMatchedTetherApnSetting();
4905 } else {
4906 return false;
4907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 } finally {
4909 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004910 }
Junda Liu475951f2014-11-07 16:45:03 -08004911 }
4912
4913 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004914 * Set mobile data enabled
4915 * Used by the user through settings etc to turn on/off mobile data
4916 *
4917 * @param enable {@code true} turn turn data on, else {@code false}
4918 */
4919 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004920 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4922 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923
4924 final long identity = Binder.clearCallingIdentity();
4925 try {
4926 int phoneId = mSubscriptionController.getPhoneId(subId);
4927 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4928 Phone phone = PhoneFactory.getPhone(phoneId);
4929 if (phone != null) {
4930 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004931 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004933 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 }
4935 } finally {
4936 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004937 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004938 }
4939
4940 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004941 * Get the user enabled state of Mobile Data.
4942 *
4943 * TODO: remove and use isUserDataEnabled.
4944 * This can't be removed now because some vendor codes
4945 * calls through ITelephony directly while they should
4946 * use TelephonyManager.
4947 *
4948 * @return true on enabled
4949 */
4950 @Override
4951 public boolean getDataEnabled(int subId) {
4952 return isUserDataEnabled(subId);
4953 }
4954
4955 /**
4956 * Get whether mobile data is enabled per user setting.
4957 *
4958 * There are other factors deciding whether mobile data is actually enabled, but they are
4959 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004960 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004961 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004962 *
4963 * @return {@code true} if data is enabled else {@code false}
4964 */
4965 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004966 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004967 try {
4968 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4969 null);
4970 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4972 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004973 }
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("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4979 Phone phone = PhoneFactory.getPhone(phoneId);
4980 if (phone != null) {
4981 boolean retVal = phone.isUserDataEnabled();
4982 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4983 return retVal;
4984 } else {
4985 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4986 return false;
4987 }
4988 } finally {
4989 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004990 }
4991 }
4992
4993 /**
4994 * Get whether mobile data is enabled.
4995 *
4996 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4997 * whether mobile data is actually enabled.
4998 *
4999 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5000 *
5001 * @return {@code true} if data is enabled else {@code false}
5002 */
5003 @Override
5004 public boolean isDataEnabled(int subId) {
5005 try {
5006 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5007 null);
5008 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5010 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012
5013 final long identity = Binder.clearCallingIdentity();
5014 try {
5015 int phoneId = mSubscriptionController.getPhoneId(subId);
5016 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5017 Phone phone = PhoneFactory.getPhone(phoneId);
5018 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005019 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5021 return retVal;
5022 } else {
5023 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5024 return false;
5025 }
5026 } finally {
5027 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005028 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005029 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005030
5031 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005032 public int getCarrierPrivilegeStatus(int subId) {
5033 final Phone phone = getPhone(subId);
5034 if (phone == null) {
5035 loge("getCarrierPrivilegeStatus: Invalid subId");
5036 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5037 }
5038 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005039 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005040 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005041 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5042 }
5043 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005044 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005045 }
Junda Liu29340342014-07-10 15:23:27 -07005046
5047 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005048 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5049 final Phone phone = getPhone(subId);
5050 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005051 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005052 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5053 }
5054 UiccProfile profile =
5055 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5056 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005057 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005058 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5059 }
5060 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
5061 }
5062
5063 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005064 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5065 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005066 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005067 }
5068
5069 int phoneId = SubscriptionManager.getPhoneId(subId);
5070 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005071 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005072 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005073 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5074 }
chen xuf7e9fe82019-05-09 19:31:02 -07005075
5076 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005077 }
5078
5079 @Override
5080 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005081 if (TextUtils.isEmpty(pkgName))
5082 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005083 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5084 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5085 UiccCard card = UiccController.getInstance().getUiccCard(i);
5086 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005087 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005088 continue;
5089 }
5090
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005091 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005092 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5093 break;
5094 }
5095 }
5096
5097 return result;
Junda Liu29340342014-07-10 15:23:27 -07005098 }
Derek Tan89e89d42014-07-08 17:00:10 -07005099
5100 @Override
Junda Liue64de782015-04-16 17:19:16 -07005101 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5102 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5103 loge("phoneId " + phoneId + " is not valid.");
5104 return null;
5105 }
5106 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005107 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005108 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005109 return null ;
5110 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005111 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005112 }
5113
Amith Yamasani6e118872016-02-19 12:53:51 -08005114 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005115 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005116 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005117 List<String> privilegedPackages = new ArrayList<>();
5118 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005119 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5120 // has UICC in that slot.
5121 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005122 if (card.hasCarrierPrivilegeRules()) {
5123 if (packages == null) {
5124 // Only check packages in user 0 for now
5125 packages = pm.getInstalledPackagesAsUser(
5126 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07005127 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
5128 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005129 }
5130 for (int p = packages.size() - 1; p >= 0; p--) {
5131 PackageInfo pkgInfo = packages.get(p);
5132 if (pkgInfo != null && pkgInfo.packageName != null
5133 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005134 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005135 privilegedPackages.add(pkgInfo.packageName);
5136 }
5137 }
5138 }
5139 }
5140 return privilegedPackages;
5141 }
5142
chen xuf7e9fe82019-05-09 19:31:02 -07005143 @Override
5144 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5145 List<String> privilegedPackages = new ArrayList<>();
5146 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5147 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5148 }
5149 return privilegedPackages;
5150 }
5151
Wink Savilleb564aae2014-10-23 10:18:09 -07005152 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005153 final Phone phone = getPhone(subId);
5154 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005155 if (card == null) {
5156 loge("getIccId: No UICC");
5157 return null;
5158 }
5159 String iccId = card.getIccId();
5160 if (TextUtils.isEmpty(iccId)) {
5161 loge("getIccId: ICC ID is null or empty.");
5162 return null;
5163 }
5164 return iccId;
5165 }
5166
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005167 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005168 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5169 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005170 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5171 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 final long identity = Binder.clearCallingIdentity();
5174 try {
5175 final String iccId = getIccId(subId);
5176 final Phone phone = getPhone(subId);
5177 if (phone == null) {
5178 return false;
5179 }
5180 final String subscriberId = phone.getSubscriberId();
5181
5182 if (DBG_MERGE) {
5183 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5184 + subscriberId + " to " + number);
5185 }
5186
5187 if (TextUtils.isEmpty(iccId)) {
5188 return false;
5189 }
5190
5191 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5192
5193 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5194 if (alphaTag == null) {
5195 editor.remove(alphaTagPrefKey);
5196 } else {
5197 editor.putString(alphaTagPrefKey, alphaTag);
5198 }
5199
5200 // Record both the line number and IMSI for this ICCID, since we need to
5201 // track all merged IMSIs based on line number
5202 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5203 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5204 if (number == null) {
5205 editor.remove(numberPrefKey);
5206 editor.remove(subscriberPrefKey);
5207 } else {
5208 editor.putString(numberPrefKey, number);
5209 editor.putString(subscriberPrefKey, subscriberId);
5210 }
5211
5212 editor.commit();
5213 return true;
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005216 }
Derek Tan7226c842014-07-02 17:42:23 -07005217 }
5218
5219 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005220 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005221 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005223 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005224 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005225 return null;
5226 }
Derek Tan97ebb422014-09-05 16:55:38 -07005227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 String iccId = getIccId(subId);
5231 if (iccId != null) {
5232 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5233 if (DBG_MERGE) {
5234 log("getLine1NumberForDisplay returning "
5235 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5236 }
5237 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5240 return null;
5241 } finally {
5242 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005243 }
Derek Tan7226c842014-07-02 17:42:23 -07005244 }
5245
5246 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005247 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005249 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005250 return null;
5251 }
Derek Tan97ebb422014-09-05 16:55:38 -07005252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005253 final long identity = Binder.clearCallingIdentity();
5254 try {
5255 String iccId = getIccId(subId);
5256 if (iccId != null) {
5257 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5258 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5259 }
5260 return null;
5261 } finally {
5262 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005263 }
Derek Tan7226c842014-07-02 17:42:23 -07005264 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005265
5266 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005267 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005268 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5269 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005271 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5272 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005273 return null;
5274 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005275
Jordan Liub49b04b2019-05-06 14:45:15 -07005276 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5277 // the process, where TelephonyManager was instantiated.
5278 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005279 final long identity = Binder.clearCallingIdentity();
5280 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005281 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 final TelephonyManager tele = TelephonyManager.from(context);
5283 final SubscriptionManager sub = SubscriptionManager.from(context);
5284
5285 // Figure out what subscribers are currently active
5286 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287
Jordan Liub49b04b2019-05-06 14:45:15 -07005288 // Only consider subs which match the current subId
5289 // This logic can be simplified. See b/131189269 for progress.
5290 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005291 activeSubscriberIds.add(tele.getSubscriberId(subId));
5292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293
5294 // First pass, find a number override for an active subscriber
5295 String mergeNumber = null;
5296 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5297 for (String key : prefs.keySet()) {
5298 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5299 final String subscriberId = (String) prefs.get(key);
5300 if (activeSubscriberIds.contains(subscriberId)) {
5301 final String iccId = key.substring(
5302 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5303 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5304 mergeNumber = (String) prefs.get(numberKey);
5305 if (DBG_MERGE) {
5306 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5307 + " for active subscriber " + subscriberId);
5308 }
5309 if (!TextUtils.isEmpty(mergeNumber)) {
5310 break;
5311 }
5312 }
5313 }
5314 }
5315
5316 // Shortcut when no active merged subscribers
5317 if (TextUtils.isEmpty(mergeNumber)) {
5318 return null;
5319 }
5320
5321 // Second pass, find all subscribers under that line override
5322 final ArraySet<String> result = new ArraySet<>();
5323 for (String key : prefs.keySet()) {
5324 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5325 final String number = (String) prefs.get(key);
5326 if (mergeNumber.equals(number)) {
5327 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5328 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5329 final String subscriberId = (String) prefs.get(subscriberKey);
5330 if (!TextUtils.isEmpty(subscriberId)) {
5331 result.add(subscriberId);
5332 }
5333 }
5334 }
5335 }
5336
5337 final String[] resultArray = result.toArray(new String[result.size()]);
5338 Arrays.sort(resultArray);
5339 if (DBG_MERGE) {
5340 Slog.d(LOG_TAG,
5341 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5342 }
5343 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005344 } finally {
5345 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005346 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005347 }
5348
5349 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005350 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5351 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5352
5353 final long identity = Binder.clearCallingIdentity();
5354 try {
5355 final TelephonyManager telephonyManager = mApp.getSystemService(
5356 TelephonyManager.class);
5357 String subscriberId = telephonyManager.getSubscriberId(subId);
5358 if (subscriberId == null) {
5359 if (DBG) {
5360 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5361 + subId);
5362 }
5363 return null;
5364 }
5365
5366 final SubscriptionInfo info = SubscriptionController.getInstance()
5367 .getSubscriptionInfo(subId);
5368 final ParcelUuid groupUuid = info.getGroupUuid();
5369 // If it doesn't belong to any group, return just subscriberId of itself.
5370 if (groupUuid == null) {
5371 return new String[]{subscriberId};
5372 }
5373
5374 // Get all subscriberIds from the group.
5375 final List<String> mergedSubscriberIds = new ArrayList<>();
5376 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5377 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5378 for (SubscriptionInfo subInfo : groupInfos) {
5379 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5380 if (subscriberId != null) {
5381 mergedSubscriberIds.add(subscriberId);
5382 }
5383 }
5384
5385 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388
5389 }
5390 }
5391
5392 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005393 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005394 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5395 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396
5397 final long identity = Binder.clearCallingIdentity();
5398 try {
5399 final Phone phone = getPhone(subId);
5400 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005404 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005405
5406 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005407 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005408 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5409 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005410 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411
5412 final long identity = Binder.clearCallingIdentity();
5413 try {
5414 final Phone phone = getPhone(subId);
5415 if (phone == null) {
5416 return false;
5417 }
5418 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5419 cdmaNonRoamingList);
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005422 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005423 }
5424
5425 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005426 @Deprecated
5427 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5428 enforceModifyPermission();
5429
5430 int returnValue = 0;
5431 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005432 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005433 if(result.exception == null) {
5434 if (result.result != null) {
5435 byte[] responseData = (byte[])(result.result);
5436 if(responseData.length > oemResp.length) {
5437 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5438 responseData.length + "bytes. Buffer Size is " +
5439 oemResp.length + "bytes.");
5440 }
5441 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5442 returnValue = responseData.length;
5443 }
5444 } else {
5445 CommandException ex = (CommandException) result.exception;
5446 returnValue = ex.getCommandError().ordinal();
5447 if(returnValue > 0) returnValue *= -1;
5448 }
5449 } catch (RuntimeException e) {
5450 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5451 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5452 if(returnValue > 0) returnValue *= -1;
5453 }
5454
5455 return returnValue;
5456 }
5457
5458 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005459 public void setRadioCapability(RadioAccessFamily[] rafs) {
5460 try {
5461 ProxyController.getInstance().setRadioCapability(rafs);
5462 } catch (RuntimeException e) {
5463 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5464 }
5465 }
5466
5467 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005468 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005469 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005470 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005471 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005472 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 final long identity = Binder.clearCallingIdentity();
5475 try {
chen xub97461a2018-10-26 14:17:57 -07005476 TelephonyPermissions
5477 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5478 mApp, phone.getSubId(), "getRadioAccessFamily");
5479 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 } finally {
5481 Binder.restoreCallingIdentity(identity);
5482 }
chen xub97461a2018-10-26 14:17:57 -07005483 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005484 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005485
5486 @Override
5487 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005488 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005489 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490
5491 final long identity = Binder.clearCallingIdentity();
5492 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005493 ImsManager.getInstance(defaultPhone.getContext(),
5494 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005498 }
5499
5500 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005501 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005502 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005504 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005505 return false;
5506 }
Svet Ganovb320e182015-04-16 12:30:10 -07005507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 // Check the user preference and the system-level IMS setting. Even if the user has
5511 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5512 // In the long run, we may instead need to check if there exists a connection service
5513 // which can support video calling.
5514 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005515 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 return imsManager.isVtEnabledByPlatform()
5517 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5518 && imsManager.isVtEnabledByUser();
5519 } finally {
5520 Binder.restoreCallingIdentity(identity);
5521 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005522 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005523
Andrew Leea1239f22015-03-02 17:44:07 -08005524 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5527 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5528 return false;
5529 }
5530
5531 final long identity = Binder.clearCallingIdentity();
5532 try {
5533 CarrierConfigManager configManager =
5534 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005535 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5537 } finally {
5538 Binder.restoreCallingIdentity(identity);
5539 }
Andrew Leea1239f22015-03-02 17:44:07 -08005540 }
5541
5542 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 public boolean isWorldPhone(int subId, String callingPackage) {
5544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5545 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5546 return false;
5547 }
5548
5549 final long identity = Binder.clearCallingIdentity();
5550 try {
5551 CarrierConfigManager configManager =
5552 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005553 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5555 } finally {
5556 Binder.restoreCallingIdentity(identity);
5557 }
Andrew Leea1239f22015-03-02 17:44:07 -08005558 }
5559
Andrew Lee9431b832015-03-09 18:46:45 -07005560 @Override
5561 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005562 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005563 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005564 }
5565
5566 @Override
5567 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005568 final long identity = Binder.clearCallingIdentity();
5569 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005570 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005571 } finally {
5572 Binder.restoreCallingIdentity(identity);
5573 }
Andrew Lee9431b832015-03-09 18:46:45 -07005574 }
5575
Hall Liuf6668912018-10-31 17:05:23 -07005576 /**
5577 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5578 * support for the feature and device firmware support.
5579 *
5580 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5581 */
5582 @Override
5583 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005585 final Phone phone = getPhone(subscriptionId);
5586 if (phone == null) {
5587 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5588 return false;
5589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005591 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5593 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005594 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 return isCarrierSupported && isDeviceSupported;
5596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
Hall Liu98187582018-01-22 19:15:32 -08005599 }
5600
Hall Liuf6668912018-10-31 17:05:23 -07005601 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005602 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5603 * RTT setting, will return true if the device and carrier both support RTT.
5604 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005605 */
5606 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 final long identity = Binder.clearCallingIdentity();
5608 try {
Hall Liu6a06be62019-07-23 18:39:00 -07005609 boolean isRttSupported = isRttSupported(subscriptionId);
5610 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005611 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liu6a06be62019-07-23 18:39:00 -07005612 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5613 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5614 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 } finally {
5616 Binder.restoreCallingIdentity(identity);
5617 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005618 }
5619
Sanket Padawe7310cc72015-01-14 09:53:20 -08005620 /**
5621 * Returns the unique device ID of phone, for example, the IMEI for
5622 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5623 *
5624 * <p>Requires Permission:
5625 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5626 */
5627 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005628 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005629 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005630 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005631 return null;
5632 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005633 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005634 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5635 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005636 return null;
5637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638
5639 final long identity = Binder.clearCallingIdentity();
5640 try {
5641 return phone.getDeviceId();
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005645 }
5646
Ping Sunc67b7c22016-03-02 19:16:45 +08005647 /**
5648 * {@hide}
5649 * Returns the IMS Registration Status on a particular subid
5650 *
5651 * @param subId
5652 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005653 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005654 Phone phone = getPhone(subId);
5655 if (phone != null) {
5656 return phone.isImsRegistered();
5657 } else {
5658 return false;
5659 }
5660 }
5661
Santos Cordon7a1885b2015-02-03 11:15:19 -08005662 @Override
5663 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 final long identity = Binder.clearCallingIdentity();
5665 try {
5666 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5667 } finally {
5668 Binder.restoreCallingIdentity(identity);
5669 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005670 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005671
Tyler Gunnf70ed162019-04-03 15:28:53 -07005672 @Override
5673 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 Phone phone = getPhone(subscriptionId);
5677 if (phone == null) {
5678 return null;
5679 }
5680 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
5684 }
5685
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005686 /**
5687 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005688 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005689 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 final long identity = Binder.clearCallingIdentity();
5691 try {
5692 Phone phone = getPhone(subId);
5693 if (phone != null) {
5694 return phone.isWifiCallingEnabled();
5695 } else {
5696 return false;
5697 }
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005700 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005701 }
5702
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005703 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005704 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005705 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005706 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 final long identity = Binder.clearCallingIdentity();
5708 try {
5709 Phone phone = getPhone(subId);
5710 if (phone != null) {
5711 return phone.isVideoEnabled();
5712 } else {
5713 return false;
5714 }
5715 } finally {
5716 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005717 }
5718 }
5719
5720 /**
5721 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5722 * defined in {@link ImsRegistrationImplBase}.
5723 */
5724 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 final long identity = Binder.clearCallingIdentity();
5726 try {
5727 Phone phone = getPhone(subId);
5728 if (phone != null) {
5729 return phone.getImsRegistrationTech();
5730 } else {
5731 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5732 }
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005735 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005736 }
5737
Stuart Scott8eef64f2015-04-08 15:13:54 -07005738 @Override
5739 public void factoryReset(int subId) {
5740 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005741 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5742 return;
5743 }
5744
Svet Ganovcc087f82015-05-12 20:35:54 -07005745 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005746
Svet Ganovcc087f82015-05-12 20:35:54 -07005747 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005748 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5749 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005750 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005751 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005752 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005753 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5754 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005755 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005756 // There has been issues when Sms raw table somehow stores orphan
5757 // fragments. They lead to garbled message when new fragments come
5758 // in and combined with those stale ones. In case this happens again,
5759 // user can reset all network settings which will clean up this table.
5760 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005761 // Clean up IMS settings as well here.
5762 int slotId = getSlotIndex(subId);
5763 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5764 ImsManager.getInstance(mApp, slotId).factoryReset();
5765 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005766 } finally {
5767 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005768 }
5769 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005770
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005771 private void cleanUpSmsRawTable(Context context) {
5772 ContentResolver resolver = context.getContentResolver();
5773 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5774 resolver.delete(uri, null, null);
5775 }
5776
Narayan Kamath1c496c22015-04-16 14:40:19 +01005777 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005778 public String getSimLocaleForSubscriber(int subId) {
5779 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5780 final Phone phone = getPhone(subId);
5781 if (phone == null) {
5782 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005783 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005784 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 final long identity = Binder.clearCallingIdentity();
5786 try {
chen xu5d3637b2019-01-21 23:31:38 -08005787 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5788 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005789 if (info == null) {
5790 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5791 return null;
5792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 // Try and fetch the locale from the carrier properties or from the SIM language
5794 // preferences (EF-PL and EF-LI)...
5795 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005797 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5798 if (localeFromDefaultSim != null) {
5799 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5800 if (DBG) log("Using locale from subId: " + subId + " locale: "
5801 + localeFromDefaultSim);
5802 return localeFromDefaultSim.toLanguageTag();
5803 } else {
5804 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 }
5806 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 // The SIM language preferences only store a language (e.g. fr = French), not an
5809 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5810 // the SIM and carrier preferences does not include a country we add the country
5811 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005812 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005814 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 return mccLocale.toLanguageTag();
5816 }
5817
5818 if (DBG) log("No locale found - returning null");
5819 return null;
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005823 }
5824
5825 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005826 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005827 }
5828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829 /**
5830 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5831 */
5832 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005833 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005834 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005835
Chenjie Yu1ba97252018-01-11 18:16:20 -08005836 private final ModemActivityInfo mLastModemActivityInfo =
5837 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5838
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005839 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005840 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5841 * representing the state of the modem.
5842 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005843 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5844 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005845 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005846 */
5847 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005848 public void requestModemActivityInfo(ResultReceiver result) {
5849 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005850 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851
5852 final long identity = Binder.clearCallingIdentity();
5853 try {
5854 ModemActivityInfo ret = null;
5855 synchronized (mLastModemActivityInfo) {
5856 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5857 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005858 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005859 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5861 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005862 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5863 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864 }
5865 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005866 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5867 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 mLastModemActivityInfo.setIdleTimeMillis(
5869 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5870 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5871 mLastModemActivityInfo.setRxTimeMillis(
5872 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5873 mLastModemActivityInfo.setEnergyUsed(
5874 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005876 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5877 mLastModemActivityInfo.getSleepTimeMillis(),
5878 mLastModemActivityInfo.getIdleTimeMillis(),
5879 mLastModemActivityInfo.getTxTimeMillis(),
5880 mLastModemActivityInfo.getRxTimeMillis(),
5881 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005882 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 Bundle bundle = new Bundle();
5884 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5885 result.send(0, bundle);
5886 } finally {
5887 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005888 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005889 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005890
Siddharth Rayb8114062018-06-17 15:02:38 -07005891 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5892 // less than total activity duration.
5893 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5894 if (info == null) {
5895 return false;
5896 }
5897 int activityDurationMs =
5898 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5899 int totalTxTimeMs = 0;
5900 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5901 totalTxTimeMs += info.getTxTimeMillis()[i];
5902 }
5903 return (info.isValid()
5904 && (info.getSleepTimeMillis() <= activityDurationMs)
5905 && (info.getIdleTimeMillis() <= activityDurationMs)
5906 && (info.getRxTimeMillis() <= activityDurationMs)
5907 && (totalTxTimeMs <= activityDurationMs));
5908 }
5909
Jack Yu85bd38a2015-11-09 11:34:32 -08005910 /**
5911 * {@hide}
5912 * Returns the service state information on specified subscription.
5913 */
5914 @Override
5915 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005916 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005917 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005918 return null;
5919 }
5920
Hall Liuf19c44f2018-11-27 14:38:17 -08005921 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5922 LocationAccessPolicy.checkLocationPermission(mApp,
5923 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5924 .setCallingPackage(callingPackage)
5925 .setCallingPid(Binder.getCallingPid())
5926 .setCallingUid(Binder.getCallingUid())
5927 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005928 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005929 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5930 .build());
5931
5932 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5933 LocationAccessPolicy.checkLocationPermission(mApp,
5934 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5935 .setCallingPackage(callingPackage)
5936 .setCallingPid(Binder.getCallingPid())
5937 .setCallingUid(Binder.getCallingUid())
5938 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005939 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005940 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5941 .build());
5942 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5943 boolean hasFinePermission =
5944 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5945 boolean hasCoarsePermission =
5946 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 final long identity = Binder.clearCallingIdentity();
5949 try {
5950 final Phone phone = getPhone(subId);
5951 if (phone == null) {
5952 return null;
5953 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005954
Hall Liuf19c44f2018-11-27 14:38:17 -08005955 ServiceState ss = phone.getServiceState();
5956
5957 // Scrub out the location info in ServiceState depending on what level of access
5958 // the caller has.
5959 if (hasFinePermission) return ss;
5960 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5961 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 } finally {
5963 Binder.restoreCallingIdentity(identity);
5964 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005965 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005966
5967 /**
5968 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5969 *
5970 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5971 * voicemail ringtone.
5972 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5973 * PhoneAccount.
5974 */
5975 @Override
5976 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977 final long identity = Binder.clearCallingIdentity();
5978 try {
5979 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5980 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005981 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5985 } finally {
5986 Binder.restoreCallingIdentity(identity);
5987 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005988 }
5989
5990 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005991 * Sets the per-account voicemail ringtone.
5992 *
5993 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5994 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5995 *
5996 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5997 * voicemail ringtone.
5998 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5999 * PhoneAccount.
6000 */
6001 @Override
6002 public void setVoicemailRingtoneUri(String callingPackage,
6003 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006004 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006005 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6006 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006007 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6009 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6010 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012
6013 final long identity = Binder.clearCallingIdentity();
6014 try {
6015 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6016 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006017 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 }
6019 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6020 } finally {
6021 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006022 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006023 }
6024
6025 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006026 * Returns whether vibration is set for voicemail notification in Phone settings.
6027 *
6028 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6029 * voicemail vibration setting.
6030 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6031 */
6032 @Override
6033 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 final long identity = Binder.clearCallingIdentity();
6035 try {
6036 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6037 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006038 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6042 } finally {
6043 Binder.restoreCallingIdentity(identity);
6044 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006045 }
6046
Youhan Wange64578a2016-05-02 15:32:42 -07006047 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006048 * Sets the per-account voicemail vibration.
6049 *
6050 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6051 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6052 *
6053 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6054 * voicemail vibration setting.
6055 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6056 * specific PhoneAccount.
6057 */
6058 @Override
6059 public void setVoicemailVibrationEnabled(String callingPackage,
6060 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006061 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006062 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6063 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006064 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6066 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6067 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006068 }
6069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 final long identity = Binder.clearCallingIdentity();
6071 try {
6072 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6073 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006074 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075 }
6076 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6077 } finally {
6078 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006079 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006080 }
6081
6082 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006083 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6084 *
6085 * @throws SecurityException if the caller does not have the required permission
6086 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006087 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006088 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006089 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006090 }
6091
6092 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006093 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6094 * permission.
6095 *
6096 * @throws SecurityException if the caller does not have the required permission
6097 */
6098 private void enforceSendSmsPermission() {
6099 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6100 }
6101
6102 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006103 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006104 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006105 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006106 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006107 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108 final long identity = Binder.clearCallingIdentity();
6109 try {
6110 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006111 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 if (componentName == null) {
6113 throw new SecurityException(
6114 "Caller not current active visual voicemail package[null]");
6115 }
6116 String vvmPackage = componentName.getPackageName();
6117 if (!callingPackage.equals(vvmPackage)) {
6118 throw new SecurityException("Caller not current active visual voicemail package["
6119 + vvmPackage + "]");
6120 }
6121 } finally {
6122 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006123 }
6124 }
6125
6126 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006127 * Return the application ID for the app type.
6128 *
6129 * @param subId the subscription ID that this request applies to.
6130 * @param appType the uicc app type.
6131 * @return Application ID for specificied app type, or null if no uicc.
6132 */
6133 @Override
6134 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006135 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006136 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137
6138 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006139 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 if (phone == null) {
6141 return null;
6142 }
6143 String aid = null;
6144 try {
6145 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6146 .getApplicationByType(appType).getAid();
6147 } catch (Exception e) {
6148 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6149 }
6150 return aid;
6151 } finally {
6152 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006153 }
Youhan Wange64578a2016-05-02 15:32:42 -07006154 }
6155
Youhan Wang4001d252016-05-11 10:29:41 -07006156 /**
6157 * Return the Electronic Serial Number.
6158 *
6159 * @param subId the subscription ID that this request applies to.
6160 * @return ESN or null if error.
6161 */
6162 @Override
6163 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006164 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006165 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166
6167 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006168 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 if (phone == null) {
6170 return null;
6171 }
6172 String esn = null;
6173 try {
6174 esn = phone.getEsn();
6175 } catch (Exception e) {
6176 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6177 }
6178 return esn;
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006181 }
Youhan Wang4001d252016-05-11 10:29:41 -07006182 }
6183
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006184 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006185 * Return the Preferred Roaming List Version.
6186 *
6187 * @param subId the subscription ID that this request applies to.
6188 * @return PRLVersion or null if error.
6189 */
6190 @Override
6191 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006192 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006193 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006194
6195 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006196 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006197 if (phone == null) {
6198 return null;
6199 }
6200 String cdmaPrlVersion = null;
6201 try {
6202 cdmaPrlVersion = phone.getCdmaPrlVersion();
6203 } catch (Exception e) {
6204 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6205 }
6206 return cdmaPrlVersion;
6207 } finally {
6208 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006209 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006210 }
6211
6212 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006213 * Get snapshot of Telephony histograms
6214 * @return List of Telephony histograms
6215 * @hide
6216 */
6217 @Override
6218 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6220 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006221
6222 final long identity = Binder.clearCallingIdentity();
6223 try {
6224 return RIL.getTelephonyRILTimingHistograms();
6225 } finally {
6226 Binder.restoreCallingIdentity(identity);
6227 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006228 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006229
6230 /**
6231 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006232 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6233 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006234 * Require system privileges. In the future we may add this to carrier APIs.
6235 *
Michele Berionne482f8202018-11-27 18:57:59 -08006236 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006237 */
6238 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006239 @TelephonyManager.SetCarrierRestrictionResult
6240 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006241 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006242 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006243
Michele Berionne482f8202018-11-27 18:57:59 -08006244 if (carrierRestrictionRules == null) {
6245 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006246 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006248 final long identity = Binder.clearCallingIdentity();
6249 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006250 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006251 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252 } finally {
6253 Binder.restoreCallingIdentity(identity);
6254 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006255 }
6256
6257 /**
6258 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006259 * Get the allowed carrier list and the excluded carrier list, including the priority between
6260 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006261 * Require system privileges. In the future we may add this to carrier APIs.
6262 *
Michele Berionne482f8202018-11-27 18:57:59 -08006263 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006264 */
6265 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006266 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006267 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269
6270 final long identity = Binder.clearCallingIdentity();
6271 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006272 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6273 if (response instanceof CarrierRestrictionRules) {
6274 return (CarrierRestrictionRules) response;
6275 }
6276 // Response is an Exception of some kind,
6277 // which is signalled to the user as a NULL retval
6278 return null;
6279 } catch (Exception e) {
6280 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6281 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 } finally {
6283 Binder.restoreCallingIdentity(identity);
6284 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006285 }
6286
fionaxu59545b42016-05-25 15:53:37 -07006287 /**
6288 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6289 * @param subId the subscription ID that this action applies to.
6290 * @param enabled control enable or disable metered apns.
6291 * {@hide}
6292 */
6293 @Override
6294 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6295 enforceModifyPermission();
6296 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297
6298 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006299 if (phone == null) {
6300 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6301 return;
6302 }
6303 try {
6304 phone.carrierActionSetMeteredApnsEnabled(enabled);
6305 } catch (Exception e) {
6306 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 } finally {
6308 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006309 }
6310 }
6311
6312 /**
6313 * Action set from carrier signalling broadcast receivers to enable/disable radio
6314 * @param subId the subscription ID that this action applies to.
6315 * @param enabled control enable or disable radio.
6316 * {@hide}
6317 */
6318 @Override
6319 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6320 enforceModifyPermission();
6321 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322
6323 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006324 if (phone == null) {
6325 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6326 return;
6327 }
6328 try {
6329 phone.carrierActionSetRadioEnabled(enabled);
6330 } catch (Exception e) {
6331 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 } finally {
6333 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006334 }
6335 }
6336
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006337 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006338 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6339 * network status based on which carrier apps could apply actions accordingly,
6340 * enable/disable default url handler for example.
6341 *
6342 * @param subId the subscription ID that this action applies to.
6343 * @param report control start/stop reporting the default network status.
6344 * {@hide}
6345 */
6346 @Override
6347 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6348 enforceModifyPermission();
6349 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350
6351 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006352 if (phone == null) {
6353 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6354 return;
6355 }
6356 try {
6357 phone.carrierActionReportDefaultNetworkStatus(report);
6358 } catch (Exception e) {
6359 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360 } finally {
6361 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006362 }
6363 }
6364
6365 /**
fionaxud9622282017-07-17 17:51:30 -07006366 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6367 * @param subId the subscription ID that this action applies to.
6368 * {@hide}
6369 */
6370 @Override
6371 public void carrierActionResetAll(int subId) {
6372 enforceModifyPermission();
6373 final Phone phone = getPhone(subId);
6374 if (phone == null) {
6375 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6376 return;
6377 }
6378 try {
6379 phone.carrierActionResetAll();
6380 } catch (Exception e) {
6381 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6382 }
6383 }
6384
6385 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006386 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6387 * bug report is being generated.
6388 */
6389 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006390 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006391 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6392 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006393 writer.println("Permission Denial: can't dump Phone from pid="
6394 + Binder.getCallingPid()
6395 + ", uid=" + Binder.getCallingUid()
6396 + "without permission "
6397 + android.Manifest.permission.DUMP);
6398 return;
6399 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006400 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006401 }
Jack Yueb89b242016-06-22 13:27:47 -07006402
Brad Ebingerdac2f002018-04-03 15:17:52 -07006403 @Override
6404 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6405 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6406 throws RemoteException {
6407 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6408 }
6409
Jack Yueb89b242016-06-22 13:27:47 -07006410 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006411 * Get aggregated video call data usage since boot.
6412 *
6413 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6414 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006415 * {@hide}
6416 */
6417 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006418 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006419 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6420 null);
6421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422 final long identity = Binder.clearCallingIdentity();
6423 try {
6424 // NetworkStatsService keeps tracking the active network interface and identity. It
6425 // records the delta with the corresponding network identity.
6426 // We just return the total video call data usage snapshot since boot.
6427 Phone phone = getPhone(subId);
6428 if (phone != null) {
6429 return phone.getVtDataUsage(perUidStats);
6430 }
6431 return null;
6432 } finally {
6433 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006434 }
Jack Yueb89b242016-06-22 13:27:47 -07006435 }
Jack Yu75ab2952016-07-08 14:29:33 -07006436
6437 /**
6438 * Policy control of data connection. Usually used when data limit is passed.
6439 * @param enabled True if enabling the data, otherwise disabling.
6440 * @param subId Subscription index
6441 * {@hide}
6442 */
6443 @Override
6444 public void setPolicyDataEnabled(boolean enabled, int subId) {
6445 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446
6447 final long identity = Binder.clearCallingIdentity();
6448 try {
6449 Phone phone = getPhone(subId);
6450 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006451 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452 }
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006455 }
6456 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006457
6458 /**
6459 * Get Client request stats
6460 * @return List of Client Request Stats
6461 * @hide
6462 */
6463 @Override
6464 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006466 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006467 return null;
6468 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006469 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471 final long identity = Binder.clearCallingIdentity();
6472 try {
6473 if (phone != null) {
6474 return phone.getClientRequestStats();
6475 }
6476
6477 return null;
6478 } finally {
6479 Binder.restoreCallingIdentity(identity);
6480 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006481 }
6482
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006483 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006484 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006485 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006486 }
Jack Yueb4124c2017-02-16 15:32:43 -08006487
6488 /**
Grace Chen70990072017-03-24 17:21:30 -07006489 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006490 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006491 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006492 * @param state State of SIM (power down, power up, pass through)
6493 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6494 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6495 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006496 *
6497 **/
6498 @Override
Grace Chen70990072017-03-24 17:21:30 -07006499 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006500 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006501 Phone phone = PhoneFactory.getPhone(slotIndex);
6502
vagdeviaf9a5b92018-08-15 16:01:53 -07006503 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006505 final long identity = Binder.clearCallingIdentity();
6506 try {
6507 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006508 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509 }
6510 } finally {
6511 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006512 }
6513 }
Shuo Qiandd210312017-04-12 22:11:33 +00006514
Tyler Gunn65d45c22017-06-05 11:22:26 -07006515 private boolean isUssdApiAllowed(int subId) {
6516 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006517 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006518 if (configManager == null) {
6519 return false;
6520 }
6521 PersistableBundle pb = configManager.getConfigForSubId(subId);
6522 if (pb == null) {
6523 return false;
6524 }
6525 return pb.getBoolean(
6526 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6527 }
6528
Shuo Qiandd210312017-04-12 22:11:33 +00006529 /**
6530 * Check if phone is in emergency callback mode
6531 * @return true if phone is in emergency callback mode
6532 * @param subId sub id
6533 */
goneil9c5f4872017-12-05 14:07:56 -08006534 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006535 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006536 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006537 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538
6539 final long identity = Binder.clearCallingIdentity();
6540 try {
6541 if (phone != null) {
6542 return phone.isInEcm();
6543 } else {
6544 return false;
6545 }
6546 } finally {
6547 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006548 }
6549 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006550
6551 /**
6552 * Get the current signal strength information for the given subscription.
6553 * Because this information is not updated when the device is in a low power state
6554 * it should not be relied-upon to be current.
6555 * @param subId Subscription index
6556 * @return the most recent cached signal strength info from the modem
6557 */
6558 @Override
6559 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 final long identity = Binder.clearCallingIdentity();
6561 try {
6562 Phone p = getPhone(subId);
6563 if (p == null) {
6564 return null;
6565 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006567 return p.getSignalStrength();
6568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006571 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006572
Pengquan Meng77b7f132018-08-22 14:49:57 -07006573 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006574 * Get the current modem radio state for the given slot.
6575 * @param slotIndex slot index.
6576 * @param callingPackage the name of the package making the call.
6577 * @return the current radio power state from the modem
6578 */
6579 @Override
6580 public int getRadioPowerState(int slotIndex, String callingPackage) {
6581 Phone phone = PhoneFactory.getPhone(slotIndex);
6582 if (phone != null) {
6583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6584 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6585 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6586 }
6587
6588 final long identity = Binder.clearCallingIdentity();
6589 try {
6590 return phone.getRadioPowerState();
6591 } finally {
6592 Binder.restoreCallingIdentity(identity);
6593 }
6594 }
6595 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6596 }
6597
6598 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006599 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6600 *
6601 * <p>Requires one of the following permissions:
6602 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6603 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6604 * privileges.
6605 *
6606 * @param subId subscription id
6607 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6608 * {@code false}.
6609 */
6610 @Override
6611 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006612 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6613 null /* message */);
6614
Pengquan Menga1bb6272018-09-06 09:59:22 -07006615 boolean isEnabled = false;
6616 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006617 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006618 Phone phone = getPhone(subId);
6619 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006620 } catch (Exception e) {
6621 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6622 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006623 } finally {
6624 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006625 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006626 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006627 }
6628
6629
6630 /**
6631 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6632 *
6633 * <p> Requires permission:
6634 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6635 * privileges.
6636 *
6637 * @param subId subscription id
6638 * @param isEnabled {@code true} means enable, {@code false} means disable.
6639 */
6640 @Override
6641 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6643 mApp, subId, "setDataRoamingEnabled");
6644
Pengquan Menga1bb6272018-09-06 09:59:22 -07006645 final long identity = Binder.clearCallingIdentity();
6646 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006647 Phone phone = getPhone(subId);
6648 if (phone != null) {
6649 phone.setDataRoamingEnabled(isEnabled);
6650 }
6651 } finally {
6652 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006653 }
6654 }
6655
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006656 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006657 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006658 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6659 mApp, subId, "isManualNetworkSelectionAllowed");
6660
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006661 boolean isAllowed = true;
6662 final long identity = Binder.clearCallingIdentity();
6663 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006664 Phone phone = getPhone(subId);
6665 if (phone != null) {
6666 isAllowed = phone.isCspPlmnEnabled();
6667 }
6668 } finally {
6669 Binder.restoreCallingIdentity(identity);
6670 }
6671 return isAllowed;
6672 }
6673
6674 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006675 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006676 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006677 try {
6678 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006679 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006680 } catch (SecurityException e) {
6681 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6682 // has carrier privileges on an active UICC
6683 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6684 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006685 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006686 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006687 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006688
6689 final long identity = Binder.clearCallingIdentity();
6690 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006691 UiccController uiccController = UiccController.getInstance();
6692 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006693 if (hasReadPermission) {
6694 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006695 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006696
6697 // Remove private info if the caller doesn't have access
6698 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6699 for (UiccCardInfo cardInfo : cardInfos) {
6700 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6701 // is available
6702 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6703 if (card == null || card.getUiccProfile() == null) {
6704 // assume no access if the card or profile is unavailable
6705 filteredInfos.add(cardInfo.getUnprivileged());
6706 continue;
6707 }
6708 UiccProfile profile = card.getUiccProfile();
6709 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6710 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6711 filteredInfos.add(cardInfo);
6712 } else {
6713 filteredInfos.add(cardInfo.getUnprivileged());
6714 }
6715 }
6716 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006717 } finally {
6718 Binder.restoreCallingIdentity(identity);
6719 }
6720 }
6721
6722 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006723 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006724 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726 final long identity = Binder.clearCallingIdentity();
6727 try {
6728 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6729 if (slots == null) {
6730 Rlog.i(LOG_TAG, "slots is null.");
6731 return null;
6732 }
6733
6734 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6735 for (int i = 0; i < slots.length; i++) {
6736 UiccSlot slot = slots[i];
6737 if (slot == null) {
6738 continue;
6739 }
6740
Jordan Liu7be7e652019-05-06 18:55:02 +00006741 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006742 UiccCard card = slot.getUiccCard();
6743 if (card != null) {
6744 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006745 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006746 cardId = slot.getEid();
6747 if (TextUtils.isEmpty(cardId)) {
6748 cardId = slot.getIccId();
6749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 }
6751
Jordan Liu857451f2019-05-09 16:35:35 -07006752 if (cardId != null) {
6753 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6754 // if cardId is an EID, it's all digits so this is fine
6755 cardId = IccUtils.stripTrailingFs(cardId);
6756 }
6757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 int cardState = 0;
6759 switch (slot.getCardState()) {
6760 case CARDSTATE_ABSENT:
6761 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6762 break;
6763 case CARDSTATE_PRESENT:
6764 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6765 break;
6766 case CARDSTATE_ERROR:
6767 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6768 break;
6769 case CARDSTATE_RESTRICTED:
6770 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6771 break;
6772 default:
6773 break;
6774
6775 }
6776
6777 infos[i] = new UiccSlotInfo(
6778 slot.isActive(),
6779 slot.isEuicc(),
6780 cardId,
6781 cardState,
6782 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006783 slot.isExtendedApduSupported(),
6784 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 }
6786 return infos;
6787 } finally {
6788 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006789 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006790 }
6791
6792 @Override
6793 public boolean switchSlots(int[] physicalSlots) {
6794 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795
6796 final long identity = Binder.clearCallingIdentity();
6797 try {
6798 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006802 }
Jack Yu4c988042018-02-27 15:30:01 -08006803
6804 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006805 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006806 final long identity = Binder.clearCallingIdentity();
6807 try {
6808 return UiccController.getInstance().getCardIdForDefaultEuicc();
6809 } finally {
6810 Binder.restoreCallingIdentity(identity);
6811 }
6812 }
6813
6814 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006815 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6816 enforceModifyPermission();
6817 final Phone phone = getPhone(subId);
6818 if (phone == null) {
6819 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6820 return;
6821 }
6822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823 final long identity = Binder.clearCallingIdentity();
6824 try {
6825 phone.setRadioIndicationUpdateMode(filters, mode);
6826 } finally {
6827 Binder.restoreCallingIdentity(identity);
6828 }
Jack Yu4c988042018-02-27 15:30:01 -08006829 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006830
6831 /**
goneil47ffb6e2018-04-06 15:40:58 -07006832 * A test API to reload the UICC profile.
6833 *
6834 * <p>Requires that the calling app has permission
6835 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6836 * @hide
6837 */
6838 @Override
6839 public void refreshUiccProfile(int subId) {
6840 enforceModifyPermission();
6841
6842 final long identity = Binder.clearCallingIdentity();
6843 try {
6844 Phone phone = getPhone(subId);
6845 if (phone == null) {
6846 return;
6847 }
6848 UiccCard uiccCard = phone.getUiccCard();
6849 if (uiccCard == null) {
6850 return;
6851 }
6852 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6853 if (uiccProfile == null) {
6854 return;
6855 }
6856 uiccProfile.refresh();
6857 } finally {
6858 Binder.restoreCallingIdentity(identity);
6859 }
6860 }
6861
6862 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006863 * Returns false if the mobile data is disabled by default, otherwise return true.
6864 */
6865 private boolean getDefaultDataEnabled() {
6866 return "true".equalsIgnoreCase(
6867 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6868 }
6869
6870 /**
6871 * Returns true if the data roaming is enabled by default, i.e the system property
6872 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6873 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6874 */
6875 private boolean getDefaultDataRoamingEnabled(int subId) {
6876 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006877 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006878 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6879 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6880 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6881 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6882 return isDataRoamingEnabled;
6883 }
6884
6885 /**
6886 * Returns the default network type for the given {@code subId}, if the default network type is
6887 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6888 */
6889 private int getDefaultNetworkType(int subId) {
6890 return Integer.parseInt(
6891 TelephonyManager.getTelephonyProperty(
6892 mSubscriptionController.getPhoneId(subId),
6893 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6894 String.valueOf(Phone.PREFERRED_NT_MODE)));
6895 }
fionaxua13278b2018-03-21 00:08:13 -07006896
6897 @Override
6898 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006899 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006900 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006901
6902 final long identity = Binder.clearCallingIdentity();
6903 try {
6904 final Phone phone = getPhone(subId);
6905 if (phone == null) {
6906 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6907 return;
6908 }
chen xueaba88a2019-03-15 13:15:10 -07006909 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6910 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 } finally {
6912 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006913 }
fionaxua13278b2018-03-21 00:08:13 -07006914 }
6915
6916 @Override
6917 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006918 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919
6920 final long identity = Binder.clearCallingIdentity();
6921 try {
6922 final Phone phone = getPhone(subId);
6923 if (phone == null) {
6924 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6925 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6926 }
6927 return phone.getCarrierIdListVersion();
6928 } finally {
6929 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006930 }
fionaxua13278b2018-03-21 00:08:13 -07006931 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006932
6933 @Override
6934 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6936 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6937 return -1;
6938 }
6939
6940 final long identity = Binder.clearCallingIdentity();
6941 try {
6942 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6943 } finally {
6944 Binder.restoreCallingIdentity(identity);
6945 }
6946 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006947
6948 @Override
6949 public int getCdmaRoamingMode(int subId) {
6950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6951 mApp, subId, "getCdmaRoamingMode");
6952
6953 final long identity = Binder.clearCallingIdentity();
6954 try {
6955 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
6958 }
6959 }
6960
6961 @Override
6962 public boolean setCdmaRoamingMode(int subId, int mode) {
6963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6964 mApp, subId, "setCdmaRoamingMode");
6965
6966 final long identity = Binder.clearCallingIdentity();
6967 try {
6968 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
6972 }
6973
6974 @Override
6975 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6977 mApp, subId, "setCdmaSubscriptionMode");
6978
6979 final long identity = Binder.clearCallingIdentity();
6980 try {
6981 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6982 } finally {
6983 Binder.restoreCallingIdentity(identity);
6984 }
6985 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006986
sqianc5eccab2018-10-19 18:46:41 -07006987 @Override
sqian8c685422019-02-22 15:55:18 -08006988 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006989 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006991 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006992 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6993 }
6994 final long identity = Binder.clearCallingIdentity();
6995 try {
sqian854d44b2018-12-12 16:48:18 -08006996 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6997 for (Phone phone: PhoneFactory.getPhones()) {
6998 if (phone.getEmergencyNumberTracker() != null
6999 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7000 emergencyNumberListInternal.put(
7001 phone.getSubId(),
7002 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7003 }
sqian11b7a0e2018-12-05 18:48:28 -08007004 }
sqian854d44b2018-12-12 16:48:18 -08007005 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
sqianc5eccab2018-10-19 18:46:41 -07007009 }
7010
7011 @Override
sqian8c685422019-02-22 15:55:18 -08007012 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007013 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007014 if (!exactMatch) {
7015 TelephonyPermissions
7016 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007017 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007018 }
7019 final long identity = Binder.clearCallingIdentity();
7020 try {
sqian854d44b2018-12-12 16:48:18 -08007021 for (Phone phone: PhoneFactory.getPhones()) {
7022 if (phone.getEmergencyNumberTracker() != null
7023 && phone.getEmergencyNumberTracker() != null) {
7024 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7025 number, exactMatch)) {
7026 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007027 }
7028 }
sqian11b7a0e2018-12-05 18:48:28 -08007029 }
7030 return false;
7031 } finally {
7032 Binder.restoreCallingIdentity(identity);
7033 }
7034 }
7035
sqianf4ca7ed2019-01-15 18:32:07 -08007036 /**
7037 * Update emergency number list for test mode.
7038 */
7039 @Override
7040 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7041 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7042 "updateEmergencyNumberListTestMode");
7043
7044 final long identity = Binder.clearCallingIdentity();
7045 try {
7046 for (Phone phone: PhoneFactory.getPhones()) {
7047 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7048 if (tracker != null) {
7049 tracker.executeEmergencyNumberTestModeCommand(action, num);
7050 }
7051 }
7052 } finally {
7053 Binder.restoreCallingIdentity(identity);
7054 }
7055 }
7056
7057 /**
7058 * Get the full emergency number list for test mode.
7059 */
7060 @Override
7061 public List<String> getEmergencyNumberListTestMode() {
7062 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7063 "getEmergencyNumberListTestMode");
7064
7065 final long identity = Binder.clearCallingIdentity();
7066 try {
7067 Set<String> emergencyNumbers = new HashSet<>();
7068 for (Phone phone: PhoneFactory.getPhones()) {
7069 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7070 if (tracker != null) {
7071 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7072 emergencyNumbers.add(num.getNumber());
7073 }
7074 }
7075 }
7076 return new ArrayList<>(emergencyNumbers);
7077 } finally {
7078 Binder.restoreCallingIdentity(identity);
7079 }
7080 }
7081
chen xud6b45bd2018-10-30 22:27:10 -07007082 @Override
7083 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7084 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7085 Phone phone = getPhone(subId);
7086 if (phone == null) {
7087 return null;
7088 }
7089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 UiccProfile profile = UiccController.getInstance()
7092 .getUiccProfileForPhone(phone.getPhoneId());
7093 if (profile != null) {
7094 return profile.getCertsFromCarrierPrivilegeAccessRules();
7095 }
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
7098 }
7099 return null;
7100 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007101
7102 /**
7103 * Enable or disable a modem stack.
7104 */
7105 @Override
7106 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7107 enforceModifyPermission();
7108
7109 final long identity = Binder.clearCallingIdentity();
7110 try {
7111 Phone phone = PhoneFactory.getPhone(slotIndex);
7112 if (phone == null) {
7113 return false;
7114 } else {
7115 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7116 }
7117 } finally {
7118 Binder.restoreCallingIdentity(identity);
7119 }
7120 }
Michelecea4cf22018-12-21 15:00:11 -08007121
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007122 /**
7123 * Whether a modem stack is enabled or not.
7124 */
7125 @Override
7126 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7127 Phone phone = PhoneFactory.getPhone(slotIndex);
7128 if (phone == null) return false;
7129
7130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7131 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7132 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7133 }
7134
7135 final long identity = Binder.clearCallingIdentity();
7136 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007137 try {
7138 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7139 } catch (NoSuchElementException ex) {
7140 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7141 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007142 } finally {
7143 Binder.restoreCallingIdentity(identity);
7144 }
7145 }
7146
Michelecea4cf22018-12-21 15:00:11 -08007147 @Override
Michele0ea7d782019-03-19 14:58:42 -07007148 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007149 enforceModifyPermission();
7150
7151 final long identity = Binder.clearCallingIdentity();
7152 try {
7153 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007154 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007155 .commit();
7156 } finally {
7157 Binder.restoreCallingIdentity(identity);
7158 }
7159 }
7160
7161 @Override
Michele0ea7d782019-03-19 14:58:42 -07007162 @TelephonyManager.IsMultiSimSupportedResult
7163 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007165 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7166 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007167 }
Michelecea4cf22018-12-21 15:00:11 -08007168
7169 final long identity = Binder.clearCallingIdentity();
7170 try {
Michele0ea7d782019-03-19 14:58:42 -07007171 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007172 } finally {
7173 Binder.restoreCallingIdentity(identity);
7174 }
7175 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007176
Michele0ea7d782019-03-19 14:58:42 -07007177 @TelephonyManager.IsMultiSimSupportedResult
7178 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007179 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7180 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7181 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007182 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7183 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007184 }
7185 // Check if the hardware supports multisim functionality. If usage of multisim is not
7186 // supported by the modem, indicate that it is restricted.
7187 PhoneCapability staticCapability =
7188 mPhoneConfigurationManager.getStaticPhoneCapability();
7189 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007190 loge("isMultiSimSupportedInternal: no static configuration available");
7191 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007192 }
7193 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007194 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7195 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007196 }
7197 // Check if support of multiple SIMs is restricted by carrier
7198 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007199 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007200 }
7201
Michele0ea7d782019-03-19 14:58:42 -07007202 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007203 }
7204
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007205 /**
7206 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007207 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7208 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7209 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007210 * @param numOfSims number of active sims we want to switch to
7211 */
7212 @Override
7213 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007214 if (numOfSims == 1) {
7215 enforceModifyPermission();
7216 } else {
7217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7218 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7219 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007220 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007221
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007222 try {
Michele30b57b22019-03-01 12:01:14 -08007223 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007224 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007225 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7226 return;
7227 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007228 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7229 } finally {
7230 Binder.restoreCallingIdentity(identity);
7231 }
7232 }
7233
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007234 @Override
7235 public boolean isApplicationOnUicc(int subId, int appType) {
7236 enforceReadPrivilegedPermission("isApplicationOnUicc");
7237 Phone phone = getPhone(subId);
7238 if (phone == null) {
7239 return false;
7240 }
7241 final long identity = Binder.clearCallingIdentity();
7242 try {
7243 UiccCard uiccCard = phone.getUiccCard();
7244 if (uiccCard == null) {
7245 return false;
7246 }
7247 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7248 if (uiccProfile == null) {
7249 return false;
7250 }
7251 if (TelephonyManager.APPTYPE_SIM <= appType
7252 && appType <= TelephonyManager.APPTYPE_ISIM) {
7253 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7254 }
7255 return false;
7256 } finally {
7257 Binder.restoreCallingIdentity(identity);
7258 }
7259 }
7260
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007261 /**
chen xub4baa772019-04-03 10:23:41 -07007262 * Get whether making changes to modem configurations will trigger reboot.
7263 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007264 */
7265 @Override
chen xub4baa772019-04-03 10:23:41 -07007266 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7268 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7269 return false;
7270 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7274 } finally {
7275 Binder.restoreCallingIdentity(identity);
7276 }
7277 }
7278
Nathan Harold29f5f052019-02-15 13:41:57 -08007279 private void updateModemStateMetrics() {
7280 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7281 // TODO: check the state for each modem if the api is ready.
7282 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7283 }
7284
Pengquan Meng3889a572019-01-23 11:16:29 -08007285 @Override
7286 public int[] getSlotsMapping() {
7287 enforceReadPrivilegedPermission("getSlotsMapping");
7288
7289 final long identity = Binder.clearCallingIdentity();
7290 try {
7291 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7292 // All logical slots should have a mapping to a physical slot.
7293 int[] logicalSlotsMapping = new int[phoneCount];
7294 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7295 for (int i = 0; i < slotInfos.length; i++) {
7296 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7297 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7298 }
7299 }
7300 return logicalSlotsMapping;
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303 }
7304 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007305
7306 /**
7307 * Get the IRadio HAL Version
7308 */
7309 @Override
7310 public int getRadioHalVersion() {
7311 Phone phone = getDefaultPhone();
7312 if (phone == null) return -1;
7313 HalVersion hv = phone.getHalVersion();
7314 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7315 return hv.major * 100 + hv.minor;
7316 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007317
7318 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007319 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7320 * corresponding network requests on a subId.
7321 *
7322 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007323 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007324 * 2) APN is un-metered for this subscription, or
7325 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7326 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7327 *
7328 * @return whether data is allowed for a apn type.
7329 *
7330 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007331 */
7332 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007333 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007334 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7335 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007336
7337 // Now that all security checks passes, perform the operation as ourselves.
7338 final long identity = Binder.clearCallingIdentity();
7339 try {
7340 Phone phone = getPhone(subId);
7341 if (phone == null) return false;
7342
Jack Yu41407ee2019-05-13 16:54:09 -07007343 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007344 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7345 } finally {
7346 Binder.restoreCallingIdentity(identity);
7347 }
7348 }
7349
7350 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007351 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007352 enforceReadPrivilegedPermission("isApnMetered");
7353
7354 // Now that all security checks passes, perform the operation as ourselves.
7355 final long identity = Binder.clearCallingIdentity();
7356 try {
7357 Phone phone = getPhone(subId);
7358 if (phone == null) return true; // By default return true.
7359
Jack Yu41407ee2019-05-13 16:54:09 -07007360 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007361 } finally {
7362 Binder.restoreCallingIdentity(identity);
7363 }
7364 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007365
7366 @Override
7367 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7368 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7369 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7370 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7371 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7372 }
7373 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7374 Intent intent = new Intent();
7375 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7376 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7377 // Bring up choose default SMS subscription dialog right now
7378 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7379 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7380 mApp.startActivity(intent);
7381 }
chen xud5ca2d52019-05-28 15:20:57 -07007382
7383 @Override
7384 public String getMmsUAProfUrl(int subId) {
7385 //TODO investigate if this API should require proper permission check in R b/133791609
7386 final long identity = Binder.clearCallingIdentity();
7387 try {
7388 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7389 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7390 } finally {
7391 Binder.restoreCallingIdentity(identity);
7392 }
7393 }
7394
7395 @Override
7396 public String getMmsUserAgent(int subId) {
7397 //TODO investigate if this API should require proper permission check in R b/133791609
7398 final long identity = Binder.clearCallingIdentity();
7399 try {
7400 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7401 .getString(com.android.internal.R.string.config_mms_user_agent);
7402 } finally {
7403 Binder.restoreCallingIdentity(identity);
7404 }
7405 }
Jack Yub07d4972019-05-28 16:12:25 -07007406
7407 @Override
7408 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7409 enforceModifyPermission();
7410
7411 // Now that all security checks passes, perform the operation as ourselves.
7412 final long identity = Binder.clearCallingIdentity();
7413 try {
7414 Phone phone = getPhone(subId);
7415 if (phone == null) return false;
7416
7417 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7418 } finally {
7419 Binder.restoreCallingIdentity(identity);
7420 }
7421 }
7422
7423 @Override
7424 public boolean isDataAllowedInVoiceCall(int subId) {
7425 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7426
7427 // Now that all security checks passes, perform the operation as ourselves.
7428 final long identity = Binder.clearCallingIdentity();
7429 try {
7430 Phone phone = getPhone(subId);
7431 if (phone == null) return false;
7432
7433 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7434 } finally {
7435 Binder.restoreCallingIdentity(identity);
7436 }
7437 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007438
7439 /**
7440 * Updates whether conference event pacakge handling is enabled.
7441 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7442 * otherwise.
7443 */
7444 @Override
7445 public void setCepEnabled(boolean isCepEnabled) {
7446 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7447
7448 final long identity = Binder.clearCallingIdentity();
7449 try {
7450 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7451 for (Phone phone : PhoneFactory.getPhones()) {
7452 Phone defaultPhone = phone.getImsPhone();
7453 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7454 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7455 ImsPhoneCallTracker imsPhoneCallTracker =
7456 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7457 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7458 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7459 + imsPhone.getMsisdn());
7460 }
7461 }
7462 } finally {
7463 Binder.restoreCallingIdentity(identity);
7464 }
7465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007466}