blob: 337d998bfcc8f1ad6f661f2d578f66d118b6637e [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 Ebinger35c841c2018-10-01 10:40:55 -0700102import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800103import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700104import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsMmTelFeature;
106import android.telephony.ims.aidl.IImsRcsFeature;
107import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700108import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700109import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800110import android.telephony.ims.feature.MmTelFeature;
111import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800112import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800114import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800116import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800118
Andrew Lee312e8172014-10-23 17:01:36 -0700119import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800120import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700122import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700123import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800124import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700125import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700126import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800128import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700129import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800130import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800132import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700133import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100134import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700135import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700136import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700138import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800139import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700140import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700141import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700142import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700143import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700144import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700145import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700146import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700147import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800148import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800149import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700150import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800151import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700152import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800153import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700154import com.android.internal.telephony.imsphone.ImsPhone;
155import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800156import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900157import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.uicc.IccIoResult;
159import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800160import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700161import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800164import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000165import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700166import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700168import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700169import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800170import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700171import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700172import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800173
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700174import java.io.FileDescriptor;
175import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800177import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800178import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800179import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800180import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100181import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800182import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700183import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800184import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185
186/**
187 * Implementation of the ITelephony interface.
188 */
Santos Cordon117fee72014-05-16 17:56:12 -0700189public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190 private static final String LOG_TAG = "PhoneInterfaceManager";
191 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
192 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800193 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
195 // Message codes used with mMainThreadHandler
196 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700197 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
198 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199 private static final int CMD_OPEN_CHANNEL = 9;
200 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
201 private static final int CMD_CLOSE_CHANNEL = 11;
202 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800203 private static final int CMD_NV_READ_ITEM = 13;
204 private static final int EVENT_NV_READ_ITEM_DONE = 14;
205 private static final int CMD_NV_WRITE_ITEM = 15;
206 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
207 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
208 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700209 private static final int CMD_RESET_MODEM_CONFIG = 19;
210 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800211 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
212 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
213 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
214 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800215 private static final int CMD_SEND_ENVELOPE = 25;
216 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000217 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
218 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700219 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
220 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
221 private static final int CMD_EXCHANGE_SIM_IO = 31;
222 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800223 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
224 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700225 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
226 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700227 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
228 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700229 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
230 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
231 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
232 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700233 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
234 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
235 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
236 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700237 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800238 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
239 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000240 private static final int CMD_SWITCH_SLOTS = 50;
241 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700242 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
243 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
244 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
245 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
246 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
247 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
248 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
249 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700250 private static final int CMD_GET_ALL_CELL_INFO = 60;
251 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
252 private static final int CMD_GET_CELL_LOCATION = 62;
253 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700254 private static final int CMD_MODEM_REBOOT = 64;
255 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700256 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
257 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800258 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
259 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700260 private static final int CMD_GET_MODEM_STATUS = 70;
261 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700262 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
263 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700264
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800265 // Parameters of select command.
266 private static final int SELECT_COMMAND = 0xA4;
267 private static final int SELECT_P1 = 0x04;
268 private static final int SELECT_P2 = 0;
269 private static final int SELECT_P3 = 0x10;
270
Pengquan Meng85728fb2018-03-12 16:31:21 -0700271 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
272 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
273 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
274
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 /** The singleton instance. */
276 private static PhoneInterfaceManager sInstance;
277
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700280 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private AppOpsManager mAppOps;
282 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800283 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700285 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
Derek Tan97ebb422014-09-05 16:55:38 -0700287 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
288 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800289 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800290 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700291
Michelecea4cf22018-12-21 15:00:11 -0800292 // String to store multi SIM allowed
293 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
294
Derek Tan740e1672017-06-27 14:56:27 -0700295 // The AID of ISD-R.
296 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
297
yinxub1bed742017-04-17 11:45:04 -0700298 private NetworkScanRequestTracker mNetworkScanRequestTracker;
299
David Kelly5e06a7f2018-03-12 14:10:59 +0000300 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
301 private static final int MANUFACTURER_CODE_LENGTH = 8;
302
Derek Tan89e89d42014-07-08 17:00:10 -0700303 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700304 * A request object to use for transmitting data to an ICC.
305 */
306 private static final class IccAPDUArgument {
307 public int channel, cla, command, p1, p2, p3;
308 public String data;
309
310 public IccAPDUArgument(int channel, int cla, int command,
311 int p1, int p2, int p3, String data) {
312 this.channel = channel;
313 this.cla = cla;
314 this.command = command;
315 this.p1 = p1;
316 this.p2 = p2;
317 this.p3 = p3;
318 this.data = data;
319 }
320 }
321
322 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700323 * A request object to use for transmitting data to an ICC.
324 */
325 private static final class ManualNetworkSelectionArgument {
326 public OperatorInfo operatorInfo;
327 public boolean persistSelection;
328
329 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
330 this.operatorInfo = operatorInfo;
331 this.persistSelection = persistSelection;
332 }
333 }
334
335 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
337 * request after sending. The main thread will notify the request when it is complete.
338 */
339 private static final class MainThreadRequest {
340 /** The argument to use for the request */
341 public Object argument;
342 /** The result of the request that is run on the main thread */
343 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800344 // The subscriber id that this request applies to. Defaults to
345 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
346 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347
Nathan Harold92bed182018-10-12 18:16:49 -0700348 // In cases where subId is unavailable, the caller needs to specify the phone.
349 public Phone phone;
350
vagdeviaf9a5b92018-08-15 16:01:53 -0700351 public WorkSource workSource;
352
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 public MainThreadRequest(Object argument) {
354 this.argument = argument;
355 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800356
Nathan Harold92bed182018-10-12 18:16:49 -0700357 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
358 this.argument = argument;
359 if (phone != null) {
360 this.phone = phone;
361 }
362 this.workSource = workSource;
363 }
364
vagdeviaf9a5b92018-08-15 16:01:53 -0700365 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800366 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800367 if (subId != null) {
368 this.subId = subId;
369 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700370 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 }
373
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800374 private static final class IncomingThirdPartyCallArgs {
375 public final ComponentName component;
376 public final String callId;
377 public final String callerDisplayName;
378
379 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
380 String callerDisplayName) {
381 this.component = component;
382 this.callId = callId;
383 this.callerDisplayName = callerDisplayName;
384 }
385 }
386
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 /**
388 * A handler that processes messages on the main thread in the phone process. Since many
389 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
390 * inbound binder threads to the main thread in the phone process. The Binder thread
391 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
392 * on, which will be notified when the operation completes and will contain the result of the
393 * request.
394 *
395 * <p>If a MainThreadRequest object is provided in the msg.obj field,
396 * note that request.result must be set to something non-null for the calling thread to
397 * unblock.
398 */
399 private final class MainThreadHandler extends Handler {
400 @Override
401 public void handleMessage(Message msg) {
402 MainThreadRequest request;
403 Message onCompleted;
404 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800405 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700406 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800407 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408
409 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700410 case CMD_HANDLE_USSD_REQUEST: {
411 request = (MainThreadRequest) msg.obj;
412 final Phone phone = getPhoneFromRequest(request);
413 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
414 String ussdRequest = ussdObject.first;
415 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700416
Pengquan Menga1bb6272018-09-06 09:59:22 -0700417 if (!isUssdApiAllowed(request.subId)) {
418 // Carrier does not support use of this API, return failure.
419 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
420 UssdResponse response = new UssdResponse(ussdRequest, null);
421 Bundle returnData = new Bundle();
422 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
423 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700424
Pengquan Menga1bb6272018-09-06 09:59:22 -0700425 request.result = true;
426 notifyRequester(request);
427 return;
428 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700429
Pengquan Menga1bb6272018-09-06 09:59:22 -0700430 try {
431 request.result = phone != null
432 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
433 } catch (CallStateException cse) {
434 request.result = false;
435 }
436 // Wake up the requesting thread
437 notifyRequester(request);
438 break;
pkanwar32d516d2016-10-14 19:37:38 -0700439 }
440
Yorke Lee716f67e2015-06-17 15:39:16 -0700441 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700443 final Phone phone = getPhoneFromRequest(request);
444 request.result = phone != null ?
445 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
446 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700448 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700451
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800455 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700456 if (uiccCard == null) {
457 loge("iccTransmitApduLogicalChannel: No UICC");
458 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700460 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
462 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700463 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 iccArgument.channel, iccArgument.cla, iccArgument.command,
465 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700467 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700468 break;
469
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700471 ar = (AsyncResult) msg.obj;
472 request = (MainThreadRequest) ar.userObj;
473 if (ar.exception == null && ar.result != null) {
474 request.result = ar.result;
475 } else {
476 request.result = new IccIoResult(0x6F, 0, (byte[])null);
477 if (ar.result == null) {
478 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800479 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800481 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700482 } else {
483 loge("iccTransmitApduLogicalChannel: Unknown exception");
484 }
485 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 break;
488
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
490 request = (MainThreadRequest) msg.obj;
491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 if (uiccCard == null) {
494 loge("iccTransmitApduBasicChannel: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 } else {
498 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
499 request);
500 uiccCard.iccTransmitApduBasicChannel(
501 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
502 iccArgument.p3, iccArgument.data, onCompleted);
503 }
504 break;
505
506 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
507 ar = (AsyncResult) msg.obj;
508 request = (MainThreadRequest) ar.userObj;
509 if (ar.exception == null && ar.result != null) {
510 request.result = ar.result;
511 } else {
512 request.result = new IccIoResult(0x6F, 0, (byte[])null);
513 if (ar.result == null) {
514 loge("iccTransmitApduBasicChannel: Empty response");
515 } else if (ar.exception instanceof CommandException) {
516 loge("iccTransmitApduBasicChannel: CommandException: " +
517 ar.exception);
518 } else {
519 loge("iccTransmitApduBasicChannel: Unknown exception");
520 }
521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 break;
524
525 case CMD_EXCHANGE_SIM_IO:
526 request = (MainThreadRequest) msg.obj;
527 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800528 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 if (uiccCard == null) {
530 loge("iccExchangeSimIO: No UICC");
531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 } else {
534 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
535 request);
536 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
537 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
538 iccArgument.data, onCompleted);
539 }
540 break;
541
542 case EVENT_EXCHANGE_SIM_IO_DONE:
543 ar = (AsyncResult) msg.obj;
544 request = (MainThreadRequest) ar.userObj;
545 if (ar.exception == null && ar.result != null) {
546 request.result = ar.result;
547 } else {
548 request.result = new IccIoResult(0x6f, 0, (byte[])null);
549 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 break;
552
Derek Tan4d5e5c12014-02-04 11:54:58 -0800553 case CMD_SEND_ENVELOPE:
554 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800555 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 if (uiccCard == null) {
557 loge("sendEnvelopeWithStatus: No UICC");
558 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 } else {
561 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
562 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
563 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800564 break;
565
566 case EVENT_SEND_ENVELOPE_DONE:
567 ar = (AsyncResult) msg.obj;
568 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700569 if (ar.exception == null && ar.result != null) {
570 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800571 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700572 request.result = new IccIoResult(0x6F, 0, (byte[])null);
573 if (ar.result == null) {
574 loge("sendEnvelopeWithStatus: Empty response");
575 } else if (ar.exception instanceof CommandException) {
576 loge("sendEnvelopeWithStatus: CommandException: " +
577 ar.exception);
578 } else {
579 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
580 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800581 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800583 break;
584
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 case CMD_OPEN_CHANNEL:
586 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800587 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800588 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 if (uiccCard == null) {
590 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800591 request.result = new IccOpenLogicalChannelResponse(-1,
592 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 } else {
595 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800596 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
597 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 break;
600
601 case EVENT_OPEN_CHANNEL_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 int[] result = (int[]) ar.result;
607 int channelId = result[0];
608 byte[] selectResponse = null;
609 if (result.length > 1) {
610 selectResponse = new byte[result.length - 1];
611 for (int i = 1; i < result.length; ++i) {
612 selectResponse[i - 1] = (byte) result[i];
613 }
614 }
615 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700616 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 if (ar.result == null) {
619 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 if (ar.exception != null) {
622 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
623 }
624
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700626 if (ar.exception instanceof CommandException) {
627 CommandException.Error error =
628 ((CommandException) (ar.exception)).getCommandError();
629 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700630 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700631 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700632 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 }
634 }
635 openChannelResp = new IccOpenLogicalChannelResponse(
636 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700638 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 break;
641
642 case CMD_CLOSE_CHANNEL:
643 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800644 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700645 if (uiccCard == null) {
646 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900647 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700649 } else {
650 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
651 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
652 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 break;
654
655 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800656 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
657 break;
658
659 case CMD_NV_READ_ITEM:
660 request = (MainThreadRequest) msg.obj;
661 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800662 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
663 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800664 break;
665
666 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 ar = (AsyncResult) msg.obj;
668 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800669 if (ar.exception == null && ar.result != null) {
670 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800672 request.result = "";
673 if (ar.result == null) {
674 loge("nvReadItem: Empty response");
675 } else if (ar.exception instanceof CommandException) {
676 loge("nvReadItem: CommandException: " +
677 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800679 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 }
681 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700682 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 break;
684
Jake Hambye994d462014-02-03 13:10:13 -0800685 case CMD_NV_WRITE_ITEM:
686 request = (MainThreadRequest) msg.obj;
687 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
688 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800689 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700690 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
693 case EVENT_NV_WRITE_ITEM_DONE:
694 handleNullReturnEvent(msg, "nvWriteItem");
695 break;
696
697 case CMD_NV_WRITE_CDMA_PRL:
698 request = (MainThreadRequest) msg.obj;
699 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800700 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_WRITE_CDMA_PRL_DONE:
704 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
705 break;
706
chen xu6dac5ab2018-10-26 17:39:23 -0700707 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800708 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700709 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800710 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800711 break;
712
chen xu6dac5ab2018-10-26 17:39:23 -0700713 case EVENT_RESET_MODEM_CONFIG_DONE:
714 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800715 break;
716
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 case CMD_GET_PREFERRED_NETWORK_TYPE:
718 request = (MainThreadRequest) msg.obj;
719 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700720 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800721 break;
722
723 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
724 ar = (AsyncResult) msg.obj;
725 request = (MainThreadRequest) ar.userObj;
726 if (ar.exception == null && ar.result != null) {
727 request.result = ar.result; // Integer
728 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800729 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 if (ar.result == null) {
731 loge("getPreferredNetworkType: Empty response");
732 } else if (ar.exception instanceof CommandException) {
733 loge("getPreferredNetworkType: CommandException: " +
734 ar.exception);
735 } else {
736 loge("getPreferredNetworkType: Unknown exception");
737 }
738 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700739 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 break;
741
742 case CMD_SET_PREFERRED_NETWORK_TYPE:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
745 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700746 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 break;
748
749 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
750 handleNullReturnEvent(msg, "setPreferredNetworkType");
751 break;
752
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000753 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
754 request = (MainThreadRequest)msg.obj;
755 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800756 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000757 break;
758
759 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
760 ar = (AsyncResult)msg.obj;
761 request = (MainThreadRequest)ar.userObj;
762 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700763 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000764 break;
765
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800766 case CMD_SET_VOICEMAIL_NUMBER:
767 request = (MainThreadRequest) msg.obj;
768 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
769 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800770 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
771 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800772 break;
773
774 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
775 handleNullReturnEvent(msg, "setVoicemailNumber");
776 break;
777
Stuart Scott54788802015-03-30 13:18:01 -0700778 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
779 request = (MainThreadRequest) msg.obj;
780 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
781 request);
782 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
783 break;
784
785 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
786 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
787 break;
788
Shishir Agrawal302c8692015-06-19 13:49:39 -0700789 case CMD_PERFORM_NETWORK_SCAN:
790 request = (MainThreadRequest) msg.obj;
791 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
792 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
793 break;
794
795 case EVENT_PERFORM_NETWORK_SCAN_DONE:
796 ar = (AsyncResult) msg.obj;
797 request = (MainThreadRequest) ar.userObj;
798 CellNetworkScanResult cellScanResult;
799 if (ar.exception == null && ar.result != null) {
800 cellScanResult = new CellNetworkScanResult(
801 CellNetworkScanResult.STATUS_SUCCESS,
802 (List<OperatorInfo>) ar.result);
803 } else {
804 if (ar.result == null) {
805 loge("getCellNetworkScanResults: Empty response");
806 }
807 if (ar.exception != null) {
808 loge("getCellNetworkScanResults: Exception: " + ar.exception);
809 }
810 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
811 if (ar.exception instanceof CommandException) {
812 CommandException.Error error =
813 ((CommandException) (ar.exception)).getCommandError();
814 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
815 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
816 } else if (error == CommandException.Error.GENERIC_FAILURE) {
817 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
818 }
819 }
820 cellScanResult = new CellNetworkScanResult(errorCode, null);
821 }
822 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700823 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 break;
825
826 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
827 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700828 ManualNetworkSelectionArgument selArg =
829 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
831 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700832 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
833 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700834 break;
835
836 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
839 if (ar.exception == null) {
840 request.result = true;
841 } else {
842 request.result = false;
843 loge("setNetworkSelectionModeManual " + ar.exception);
844 }
845 notifyRequester(request);
846 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700847 break;
848
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700849 case CMD_GET_MODEM_ACTIVITY_INFO:
850 request = (MainThreadRequest) msg.obj;
851 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700852 if (defaultPhone != null) {
853 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
854 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 break;
856
857 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
858 ar = (AsyncResult) msg.obj;
859 request = (MainThreadRequest) ar.userObj;
860 if (ar.exception == null && ar.result != null) {
861 request.result = ar.result;
862 } else {
863 if (ar.result == null) {
864 loge("queryModemActivityInfo: Empty response");
865 } else if (ar.exception instanceof CommandException) {
866 loge("queryModemActivityInfo: CommandException: " +
867 ar.exception);
868 } else {
869 loge("queryModemActivityInfo: Unknown exception");
870 }
871 }
Amit Mahajand4766222016-01-28 15:28:28 -0800872 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
873 if (request.result == null) {
874 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
875 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700876 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700877 break;
878
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 case CMD_SET_ALLOWED_CARRIERS:
880 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800881 CarrierRestrictionRules argument =
882 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700883 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800884 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 break;
886
887 case EVENT_SET_ALLOWED_CARRIERS_DONE:
888 ar = (AsyncResult) msg.obj;
889 request = (MainThreadRequest) ar.userObj;
890 if (ar.exception == null && ar.result != null) {
891 request.result = ar.result;
892 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800893 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
894 if (ar.exception instanceof CommandException) {
895 loge("setAllowedCarriers: CommandException: " + ar.exception);
896 CommandException.Error error =
897 ((CommandException) (ar.exception)).getCommandError();
898 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
899 request.result =
900 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
901 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700902 } else {
903 loge("setAllowedCarriers: Unknown exception");
904 }
905 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700906 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 break;
908
909 case CMD_GET_ALLOWED_CARRIERS:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800912 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 break;
914
915 case EVENT_GET_ALLOWED_CARRIERS_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null && ar.result != null) {
919 request.result = ar.result;
920 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800921 request.result = new IllegalStateException(
922 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700923 if (ar.result == null) {
924 loge("getAllowedCarriers: Empty response");
925 } else if (ar.exception instanceof CommandException) {
926 loge("getAllowedCarriers: CommandException: " +
927 ar.exception);
928 } else {
929 loge("getAllowedCarriers: Unknown exception");
930 }
931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700932 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700933 break;
934
Nathan Haroldb3014052017-01-25 15:57:32 -0800935 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
936 ar = (AsyncResult) msg.obj;
937 request = (MainThreadRequest) ar.userObj;
938 if (ar.exception == null && ar.result != null) {
939 request.result = ar.result;
940 } else {
941 request.result = new IllegalArgumentException(
942 "Failed to retrieve Forbidden Plmns");
943 if (ar.result == null) {
944 loge("getForbiddenPlmns: Empty response");
945 } else {
946 loge("getForbiddenPlmns: Unknown exception");
947 }
948 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700949 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800950 break;
951
952 case CMD_GET_FORBIDDEN_PLMNS:
953 request = (MainThreadRequest) msg.obj;
954 uiccCard = getUiccCardFromRequest(request);
955 if (uiccCard == null) {
956 loge("getForbiddenPlmns() UiccCard is null");
957 request.result = new IllegalArgumentException(
958 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700959 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800960 break;
961 }
962 Integer appType = (Integer) request.argument;
963 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
964 if (uiccApp == null) {
965 loge("getForbiddenPlmns() no app with specified type -- "
966 + appType);
967 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700968 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800969 break;
970 } else {
971 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
972 + " specified type -- " + appType);
973 }
974 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
975 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
976 onCompleted);
977 break;
978
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000979 case CMD_SWITCH_SLOTS:
980 request = (MainThreadRequest) msg.obj;
981 int[] physicalSlots = (int[]) request.argument;
982 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
983 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
984 break;
985
986 case EVENT_SWITCH_SLOTS_DONE:
987 ar = (AsyncResult) msg.obj;
988 request = (MainThreadRequest) ar.userObj;
989 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700990 notifyRequester(request);
991 break;
992 case CMD_GET_NETWORK_SELECTION_MODE:
993 request = (MainThreadRequest) msg.obj;
994 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
995 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
996 break;
997
998 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception != null) {
1002 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1003 } else {
1004 int mode = ((int[]) ar.result)[0];
1005 if (mode == 0) {
1006 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1007 } else {
1008 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1009 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001010 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001011 notifyRequester(request);
1012 break;
1013 case CMD_GET_CDMA_ROAMING_MODE:
1014 request = (MainThreadRequest) msg.obj;
1015 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1016 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1017 break;
1018 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1019 ar = (AsyncResult) msg.obj;
1020 request = (MainThreadRequest) ar.userObj;
1021 if (ar.exception != null) {
1022 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1023 } else {
1024 request.result = ((int[]) ar.result)[0];
1025 }
1026 notifyRequester(request);
1027 break;
1028 case CMD_SET_CDMA_ROAMING_MODE:
1029 request = (MainThreadRequest) msg.obj;
1030 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1031 int mode = (int) request.argument;
1032 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1033 break;
1034 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
1037 request.result = ar.exception == null;
1038 notifyRequester(request);
1039 break;
1040 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1041 request = (MainThreadRequest) msg.obj;
1042 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1043 int subscriptionMode = (int) request.argument;
1044 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1045 break;
1046 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1047 ar = (AsyncResult) msg.obj;
1048 request = (MainThreadRequest) ar.userObj;
1049 request.result = ar.exception == null;
1050 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001051 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001052 case CMD_GET_ALL_CELL_INFO:
1053 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001054 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001055 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 case EVENT_GET_ALL_CELL_INFO_DONE:
1058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001060 // If a timeout occurs, the response will be null
1061 request.result = (ar.exception == null && ar.result != null)
1062 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 synchronized (request) {
1064 request.notifyAll();
1065 }
1066 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001067 case CMD_REQUEST_CELL_INFO_UPDATE:
1068 request = (MainThreadRequest) msg.obj;
1069 request.phone.requestCellInfoUpdate(request.workSource,
1070 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1071 break;
1072 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1076 try {
1077 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001079 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1080 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001081 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001082 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001083 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 } else {
1085 // use the result as returned
1086 cb.onCellInfo((List<CellInfo>) ar.result);
1087 }
1088 } catch (RemoteException re) {
1089 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1090 }
1091 break;
1092 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001093 request = (MainThreadRequest) msg.obj;
1094 WorkSource ws = (WorkSource) request.argument;
1095 Phone phone = getPhoneFromRequest(request);
1096 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1097 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001098 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001099 ar = (AsyncResult) msg.obj;
1100 request = (MainThreadRequest) ar.userObj;
1101 if (ar.exception == null) {
1102 request.result = ar.result;
1103 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001104 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001105 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1106 ? new CdmaCellLocation() : new GsmCellLocation();
1107 }
1108
1109 synchronized (request) {
1110 request.notifyAll();
1111 }
1112 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001113 case CMD_MODEM_REBOOT:
1114 request = (MainThreadRequest) msg.obj;
1115 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001116 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001117 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001118 case EVENT_CMD_MODEM_REBOOT_DONE:
1119 handleNullReturnEvent(msg, "rebootModem");
1120 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001121 case CMD_REQUEST_ENABLE_MODEM:
1122 request = (MainThreadRequest) msg.obj;
1123 boolean enable = (boolean) request.argument;
1124 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001125 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001126 PhoneConfigurationManager.getInstance()
1127 .enablePhone(request.phone, enable, onCompleted);
1128 break;
1129 case EVENT_ENABLE_MODEM_DONE:
1130 ar = (AsyncResult) msg.obj;
1131 request = (MainThreadRequest) ar.userObj;
1132 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001133 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001134 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001135 if ((boolean) request.result) {
1136 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1137 updateModemStateMetrics();
1138 } else {
1139 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1140 + ar.exception);
1141 }
1142 notifyRequester(request);
1143 break;
1144 case CMD_GET_MODEM_STATUS:
1145 request = (MainThreadRequest) msg.obj;
1146 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1147 PhoneConfigurationManager.getInstance()
1148 .getPhoneStatusFromModem(request.phone, onCompleted);
1149 break;
1150 case EVENT_GET_MODEM_STATUS_DONE:
1151 ar = (AsyncResult) msg.obj;
1152 request = (MainThreadRequest) ar.userObj;
1153 int id = request.phone.getPhoneId();
1154 if (ar.exception == null && ar.result != null) {
1155 request.result = ar.result;
1156 //update the cache as modem status has changed
1157 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1158 (boolean) request.result);
1159 } else {
1160 // Return true if modem status cannot be retrieved. For most cases,
1161 // modem status is on. And for older version modems, GET_MODEM_STATUS
1162 // and disable modem are not supported. Modem is always on.
1163 // TODO: this should be fixed in R to support a third
1164 // status UNKNOWN b/131631629
1165 request.result = true;
1166 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1167 + ar.exception);
1168 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001169 notifyRequester(request);
1170 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001171 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1172 ar = (AsyncResult) msg.obj;
1173 request = (MainThreadRequest) ar.userObj;
1174 if (ar.exception == null && ar.result != null) {
1175 request.result = ar.result;
1176 } else {
1177 request.result = -1;
1178 loge("Failed to set Forbidden Plmns");
1179 if (ar.result == null) {
1180 loge("setForbidenPlmns: Empty response");
1181 } else if (ar.exception != null) {
1182 loge("setForbiddenPlmns: Exception: " + ar.exception);
1183 request.result = -1;
1184 } else {
1185 loge("setForbiddenPlmns: Unknown exception");
1186 }
1187 }
1188 notifyRequester(request);
1189 break;
1190 case CMD_SET_FORBIDDEN_PLMNS:
1191 request = (MainThreadRequest) msg.obj;
1192 uiccCard = getUiccCardFromRequest(request);
1193 if (uiccCard == null) {
1194 loge("setForbiddenPlmns: UiccCard is null");
1195 request.result = -1;
1196 notifyRequester(request);
1197 break;
1198 }
1199 Pair<Integer, List<String>> setFplmnsArgs =
1200 (Pair<Integer, List<String>>) request.argument;
1201 appType = setFplmnsArgs.first;
1202 List<String> fplmns = setFplmnsArgs.second;
1203 uiccApp = uiccCard.getApplicationByType(appType);
1204 if (uiccApp == null) {
1205 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1206 request.result = -1;
1207 loge("Failed to get UICC App");
1208 notifyRequester(request);
1209 } else {
1210 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1211 ((SIMRecords) uiccApp.getIccRecords())
1212 .setForbiddenPlmns(onCompleted, fplmns);
1213 }
1214 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001215 default:
1216 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1217 break;
1218 }
1219 }
Jake Hambye994d462014-02-03 13:10:13 -08001220
Pengquan Menga1bb6272018-09-06 09:59:22 -07001221 private void notifyRequester(MainThreadRequest request) {
1222 synchronized (request) {
1223 request.notifyAll();
1224 }
1225 }
1226
Jake Hambye994d462014-02-03 13:10:13 -08001227 private void handleNullReturnEvent(Message msg, String command) {
1228 AsyncResult ar = (AsyncResult) msg.obj;
1229 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1230 if (ar.exception == null) {
1231 request.result = true;
1232 } else {
1233 request.result = false;
1234 if (ar.exception instanceof CommandException) {
1235 loge(command + ": CommandException: " + ar.exception);
1236 } else {
1237 loge(command + ": Unknown exception");
1238 }
1239 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001240 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242 }
1243
1244 /**
1245 * Posts the specified command to be executed on the main thread,
1246 * waits for the request to complete, and returns the result.
1247 * @see #sendRequestAsync
1248 */
1249 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001250 return sendRequest(
1251 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001252 }
1253
1254 /**
1255 * Posts the specified command to be executed on the main thread,
1256 * waits for the request to complete, and returns the result.
1257 * @see #sendRequestAsync
1258 */
1259 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1260 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001261 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001262 }
1263
1264 /**
1265 * Posts the specified command to be executed on the main thread,
1266 * waits for the request to complete, and returns the result.
1267 * @see #sendRequestAsync
1268 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001269 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001270 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001271 }
1272
1273 /**
1274 * Posts the specified command to be executed on the main thread,
1275 * waits for the request to complete, and returns the result.
1276 * @see #sendRequestAsync
1277 */
Nathan Harold92bed182018-10-12 18:16:49 -07001278 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1279 return sendRequest(command, argument, subId, null, workSource);
1280 }
1281
1282 /**
1283 * Posts the specified command to be executed on the main thread,
1284 * waits for the request to complete, and returns the result.
1285 * @see #sendRequestAsync
1286 */
1287 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1288 return sendRequest(
1289 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1290 }
1291
1292 /**
1293 * Posts the specified command to be executed on the main thread,
1294 * waits for the request to complete, and returns the result.
1295 * @see #sendRequestAsync
1296 */
1297 private Object sendRequest(
1298 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1300 throw new RuntimeException("This method will deadlock if called from the main thread.");
1301 }
1302
Nathan Harold92bed182018-10-12 18:16:49 -07001303 MainThreadRequest request = null;
1304 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1305 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1306 } else if (phone != null) {
1307 request = new MainThreadRequest(argument, phone, workSource);
1308 } else {
1309 request = new MainThreadRequest(argument, subId, workSource);
1310 }
1311
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 Message msg = mMainThreadHandler.obtainMessage(command, request);
1313 msg.sendToTarget();
1314
1315 // Wait for the request to complete
1316 synchronized (request) {
1317 while (request.result == null) {
1318 try {
1319 request.wait();
1320 } catch (InterruptedException e) {
1321 // Do nothing, go back and wait until the request is complete
1322 }
1323 }
1324 }
1325 return request.result;
1326 }
1327
1328 /**
1329 * Asynchronous ("fire and forget") version of sendRequest():
1330 * Posts the specified command to be executed on the main thread, and
1331 * returns immediately.
1332 * @see #sendRequest
1333 */
1334 private void sendRequestAsync(int command) {
1335 mMainThreadHandler.sendEmptyMessage(command);
1336 }
1337
1338 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001339 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001340 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001341 */
1342 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001343 sendRequestAsync(command, argument, null, null);
1344 }
1345
1346 /**
1347 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1348 * @see {@link #sendRequest(int,Object)}
1349 */
1350 private void sendRequestAsync(
1351 int command, Object argument, Phone phone, WorkSource workSource) {
1352 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001353 Message msg = mMainThreadHandler.obtainMessage(command, request);
1354 msg.sendToTarget();
1355 }
1356
1357 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358 * Initialize the singleton PhoneInterfaceManager instance.
1359 * This is only done once, at startup, from PhoneApp.onCreate().
1360 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001361 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 synchronized (PhoneInterfaceManager.class) {
1363 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001364 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 } else {
1366 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1367 }
1368 return sInstance;
1369 }
1370 }
1371
1372 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001373 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001376 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1378 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001379 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 mTelephonySharedPreferences =
1381 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001382 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001383 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001384
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 publish();
1386 }
1387
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001388 private Phone getDefaultPhone() {
1389 Phone thePhone = getPhone(getDefaultSubscription());
1390 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1391 }
1392
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 private void publish() {
1394 if (DBG) log("publish: " + this);
1395
1396 ServiceManager.addService("phone", this);
1397 }
1398
Stuart Scott584921c2015-01-15 17:10:34 -08001399 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001400 if (request.phone != null) {
1401 return request.phone;
1402 } else {
1403 return getPhoneFromSubId(request.subId);
1404 }
1405 }
1406
1407 private Phone getPhoneFromSubId(int subId) {
1408 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1409 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001410 }
1411
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001412 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1413 Phone phone = getPhoneFromRequest(request);
1414 return phone == null ? null :
1415 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1416 }
1417
Wink Saville36469e72014-06-11 15:17:00 -07001418 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001419 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001420 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001422
1423 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001424 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001425 }
1426
Wink Savilleb564aae2014-10-23 10:18:09 -07001427 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 if (DBG) log("dial: " + number);
1429 // No permission check needed here: This is just a wrapper around the
1430 // ACTION_DIAL intent, which is available to any app since it puts up
1431 // the UI before it does anything.
1432
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001433 final long identity = Binder.clearCallingIdentity();
1434 try {
1435 String url = createTelUrl(number);
1436 if (url == null) {
1437 return;
1438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001440 // PENDING: should we just silently fail if phone is offhook or ringing?
1441 PhoneConstants.State state = mCM.getState(subId);
1442 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1443 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1444 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1445 mApp.startActivity(intent);
1446 }
1447 } finally {
1448 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 }
1450 }
1451
1452 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001453 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001454 }
1455
Wink Savilleb564aae2014-10-23 10:18:09 -07001456 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 if (DBG) log("call: " + number);
1458
1459 // This is just a wrapper around the ACTION_CALL intent, but we still
1460 // need to do a permission check since we're calling startActivity()
1461 // from the context of the phone app.
1462 enforceCallPermission();
1463
Jordan Liu1617b712019-07-10 15:06:26 -07001464 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 != AppOpsManager.MODE_ALLOWED) {
1466 return;
1467 }
1468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001469 final long identity = Binder.clearCallingIdentity();
1470 try {
1471 String url = createTelUrl(number);
1472 if (url == null) {
1473 return;
1474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001476 boolean isValid = false;
1477 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1478 if (slist != null) {
1479 for (SubscriptionInfo subInfoRecord : slist) {
1480 if (subInfoRecord.getSubscriptionId() == subId) {
1481 isValid = true;
1482 break;
1483 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001484 }
Wink Saville08874612014-08-31 19:19:58 -07001485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001486 if (!isValid) {
1487 return;
1488 }
Wink Saville08874612014-08-31 19:19:58 -07001489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001490 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1491 intent.putExtra(SUBSCRIPTION_KEY, subId);
1492 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1493 mApp.startActivity(intent);
1494 } finally {
1495 Binder.restoreCallingIdentity(identity);
1496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 }
1498
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001500 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001501 }
1502
Wink Savilleb564aae2014-10-23 10:18:09 -07001503 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001504 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001505 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1506 }
1507
1508 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001509 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001510 }
1511
Wink Savilleb564aae2014-10-23 10:18:09 -07001512 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001513 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001514 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1515 }
1516
1517 /** {@hide} */
1518 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001519 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001520 }
1521
Wink Savilleb564aae2014-10-23 10:18:09 -07001522 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001524
1525 final long identity = Binder.clearCallingIdentity();
1526 try {
1527 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1528 checkSimPin.start();
1529 return checkSimPin.unlockSim(null, pin);
1530 } finally {
1531 Binder.restoreCallingIdentity(identity);
1532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 }
1534
Wink Saville9de0f752013-10-22 19:04:03 -07001535 /** {@hide} */
1536 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001537 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001538 }
1539
Wink Savilleb564aae2014-10-23 10:18:09 -07001540 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001542
1543 final long identity = Binder.clearCallingIdentity();
1544 try {
1545 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1546 checkSimPuk.start();
1547 return checkSimPuk.unlockSim(puk, pin);
1548 } finally {
1549 Binder.restoreCallingIdentity(identity);
1550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001551 }
1552
1553 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001554 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 * a synchronous one.
1556 */
1557 private static class UnlockSim extends Thread {
1558
1559 private final IccCard mSimCard;
1560
1561 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001562 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1563 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564
1565 // For replies from SimCard interface
1566 private Handler mHandler;
1567
1568 // For async handler to identify request type
1569 private static final int SUPPLY_PIN_COMPLETE = 100;
1570
1571 public UnlockSim(IccCard simCard) {
1572 mSimCard = simCard;
1573 }
1574
1575 @Override
1576 public void run() {
1577 Looper.prepare();
1578 synchronized (UnlockSim.this) {
1579 mHandler = new Handler() {
1580 @Override
1581 public void handleMessage(Message msg) {
1582 AsyncResult ar = (AsyncResult) msg.obj;
1583 switch (msg.what) {
1584 case SUPPLY_PIN_COMPLETE:
1585 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1586 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001587 mRetryCount = msg.arg1;
1588 if (ar.exception != null) {
1589 if (ar.exception instanceof CommandException &&
1590 ((CommandException)(ar.exception)).getCommandError()
1591 == CommandException.Error.PASSWORD_INCORRECT) {
1592 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1593 } else {
1594 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1595 }
1596 } else {
1597 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 mDone = true;
1600 UnlockSim.this.notifyAll();
1601 }
1602 break;
1603 }
1604 }
1605 };
1606 UnlockSim.this.notifyAll();
1607 }
1608 Looper.loop();
1609 }
1610
1611 /*
1612 * Use PIN or PUK to unlock SIM card
1613 *
1614 * If PUK is null, unlock SIM card with PIN
1615 *
1616 * If PUK is not null, unlock SIM card with PUK and set PIN code
1617 */
Wink Saville9de0f752013-10-22 19:04:03 -07001618 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619
1620 while (mHandler == null) {
1621 try {
1622 wait();
1623 } catch (InterruptedException e) {
1624 Thread.currentThread().interrupt();
1625 }
1626 }
1627 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1628
1629 if (puk == null) {
1630 mSimCard.supplyPin(pin, callback);
1631 } else {
1632 mSimCard.supplyPuk(puk, pin, callback);
1633 }
1634
1635 while (!mDone) {
1636 try {
1637 Log.d(LOG_TAG, "wait for done");
1638 wait();
1639 } catch (InterruptedException e) {
1640 // Restore the interrupted status
1641 Thread.currentThread().interrupt();
1642 }
1643 }
1644 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001645 int[] resultArray = new int[2];
1646 resultArray[0] = mResult;
1647 resultArray[1] = mRetryCount;
1648 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 }
1650 }
1651
1652 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001653 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001654
1655 }
1656
Wink Savilleb564aae2014-10-23 10:18:09 -07001657 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 // No permission check needed here: this call is harmless, and it's
1659 // needed for the ServiceState.requestStateUpdate() call (which is
1660 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001661 final long identity = Binder.clearCallingIdentity();
1662 try {
1663 final Phone phone = getPhone(subId);
1664 if (phone != null) {
1665 phone.updateServiceLocation();
1666 }
1667 } finally {
1668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 }
1671
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001672 @Override
1673 public boolean isRadioOn(String callingPackage) {
1674 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001675 }
1676
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001677 @Override
1678 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001679 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001680 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001681 return false;
1682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001683
1684 final long identity = Binder.clearCallingIdentity();
1685 try {
1686 return isRadioOnForSubscriber(subId);
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
1689 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001690 }
1691
1692 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 final Phone phone = getPhone(subId);
1696 if (phone != null) {
1697 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1698 } else {
1699 return false;
1700 }
1701 } finally {
1702 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 }
1705
1706 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001707 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 }
Wink Saville36469e72014-06-11 15:17:00 -07001709
Wink Savilleb564aae2014-10-23 10:18:09 -07001710 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001712
1713 final long identity = Binder.clearCallingIdentity();
1714 try {
1715 final Phone phone = getPhone(subId);
1716 if (phone != null) {
1717 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1718 }
1719 } finally {
1720 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001721 }
Wink Saville36469e72014-06-11 15:17:00 -07001722 }
1723
1724 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001725 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001726 }
1727
Wink Savilleb564aae2014-10-23 10:18:09 -07001728 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001729 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001730
1731 final long identity = Binder.clearCallingIdentity();
1732 try {
1733 final Phone phone = getPhone(subId);
1734 if (phone == null) {
1735 return false;
1736 }
1737 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1738 toggleRadioOnOffForSubscriber(subId);
1739 }
1740 return true;
1741 } finally {
1742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
Wink Saville36469e72014-06-11 15:17:00 -07001745
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001746 public boolean needMobileRadioShutdown() {
1747 /*
1748 * If any of the Radios are available, it will need to be
1749 * shutdown. So return true if any Radio is available.
1750 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001751 final long identity = Binder.clearCallingIdentity();
1752 try {
1753 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1754 Phone phone = PhoneFactory.getPhone(i);
1755 if (phone != null && phone.isRadioAvailable()) return true;
1756 }
1757 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1758 return false;
1759 } finally {
1760 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001761 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001762 }
1763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001764 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001765 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001766 enforceModifyPermission();
1767
1768 final long identity = Binder.clearCallingIdentity();
1769 try {
1770 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1771 logv("Shutting down Phone " + i);
1772 shutdownRadioUsingPhoneId(i);
1773 }
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001776 }
1777 }
1778
1779 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001780 Phone phone = PhoneFactory.getPhone(phoneId);
1781 if (phone != null && phone.isRadioAvailable()) {
1782 phone.shutdownRadio();
1783 }
1784 }
1785
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001787 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001788
1789 final long identity = Binder.clearCallingIdentity();
1790 try {
1791 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1792 if (defaultPhone != null) {
1793 defaultPhone.setRadioPower(turnOn);
1794 return true;
1795 } else {
1796 loge("There's no default phone.");
1797 return false;
1798 }
1799 } finally {
1800 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001801 }
Wink Saville36469e72014-06-11 15:17:00 -07001802 }
1803
Wink Savilleb564aae2014-10-23 10:18:09 -07001804 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001806
1807 final long identity = Binder.clearCallingIdentity();
1808 try {
1809 final Phone phone = getPhone(subId);
1810 if (phone != null) {
1811 phone.setRadioPower(turnOn);
1812 return true;
1813 } else {
1814 return false;
1815 }
1816 } finally {
1817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 }
1820
Wink Saville36469e72014-06-11 15:17:00 -07001821 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001822 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 public boolean enableDataConnectivity() {
1824 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001825
1826 final long identity = Binder.clearCallingIdentity();
1827 try {
1828 int subId = mSubscriptionController.getDefaultDataSubId();
1829 final Phone phone = getPhone(subId);
1830 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001831 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001832 return true;
1833 } else {
1834 return false;
1835 }
1836 } finally {
1837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 }
1840
Wink Saville36469e72014-06-11 15:17:00 -07001841 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001842 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 public boolean disableDataConnectivity() {
1844 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001845
1846 final long identity = Binder.clearCallingIdentity();
1847 try {
1848 int subId = mSubscriptionController.getDefaultDataSubId();
1849 final Phone phone = getPhone(subId);
1850 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001851 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852 return true;
1853 } else {
1854 return false;
1855 }
1856 } finally {
1857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 }
1860
Sanket Padawe356d7632015-06-22 14:03:32 -07001861 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001862 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001863 final long identity = Binder.clearCallingIdentity();
1864 try {
1865 final Phone phone = getPhone(subId);
1866 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001867 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001868 } else {
1869 return false;
1870 }
1871 } finally {
1872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 }
1875
1876 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001877 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001878 }
1879
pkanwarae03a6b2016-11-06 20:37:09 -08001880 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001881 enforceCallPermission();
1882
1883 final long identity = Binder.clearCallingIdentity();
1884 try {
1885 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1886 return;
1887 }
1888 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1889 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
1892 }
pkanwar32d516d2016-10-14 19:37:38 -07001893 };
1894
Wink Savilleb564aae2014-10-23 10:18:09 -07001895 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001897
1898 final long identity = Binder.clearCallingIdentity();
1899 try {
1900 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1901 return false;
1902 }
1903 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1904 } finally {
1905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001910 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001911 }
1912
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001913 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 final long identity = Binder.clearCallingIdentity();
1915 try {
1916 Phone phone = PhoneFactory.getPhone(slotIndex);
1917 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1918 PhoneConstantConversions.convertCallState(phone.getState());
1919 } finally {
1920 Binder.restoreCallingIdentity(identity);
1921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001925 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001926 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1927 }
1928
1929 @Override
1930 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001931 final long identity = Binder.clearCallingIdentity();
1932 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001933 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001934 if (phone != null) {
1935 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1936 } else {
1937 return PhoneConstantConversions.convertDataState(
1938 PhoneConstants.DataState.DISCONNECTED);
1939 }
1940 } finally {
1941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001946 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001947 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1948 }
1949
1950 @Override
1951 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001952 final long identity = Binder.clearCallingIdentity();
1953 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001954 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 if (phone != null) {
1956 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1957 } else {
1958 return TelephonyManager.DATA_ACTIVITY_NONE;
1959 }
1960 } finally {
1961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 }
1964
1965 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001966 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001967 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001968 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001969
1970 LocationAccessPolicy.LocationPermissionResult locationResult =
1971 LocationAccessPolicy.checkLocationPermission(mApp,
1972 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1973 .setCallingPackage(callingPackage)
1974 .setCallingPid(Binder.getCallingPid())
1975 .setCallingUid(Binder.getCallingUid())
1976 .setMethod("getCellLocation")
1977 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1978 .build());
1979 switch (locationResult) {
1980 case DENIED_HARD:
1981 throw new SecurityException("Not allowed to access cell location");
1982 case DENIED_SOFT:
1983 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 }
1985
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001986 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987 final long identity = Binder.clearCallingIdentity();
1988 try {
1989 if (DBG_LOC) log("getCellLocation: is active user");
1990 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001991 int subId = mSubscriptionController.getDefaultDataSubId();
1992 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1993 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001994 return data;
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
1997 }
Svetoslav64fad262015-04-14 14:35:21 -07001998 }
1999
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002001 public String getNetworkCountryIsoForPhone(int phoneId) {
2002 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2003 // registered cell info, so return a NULL country instead.
2004 final long identity = Binder.clearCallingIdentity();
2005 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002006 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2007 // Get default phone in this case.
2008 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2009 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002010 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002011 // Todo: fix this when we can get the actual cellular network info when the device
2012 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002013 if (TelephonyManager.NETWORK_TYPE_IWLAN
2014 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2015 return "";
2016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002017 Phone phone = PhoneFactory.getPhone(phoneId);
2018 if (phone != null) {
2019 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002020 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021 if (sst != null) {
2022 LocaleTracker lt = sst.getLocaleTracker();
2023 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002024 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2025 return lt.getCurrentCountry();
2026 } else if (emergencyNumberTracker != null) {
2027 return emergencyNumberTracker.getEmergencyCountryIso();
2028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002029 }
2030 }
2031 }
2032 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002033 } finally {
2034 Binder.restoreCallingIdentity(identity);
2035 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002036 }
2037
2038 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002040 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002041 }
2042
Sanket Padawe356d7632015-06-22 14:03:32 -07002043 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002044 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 mApp.enforceCallingOrSelfPermission(
2046 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002047
2048 final long identity = Binder.clearCallingIdentity();
2049 try {
2050 final Phone phone = getPhone(subId);
2051 if (phone != null) {
2052 phone.enableLocationUpdates();
2053 }
2054 } finally {
2055 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 }
2058
2059 @Override
2060 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002061 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002062 }
2063
Sanket Padawe356d7632015-06-22 14:03:32 -07002064 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002065 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 mApp.enforceCallingOrSelfPermission(
2067 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002068
2069 final long identity = Binder.clearCallingIdentity();
2070 try {
2071 final Phone phone = getPhone(subId);
2072 if (phone != null) {
2073 phone.disableLocationUpdates();
2074 }
2075 } finally {
2076 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002077 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 }
2079
Nathan Harold31d7ff32018-10-15 20:20:30 -07002080 /**
2081 * Returns the target SDK version number for a given package name.
2082 *
Nathan Haroldec184742019-07-10 17:04:16 -07002083 * This call MUST be invoked before clearing the calling UID.
2084 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002085 * @return target SDK if the package is found or INT_MAX.
2086 */
2087 private int getTargetSdk(String packageName) {
2088 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002089 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002090 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002091 if (ai != null) return ai.targetSdkVersion;
2092 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002093 loge("Failed to get package info for pkg="
2094 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002095 }
2096 return Integer.MAX_VALUE;
2097 }
2098
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 @Override
2100 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002101 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2102 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002103 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2104 throw new SecurityException(
2105 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2106 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002107
Jordan Liu1617b712019-07-10 15:06:26 -07002108 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2110 return null;
2111 }
Svetoslav64fad262015-04-14 14:35:21 -07002112
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002113 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114
Nathan Haroldf180aac2018-06-01 18:43:55 -07002115 List<CellInfo> info = getAllCellInfo(callingPackage);
2116 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117
Nathan Haroldf180aac2018-06-01 18:43:55 -07002118 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2119 for (CellInfo ci : info) {
2120 if (ci instanceof CellInfoGsm) {
2121 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2122 } else if (ci instanceof CellInfoWcdma) {
2123 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002126 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002129 private List<CellInfo> getCachedCellInfo() {
2130 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2131 for (Phone phone : PhoneFactory.getPhones()) {
2132 List<CellInfo> info = phone.getAllCellInfo();
2133 if (info != null) cellInfos.addAll(info);
2134 }
2135 return cellInfos;
2136 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137
2138 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002139 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002140 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002141 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002142
2143 LocationAccessPolicy.LocationPermissionResult locationResult =
2144 LocationAccessPolicy.checkLocationPermission(mApp,
2145 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2146 .setCallingPackage(callingPackage)
2147 .setCallingPid(Binder.getCallingPid())
2148 .setCallingUid(Binder.getCallingUid())
2149 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002150 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002151 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2152 .build());
2153 switch (locationResult) {
2154 case DENIED_HARD:
2155 throw new SecurityException("Not allowed to access cell info");
2156 case DENIED_SOFT:
2157 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 }
2159
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002160 final int targetSdk = getTargetSdk(callingPackage);
2161 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2162 return getCachedCellInfo();
2163 }
2164
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002165 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002166 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002167 final long identity = Binder.clearCallingIdentity();
2168 try {
2169 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2170 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002171 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002172 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002173 if (info != null) cellInfos.addAll(info);
2174 }
2175 return cellInfos;
2176 } finally {
2177 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 }
2179 }
2180
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002181 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002182 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2183 requestCellInfoUpdateInternal(
2184 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2185 }
2186
2187 @Override
2188 public void requestCellInfoUpdateWithWorkSource(
2189 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2190 enforceModifyPermission();
2191 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2192 }
2193
2194 private void requestCellInfoUpdateInternal(
2195 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002196 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002197 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002198
2199 LocationAccessPolicy.LocationPermissionResult locationResult =
2200 LocationAccessPolicy.checkLocationPermission(mApp,
2201 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2202 .setCallingPackage(callingPackage)
2203 .setCallingPid(Binder.getCallingPid())
2204 .setCallingUid(Binder.getCallingUid())
2205 .setMethod("requestCellInfoUpdate")
2206 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2207 .build());
2208 switch (locationResult) {
2209 case DENIED_HARD:
2210 throw new SecurityException("Not allowed to access cell info");
2211 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002212 try {
2213 cb.onCellInfo(new ArrayList<CellInfo>());
2214 } catch (RemoteException re) {
2215 // Drop without consequences
2216 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002217 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002218 }
2219
Nathan Harolda939a962019-05-09 10:13:47 -07002220
2221 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002222 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2223
2224 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2225 }
2226
2227 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002229 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002230 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231
2232 final long identity = Binder.clearCallingIdentity();
2233 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002234 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235 } finally {
2236 Binder.restoreCallingIdentity(identity);
2237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 }
2239
Shishir Agrawala9f32182016-04-12 12:00:16 -07002240 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002241 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002242 Phone phone = PhoneFactory.getPhone(slotIndex);
2243 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002244 return null;
2245 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002246 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002247 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2248 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002249 return null;
2250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002251
2252 final long identity = Binder.clearCallingIdentity();
2253 try {
2254 return phone.getImei();
2255 } finally {
2256 Binder.restoreCallingIdentity(identity);
2257 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002258 }
2259
2260 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002261 public String getTypeAllocationCodeForSlot(int slotIndex) {
2262 Phone phone = PhoneFactory.getPhone(slotIndex);
2263 String tac = null;
2264 if (phone != null) {
2265 String imei = phone.getImei();
2266 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2267 }
2268 return tac;
2269 }
2270
2271 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002272 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002273 Phone phone = PhoneFactory.getPhone(slotIndex);
2274 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002275 return null;
2276 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002277
Jeff Davidson913390f2018-02-23 17:11:49 -08002278 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002279 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2280 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002281 return null;
2282 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002283
2284 final long identity = Binder.clearCallingIdentity();
2285 try {
2286 return phone.getMeid();
2287 } finally {
2288 Binder.restoreCallingIdentity(identity);
2289 }
Jack Yu2af8d712017-03-15 17:14:14 -07002290 }
2291
2292 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002293 public String getManufacturerCodeForSlot(int slotIndex) {
2294 Phone phone = PhoneFactory.getPhone(slotIndex);
2295 String manufacturerCode = null;
2296 if (phone != null) {
2297 String meid = phone.getMeid();
2298 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2299 }
2300 return manufacturerCode;
2301 }
2302
2303 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002304 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002305 Phone phone = PhoneFactory.getPhone(slotIndex);
2306 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002307 return null;
2308 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002309 int subId = phone.getSubId();
2310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2311 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2312 return null;
2313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002314
2315 final long identity = Binder.clearCallingIdentity();
2316 try {
2317 return phone.getDeviceSvn();
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
2320 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002321 }
2322
fionaxu43304da2017-11-27 22:51:16 -08002323 @Override
2324 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 final Phone phone = getPhone(subId);
2328 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
2331 }
fionaxu43304da2017-11-27 22:51:16 -08002332 }
2333
2334 @Override
2335 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002336 final long identity = Binder.clearCallingIdentity();
2337 try {
2338 final Phone phone = getPhone(subId);
2339 return phone == null ? null : phone.getCarrierName();
2340 } finally {
2341 Binder.restoreCallingIdentity(identity);
2342 }
fionaxu43304da2017-11-27 22:51:16 -08002343 }
2344
calvinpanffe225e2018-11-01 19:43:06 +08002345 @Override
chen xu0026ca62019-03-06 15:28:50 -08002346 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002347 final long identity = Binder.clearCallingIdentity();
2348 try {
2349 final Phone phone = getPhone(subId);
2350 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002351 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002352 } finally {
2353 Binder.restoreCallingIdentity(identity);
2354 }
2355 }
2356
2357 @Override
chen xu0026ca62019-03-06 15:28:50 -08002358 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002362 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002363 } finally {
2364 Binder.restoreCallingIdentity(identity);
2365 }
2366 }
2367
chen xu651eec72018-11-11 19:03:44 -08002368 @Override
chen xu864e11c2018-12-06 22:10:03 -08002369 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2370 if (!isSubscriptionMccMnc) {
2371 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2372 }
chen xu651eec72018-11-11 19:03:44 -08002373 final Phone phone = PhoneFactory.getPhone(slotIndex);
2374 if (phone == null) {
2375 return TelephonyManager.UNKNOWN_CARRIER_ID;
2376 }
2377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2380 } finally {
2381 Binder.restoreCallingIdentity(identity);
2382 }
2383 }
2384
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 //
2386 // Internal helper methods.
2387 //
2388
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002389 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2391 *
2392 * @throws SecurityException if the caller does not have the required permission
2393 */
2394 private void enforceModifyPermission() {
2395 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2396 }
2397
2398 /**
2399 * Make sure the caller has the CALL_PHONE permission.
2400 *
2401 * @throws SecurityException if the caller does not have the required permission
2402 */
2403 private void enforceCallPermission() {
2404 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2405 }
2406
Stuart Scott8eef64f2015-04-08 15:13:54 -07002407 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002408 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002409 "ConnectivityService");
2410 }
2411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 private String createTelUrl(String number) {
2413 if (TextUtils.isEmpty(number)) {
2414 return null;
2415 }
2416
Jake Hambye994d462014-02-03 13:10:13 -08002417 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 }
2419
Ihab Awadf9e92732013-12-05 18:02:52 -08002420 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2422 }
2423
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002424 private static void logv(String msg) {
2425 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2426 }
2427
Ihab Awadf9e92732013-12-05 18:02:52 -08002428 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2430 }
2431
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002432 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002434 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002435 }
2436
Sanket Padawe356d7632015-06-22 14:03:32 -07002437 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002438 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002439 final long identity = Binder.clearCallingIdentity();
2440 try {
2441 final Phone phone = PhoneFactory.getPhone(slotIndex);
2442 if (phone == null) {
2443 return PhoneConstants.PHONE_TYPE_NONE;
2444 } else {
2445 return phone.getPhoneType();
2446 }
2447 } finally {
2448 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 }
2451
2452 /**
2453 * Returns the CDMA ERI icon index to display
2454 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002455 @Override
2456 public int getCdmaEriIconIndex(String callingPackage) {
2457 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002458 }
2459
Sanket Padawe356d7632015-06-22 14:03:32 -07002460 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002461 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002463 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002464 return -1;
2465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466
2467 final long identity = Binder.clearCallingIdentity();
2468 try {
2469 final Phone phone = getPhone(subId);
2470 if (phone != null) {
2471 return phone.getCdmaEriIconIndex();
2472 } else {
2473 return -1;
2474 }
2475 } finally {
2476 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 }
2479
2480 /**
2481 * Returns the CDMA ERI icon mode,
2482 * 0 - ON
2483 * 1 - FLASHING
2484 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002485 @Override
2486 public int getCdmaEriIconMode(String callingPackage) {
2487 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002488 }
2489
Sanket Padawe356d7632015-06-22 14:03:32 -07002490 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002491 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002493 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002494 return -1;
2495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496
2497 final long identity = Binder.clearCallingIdentity();
2498 try {
2499 final Phone phone = getPhone(subId);
2500 if (phone != null) {
2501 return phone.getCdmaEriIconMode();
2502 } else {
2503 return -1;
2504 }
2505 } finally {
2506 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 }
2509
2510 /**
2511 * Returns the CDMA ERI text,
2512 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002513 @Override
2514 public String getCdmaEriText(String callingPackage) {
2515 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002516 }
2517
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002519 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002521 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 return null;
2523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524
2525 final long identity = Binder.clearCallingIdentity();
2526 try {
2527 final Phone phone = getPhone(subId);
2528 if (phone != null) {
2529 return phone.getCdmaEriText();
2530 } else {
2531 return null;
2532 }
2533 } finally {
2534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536 }
2537
2538 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002539 * Returns the CDMA MDN.
2540 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002541 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002542 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2544 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545
2546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002549 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002550 return phone.getLine1Number();
2551 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002552 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553 return null;
2554 }
2555 } finally {
2556 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002557 }
2558 }
2559
2560 /**
2561 * Returns the CDMA MIN.
2562 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002564 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2566 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567
2568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 final Phone phone = getPhone(subId);
2571 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2572 return phone.getCdmaMin();
2573 } else {
2574 return null;
2575 }
2576 } finally {
2577 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002578 }
2579 }
2580
Hall Liud892bec2018-11-30 14:51:45 -08002581 @Override
2582 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2583 INumberVerificationCallback callback, String callingPackage) {
2584 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2585 != PERMISSION_GRANTED) {
2586 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2587 }
2588 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2589
2590 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2591 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2592 throw new SecurityException("Calling package must be configured in the device config");
2593 }
2594
2595 if (range == null) {
2596 throw new NullPointerException("Range must be non-null");
2597 }
2598
2599 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002600 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002601
2602 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2603 }
2604
Junda Liuca05d5d2014-08-14 22:36:34 -07002605 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 * Returns true if CDMA provisioning needs to run.
2607 */
2608 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 final long identity = Binder.clearCallingIdentity();
2610 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002611 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 } finally {
2613 Binder.restoreCallingIdentity(identity);
2614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002615 }
2616
2617 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002618 * Sets the voice mail number of a given subId.
2619 */
2620 @Override
2621 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002622 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2627 new Pair<String, String>(alphaTag, number), new Integer(subId));
2628 return success;
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
2631 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002632 }
2633
Ta-wei Yen87c49842016-05-13 21:19:52 -07002634 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002635 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2636 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002637 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002638 if (!TextUtils.equals(callingPackage, systemDialer)) {
2639 throw new SecurityException("caller must be system dialer");
2640 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641
2642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2645 if (phoneAccountHandle == null) {
2646 return null;
2647 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002648 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649 } finally {
2650 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002651 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002652 }
2653
2654 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002655 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002656 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002658 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002659 return null;
2660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002662 final long identity = Binder.clearCallingIdentity();
2663 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002664 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002665 } finally {
2666 Binder.restoreCallingIdentity(identity);
2667 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002668 }
2669
2670 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002671 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2672 VisualVoicemailSmsFilterSettings settings) {
2673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674
2675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002678 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 } finally {
2680 Binder.restoreCallingIdentity(identity);
2681 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002682 }
2683
2684 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002685 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2686 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002691 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 } finally {
2693 Binder.restoreCallingIdentity(identity);
2694 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002695 }
2696
2697 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002698 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2699 String callingPackage, int subId) {
2700 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701
2702 final long identity = Binder.clearCallingIdentity();
2703 try {
2704 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002705 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706 } finally {
2707 Binder.restoreCallingIdentity(identity);
2708 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002709 }
2710
2711 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002712 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002713 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714
2715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002718 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 } finally {
2720 Binder.restoreCallingIdentity(identity);
2721 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002722 }
2723
2724 @Override
2725 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2726 String number, int port, String text, PendingIntent sentIntent) {
2727 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002728 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002729 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002730 SmsController smsController = PhoneFactory.getSmsController();
2731 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2732 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002733 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002734
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002735 /**
fionaxu0152e512016-11-14 13:36:14 -08002736 * Sets the voice activation state of a given subId.
2737 */
2738 @Override
2739 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2741 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742
2743 final long identity = Binder.clearCallingIdentity();
2744 try {
2745 final Phone phone = getPhone(subId);
2746 if (phone != null) {
2747 phone.setVoiceActivationState(activationState);
2748 } else {
2749 loge("setVoiceActivationState fails with invalid subId: " + subId);
2750 }
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002753 }
2754 }
2755
2756 /**
2757 * Sets the data activation state of a given subId.
2758 */
2759 @Override
2760 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2762 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 final Phone phone = getPhone(subId);
2767 if (phone != null) {
2768 phone.setDataActivationState(activationState);
2769 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002770 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 }
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002774 }
2775 }
2776
2777 /**
2778 * Returns the voice activation state of a given subId.
2779 */
2780 @Override
2781 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002782 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783
fionaxu0152e512016-11-14 13:36:14 -08002784 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 final long identity = Binder.clearCallingIdentity();
2786 try {
2787 if (phone != null) {
2788 return phone.getVoiceActivationState();
2789 } else {
2790 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2791 }
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002794 }
2795 }
2796
2797 /**
2798 * Returns the data activation state of a given subId.
2799 */
2800 @Override
2801 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002802 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803
fionaxu0152e512016-11-14 13:36:14 -08002804 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 if (phone != null) {
2808 return phone.getDataActivationState();
2809 } else {
2810 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002814 }
2815 }
2816
2817 /**
Wink Saville36469e72014-06-11 15:17:00 -07002818 * Returns the unread count of voicemails for a subId
2819 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002820 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002821 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2823 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2824 return 0;
2825 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 final long identity = Binder.clearCallingIdentity();
2827 try {
2828 final Phone phone = getPhone(subId);
2829 if (phone != null) {
2830 return phone.getVoiceMessageCount();
2831 } else {
2832 return 0;
2833 }
2834 } finally {
2835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002837 }
2838
2839 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002840 * returns true, if the device is in a state where both voice and data
2841 * are supported simultaneously. This can change based on location or network condition.
2842 */
2843 @Override
2844 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 final Phone phone = getPhone(subId);
2848 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
2851 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002852 }
2853
2854 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002855 * Send the dialer code if called from the current default dialer or the caller has
2856 * carrier privilege.
2857 * @param inputCode The dialer code to send
2858 */
2859 @Override
2860 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002861 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002862 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2864 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002865 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002866 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2867 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869
2870 final long identity = Binder.clearCallingIdentity();
2871 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002872 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873 } finally {
2874 Binder.restoreCallingIdentity(identity);
2875 }
fionaxu235cc5e2017-03-06 22:25:57 -08002876 }
2877
Pengquan Menga1bb6272018-09-06 09:59:22 -07002878 @Override
2879 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002880 if (!isActiveSubscription(subId)) {
2881 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2882 }
2883
Pengquan Menga1bb6272018-09-06 09:59:22 -07002884 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2885 }
2886
Brad Ebinger35c841c2018-10-01 10:40:55 -07002887 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002888 public boolean isInEmergencySmsMode() {
2889 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 for (Phone phone : PhoneFactory.getPhones()) {
2893 if (phone.isInEmergencySmsMode()) {
2894 return true;
2895 }
2896 }
2897 } finally {
2898 Binder.restoreCallingIdentity(identity);
2899 }
2900 return false;
2901 }
2902
2903 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002904 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2905 throws RemoteException {
2906 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002907 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2908 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2909 "IMS not available on device.");
2910 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002911 final long token = Binder.clearCallingIdentity();
2912 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002913 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002914 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002915 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002916 } catch (ImsException e) {
2917 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002918 } finally {
2919 Binder.restoreCallingIdentity(token);
2920 }
2921 }
2922
2923 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002924 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2925 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002926 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2927 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2928 }
2929 Binder.withCleanCallingIdentity(() -> {
2930 try {
2931 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002932 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002933 .removeRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002934 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002935 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2936 + "is inactive, ignoring unregister.");
2937 // If the subscription is no longer active, just return, since the callback
2938 // will already have been removed internally.
2939 }
2940 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002941 }
2942
2943 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002944 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2945 throws RemoteException {
2946 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002947 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2948 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2949 "IMS not available on device.");
2950 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2952 final long token = Binder.clearCallingIdentity();
2953 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002954 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002955 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002956 } catch (ImsException e) {
2957 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002958 } finally {
2959 Binder.restoreCallingIdentity(token);
2960 }
2961 }
2962
2963 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002964 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2965 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002966
2967 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2968 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2969 }
2970 Binder.withCleanCallingIdentity(() -> {
2971 try {
2972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002973 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002974 .removeCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002975 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002976 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2977 + "is inactive, ignoring unregister.");
2978 // If the subscription is no longer active, just return, since the callback
2979 // will already have been removed internally.
2980 }
2981 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002982 }
2983
2984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002985 public boolean isCapable(int subId, int capability, int regTech) {
2986 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2988 final long token = Binder.clearCallingIdentity();
2989 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002990 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002991 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002992 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2994 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002995 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002996 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2997 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002998 } finally {
2999 Binder.restoreCallingIdentity(token);
3000 }
3001 }
3002
3003 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003004 public boolean isAvailable(int subId, int capability, int regTech) {
3005 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003006 final long token = Binder.clearCallingIdentity();
3007 try {
3008 Phone phone = getPhone(subId);
3009 if (phone == null) return false;
3010 return phone.isImsCapabilityAvailable(capability, regTech);
3011 } finally {
3012 Binder.restoreCallingIdentity(token);
3013 }
3014 }
3015
Brad Ebinger77b832e2019-10-17 17:03:22 -07003016 /**
3017 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3018 * subscription.
3019 * @param subId The subscription to use to check the configuration.
3020 * @param callback The callback that will be used to send the result.
3021 * @param capability The MmTelFeature capability that will be used to send the result.
3022 * @param transportType The transport type of the MmTelFeature capability.
3023 */
3024 @Override
3025 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3026 int transportType) {
3027 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3028 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3029 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3030 "IMS not available on device.");
3031 }
3032 final long token = Binder.clearCallingIdentity();
3033 try {
3034 int slotId = getSlotIndex(subId);
3035 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3036 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3037 + subId + "'");
3038 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3039 }
3040 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3041 transportType, aBoolean -> {
3042 try {
3043 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3044 } catch (RemoteException e) {
3045 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3046 + "running. Ignore");
3047 }
3048 });
3049 } finally {
3050 Binder.restoreCallingIdentity(token);
3051 }
3052 }
3053
Brad Ebinger35c841c2018-10-01 10:40:55 -07003054 @Override
3055 public boolean isAdvancedCallingSettingEnabled(int subId) {
3056 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3057 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3058 final long token = Binder.clearCallingIdentity();
3059 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003060 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003061 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003062 } catch (ImsException e) {
3063 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003064 } finally {
3065 Binder.restoreCallingIdentity(token);
3066 }
3067 }
3068
3069 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003070 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003072 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003076 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003078 } catch (ImsException e) {
3079 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003080 } finally {
3081 Binder.restoreCallingIdentity(identity);
3082 }
3083 }
3084
3085 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003086 public boolean isVtSettingEnabled(int subId) {
3087 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003088 final long identity = Binder.clearCallingIdentity();
3089 try {
3090 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003091 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3092 } catch (ImsException e) {
3093 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003094 } finally {
3095 Binder.restoreCallingIdentity(identity);
3096 }
3097 }
3098
3099 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003100 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003102 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003106 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003107 } catch (ImsException e) {
3108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
3112 }
3113
3114 @Override
3115 public boolean isVoWiFiSettingEnabled(int subId) {
3116 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3117 final long identity = Binder.clearCallingIdentity();
3118 try {
3119 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003120 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003121 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003122 } catch (ImsException e) {
3123 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003124 } finally {
3125 Binder.restoreCallingIdentity(identity);
3126 }
3127 }
3128
3129 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003130 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003132 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003136 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003137 } catch (ImsException e) {
3138 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003139 } finally {
3140 Binder.restoreCallingIdentity(identity);
3141 }
3142 }
3143
3144 @Override
3145 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3146 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003150 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003151 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003152 } catch (ImsException e) {
3153 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
3157 }
3158
3159 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003160 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003162 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003166 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003167 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003168 } catch (ImsException e) {
3169 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003170 } finally {
3171 Binder.restoreCallingIdentity(identity);
3172 }
3173 }
3174
3175 @Override
3176 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3178 "setVoWiFiNonPersistent");
3179 final long identity = Binder.clearCallingIdentity();
3180 try {
3181 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003182 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003183 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003184 } catch (ImsException e) {
3185 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
3189 }
3190
3191 @Override
3192 public int getVoWiFiModeSetting(int subId) {
3193 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003197 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003198 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003199 } catch (ImsException e) {
3200 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003201 } finally {
3202 Binder.restoreCallingIdentity(identity);
3203 }
3204 }
3205
3206 @Override
3207 public void setVoWiFiModeSetting(int subId, int mode) {
3208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3209 "setVoWiFiModeSetting");
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003213 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003215 } catch (ImsException e) {
3216 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
3220 }
3221
3222 @Override
3223 public int getVoWiFiRoamingModeSetting(int subId) {
3224 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003228 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003230 } catch (ImsException e) {
3231 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
3235 }
3236
3237 @Override
3238 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3240 "setVoWiFiRoamingModeSetting");
3241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003244 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003246 } catch (ImsException e) {
3247 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 } finally {
3249 Binder.restoreCallingIdentity(identity);
3250 }
3251 }
3252
3253 @Override
3254 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3256 "setRttCapabilityEnabled");
3257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003260 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3261 } catch (ImsException e) {
3262 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003263 } finally {
3264 Binder.restoreCallingIdentity(identity);
3265 }
3266 }
3267
3268 @Override
3269 public boolean isTtyOverVolteEnabled(int subId) {
3270 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003276 } catch (ImsException e) {
3277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 } finally {
3279 Binder.restoreCallingIdentity(identity);
3280 }
3281 }
3282
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003283 @Override
3284 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3285 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3286 final long identity = Binder.clearCallingIdentity();
3287 try {
3288 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003289 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003290 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003291 } catch (ImsException e) {
3292 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003293 } finally {
3294 Binder.restoreCallingIdentity(identity);
3295 }
3296 }
3297
3298 @Override
3299 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3300 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3301 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003302 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3303 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3304 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003305 try {
3306 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003307 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003308 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003309 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003310 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3311 + "is inactive, ignoring unregister.");
3312 // If the subscription is no longer active, just return, since the callback will already
3313 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
3317 }
3318
3319 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003320 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3321 boolean isProvisioned) {
3322 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3323 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3324 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3325 }
3326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3327 "setProvisioningStatusForCapability");
3328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3331 Phone phone = getPhone(subId);
3332 if (phone == null) {
3333 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3334 + subId);
3335 return;
3336 }
3337 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3338 return;
3339 }
3340
3341 // this capability requires provisioning, route to the correct API.
3342 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3343 switch (capability) {
3344 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3345 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3346 ims.setVolteProvisioned(isProvisioned);
3347 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3348 ims.setWfcProvisioned(isProvisioned);
3349 }
3350 break;
3351 }
3352 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3353 // There is currently no difference in VT provisioning type.
3354 ims.setVtProvisioned(isProvisioned);
3355 break;
3356 }
3357 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3358 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3359 // change the capability of the feature instead if needed.
3360 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3361 == isProvisioned) {
3362 // No change in provisioning.
3363 return;
3364 }
3365 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3366 try {
3367 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003368 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003369 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3370 + ", Exception" + e.getMessage());
3371 }
3372 break;
3373 }
3374 default: {
3375 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3376 + capability + "', which does not require provisioning.");
3377 }
3378 }
3379
3380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
3383 }
3384
3385 @Override
3386 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3387 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3388 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3389 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3390 }
3391 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3395 Phone phone = getPhone(subId);
3396 if (phone == null) {
3397 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3398 + subId);
3399 // We will fail with "true" as the provisioning status because this is the default
3400 // if we do not require provisioning.
3401 return true;
3402 }
3403
3404 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3405 return true;
3406 }
3407
3408 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3409 switch (capability) {
3410 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3411 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3412 return ims.isVolteProvisionedOnDevice();
3413 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3414 return ims.isWfcProvisionedOnDevice();
3415 }
3416 // This should never happen, since we are checking tech above to make sure it
3417 // is either LTE or IWLAN.
3418 throw new IllegalArgumentException("Invalid radio technology for voice "
3419 + "capability.");
3420 }
3421 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3422 // There is currently no difference in VT provisioning type.
3423 return ims.isVtProvisionedOnDevice();
3424 }
3425 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3426 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3427 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3428 }
3429 default: {
3430 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3431 + capability + "', which does not require provisioning.");
3432 }
3433 }
3434
3435 } finally {
3436 Binder.restoreCallingIdentity(identity);
3437 }
3438 }
3439
3440 @Override
3441 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3442 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3443 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3444 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3445 }
3446 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3447 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3448 return (provisionedBits & capability) > 0;
3449 }
3450
3451 @Override
3452 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3453 boolean isProvisioned) {
3454 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3455 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3456 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3457 }
3458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3459 "setProvisioningStatusForCapability");
3460 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3461 // If the current provisioning status for capability already matches isProvisioned,
3462 // do nothing.
3463 if (((provisionedBits & capability) > 0) == isProvisioned) {
3464 return;
3465 }
3466 if (isProvisioned) {
3467 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3468 } else {
3469 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3470 }
3471 }
3472
3473 /**
3474 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3475 * technology. The bitfield should mirror the bitfield defined by
3476 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3477 */
3478 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3479 String key = getMmTelProvisioningKey(subId, tech);
3480 // Default is no capabilities are provisioned.
3481 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3482 }
3483
3484 /**
3485 * Sets the MmTel capability provisioning bitfield (defined by
3486 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3487 * technology specified.
3488 *
3489 * Note: This is a synchronous command and should not be called on UI thread.
3490 */
3491 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3492 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3493 String key = getMmTelProvisioningKey(subId, tech);
3494 editor.putInt(key, newField);
3495 editor.commit();
3496 }
3497
3498 private static String getMmTelProvisioningKey(int subId, int tech) {
3499 // resulting key is provision_ims_mmtel_{subId}_{tech}
3500 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3501 }
3502
3503 /**
3504 * Query CarrierConfig to see if the specified capability requires provisioning for the
3505 * carrier associated with the subscription id.
3506 */
3507 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3508 int capability) {
3509 CarrierConfigManager configManager = new CarrierConfigManager(context);
3510 PersistableBundle c = configManager.getConfigForSubId(subId);
3511 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003512 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003513 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3514 false);
3515 boolean requireVoiceVtProvisioning = c.getBoolean(
3516 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3517
3518 // First check to make sure that the capability requires provisioning.
3519 switch (capability) {
3520 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3521 // intentional fallthrough
3522 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3523 if (requireVoiceVtProvisioning) {
3524 // Voice and Video requires provisioning
3525 return true;
3526 }
3527 break;
3528 }
3529 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3530 if (requireUtProvisioning) {
3531 // UT requires provisioning
3532 return true;
3533 }
3534 break;
3535 }
3536 }
3537 return false;
3538 }
3539
3540 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003541 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003542 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3543 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3544 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003545 enforceReadPrivilegedPermission("getImsProvisioningInt");
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003549 int slotId = getSlotIndex(subId);
3550 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3551 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3552 + subId + "' for key:" + key);
3553 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3554 }
3555 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003556 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003557 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3558 + subId + "' for key:" + key);
3559 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
3563 }
3564
3565 @Override
3566 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003567 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3568 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3569 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003570 enforceReadPrivilegedPermission("getImsProvisioningString");
3571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003574 int slotId = getSlotIndex(subId);
3575 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3576 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3577 + subId + "' for key:" + key);
3578 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3579 }
3580 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003581 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003582 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3583 + subId + "' for key:" + key);
3584 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003585 } finally {
3586 Binder.restoreCallingIdentity(identity);
3587 }
3588 }
3589
3590 @Override
3591 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003592 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3593 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3594 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3596 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003600 int slotId = getSlotIndex(subId);
3601 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3602 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3603 + subId + "' for key:" + key);
3604 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3605 }
3606 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003607 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003608 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3609 + "' for key:" + key);
3610 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003611 } finally {
3612 Binder.restoreCallingIdentity(identity);
3613 }
3614 }
3615
3616 @Override
3617 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003618 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3619 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3620 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3622 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003626 int slotId = getSlotIndex(subId);
3627 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3628 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3629 + subId + "' for key:" + key);
3630 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3631 }
3632 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003633 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003634 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3635 + "' for key:" + key);
3636 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
3640 }
3641
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003642 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 int slotId = SubscriptionManager.getSlotIndex(subId);
3644 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003645 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3646 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003647 }
3648 return slotId;
3649 }
3650
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003651 private int getSlotIndex(int subId) {
3652 int slotId = SubscriptionManager.getSlotIndex(subId);
3653 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3654 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3655 }
3656 return slotId;
3657 }
3658
Wink Saville36469e72014-06-11 15:17:00 -07003659 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003660 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003661 */
3662 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003663 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003664 final int targetSdk = getTargetSdk(callingPackage);
3665 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3666 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3667 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003668 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3669 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003670 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3671 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 final Phone phone = getPhone(subId);
3676 if (phone != null) {
3677 return phone.getServiceState().getDataNetworkType();
3678 } else {
3679 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3680 }
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003684 }
3685
3686 /**
3687 * Returns the data network type
3688 */
3689 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003690 public int getDataNetworkType(String callingPackage) {
3691 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003692 }
3693
3694 /**
3695 * Returns the data network type for a subId
3696 */
3697 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003698 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003700 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003701 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3702 }
3703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 final Phone phone = getPhone(subId);
3707 if (phone != null) {
3708 return phone.getServiceState().getDataNetworkType();
3709 } else {
3710 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3711 }
3712 } finally {
3713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003715 }
3716
3717 /**
Wink Saville36469e72014-06-11 15:17:00 -07003718 * Returns the Voice network type for a subId
3719 */
3720 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003721 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003722 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003723 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003724 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3725 }
3726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 final Phone phone = getPhone(subId);
3730 if (phone != null) {
3731 return phone.getServiceState().getVoiceNetworkType();
3732 } else {
3733 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3734 }
3735 } finally {
3736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003738 }
3739
3740 /**
3741 * @return true if a ICC card is present
3742 */
3743 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003744 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003745 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3746 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003747 }
3748
3749 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003750 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003751 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003752 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003753 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003754 final long identity = Binder.clearCallingIdentity();
3755 try {
3756 final Phone phone = PhoneFactory.getPhone(slotIndex);
3757 if (phone != null) {
3758 return phone.getIccCard().hasIccCard();
3759 } else {
3760 return false;
3761 }
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003765 }
3766
3767 /**
3768 * Return if the current radio is LTE on CDMA. This
3769 * is a tri-state return value as for a period of time
3770 * the mode may be unknown.
3771 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003772 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003773 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003774 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003775 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003776 @Override
3777 public int getLteOnCdmaMode(String callingPackage) {
3778 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003779 }
3780
Sanket Padawe356d7632015-06-22 14:03:32 -07003781 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003782 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003784 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003785 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3786 }
3787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003788 final long identity = Binder.clearCallingIdentity();
3789 try {
3790 final Phone phone = getPhone(subId);
3791 if (phone == null) {
3792 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3793 } else {
3794 return phone.getLteOnCdmaMode();
3795 }
3796 } finally {
3797 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003798 }
Wink Saville36469e72014-06-11 15:17:00 -07003799 }
3800
Wink Saville36469e72014-06-11 15:17:00 -07003801 /**
3802 * {@hide}
3803 * Returns Default subId, 0 in the case of single standby.
3804 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003805 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003806 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003807 }
3808
Shishir Agrawala9f32182016-04-12 12:00:16 -07003809 private int getSlotForDefaultSubscription() {
3810 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3811 }
3812
Wink Savilleb564aae2014-10-23 10:18:09 -07003813 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003814 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003815 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003816
Pengquan Menge92a50d2018-09-21 15:54:48 -07003817 private boolean isActiveSubscription(int subId) {
3818 return mSubscriptionController.isActiveSubId(subId);
3819 }
3820
Ihab Awadf2177b72013-11-25 13:33:23 -08003821 /**
3822 * @see android.telephony.TelephonyManager.WifiCallingChoices
3823 */
3824 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825 final long identity = Binder.clearCallingIdentity();
3826 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003827 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3829 getWhenToMakeWifiCallsDefaultPreference());
3830 } finally {
3831 Binder.restoreCallingIdentity(identity);
3832 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003833 }
3834
3835 /**
3836 * @see android.telephony.TelephonyManager.WifiCallingChoices
3837 */
3838 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003842 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003843 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3844 } finally {
3845 Binder.restoreCallingIdentity(identity);
3846 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003847 }
3848
Sailesh Nepald1e68152013-12-12 19:08:02 -08003849 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003850 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003851 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003852 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003853
Jordan Liu4c733742019-02-28 12:03:40 -08003854 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3855 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3856 if (phoneId == -1) {
3857 throw new IllegalArgumentException("Given slot index: " + slotIndex
3858 + " does not correspond to an active phone");
3859 }
3860 return PhoneFactory.getPhone(phoneId);
3861 }
3862
Shishir Agrawal566b7612013-10-28 14:41:00 -07003863 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003864 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3865 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3867 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003868 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003869 if (DBG) {
3870 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3871 }
3872 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3873 p2);
3874 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003875
Jordan Liu4c733742019-02-28 12:03:40 -08003876
3877 @Override
3878 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3879 int slotIndex, String callingPackage, String aid, int p2) {
3880 enforceModifyPermission();
3881 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3882 if (DBG) {
3883 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3884 }
3885 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3886 callingPackage, aid, p2);
3887 }
3888
3889 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3890 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 if (TextUtils.equals(ISDR_AID, aid)) {
3894 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003895 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3896 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 if (bestComponent == null
3898 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3899 loge("The calling package is not allowed to access ISD-R.");
3900 throw new SecurityException(
3901 "The calling package is not allowed to access ISD-R.");
3902 }
Derek Tan740e1672017-06-27 14:56:27 -07003903 }
Derek Tan740e1672017-06-27 14:56:27 -07003904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003906 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3907 null /* workSource */);
3908 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909 return response;
3910 } finally {
3911 Binder.restoreCallingIdentity(identity);
3912 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003913 }
3914
3915 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003916 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3918 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003919 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3920 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3921 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003922
Jordan Liu4c733742019-02-28 12:03:40 -08003923 @Override
3924 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3925 enforceModifyPermission();
3926 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3927 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3928 channel);
3929 }
3930
3931 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003932 final long identity = Binder.clearCallingIdentity();
3933 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003934 if (channel < 0) {
3935 return false;
3936 }
Jordan Liu4c733742019-02-28 12:03:40 -08003937 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3938 null /* workSource */);
3939 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003940 return success;
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003943 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003944 }
3945
3946 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003947 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003948 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3950 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003951 if (DBG) {
3952 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3953 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3954 + p3 + " data=" + data);
3955 }
3956 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3957 command, p1, p2, p3, data);
3958 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003959
Jordan Liu4c733742019-02-28 12:03:40 -08003960 @Override
3961 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3962 int command, int p1, int p2, int p3, String data) {
3963 enforceModifyPermission();
3964 if (DBG) {
3965 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3966 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3967 + p3 + " data=" + data);
3968 }
3969 return iccTransmitApduLogicalChannelWithPermission(
3970 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3971 data);
3972 }
3973
3974 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3975 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976 final long identity = Binder.clearCallingIdentity();
3977 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003978 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979 return "";
3980 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003983 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3984 null /* workSource */);
3985 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 // Append the returned status code to the end of the response payload.
3988 String s = Integer.toHexString(
3989 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3990 if (response.payload != null) {
3991 s = IccUtils.bytesToHexString(response.payload) + s;
3992 }
3993 return s;
3994 } finally {
3995 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003996 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003997 }
Jake Hambye994d462014-02-03 13:10:13 -08003998
Evan Charltonc66da362014-05-16 14:06:40 -07003999 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004000 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4001 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4003 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004005 if (DBG) {
4006 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4007 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4008 }
4009 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4010 cla, command, p1, p2, p3, data);
4011 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004012
Jordan Liu4c733742019-02-28 12:03:40 -08004013 @Override
4014 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4015 int command, int p1, int p2, int p3, String data) {
4016 enforceModifyPermission();
4017 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4018 if (DBG) {
4019 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4020 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4021 + " data=" + data);
4022 }
4023
4024 return iccTransmitApduBasicChannelWithPermission(
4025 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4026 p2, p3, data);
4027 }
4028
4029 // open APDU basic channel assuming the caller has sufficient permissions
4030 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4031 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4035 && TextUtils.equals(ISDR_AID, data)) {
4036 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004037 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4038 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004039 if (bestComponent == null
4040 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4041 loge("The calling package is not allowed to select ISD-R.");
4042 throw new SecurityException(
4043 "The calling package is not allowed to select ISD-R.");
4044 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004045 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004048 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4049 null /* workSource */);
4050 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 // Append the returned status code to the end of the response payload.
4053 String s = Integer.toHexString(
4054 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4055 if (response.payload != null) {
4056 s = IccUtils.bytesToHexString(response.payload) + s;
4057 }
4058 return s;
4059 } finally {
4060 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004061 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004062 }
4063
4064 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004065 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004066 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4068 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 if (DBG) {
4073 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4074 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4075 }
4076
4077 IccIoResult response =
4078 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4079 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4080 subId);
4081
4082 if (DBG) {
4083 log("Exchange SIM_IO [R]" + response);
4084 }
4085
4086 byte[] result = null;
4087 int length = 2;
4088 if (response.payload != null) {
4089 length = 2 + response.payload.length;
4090 result = new byte[length];
4091 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4092 } else {
4093 result = new byte[length];
4094 }
4095
4096 result[length - 1] = (byte) response.sw2;
4097 result[length - 2] = (byte) response.sw1;
4098 return result;
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004101 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004102 }
4103
Nathan Haroldb3014052017-01-25 15:57:32 -08004104 /**
4105 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4106 * on a particular subscription
4107 */
sqianb6e41952018-03-12 14:54:01 -07004108 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4110 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4111 return null;
4112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004113
4114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 if (appType != TelephonyManager.APPTYPE_USIM
4117 && appType != TelephonyManager.APPTYPE_SIM) {
4118 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4119 return null;
4120 }
4121 Object response = sendRequest(
4122 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4123 if (response instanceof String[]) {
4124 return (String[]) response;
4125 }
yincheng zhaod698b842019-09-06 17:06:54 -07004126 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004128 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004129 } finally {
4130 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004131 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004132 }
4133
yincheng zhaod698b842019-09-06 17:06:54 -07004134 /**
4135 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4136 * subscription.
4137 *
4138 * @param subId the id of the subscription.
4139 * @param appType the uicc app type, must be USIM or SIM.
4140 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4141 * @param callingPackage the op Package name.
4142 * @return number of fplmns that is successfully written to the SIM.
4143 */
4144 public int setForbiddenPlmns(
4145 int subId, int appType, List<String> fplmns, String callingPackage) {
4146 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4147 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4148 if (DBG) logv("no permissions for setForbiddenplmns");
4149 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4150 }
4151 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4152 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4153 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4154 }
4155 if (fplmns == null) {
4156 throw new IllegalArgumentException("Fplmn List provided is null");
4157 }
4158 for (String fplmn : fplmns) {
4159 if (!CellIdentity.isValidPlmn(fplmn)) {
4160 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4161 }
4162 }
4163 final long identity = Binder.clearCallingIdentity();
4164 try {
4165 Object response = sendRequest(
4166 CMD_SET_FORBIDDEN_PLMNS,
4167 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4168 subId);
4169 return (int) response;
4170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
4173 }
4174
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004175 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004176 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4178 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4183 if (response.payload == null) {
4184 return "";
4185 }
Evan Charltonc66da362014-05-16 14:06:40 -07004186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187 // Append the returned status code to the end of the response payload.
4188 String s = Integer.toHexString(
4189 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4190 s = IccUtils.bytesToHexString(response.payload) + s;
4191 return s;
4192 } finally {
4193 Binder.restoreCallingIdentity(identity);
4194 }
Evan Charltonc66da362014-05-16 14:06:40 -07004195 }
4196
Jake Hambye994d462014-02-03 13:10:13 -08004197 /**
4198 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4199 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4200 *
4201 * @param itemID the ID of the item to read
4202 * @return the NV item as a String, or null on error.
4203 */
4204 @Override
4205 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004206 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4208 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209
4210 final long identity = Binder.clearCallingIdentity();
4211 try {
4212 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004213 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4215 return value;
4216 } finally {
4217 Binder.restoreCallingIdentity(identity);
4218 }
Jake Hambye994d462014-02-03 13:10:13 -08004219 }
4220
4221 /**
4222 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4223 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4224 *
4225 * @param itemID the ID of the item to read
4226 * @param itemValue the value to write, as a String
4227 * @return true on success; false on any failure
4228 */
4229 @Override
4230 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004231 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4233 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004234
4235 final long identity = Binder.clearCallingIdentity();
4236 try {
4237 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4238 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004239 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4241 return success;
4242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
Jake Hambye994d462014-02-03 13:10:13 -08004245 }
4246
4247 /**
4248 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4249 * Used for device configuration by some CDMA operators.
4250 *
4251 * @param preferredRoamingList byte array containing the new PRL
4252 * @return true on success; false on any failure
4253 */
4254 @Override
4255 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4257 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258
4259 final long identity = Binder.clearCallingIdentity();
4260 try {
4261 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4262 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4263 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4264 return success;
4265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
Jake Hambye994d462014-02-03 13:10:13 -08004268 }
4269
4270 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004271 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004272 * Used for device configuration by some CDMA operators.
4273 *
chen xu6dac5ab2018-10-26 17:39:23 -07004274 * @param slotIndex - device slot.
4275 *
Jake Hambye994d462014-02-03 13:10:13 -08004276 * @return true on success; false on any failure
4277 */
4278 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004279 public boolean resetModemConfig(int slotIndex) {
4280 Phone phone = PhoneFactory.getPhone(slotIndex);
4281 if (phone != null) {
4282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4283 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284
chen xu6dac5ab2018-10-26 17:39:23 -07004285 final long identity = Binder.clearCallingIdentity();
4286 try {
4287 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4288 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4289 return success;
4290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 }
chen xu6dac5ab2018-10-26 17:39:23 -07004294 return false;
4295 }
4296
4297 /**
4298 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4299 *
4300 * @param slotIndex - device slot.
4301 *
4302 * @return true on success; false on any failure
4303 */
4304 @Override
4305 public boolean rebootModem(int slotIndex) {
4306 Phone phone = PhoneFactory.getPhone(slotIndex);
4307 if (phone != null) {
4308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4309 mApp, phone.getSubId(), "rebootModem");
4310
4311 final long identity = Binder.clearCallingIdentity();
4312 try {
4313 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4314 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4315 return success;
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
4319 }
4320 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004321 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004322
Svet Ganovb320e182015-04-16 12:30:10 -07004323 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004324 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004326 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004327 return new String[0];
4328 }
4329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 final long identity = Binder.clearCallingIdentity();
4331 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004332 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
Wink Saville36469e72014-06-11 15:17:00 -07004336 }
4337
Brad Ebinger51f743a2017-01-23 13:50:20 -08004338 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004339 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4340 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004341 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004342 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004343 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004344
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004347 ImsResolver resolver = PhoneFactory.getImsResolver();
4348 if (resolver == null) {
4349 // may happen if the device does not support IMS.
4350 return;
4351 }
4352 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 } finally {
4354 Binder.restoreCallingIdentity(identity);
4355 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004356 }
4357
4358 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004359 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4360 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004361 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004362 public void disableIms(int slotId) {
4363 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364
4365 final long identity = Binder.clearCallingIdentity();
4366 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004367 ImsResolver resolver = PhoneFactory.getImsResolver();
4368 if (resolver == null) {
4369 // may happen if the device does not support IMS.
4370 return;
4371 }
4372 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004376 }
4377
4378 /**
4379 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4380 * feature or {@link null} if the service is not available. If the feature is available, the
4381 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4382 */
4383 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004384 IImsServiceFeatureCallback callback) {
4385 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386
4387 final long identity = Binder.clearCallingIdentity();
4388 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004389 ImsResolver resolver = PhoneFactory.getImsResolver();
4390 if (resolver == null) {
4391 // may happen if the device does not support IMS.
4392 return null;
4393 }
4394 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395 } finally {
4396 Binder.restoreCallingIdentity(identity);
4397 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004398 }
4399
4400 /**
4401 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4402 * feature during emergency calling or {@link null} if the service is not available. If the
4403 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4404 * listener for feature updates.
4405 */
4406 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4407 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408
4409 final long identity = Binder.clearCallingIdentity();
4410 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004411 ImsResolver resolver = PhoneFactory.getImsResolver();
4412 if (resolver == null) {
4413 // may happen if the device does not support IMS.
4414 return null;
4415 }
4416 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004420 }
4421
Brad Ebinger5f64b052017-12-14 14:26:15 -08004422 /**
4423 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004424 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004425 */
4426 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4427 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004428
4429 final long identity = Binder.clearCallingIdentity();
4430 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004431 ImsResolver resolver = PhoneFactory.getImsResolver();
4432 if (resolver == null) {
4433 // may happen if the device does not support IMS.
4434 return null;
4435 }
4436 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004440 }
4441
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004442 /**
4443 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004444 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004445 */
4446 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4447 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448
4449 final long identity = Binder.clearCallingIdentity();
4450 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004451 ImsResolver resolver = PhoneFactory.getImsResolver();
4452 if (resolver == null) {
4453 // may happen if the device does not support IMS.
4454 return null;
4455 }
4456 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 } finally {
4458 Binder.restoreCallingIdentity(identity);
4459 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004460 }
4461
Brad Ebinger884c07b2018-02-15 16:17:40 -08004462 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004463 * Sets the ImsService Package Name that Telephony will bind to.
4464 *
4465 * @param slotId the slot ID that the ImsService should bind for.
4466 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4467 * ImsService is the device default ImsService.
4468 * @param packageName The package name of the application that contains the ImsService to bind
4469 * to.
4470 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4471 * @hide
4472 */
4473 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004474 int[] subIds = SubscriptionManager.getSubId(slotId);
4475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4476 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4477 "setImsService");
4478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479 final long identity = Binder.clearCallingIdentity();
4480 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004481 ImsResolver resolver = PhoneFactory.getImsResolver();
4482 if (resolver == null) {
4483 // may happen if the device does not support IMS.
4484 return false;
4485 }
4486 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4487 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004488 } finally {
4489 Binder.restoreCallingIdentity(identity);
4490 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004491 }
4492
4493 /**
4494 * Return the ImsService configuration.
4495 *
4496 * @param slotId The slot that the ImsService is associated with.
4497 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4498 * the device default.
4499 * @return the package name of the ImsService configuration.
4500 */
4501 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004502 int[] subIds = SubscriptionManager.getSubId(slotId);
4503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4504 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4505 "getImsService");
4506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004507 final long identity = Binder.clearCallingIdentity();
4508 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004509 ImsResolver resolver = PhoneFactory.getImsResolver();
4510 if (resolver == null) {
4511 // may happen if the device does not support IMS.
4512 return "";
4513 }
4514 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004515 } finally {
4516 Binder.restoreCallingIdentity(identity);
4517 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004518 }
4519
Brad Ebinger77b832e2019-10-17 17:03:22 -07004520 /**
4521 * Get the MmTelFeature state associated with the requested subscription id.
4522 * @param subId The subscription that the MmTelFeature is associated with.
4523 * @param callback A callback with an integer containing the
4524 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4525 */
4526 @Override
4527 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4528 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4529 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4530 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4531 "IMS not available on device.");
4532 }
4533 final long token = Binder.clearCallingIdentity();
4534 try {
4535 int slotId = getSlotIndex(subId);
4536 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4537 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4538 + subId + "'");
4539 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4540 }
4541 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4542 try {
4543 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4544 } catch (RemoteException e) {
4545 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4546 + "Ignore");
4547 }
4548 });
4549 } finally {
4550 Binder.restoreCallingIdentity(token);
4551 }
4552 }
4553
Wink Saville36469e72014-06-11 15:17:00 -07004554 public void setImsRegistrationState(boolean registered) {
4555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556
4557 final long identity = Binder.clearCallingIdentity();
4558 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004559 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
Wink Saville36469e72014-06-11 15:17:00 -07004563 }
4564
4565 /**
Stuart Scott54788802015-03-30 13:18:01 -07004566 * Set the network selection mode to automatic.
4567 *
4568 */
4569 @Override
4570 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4572 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573
Pengquan Menge92a50d2018-09-21 15:54:48 -07004574 if (!isActiveSubscription(subId)) {
4575 return;
4576 }
4577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004578 final long identity = Binder.clearCallingIdentity();
4579 try {
4580 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4581 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
Stuart Scott54788802015-03-30 13:18:01 -07004585 }
4586
Pengquan Mengea84e042018-09-20 14:57:26 -07004587 /**
4588 * Ask the radio to connect to the input network and change selection mode to manual.
4589 *
4590 * @param subId the id of the subscription.
4591 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4592 * the operator to attach to.
4593 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4594 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4595 * normal network selection next time.
4596 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004597 */
4598 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004599 public boolean setNetworkSelectionModeManual(
4600 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4602 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004603
4604 if (!isActiveSubscription(subId)) {
4605 return false;
4606 }
4607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608 final long identity = Binder.clearCallingIdentity();
4609 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004610 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004611 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004612 if (DBG) {
4613 log("setNetworkSelectionModeManual: subId: " + subId
4614 + " operator: " + operatorInfo);
4615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4617 } finally {
4618 Binder.restoreCallingIdentity(identity);
4619 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004620 }
4621
4622 /**
4623 * Scans for available networks.
4624 */
4625 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004626 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4628 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004629 LocationAccessPolicy.LocationPermissionResult locationResult =
4630 LocationAccessPolicy.checkLocationPermission(mApp,
4631 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4632 .setCallingPackage(callingPackage)
4633 .setCallingPid(Binder.getCallingPid())
4634 .setCallingUid(Binder.getCallingUid())
4635 .setMethod("getCellNetworkScanResults")
4636 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4637 .build());
4638 switch (locationResult) {
4639 case DENIED_HARD:
4640 throw new SecurityException("Not allowed to access scan results -- location");
4641 case DENIED_SOFT:
4642 return null;
4643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644
Pengquan Menga1bb6272018-09-06 09:59:22 -07004645 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 try {
4647 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004648 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004649 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650 } finally {
4651 Binder.restoreCallingIdentity(identity);
4652 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004653 }
4654
4655 /**
yinxub1bed742017-04-17 11:45:04 -07004656 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004657 *
yinxub1bed742017-04-17 11:45:04 -07004658 * @param subId id of the subscription
4659 * @param request contains the radio access networks with bands/channels to scan
4660 * @param messenger callback messenger for scan results or errors
4661 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004662 * @return the id of the requested scan which can be used to stop the scan.
4663 */
4664 @Override
4665 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004666 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4668 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004669 LocationAccessPolicy.LocationPermissionResult locationResult =
4670 LocationAccessPolicy.checkLocationPermission(mApp,
4671 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4672 .setCallingPackage(callingPackage)
4673 .setCallingPid(Binder.getCallingPid())
4674 .setCallingUid(Binder.getCallingUid())
4675 .setMethod("requestNetworkScan")
4676 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4677 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004678 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004679 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004680 if (e != null) {
4681 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4682 throw e;
4683 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004684 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004685 return TelephonyScanManager.INVALID_SCAN_ID;
4686 }
4687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 }
Hall Liu912dfd32019-04-25 14:02:26 -07004689 int callingUid = Binder.getCallingUid();
4690 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 return mNetworkScanRequestTracker.startNetworkScan(
4694 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004695 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
yinxu504e1392017-04-12 16:03:22 -07004699 }
4700
Hall Liub2ac8ef2019-02-28 15:56:23 -08004701 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004702 NetworkScanRequest request, int subId) {
4703 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4704 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4705 boolean hasNetworkScanPermission =
4706 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4707 == PERMISSION_GRANTED;
4708
4709 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4710 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4711 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004712 }
4713
4714 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4715 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004716 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4717 return new SecurityException("Specific channels must not be"
4718 + " scanned without location access.");
4719 }
4720 }
4721 }
4722
Hall Liub2ac8ef2019-02-28 15:56:23 -08004723 return null;
4724 }
4725
yinxu504e1392017-04-12 16:03:22 -07004726 /**
4727 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004728 *
4729 * @param subId id of the subscription
4730 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004731 */
4732 @Override
4733 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4735 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736
Hall Liu912dfd32019-04-25 14:02:26 -07004737 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738 final long identity = Binder.clearCallingIdentity();
4739 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004740 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004741 } finally {
4742 Binder.restoreCallingIdentity(identity);
4743 }
yinxu504e1392017-04-12 16:03:22 -07004744 }
4745
4746 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004747 * Get the calculated preferred network type.
4748 * Used for debugging incorrect network type.
4749 *
4750 * @return the preferred network type, defined in RILConstants.java.
4751 */
4752 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004753 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004754 final Phone defaultPhone = getDefaultPhone();
4755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4756 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004757 return RILConstants.PREFERRED_NETWORK_MODE;
4758 }
4759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 final long identity = Binder.clearCallingIdentity();
4761 try {
4762 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004763 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764 } finally {
4765 Binder.restoreCallingIdentity(identity);
4766 }
Junda Liu84d15a22014-07-02 11:21:04 -07004767 }
4768
4769 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004770 * Get the preferred network type.
4771 * Used for device configuration by some CDMA operators.
4772 *
4773 * @return the preferred network type, defined in RILConstants.java.
4774 */
4775 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004776 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004777 TelephonyPermissions
4778 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4779 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780
4781 final long identity = Binder.clearCallingIdentity();
4782 try {
4783 if (DBG) log("getPreferredNetworkType");
4784 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4785 int networkType = (result != null ? result[0] : -1);
4786 if (DBG) log("getPreferredNetworkType: " + networkType);
4787 return networkType;
4788 } finally {
4789 Binder.restoreCallingIdentity(identity);
4790 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004791 }
4792
4793 /**
4794 * Set the preferred network type.
4795 * Used for device configuration by some CDMA operators.
4796 *
4797 * @param networkType the preferred network type, defined in RILConstants.java.
4798 * @return true on success; false on any failure.
4799 */
4800 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004801 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4803 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804
4805 final long identity = Binder.clearCallingIdentity();
4806 try {
4807 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4808 Boolean success = (Boolean) sendRequest(
4809 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4810 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4811 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004812 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4814 }
4815 return success;
4816 } finally {
4817 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004818 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004819 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004820
4821 /**
Miaoa84611c2019-03-15 09:21:10 +08004822 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004823 *
Miaoa84611c2019-03-15 09:21:10 +08004824 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004825 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004826 * @hide
4827 */
4828 @Override
Miaoa84611c2019-03-15 09:21:10 +08004829 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004830 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 try {
Miaoa84611c2019-03-15 09:21:10 +08004834 if (phone != null) {
4835 return phone.hasMatchedTetherApnSetting();
4836 } else {
4837 return false;
4838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004839 } finally {
4840 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004841 }
Junda Liu475951f2014-11-07 16:45:03 -08004842 }
4843
4844 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004845 * Set mobile data enabled
4846 * Used by the user through settings etc to turn on/off mobile data
4847 *
4848 * @param enable {@code true} turn turn data on, else {@code false}
4849 */
4850 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004851 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4853 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854
4855 final long identity = Binder.clearCallingIdentity();
4856 try {
4857 int phoneId = mSubscriptionController.getPhoneId(subId);
4858 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4859 Phone phone = PhoneFactory.getPhone(phoneId);
4860 if (phone != null) {
4861 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004862 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004863 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004864 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865 }
4866 } finally {
4867 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004868 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004869 }
4870
4871 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004872 * Get the user enabled state of Mobile Data.
4873 *
4874 * TODO: remove and use isUserDataEnabled.
4875 * This can't be removed now because some vendor codes
4876 * calls through ITelephony directly while they should
4877 * use TelephonyManager.
4878 *
4879 * @return true on enabled
4880 */
4881 @Override
4882 public boolean getDataEnabled(int subId) {
4883 return isUserDataEnabled(subId);
4884 }
4885
4886 /**
4887 * Get whether mobile data is enabled per user setting.
4888 *
4889 * There are other factors deciding whether mobile data is actually enabled, but they are
4890 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004891 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004892 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004893 *
4894 * @return {@code true} if data is enabled else {@code false}
4895 */
4896 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004897 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004898 try {
4899 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4900 null);
4901 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4903 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905
4906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 int phoneId = mSubscriptionController.getPhoneId(subId);
4909 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4910 Phone phone = PhoneFactory.getPhone(phoneId);
4911 if (phone != null) {
4912 boolean retVal = phone.isUserDataEnabled();
4913 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4914 return retVal;
4915 } else {
4916 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4917 return false;
4918 }
4919 } finally {
4920 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004921 }
4922 }
4923
4924 /**
4925 * Get whether mobile data is enabled.
4926 *
4927 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4928 * whether mobile data is actually enabled.
4929 *
4930 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4931 *
4932 * @return {@code true} if data is enabled else {@code false}
4933 */
4934 @Override
4935 public boolean isDataEnabled(int subId) {
4936 try {
4937 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4938 null);
4939 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4941 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943
4944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 int phoneId = mSubscriptionController.getPhoneId(subId);
4947 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4948 Phone phone = PhoneFactory.getPhone(phoneId);
4949 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004950 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4952 return retVal;
4953 } else {
4954 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4955 return false;
4956 }
4957 } finally {
4958 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004959 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004960 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004961
4962 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004963 public int getCarrierPrivilegeStatus(int subId) {
4964 final Phone phone = getPhone(subId);
4965 if (phone == null) {
4966 loge("getCarrierPrivilegeStatus: Invalid subId");
4967 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4968 }
4969 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004970 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004971 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004972 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4973 }
4974 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004975 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004976 }
Junda Liu29340342014-07-10 15:23:27 -07004977
4978 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004979 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4980 final Phone phone = getPhone(subId);
4981 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004982 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004983 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4984 }
4985 UiccProfile profile =
4986 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4987 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09004988 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08004989 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4990 }
4991 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4992 }
4993
4994 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004995 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4996 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004997 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004998 }
4999
5000 int phoneId = SubscriptionManager.getPhoneId(subId);
5001 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005002 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005003 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005004 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5005 }
chen xuf7e9fe82019-05-09 19:31:02 -07005006
5007 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005008 }
5009
5010 @Override
5011 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005012 if (TextUtils.isEmpty(pkgName))
5013 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005014 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5015 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5016 UiccCard card = UiccController.getInstance().getUiccCard(i);
5017 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005018 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005019 continue;
5020 }
5021
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005022 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005023 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5024 break;
5025 }
5026 }
5027
5028 return result;
Junda Liu29340342014-07-10 15:23:27 -07005029 }
Derek Tan89e89d42014-07-08 17:00:10 -07005030
5031 @Override
Junda Liue64de782015-04-16 17:19:16 -07005032 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5033 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5034 loge("phoneId " + phoneId + " is not valid.");
5035 return null;
5036 }
5037 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005038 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005039 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005040 return null ;
5041 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005042 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005043 }
5044
Amith Yamasani6e118872016-02-19 12:53:51 -08005045 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005046 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005047 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005048 List<String> privilegedPackages = new ArrayList<>();
5049 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005050 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5051 // has UICC in that slot.
5052 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005053 if (card.hasCarrierPrivilegeRules()) {
5054 if (packages == null) {
5055 // Only check packages in user 0 for now
5056 packages = pm.getInstalledPackagesAsUser(
5057 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07005058 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
5059 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005060 }
5061 for (int p = packages.size() - 1; p >= 0; p--) {
5062 PackageInfo pkgInfo = packages.get(p);
5063 if (pkgInfo != null && pkgInfo.packageName != null
5064 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005065 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005066 privilegedPackages.add(pkgInfo.packageName);
5067 }
5068 }
5069 }
5070 }
5071 return privilegedPackages;
5072 }
5073
chen xuf7e9fe82019-05-09 19:31:02 -07005074 @Override
5075 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5076 List<String> privilegedPackages = new ArrayList<>();
5077 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5078 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5079 }
5080 return privilegedPackages;
5081 }
5082
Wink Savilleb564aae2014-10-23 10:18:09 -07005083 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005084 final Phone phone = getPhone(subId);
5085 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005086 if (card == null) {
5087 loge("getIccId: No UICC");
5088 return null;
5089 }
5090 String iccId = card.getIccId();
5091 if (TextUtils.isEmpty(iccId)) {
5092 loge("getIccId: ICC ID is null or empty.");
5093 return null;
5094 }
5095 return iccId;
5096 }
5097
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005098 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005099 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5100 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005101 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5102 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 final String iccId = getIccId(subId);
5107 final Phone phone = getPhone(subId);
5108 if (phone == null) {
5109 return false;
5110 }
5111 final String subscriberId = phone.getSubscriberId();
5112
5113 if (DBG_MERGE) {
5114 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5115 + subscriberId + " to " + number);
5116 }
5117
5118 if (TextUtils.isEmpty(iccId)) {
5119 return false;
5120 }
5121
5122 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5123
5124 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5125 if (alphaTag == null) {
5126 editor.remove(alphaTagPrefKey);
5127 } else {
5128 editor.putString(alphaTagPrefKey, alphaTag);
5129 }
5130
5131 // Record both the line number and IMSI for this ICCID, since we need to
5132 // track all merged IMSIs based on line number
5133 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5134 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5135 if (number == null) {
5136 editor.remove(numberPrefKey);
5137 editor.remove(subscriberPrefKey);
5138 } else {
5139 editor.putString(numberPrefKey, number);
5140 editor.putString(subscriberPrefKey, subscriberId);
5141 }
5142
5143 editor.commit();
5144 return true;
5145 } finally {
5146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005147 }
Derek Tan7226c842014-07-02 17:42:23 -07005148 }
5149
5150 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005151 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005152 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005154 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005155 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005156 return null;
5157 }
Derek Tan97ebb422014-09-05 16:55:38 -07005158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 String iccId = getIccId(subId);
5162 if (iccId != null) {
5163 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5164 if (DBG_MERGE) {
5165 log("getLine1NumberForDisplay returning "
5166 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5167 }
5168 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5171 return null;
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005174 }
Derek Tan7226c842014-07-02 17:42:23 -07005175 }
5176
5177 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005178 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005180 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005181 return null;
5182 }
Derek Tan97ebb422014-09-05 16:55:38 -07005183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 String iccId = getIccId(subId);
5187 if (iccId != null) {
5188 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5189 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5190 }
5191 return null;
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005194 }
Derek Tan7226c842014-07-02 17:42:23 -07005195 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005196
5197 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005198 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005199 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5200 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005202 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5203 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005204 return null;
5205 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005206
Jordan Liub49b04b2019-05-06 14:45:15 -07005207 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5208 // the process, where TelephonyManager was instantiated.
5209 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005210 final long identity = Binder.clearCallingIdentity();
5211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005212 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 final TelephonyManager tele = TelephonyManager.from(context);
5214 final SubscriptionManager sub = SubscriptionManager.from(context);
5215
5216 // Figure out what subscribers are currently active
5217 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218
Jordan Liub49b04b2019-05-06 14:45:15 -07005219 // Only consider subs which match the current subId
5220 // This logic can be simplified. See b/131189269 for progress.
5221 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005222 activeSubscriberIds.add(tele.getSubscriberId(subId));
5223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224
5225 // First pass, find a number override for an active subscriber
5226 String mergeNumber = null;
5227 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5228 for (String key : prefs.keySet()) {
5229 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5230 final String subscriberId = (String) prefs.get(key);
5231 if (activeSubscriberIds.contains(subscriberId)) {
5232 final String iccId = key.substring(
5233 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5234 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5235 mergeNumber = (String) prefs.get(numberKey);
5236 if (DBG_MERGE) {
5237 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5238 + " for active subscriber " + subscriberId);
5239 }
5240 if (!TextUtils.isEmpty(mergeNumber)) {
5241 break;
5242 }
5243 }
5244 }
5245 }
5246
5247 // Shortcut when no active merged subscribers
5248 if (TextUtils.isEmpty(mergeNumber)) {
5249 return null;
5250 }
5251
5252 // Second pass, find all subscribers under that line override
5253 final ArraySet<String> result = new ArraySet<>();
5254 for (String key : prefs.keySet()) {
5255 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5256 final String number = (String) prefs.get(key);
5257 if (mergeNumber.equals(number)) {
5258 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5259 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5260 final String subscriberId = (String) prefs.get(subscriberKey);
5261 if (!TextUtils.isEmpty(subscriberId)) {
5262 result.add(subscriberId);
5263 }
5264 }
5265 }
5266 }
5267
5268 final String[] resultArray = result.toArray(new String[result.size()]);
5269 Arrays.sort(resultArray);
5270 if (DBG_MERGE) {
5271 Slog.d(LOG_TAG,
5272 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5273 }
5274 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005275 } finally {
5276 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005277 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005278 }
5279
5280 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005281 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5282 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5283
5284 final long identity = Binder.clearCallingIdentity();
5285 try {
5286 final TelephonyManager telephonyManager = mApp.getSystemService(
5287 TelephonyManager.class);
5288 String subscriberId = telephonyManager.getSubscriberId(subId);
5289 if (subscriberId == null) {
5290 if (DBG) {
5291 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5292 + subId);
5293 }
5294 return null;
5295 }
5296
5297 final SubscriptionInfo info = SubscriptionController.getInstance()
5298 .getSubscriptionInfo(subId);
5299 final ParcelUuid groupUuid = info.getGroupUuid();
5300 // If it doesn't belong to any group, return just subscriberId of itself.
5301 if (groupUuid == null) {
5302 return new String[]{subscriberId};
5303 }
5304
5305 // Get all subscriberIds from the group.
5306 final List<String> mergedSubscriberIds = new ArrayList<>();
5307 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5308 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5309 for (SubscriptionInfo subInfo : groupInfos) {
5310 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5311 if (subscriberId != null) {
5312 mergedSubscriberIds.add(subscriberId);
5313 }
5314 }
5315
5316 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319
5320 }
5321 }
5322
5323 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005324 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005325 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5326 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327
5328 final long identity = Binder.clearCallingIdentity();
5329 try {
5330 final Phone phone = getPhone(subId);
5331 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005335 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005336
5337 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005338 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005339 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5340 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005341 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342
5343 final long identity = Binder.clearCallingIdentity();
5344 try {
5345 final Phone phone = getPhone(subId);
5346 if (phone == null) {
5347 return false;
5348 }
5349 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5350 cdmaNonRoamingList);
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005353 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005354 }
5355
5356 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005357 @Deprecated
5358 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5359 enforceModifyPermission();
5360
5361 int returnValue = 0;
5362 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005363 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005364 if(result.exception == null) {
5365 if (result.result != null) {
5366 byte[] responseData = (byte[])(result.result);
5367 if(responseData.length > oemResp.length) {
5368 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5369 responseData.length + "bytes. Buffer Size is " +
5370 oemResp.length + "bytes.");
5371 }
5372 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5373 returnValue = responseData.length;
5374 }
5375 } else {
5376 CommandException ex = (CommandException) result.exception;
5377 returnValue = ex.getCommandError().ordinal();
5378 if(returnValue > 0) returnValue *= -1;
5379 }
5380 } catch (RuntimeException e) {
5381 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5382 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5383 if(returnValue > 0) returnValue *= -1;
5384 }
5385
5386 return returnValue;
5387 }
5388
5389 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005390 public void setRadioCapability(RadioAccessFamily[] rafs) {
5391 try {
5392 ProxyController.getInstance().setRadioCapability(rafs);
5393 } catch (RuntimeException e) {
5394 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5395 }
5396 }
5397
5398 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005399 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005400 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005401 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005402 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005403 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 final long identity = Binder.clearCallingIdentity();
5406 try {
chen xub97461a2018-10-26 14:17:57 -07005407 TelephonyPermissions
5408 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5409 mApp, phone.getSubId(), "getRadioAccessFamily");
5410 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
chen xub97461a2018-10-26 14:17:57 -07005414 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005415 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005416
5417 @Override
5418 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005419 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421
5422 final long identity = Binder.clearCallingIdentity();
5423 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005424 ImsManager.getInstance(defaultPhone.getContext(),
5425 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005429 }
5430
5431 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005432 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005433 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005435 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005436 return false;
5437 }
Svet Ganovb320e182015-04-16 12:30:10 -07005438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 final long identity = Binder.clearCallingIdentity();
5440 try {
5441 // Check the user preference and the system-level IMS setting. Even if the user has
5442 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5443 // In the long run, we may instead need to check if there exists a connection service
5444 // which can support video calling.
5445 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005446 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 return imsManager.isVtEnabledByPlatform()
5448 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5449 && imsManager.isVtEnabledByUser();
5450 } finally {
5451 Binder.restoreCallingIdentity(identity);
5452 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005453 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005454
Andrew Leea1239f22015-03-02 17:44:07 -08005455 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5458 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5459 return false;
5460 }
5461
5462 final long identity = Binder.clearCallingIdentity();
5463 try {
5464 CarrierConfigManager configManager =
5465 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005466 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5468 } finally {
5469 Binder.restoreCallingIdentity(identity);
5470 }
Andrew Leea1239f22015-03-02 17:44:07 -08005471 }
5472
5473 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 public boolean isWorldPhone(int subId, String callingPackage) {
5475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5476 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5477 return false;
5478 }
5479
5480 final long identity = Binder.clearCallingIdentity();
5481 try {
5482 CarrierConfigManager configManager =
5483 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005484 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5486 } finally {
5487 Binder.restoreCallingIdentity(identity);
5488 }
Andrew Leea1239f22015-03-02 17:44:07 -08005489 }
5490
Andrew Lee9431b832015-03-09 18:46:45 -07005491 @Override
5492 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005493 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005494 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005495 }
5496
5497 @Override
5498 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 final long identity = Binder.clearCallingIdentity();
5500 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005501 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504 }
Andrew Lee9431b832015-03-09 18:46:45 -07005505 }
5506
Hall Liuf6668912018-10-31 17:05:23 -07005507 /**
5508 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5509 * support for the feature and device firmware support.
5510 *
5511 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5512 */
5513 @Override
5514 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005516 final Phone phone = getPhone(subscriptionId);
5517 if (phone == null) {
5518 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5519 return false;
5520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005522 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5524 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005525 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 return isCarrierSupported && isDeviceSupported;
5527 } finally {
5528 Binder.restoreCallingIdentity(identity);
5529 }
Hall Liu98187582018-01-22 19:15:32 -08005530 }
5531
Hall Liuf6668912018-10-31 17:05:23 -07005532 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005533 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5534 * RTT setting, will return true if the device and carrier both support RTT.
5535 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005536 */
5537 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 final long identity = Binder.clearCallingIdentity();
5539 try {
Hall Liu6a06be62019-07-23 18:39:00 -07005540 boolean isRttSupported = isRttSupported(subscriptionId);
5541 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005542 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liu6a06be62019-07-23 18:39:00 -07005543 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5544 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5545 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005549 }
5550
Sanket Padawe7310cc72015-01-14 09:53:20 -08005551 /**
5552 * Returns the unique device ID of phone, for example, the IMEI for
5553 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5554 *
5555 * <p>Requires Permission:
5556 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5557 */
5558 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005559 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005560 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005561 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005562 return null;
5563 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005564 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005565 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5566 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005567 return null;
5568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569
5570 final long identity = Binder.clearCallingIdentity();
5571 try {
5572 return phone.getDeviceId();
5573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005576 }
5577
Ping Sunc67b7c22016-03-02 19:16:45 +08005578 /**
5579 * {@hide}
5580 * Returns the IMS Registration Status on a particular subid
5581 *
5582 * @param subId
5583 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005584 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005585 Phone phone = getPhone(subId);
5586 if (phone != null) {
5587 return phone.isImsRegistered();
5588 } else {
5589 return false;
5590 }
5591 }
5592
Santos Cordon7a1885b2015-02-03 11:15:19 -08005593 @Override
5594 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 final long identity = Binder.clearCallingIdentity();
5596 try {
5597 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005601 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005602
Tyler Gunnf70ed162019-04-03 15:28:53 -07005603 @Override
5604 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 Phone phone = getPhone(subscriptionId);
5608 if (phone == null) {
5609 return null;
5610 }
5611 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5612 } finally {
5613 Binder.restoreCallingIdentity(identity);
5614 }
5615 }
5616
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005617 /**
5618 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005619 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005620 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 final long identity = Binder.clearCallingIdentity();
5622 try {
5623 Phone phone = getPhone(subId);
5624 if (phone != null) {
5625 return phone.isWifiCallingEnabled();
5626 } else {
5627 return false;
5628 }
5629 } finally {
5630 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005631 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005632 }
5633
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005634 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005635 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005636 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005637 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 Phone phone = getPhone(subId);
5641 if (phone != null) {
5642 return phone.isVideoEnabled();
5643 } else {
5644 return false;
5645 }
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005648 }
5649 }
5650
5651 /**
5652 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5653 * defined in {@link ImsRegistrationImplBase}.
5654 */
5655 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 final long identity = Binder.clearCallingIdentity();
5657 try {
5658 Phone phone = getPhone(subId);
5659 if (phone != null) {
5660 return phone.getImsRegistrationTech();
5661 } else {
5662 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5663 }
5664 } finally {
5665 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005666 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005667 }
5668
Stuart Scott8eef64f2015-04-08 15:13:54 -07005669 @Override
5670 public void factoryReset(int subId) {
5671 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005672 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5673 return;
5674 }
5675
Svet Ganovcc087f82015-05-12 20:35:54 -07005676 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005677
Svet Ganovcc087f82015-05-12 20:35:54 -07005678 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005679 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5680 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005681 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005682 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005683 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005684 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5685 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005686 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005687 // There has been issues when Sms raw table somehow stores orphan
5688 // fragments. They lead to garbled message when new fragments come
5689 // in and combined with those stale ones. In case this happens again,
5690 // user can reset all network settings which will clean up this table.
5691 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005692 // Clean up IMS settings as well here.
5693 int slotId = getSlotIndex(subId);
5694 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5695 ImsManager.getInstance(mApp, slotId).factoryReset();
5696 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005697 } finally {
5698 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005699 }
5700 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005701
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005702 private void cleanUpSmsRawTable(Context context) {
5703 ContentResolver resolver = context.getContentResolver();
5704 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5705 resolver.delete(uri, null, null);
5706 }
5707
Narayan Kamath1c496c22015-04-16 14:40:19 +01005708 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005709 public String getSimLocaleForSubscriber(int subId) {
5710 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5711 final Phone phone = getPhone(subId);
5712 if (phone == null) {
5713 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005714 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 final long identity = Binder.clearCallingIdentity();
5717 try {
chen xu5d3637b2019-01-21 23:31:38 -08005718 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5719 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005720 if (info == null) {
5721 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5722 return null;
5723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 // Try and fetch the locale from the carrier properties or from the SIM language
5725 // preferences (EF-PL and EF-LI)...
5726 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005728 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5729 if (localeFromDefaultSim != null) {
5730 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5731 if (DBG) log("Using locale from subId: " + subId + " locale: "
5732 + localeFromDefaultSim);
5733 return localeFromDefaultSim.toLanguageTag();
5734 } else {
5735 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 }
5737 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 // The SIM language preferences only store a language (e.g. fr = French), not an
5740 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5741 // the SIM and carrier preferences does not include a country we add the country
5742 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005743 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005745 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 return mccLocale.toLanguageTag();
5747 }
5748
5749 if (DBG) log("No locale found - returning null");
5750 return null;
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
5753 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005754 }
5755
5756 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005757 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005758 }
5759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760 /**
5761 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5762 */
5763 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005764 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005765 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005766
Chenjie Yu1ba97252018-01-11 18:16:20 -08005767 private final ModemActivityInfo mLastModemActivityInfo =
5768 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5769
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005770 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005771 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5772 * representing the state of the modem.
5773 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005774 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5775 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005776 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005777 */
5778 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005779 public void requestModemActivityInfo(ResultReceiver result) {
5780 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005781 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782
5783 final long identity = Binder.clearCallingIdentity();
5784 try {
5785 ModemActivityInfo ret = null;
5786 synchronized (mLastModemActivityInfo) {
5787 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5788 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005789 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005790 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5792 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005793 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5794 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 }
5796 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005797 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5798 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799 mLastModemActivityInfo.setIdleTimeMillis(
5800 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5801 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5802 mLastModemActivityInfo.setRxTimeMillis(
5803 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5804 mLastModemActivityInfo.setEnergyUsed(
5805 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5808 mLastModemActivityInfo.getSleepTimeMillis(),
5809 mLastModemActivityInfo.getIdleTimeMillis(),
5810 mLastModemActivityInfo.getTxTimeMillis(),
5811 mLastModemActivityInfo.getRxTimeMillis(),
5812 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 Bundle bundle = new Bundle();
5815 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5816 result.send(0, bundle);
5817 } finally {
5818 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005819 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005820 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005821
Siddharth Rayb8114062018-06-17 15:02:38 -07005822 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5823 // less than total activity duration.
5824 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5825 if (info == null) {
5826 return false;
5827 }
5828 int activityDurationMs =
5829 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5830 int totalTxTimeMs = 0;
5831 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5832 totalTxTimeMs += info.getTxTimeMillis()[i];
5833 }
5834 return (info.isValid()
5835 && (info.getSleepTimeMillis() <= activityDurationMs)
5836 && (info.getIdleTimeMillis() <= activityDurationMs)
5837 && (info.getRxTimeMillis() <= activityDurationMs)
5838 && (totalTxTimeMs <= activityDurationMs));
5839 }
5840
Jack Yu85bd38a2015-11-09 11:34:32 -08005841 /**
5842 * {@hide}
5843 * Returns the service state information on specified subscription.
5844 */
5845 @Override
5846 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005847 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005848 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005849 return null;
5850 }
5851
Hall Liuf19c44f2018-11-27 14:38:17 -08005852 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5853 LocationAccessPolicy.checkLocationPermission(mApp,
5854 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5855 .setCallingPackage(callingPackage)
5856 .setCallingPid(Binder.getCallingPid())
5857 .setCallingUid(Binder.getCallingUid())
5858 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005859 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005860 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5861 .build());
5862
5863 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5864 LocationAccessPolicy.checkLocationPermission(mApp,
5865 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5866 .setCallingPackage(callingPackage)
5867 .setCallingPid(Binder.getCallingPid())
5868 .setCallingUid(Binder.getCallingUid())
5869 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005870 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005871 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5872 .build());
5873 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5874 boolean hasFinePermission =
5875 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5876 boolean hasCoarsePermission =
5877 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 final long identity = Binder.clearCallingIdentity();
5880 try {
5881 final Phone phone = getPhone(subId);
5882 if (phone == null) {
5883 return null;
5884 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005885
Hall Liuf19c44f2018-11-27 14:38:17 -08005886 ServiceState ss = phone.getServiceState();
5887
5888 // Scrub out the location info in ServiceState depending on what level of access
5889 // the caller has.
5890 if (hasFinePermission) return ss;
5891 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5892 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005896 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005897
5898 /**
5899 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5900 *
5901 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5902 * voicemail ringtone.
5903 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5904 * PhoneAccount.
5905 */
5906 @Override
5907 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 final long identity = Binder.clearCallingIdentity();
5909 try {
5910 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5911 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005912 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5916 } finally {
5917 Binder.restoreCallingIdentity(identity);
5918 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005919 }
5920
5921 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005922 * Sets the per-account voicemail ringtone.
5923 *
5924 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5925 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5926 *
5927 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5928 * voicemail ringtone.
5929 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5930 * PhoneAccount.
5931 */
5932 @Override
5933 public void setVoicemailRingtoneUri(String callingPackage,
5934 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005935 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005936 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5937 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005938 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5940 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5941 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943
5944 final long identity = Binder.clearCallingIdentity();
5945 try {
5946 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5947 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005948 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 }
5950 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5951 } finally {
5952 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005953 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005954 }
5955
5956 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005957 * Returns whether vibration is set for voicemail notification in Phone settings.
5958 *
5959 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5960 * voicemail vibration setting.
5961 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5962 */
5963 @Override
5964 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 final long identity = Binder.clearCallingIdentity();
5966 try {
5967 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5968 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005969 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5973 } finally {
5974 Binder.restoreCallingIdentity(identity);
5975 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005976 }
5977
Youhan Wange64578a2016-05-02 15:32:42 -07005978 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005979 * Sets the per-account voicemail vibration.
5980 *
5981 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5982 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5983 *
5984 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5985 * voicemail vibration setting.
5986 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5987 * specific PhoneAccount.
5988 */
5989 @Override
5990 public void setVoicemailVibrationEnabled(String callingPackage,
5991 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005992 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005993 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5994 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005995 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5997 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5998 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005999 }
6000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 final long identity = Binder.clearCallingIdentity();
6002 try {
6003 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6004 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006005 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 }
6007 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6008 } finally {
6009 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006010 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006011 }
6012
6013 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006014 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6015 *
6016 * @throws SecurityException if the caller does not have the required permission
6017 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006018 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006019 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006020 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006021 }
6022
6023 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006024 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6025 * permission.
6026 *
6027 * @throws SecurityException if the caller does not have the required permission
6028 */
6029 private void enforceSendSmsPermission() {
6030 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6031 }
6032
6033 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006034 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006035 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006036 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006037 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006038 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 final long identity = Binder.clearCallingIdentity();
6040 try {
6041 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006042 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043 if (componentName == null) {
6044 throw new SecurityException(
6045 "Caller not current active visual voicemail package[null]");
6046 }
6047 String vvmPackage = componentName.getPackageName();
6048 if (!callingPackage.equals(vvmPackage)) {
6049 throw new SecurityException("Caller not current active visual voicemail package["
6050 + vvmPackage + "]");
6051 }
6052 } finally {
6053 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006054 }
6055 }
6056
6057 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006058 * Return the application ID for the app type.
6059 *
6060 * @param subId the subscription ID that this request applies to.
6061 * @param appType the uicc app type.
6062 * @return Application ID for specificied app type, or null if no uicc.
6063 */
6064 @Override
6065 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006066 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006067 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068
6069 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006070 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 if (phone == null) {
6072 return null;
6073 }
6074 String aid = null;
6075 try {
6076 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6077 .getApplicationByType(appType).getAid();
6078 } catch (Exception e) {
6079 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6080 }
6081 return aid;
6082 } finally {
6083 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006084 }
Youhan Wange64578a2016-05-02 15:32:42 -07006085 }
6086
Youhan Wang4001d252016-05-11 10:29:41 -07006087 /**
6088 * Return the Electronic Serial Number.
6089 *
6090 * @param subId the subscription ID that this request applies to.
6091 * @return ESN or null if error.
6092 */
6093 @Override
6094 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006095 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006096 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097
6098 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006099 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 if (phone == null) {
6101 return null;
6102 }
6103 String esn = null;
6104 try {
6105 esn = phone.getEsn();
6106 } catch (Exception e) {
6107 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6108 }
6109 return esn;
6110 } finally {
6111 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006112 }
Youhan Wang4001d252016-05-11 10:29:41 -07006113 }
6114
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006115 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006116 * Return the Preferred Roaming List Version.
6117 *
6118 * @param subId the subscription ID that this request applies to.
6119 * @return PRLVersion or null if error.
6120 */
6121 @Override
6122 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006123 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006124 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125
6126 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006127 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 if (phone == null) {
6129 return null;
6130 }
6131 String cdmaPrlVersion = null;
6132 try {
6133 cdmaPrlVersion = phone.getCdmaPrlVersion();
6134 } catch (Exception e) {
6135 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6136 }
6137 return cdmaPrlVersion;
6138 } finally {
6139 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006140 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006141 }
6142
6143 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006144 * Get snapshot of Telephony histograms
6145 * @return List of Telephony histograms
6146 * @hide
6147 */
6148 @Override
6149 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6151 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152
6153 final long identity = Binder.clearCallingIdentity();
6154 try {
6155 return RIL.getTelephonyRILTimingHistograms();
6156 } finally {
6157 Binder.restoreCallingIdentity(identity);
6158 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006159 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006160
6161 /**
6162 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006163 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6164 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006165 * Require system privileges. In the future we may add this to carrier APIs.
6166 *
Michele Berionne482f8202018-11-27 18:57:59 -08006167 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006168 */
6169 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006170 @TelephonyManager.SetCarrierRestrictionResult
6171 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006172 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006173 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006174
Michele Berionne482f8202018-11-27 18:57:59 -08006175 if (carrierRestrictionRules == null) {
6176 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006177 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179 final long identity = Binder.clearCallingIdentity();
6180 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006181 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006182 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 } finally {
6184 Binder.restoreCallingIdentity(identity);
6185 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006186 }
6187
6188 /**
6189 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006190 * Get the allowed carrier list and the excluded carrier list, including the priority between
6191 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006192 * Require system privileges. In the future we may add this to carrier APIs.
6193 *
Michele Berionne482f8202018-11-27 18:57:59 -08006194 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006195 */
6196 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006197 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006198 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006199 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006200
6201 final long identity = Binder.clearCallingIdentity();
6202 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006203 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6204 if (response instanceof CarrierRestrictionRules) {
6205 return (CarrierRestrictionRules) response;
6206 }
6207 // Response is an Exception of some kind,
6208 // which is signalled to the user as a NULL retval
6209 return null;
6210 } catch (Exception e) {
6211 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6212 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 } finally {
6214 Binder.restoreCallingIdentity(identity);
6215 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006216 }
6217
fionaxu59545b42016-05-25 15:53:37 -07006218 /**
6219 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6220 * @param subId the subscription ID that this action applies to.
6221 * @param enabled control enable or disable metered apns.
6222 * {@hide}
6223 */
6224 @Override
6225 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6226 enforceModifyPermission();
6227 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228
6229 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006230 if (phone == null) {
6231 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6232 return;
6233 }
6234 try {
6235 phone.carrierActionSetMeteredApnsEnabled(enabled);
6236 } catch (Exception e) {
6237 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 } finally {
6239 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006240 }
6241 }
6242
6243 /**
6244 * Action set from carrier signalling broadcast receivers to enable/disable radio
6245 * @param subId the subscription ID that this action applies to.
6246 * @param enabled control enable or disable radio.
6247 * {@hide}
6248 */
6249 @Override
6250 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6251 enforceModifyPermission();
6252 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253
6254 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006255 if (phone == null) {
6256 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6257 return;
6258 }
6259 try {
6260 phone.carrierActionSetRadioEnabled(enabled);
6261 } catch (Exception e) {
6262 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006263 } finally {
6264 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006265 }
6266 }
6267
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006268 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006269 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6270 * network status based on which carrier apps could apply actions accordingly,
6271 * enable/disable default url handler for example.
6272 *
6273 * @param subId the subscription ID that this action applies to.
6274 * @param report control start/stop reporting the default network status.
6275 * {@hide}
6276 */
6277 @Override
6278 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6279 enforceModifyPermission();
6280 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281
6282 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006283 if (phone == null) {
6284 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6285 return;
6286 }
6287 try {
6288 phone.carrierActionReportDefaultNetworkStatus(report);
6289 } catch (Exception e) {
6290 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291 } finally {
6292 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006293 }
6294 }
6295
6296 /**
fionaxud9622282017-07-17 17:51:30 -07006297 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6298 * @param subId the subscription ID that this action applies to.
6299 * {@hide}
6300 */
6301 @Override
6302 public void carrierActionResetAll(int subId) {
6303 enforceModifyPermission();
6304 final Phone phone = getPhone(subId);
6305 if (phone == null) {
6306 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6307 return;
6308 }
6309 try {
6310 phone.carrierActionResetAll();
6311 } catch (Exception e) {
6312 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6313 }
6314 }
6315
6316 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006317 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6318 * bug report is being generated.
6319 */
6320 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006321 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006322 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6323 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006324 writer.println("Permission Denial: can't dump Phone from pid="
6325 + Binder.getCallingPid()
6326 + ", uid=" + Binder.getCallingUid()
6327 + "without permission "
6328 + android.Manifest.permission.DUMP);
6329 return;
6330 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006331 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006332 }
Jack Yueb89b242016-06-22 13:27:47 -07006333
Brad Ebingerdac2f002018-04-03 15:17:52 -07006334 @Override
6335 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6336 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6337 throws RemoteException {
6338 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6339 }
6340
Jack Yueb89b242016-06-22 13:27:47 -07006341 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006342 * Get aggregated video call data usage since boot.
6343 *
6344 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6345 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006346 * {@hide}
6347 */
6348 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006349 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006350 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6351 null);
6352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 // NetworkStatsService keeps tracking the active network interface and identity. It
6356 // records the delta with the corresponding network identity.
6357 // We just return the total video call data usage snapshot since boot.
6358 Phone phone = getPhone(subId);
6359 if (phone != null) {
6360 return phone.getVtDataUsage(perUidStats);
6361 }
6362 return null;
6363 } finally {
6364 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006365 }
Jack Yueb89b242016-06-22 13:27:47 -07006366 }
Jack Yu75ab2952016-07-08 14:29:33 -07006367
6368 /**
6369 * Policy control of data connection. Usually used when data limit is passed.
6370 * @param enabled True if enabling the data, otherwise disabling.
6371 * @param subId Subscription index
6372 * {@hide}
6373 */
6374 @Override
6375 public void setPolicyDataEnabled(boolean enabled, int subId) {
6376 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377
6378 final long identity = Binder.clearCallingIdentity();
6379 try {
6380 Phone phone = getPhone(subId);
6381 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006382 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383 }
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006386 }
6387 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006388
6389 /**
6390 * Get Client request stats
6391 * @return List of Client Request Stats
6392 * @hide
6393 */
6394 @Override
6395 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006397 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006398 return null;
6399 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006400 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 final long identity = Binder.clearCallingIdentity();
6403 try {
6404 if (phone != null) {
6405 return phone.getClientRequestStats();
6406 }
6407
6408 return null;
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006412 }
6413
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006414 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006415 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006416 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006417 }
Jack Yueb4124c2017-02-16 15:32:43 -08006418
6419 /**
Grace Chen70990072017-03-24 17:21:30 -07006420 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006421 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006422 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006423 * @param state State of SIM (power down, power up, pass through)
6424 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6425 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6426 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006427 *
6428 **/
6429 @Override
Grace Chen70990072017-03-24 17:21:30 -07006430 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006431 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006432 Phone phone = PhoneFactory.getPhone(slotIndex);
6433
vagdeviaf9a5b92018-08-15 16:01:53 -07006434 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 final long identity = Binder.clearCallingIdentity();
6437 try {
6438 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006439 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 }
6441 } finally {
6442 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006443 }
6444 }
Shuo Qiandd210312017-04-12 22:11:33 +00006445
Tyler Gunn65d45c22017-06-05 11:22:26 -07006446 private boolean isUssdApiAllowed(int subId) {
6447 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006448 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006449 if (configManager == null) {
6450 return false;
6451 }
6452 PersistableBundle pb = configManager.getConfigForSubId(subId);
6453 if (pb == null) {
6454 return false;
6455 }
6456 return pb.getBoolean(
6457 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6458 }
6459
Shuo Qiandd210312017-04-12 22:11:33 +00006460 /**
6461 * Check if phone is in emergency callback mode
6462 * @return true if phone is in emergency callback mode
6463 * @param subId sub id
6464 */
goneil9c5f4872017-12-05 14:07:56 -08006465 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006466 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006467 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006468 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469
6470 final long identity = Binder.clearCallingIdentity();
6471 try {
6472 if (phone != null) {
6473 return phone.isInEcm();
6474 } else {
6475 return false;
6476 }
6477 } finally {
6478 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006479 }
6480 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006481
6482 /**
6483 * Get the current signal strength information for the given subscription.
6484 * Because this information is not updated when the device is in a low power state
6485 * it should not be relied-upon to be current.
6486 * @param subId Subscription index
6487 * @return the most recent cached signal strength info from the modem
6488 */
6489 @Override
6490 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491 final long identity = Binder.clearCallingIdentity();
6492 try {
6493 Phone p = getPhone(subId);
6494 if (p == null) {
6495 return null;
6496 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006498 return p.getSignalStrength();
6499 } finally {
6500 Binder.restoreCallingIdentity(identity);
6501 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006502 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006503
Pengquan Meng77b7f132018-08-22 14:49:57 -07006504 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006505 * Get the current modem radio state for the given slot.
6506 * @param slotIndex slot index.
6507 * @param callingPackage the name of the package making the call.
6508 * @return the current radio power state from the modem
6509 */
6510 @Override
6511 public int getRadioPowerState(int slotIndex, String callingPackage) {
6512 Phone phone = PhoneFactory.getPhone(slotIndex);
6513 if (phone != null) {
6514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6515 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6516 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6517 }
6518
6519 final long identity = Binder.clearCallingIdentity();
6520 try {
6521 return phone.getRadioPowerState();
6522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
6525 }
6526 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6527 }
6528
6529 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006530 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6531 *
6532 * <p>Requires one of the following permissions:
6533 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6534 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6535 * privileges.
6536 *
6537 * @param subId subscription id
6538 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6539 * {@code false}.
6540 */
6541 @Override
6542 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006543 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6544 null /* message */);
6545
Pengquan Menga1bb6272018-09-06 09:59:22 -07006546 boolean isEnabled = false;
6547 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006548 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006549 Phone phone = getPhone(subId);
6550 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006551 } catch (Exception e) {
6552 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6553 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006554 } finally {
6555 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006557 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006558 }
6559
6560
6561 /**
6562 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6563 *
6564 * <p> Requires permission:
6565 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6566 * privileges.
6567 *
6568 * @param subId subscription id
6569 * @param isEnabled {@code true} means enable, {@code false} means disable.
6570 */
6571 @Override
6572 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6574 mApp, subId, "setDataRoamingEnabled");
6575
Pengquan Menga1bb6272018-09-06 09:59:22 -07006576 final long identity = Binder.clearCallingIdentity();
6577 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006578 Phone phone = getPhone(subId);
6579 if (phone != null) {
6580 phone.setDataRoamingEnabled(isEnabled);
6581 }
6582 } finally {
6583 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006584 }
6585 }
6586
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006587 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006588 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006589 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6590 mApp, subId, "isManualNetworkSelectionAllowed");
6591
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006592 boolean isAllowed = true;
6593 final long identity = Binder.clearCallingIdentity();
6594 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006595 Phone phone = getPhone(subId);
6596 if (phone != null) {
6597 isAllowed = phone.isCspPlmnEnabled();
6598 }
6599 } finally {
6600 Binder.restoreCallingIdentity(identity);
6601 }
6602 return isAllowed;
6603 }
6604
6605 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006606 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006607 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006608 try {
6609 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006610 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006611 } catch (SecurityException e) {
6612 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6613 // has carrier privileges on an active UICC
6614 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6615 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006616 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006617 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006618 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006619
6620 final long identity = Binder.clearCallingIdentity();
6621 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006622 UiccController uiccController = UiccController.getInstance();
6623 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006624 if (hasReadPermission) {
6625 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006626 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006627
6628 // Remove private info if the caller doesn't have access
6629 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6630 for (UiccCardInfo cardInfo : cardInfos) {
6631 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6632 // is available
6633 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6634 if (card == null || card.getUiccProfile() == null) {
6635 // assume no access if the card or profile is unavailable
6636 filteredInfos.add(cardInfo.getUnprivileged());
6637 continue;
6638 }
6639 UiccProfile profile = card.getUiccProfile();
6640 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6641 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6642 filteredInfos.add(cardInfo);
6643 } else {
6644 filteredInfos.add(cardInfo.getUnprivileged());
6645 }
6646 }
6647 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006648 } finally {
6649 Binder.restoreCallingIdentity(identity);
6650 }
6651 }
6652
6653 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006654 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006655 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6660 if (slots == null) {
6661 Rlog.i(LOG_TAG, "slots is null.");
6662 return null;
6663 }
6664
6665 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6666 for (int i = 0; i < slots.length; i++) {
6667 UiccSlot slot = slots[i];
6668 if (slot == null) {
6669 continue;
6670 }
6671
Jordan Liu7be7e652019-05-06 18:55:02 +00006672 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 UiccCard card = slot.getUiccCard();
6674 if (card != null) {
6675 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006676 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006677 cardId = slot.getEid();
6678 if (TextUtils.isEmpty(cardId)) {
6679 cardId = slot.getIccId();
6680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681 }
6682
Jordan Liu857451f2019-05-09 16:35:35 -07006683 if (cardId != null) {
6684 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6685 // if cardId is an EID, it's all digits so this is fine
6686 cardId = IccUtils.stripTrailingFs(cardId);
6687 }
6688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689 int cardState = 0;
6690 switch (slot.getCardState()) {
6691 case CARDSTATE_ABSENT:
6692 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6693 break;
6694 case CARDSTATE_PRESENT:
6695 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6696 break;
6697 case CARDSTATE_ERROR:
6698 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6699 break;
6700 case CARDSTATE_RESTRICTED:
6701 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6702 break;
6703 default:
6704 break;
6705
6706 }
6707
6708 infos[i] = new UiccSlotInfo(
6709 slot.isActive(),
6710 slot.isEuicc(),
6711 cardId,
6712 cardState,
6713 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006714 slot.isExtendedApduSupported(),
6715 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 }
6717 return infos;
6718 } finally {
6719 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006720 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006721 }
6722
6723 @Override
6724 public boolean switchSlots(int[] physicalSlots) {
6725 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726
6727 final long identity = Binder.clearCallingIdentity();
6728 try {
6729 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6730 } finally {
6731 Binder.restoreCallingIdentity(identity);
6732 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006733 }
Jack Yu4c988042018-02-27 15:30:01 -08006734
6735 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006736 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006737 final long identity = Binder.clearCallingIdentity();
6738 try {
6739 return UiccController.getInstance().getCardIdForDefaultEuicc();
6740 } finally {
6741 Binder.restoreCallingIdentity(identity);
6742 }
6743 }
6744
6745 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006746 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6747 enforceModifyPermission();
6748 final Phone phone = getPhone(subId);
6749 if (phone == null) {
6750 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6751 return;
6752 }
6753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006754 final long identity = Binder.clearCallingIdentity();
6755 try {
6756 phone.setRadioIndicationUpdateMode(filters, mode);
6757 } finally {
6758 Binder.restoreCallingIdentity(identity);
6759 }
Jack Yu4c988042018-02-27 15:30:01 -08006760 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006761
6762 /**
goneil47ffb6e2018-04-06 15:40:58 -07006763 * A test API to reload the UICC profile.
6764 *
6765 * <p>Requires that the calling app has permission
6766 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6767 * @hide
6768 */
6769 @Override
6770 public void refreshUiccProfile(int subId) {
6771 enforceModifyPermission();
6772
6773 final long identity = Binder.clearCallingIdentity();
6774 try {
6775 Phone phone = getPhone(subId);
6776 if (phone == null) {
6777 return;
6778 }
6779 UiccCard uiccCard = phone.getUiccCard();
6780 if (uiccCard == null) {
6781 return;
6782 }
6783 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6784 if (uiccProfile == null) {
6785 return;
6786 }
6787 uiccProfile.refresh();
6788 } finally {
6789 Binder.restoreCallingIdentity(identity);
6790 }
6791 }
6792
6793 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006794 * Returns false if the mobile data is disabled by default, otherwise return true.
6795 */
6796 private boolean getDefaultDataEnabled() {
6797 return "true".equalsIgnoreCase(
6798 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6799 }
6800
6801 /**
6802 * Returns true if the data roaming is enabled by default, i.e the system property
6803 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6804 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6805 */
6806 private boolean getDefaultDataRoamingEnabled(int subId) {
6807 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006808 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006809 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6810 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6811 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6812 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6813 return isDataRoamingEnabled;
6814 }
6815
6816 /**
6817 * Returns the default network type for the given {@code subId}, if the default network type is
6818 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6819 */
6820 private int getDefaultNetworkType(int subId) {
6821 return Integer.parseInt(
6822 TelephonyManager.getTelephonyProperty(
6823 mSubscriptionController.getPhoneId(subId),
6824 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6825 String.valueOf(Phone.PREFERRED_NT_MODE)));
6826 }
fionaxua13278b2018-03-21 00:08:13 -07006827
6828 @Override
6829 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006830 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006831 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832
6833 final long identity = Binder.clearCallingIdentity();
6834 try {
6835 final Phone phone = getPhone(subId);
6836 if (phone == null) {
6837 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6838 return;
6839 }
chen xueaba88a2019-03-15 13:15:10 -07006840 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6841 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842 } finally {
6843 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006844 }
fionaxua13278b2018-03-21 00:08:13 -07006845 }
6846
6847 @Override
6848 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006849 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006850
6851 final long identity = Binder.clearCallingIdentity();
6852 try {
6853 final Phone phone = getPhone(subId);
6854 if (phone == null) {
6855 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6856 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6857 }
6858 return phone.getCarrierIdListVersion();
6859 } finally {
6860 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006861 }
fionaxua13278b2018-03-21 00:08:13 -07006862 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006863
6864 @Override
6865 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6867 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6868 return -1;
6869 }
6870
6871 final long identity = Binder.clearCallingIdentity();
6872 try {
6873 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
6876 }
6877 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006878
6879 @Override
6880 public int getCdmaRoamingMode(int subId) {
6881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6882 mApp, subId, "getCdmaRoamingMode");
6883
6884 final long identity = Binder.clearCallingIdentity();
6885 try {
6886 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6887 } finally {
6888 Binder.restoreCallingIdentity(identity);
6889 }
6890 }
6891
6892 @Override
6893 public boolean setCdmaRoamingMode(int subId, int mode) {
6894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6895 mApp, subId, "setCdmaRoamingMode");
6896
6897 final long identity = Binder.clearCallingIdentity();
6898 try {
6899 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6900 } finally {
6901 Binder.restoreCallingIdentity(identity);
6902 }
6903 }
6904
6905 @Override
6906 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6908 mApp, subId, "setCdmaSubscriptionMode");
6909
6910 final long identity = Binder.clearCallingIdentity();
6911 try {
6912 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6913 } finally {
6914 Binder.restoreCallingIdentity(identity);
6915 }
6916 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006917
sqianc5eccab2018-10-19 18:46:41 -07006918 @Override
sqian8c685422019-02-22 15:55:18 -08006919 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006920 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006922 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006923 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6924 }
6925 final long identity = Binder.clearCallingIdentity();
6926 try {
sqian854d44b2018-12-12 16:48:18 -08006927 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6928 for (Phone phone: PhoneFactory.getPhones()) {
6929 if (phone.getEmergencyNumberTracker() != null
6930 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6931 emergencyNumberListInternal.put(
6932 phone.getSubId(),
6933 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6934 }
sqian11b7a0e2018-12-05 18:48:28 -08006935 }
sqian854d44b2018-12-12 16:48:18 -08006936 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006937 } finally {
6938 Binder.restoreCallingIdentity(identity);
6939 }
sqianc5eccab2018-10-19 18:46:41 -07006940 }
6941
6942 @Override
sqian8c685422019-02-22 15:55:18 -08006943 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006944 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006945 if (!exactMatch) {
6946 TelephonyPermissions
6947 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006948 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006949 }
6950 final long identity = Binder.clearCallingIdentity();
6951 try {
sqian854d44b2018-12-12 16:48:18 -08006952 for (Phone phone: PhoneFactory.getPhones()) {
6953 if (phone.getEmergencyNumberTracker() != null
6954 && phone.getEmergencyNumberTracker() != null) {
6955 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6956 number, exactMatch)) {
6957 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006958 }
6959 }
sqian11b7a0e2018-12-05 18:48:28 -08006960 }
6961 return false;
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
6964 }
6965 }
6966
sqianf4ca7ed2019-01-15 18:32:07 -08006967 /**
6968 * Update emergency number list for test mode.
6969 */
6970 @Override
6971 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6973 "updateEmergencyNumberListTestMode");
6974
6975 final long identity = Binder.clearCallingIdentity();
6976 try {
6977 for (Phone phone: PhoneFactory.getPhones()) {
6978 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6979 if (tracker != null) {
6980 tracker.executeEmergencyNumberTestModeCommand(action, num);
6981 }
6982 }
6983 } finally {
6984 Binder.restoreCallingIdentity(identity);
6985 }
6986 }
6987
6988 /**
6989 * Get the full emergency number list for test mode.
6990 */
6991 @Override
6992 public List<String> getEmergencyNumberListTestMode() {
6993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6994 "getEmergencyNumberListTestMode");
6995
6996 final long identity = Binder.clearCallingIdentity();
6997 try {
6998 Set<String> emergencyNumbers = new HashSet<>();
6999 for (Phone phone: PhoneFactory.getPhones()) {
7000 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7001 if (tracker != null) {
7002 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7003 emergencyNumbers.add(num.getNumber());
7004 }
7005 }
7006 }
7007 return new ArrayList<>(emergencyNumbers);
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
7011 }
7012
chen xud6b45bd2018-10-30 22:27:10 -07007013 @Override
7014 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7015 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7016 Phone phone = getPhone(subId);
7017 if (phone == null) {
7018 return null;
7019 }
7020 final long identity = Binder.clearCallingIdentity();
7021 try {
7022 UiccProfile profile = UiccController.getInstance()
7023 .getUiccProfileForPhone(phone.getPhoneId());
7024 if (profile != null) {
7025 return profile.getCertsFromCarrierPrivilegeAccessRules();
7026 }
7027 } finally {
7028 Binder.restoreCallingIdentity(identity);
7029 }
7030 return null;
7031 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007032
7033 /**
7034 * Enable or disable a modem stack.
7035 */
7036 @Override
7037 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7038 enforceModifyPermission();
7039
7040 final long identity = Binder.clearCallingIdentity();
7041 try {
7042 Phone phone = PhoneFactory.getPhone(slotIndex);
7043 if (phone == null) {
7044 return false;
7045 } else {
7046 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7047 }
7048 } finally {
7049 Binder.restoreCallingIdentity(identity);
7050 }
7051 }
Michelecea4cf22018-12-21 15:00:11 -08007052
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007053 /**
7054 * Whether a modem stack is enabled or not.
7055 */
7056 @Override
7057 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7058 Phone phone = PhoneFactory.getPhone(slotIndex);
7059 if (phone == null) return false;
7060
7061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7062 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7063 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7064 }
7065
7066 final long identity = Binder.clearCallingIdentity();
7067 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007068 try {
7069 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7070 } catch (NoSuchElementException ex) {
7071 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7072 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007073 } finally {
7074 Binder.restoreCallingIdentity(identity);
7075 }
7076 }
7077
Michelecea4cf22018-12-21 15:00:11 -08007078 @Override
Michele0ea7d782019-03-19 14:58:42 -07007079 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007080 enforceModifyPermission();
7081
7082 final long identity = Binder.clearCallingIdentity();
7083 try {
7084 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007085 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007086 .commit();
7087 } finally {
7088 Binder.restoreCallingIdentity(identity);
7089 }
7090 }
7091
7092 @Override
Michele0ea7d782019-03-19 14:58:42 -07007093 @TelephonyManager.IsMultiSimSupportedResult
7094 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007095 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007096 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7097 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007098 }
Michelecea4cf22018-12-21 15:00:11 -08007099
7100 final long identity = Binder.clearCallingIdentity();
7101 try {
Michele0ea7d782019-03-19 14:58:42 -07007102 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007103 } finally {
7104 Binder.restoreCallingIdentity(identity);
7105 }
7106 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007107
Michele0ea7d782019-03-19 14:58:42 -07007108 @TelephonyManager.IsMultiSimSupportedResult
7109 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007110 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7111 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7112 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007113 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7114 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007115 }
7116 // Check if the hardware supports multisim functionality. If usage of multisim is not
7117 // supported by the modem, indicate that it is restricted.
7118 PhoneCapability staticCapability =
7119 mPhoneConfigurationManager.getStaticPhoneCapability();
7120 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007121 loge("isMultiSimSupportedInternal: no static configuration available");
7122 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007123 }
7124 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007125 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7126 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007127 }
7128 // Check if support of multiple SIMs is restricted by carrier
7129 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007130 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007131 }
7132
Michele0ea7d782019-03-19 14:58:42 -07007133 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007134 }
7135
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007136 /**
7137 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007138 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7139 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7140 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007141 * @param numOfSims number of active sims we want to switch to
7142 */
7143 @Override
7144 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007145 if (numOfSims == 1) {
7146 enforceModifyPermission();
7147 } else {
7148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7149 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7150 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007151 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007152
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007153 try {
Michele30b57b22019-03-01 12:01:14 -08007154 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007155 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007156 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7157 return;
7158 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007159 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7160 } finally {
7161 Binder.restoreCallingIdentity(identity);
7162 }
7163 }
7164
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007165 @Override
7166 public boolean isApplicationOnUicc(int subId, int appType) {
7167 enforceReadPrivilegedPermission("isApplicationOnUicc");
7168 Phone phone = getPhone(subId);
7169 if (phone == null) {
7170 return false;
7171 }
7172 final long identity = Binder.clearCallingIdentity();
7173 try {
7174 UiccCard uiccCard = phone.getUiccCard();
7175 if (uiccCard == null) {
7176 return false;
7177 }
7178 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7179 if (uiccProfile == null) {
7180 return false;
7181 }
7182 if (TelephonyManager.APPTYPE_SIM <= appType
7183 && appType <= TelephonyManager.APPTYPE_ISIM) {
7184 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7185 }
7186 return false;
7187 } finally {
7188 Binder.restoreCallingIdentity(identity);
7189 }
7190 }
7191
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007192 /**
chen xub4baa772019-04-03 10:23:41 -07007193 * Get whether making changes to modem configurations will trigger reboot.
7194 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007195 */
7196 @Override
chen xub4baa772019-04-03 10:23:41 -07007197 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7199 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7200 return false;
7201 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007202 final long identity = Binder.clearCallingIdentity();
7203 try {
7204 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7205 } finally {
7206 Binder.restoreCallingIdentity(identity);
7207 }
7208 }
7209
Nathan Harold29f5f052019-02-15 13:41:57 -08007210 private void updateModemStateMetrics() {
7211 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7212 // TODO: check the state for each modem if the api is ready.
7213 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7214 }
7215
Pengquan Meng3889a572019-01-23 11:16:29 -08007216 @Override
7217 public int[] getSlotsMapping() {
7218 enforceReadPrivilegedPermission("getSlotsMapping");
7219
7220 final long identity = Binder.clearCallingIdentity();
7221 try {
7222 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7223 // All logical slots should have a mapping to a physical slot.
7224 int[] logicalSlotsMapping = new int[phoneCount];
7225 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7226 for (int i = 0; i < slotInfos.length; i++) {
7227 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7228 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7229 }
7230 }
7231 return logicalSlotsMapping;
7232 } finally {
7233 Binder.restoreCallingIdentity(identity);
7234 }
7235 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007236
7237 /**
7238 * Get the IRadio HAL Version
7239 */
7240 @Override
7241 public int getRadioHalVersion() {
7242 Phone phone = getDefaultPhone();
7243 if (phone == null) return -1;
7244 HalVersion hv = phone.getHalVersion();
7245 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7246 return hv.major * 100 + hv.minor;
7247 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007248
7249 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007250 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7251 * corresponding network requests on a subId.
7252 *
7253 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007254 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007255 * 2) APN is un-metered for this subscription, or
7256 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7257 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7258 *
7259 * @return whether data is allowed for a apn type.
7260 *
7261 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007262 */
7263 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007264 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007266 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7267 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007268 }
7269
7270 // Now that all security checks passes, perform the operation as ourselves.
7271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 Phone phone = getPhone(subId);
7274 if (phone == null) return false;
7275
Jack Yu41407ee2019-05-13 16:54:09 -07007276 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007277 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
7281 }
7282
7283 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007284 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007285 enforceReadPrivilegedPermission("isApnMetered");
7286
7287 // Now that all security checks passes, perform the operation as ourselves.
7288 final long identity = Binder.clearCallingIdentity();
7289 try {
7290 Phone phone = getPhone(subId);
7291 if (phone == null) return true; // By default return true.
7292
Jack Yu41407ee2019-05-13 16:54:09 -07007293 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007294 } finally {
7295 Binder.restoreCallingIdentity(identity);
7296 }
7297 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007298
7299 @Override
7300 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7301 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7302 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7303 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7304 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7305 }
7306 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7307 Intent intent = new Intent();
7308 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7309 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7310 // Bring up choose default SMS subscription dialog right now
7311 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7312 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7313 mApp.startActivity(intent);
7314 }
chen xud5ca2d52019-05-28 15:20:57 -07007315
7316 @Override
7317 public String getMmsUAProfUrl(int subId) {
7318 //TODO investigate if this API should require proper permission check in R b/133791609
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7322 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
7326 }
7327
7328 @Override
7329 public String getMmsUserAgent(int subId) {
7330 //TODO investigate if this API should require proper permission check in R b/133791609
7331 final long identity = Binder.clearCallingIdentity();
7332 try {
7333 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7334 .getString(com.android.internal.R.string.config_mms_user_agent);
7335 } finally {
7336 Binder.restoreCallingIdentity(identity);
7337 }
7338 }
Jack Yub07d4972019-05-28 16:12:25 -07007339
7340 @Override
7341 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7342 enforceModifyPermission();
7343
7344 // Now that all security checks passes, perform the operation as ourselves.
7345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 Phone phone = getPhone(subId);
7348 if (phone == null) return false;
7349
7350 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7351 } finally {
7352 Binder.restoreCallingIdentity(identity);
7353 }
7354 }
7355
7356 @Override
7357 public boolean isDataAllowedInVoiceCall(int subId) {
7358 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7359
7360 // Now that all security checks passes, perform the operation as ourselves.
7361 final long identity = Binder.clearCallingIdentity();
7362 try {
7363 Phone phone = getPhone(subId);
7364 if (phone == null) return false;
7365
7366 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7367 } finally {
7368 Binder.restoreCallingIdentity(identity);
7369 }
7370 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007371
7372 /**
7373 * Updates whether conference event pacakge handling is enabled.
7374 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7375 * otherwise.
7376 */
7377 @Override
7378 public void setCepEnabled(boolean isCepEnabled) {
7379 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7380
7381 final long identity = Binder.clearCallingIdentity();
7382 try {
7383 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7384 for (Phone phone : PhoneFactory.getPhones()) {
7385 Phone defaultPhone = phone.getImsPhone();
7386 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7387 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7388 ImsPhoneCallTracker imsPhoneCallTracker =
7389 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7390 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7391 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7392 + imsPhone.getMsisdn());
7393 }
7394 }
7395 } finally {
7396 Binder.restoreCallingIdentity(identity);
7397 }
7398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007399}