blob: fc3e3f56fa648693c2d095f30e8fda014ff4925d [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070071import android.telephony.CellInfoGsm;
72import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070073import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070074import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070075import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070076import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080077import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070078import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080079import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070080import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080081import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080082import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070083import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080084import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070085import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080087import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080088import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080089import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070090import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080092import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080093import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000094import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070095import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070096import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -0700100import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
160import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700162import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000166import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800167import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700168import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700171import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800172import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700174import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800175
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700176import java.io.FileDescriptor;
177import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800180import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800181import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800182import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100183import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700185import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188/**
189 * Implementation of the ITelephony interface.
190 */
Santos Cordon117fee72014-05-16 17:56:12 -0700191public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 private static final String LOG_TAG = "PhoneInterfaceManager";
193 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
194 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800195 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197 // Message codes used with mMainThreadHandler
198 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700199 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
200 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201 private static final int CMD_OPEN_CHANNEL = 9;
202 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
203 private static final int CMD_CLOSE_CHANNEL = 11;
204 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800205 private static final int CMD_NV_READ_ITEM = 13;
206 private static final int EVENT_NV_READ_ITEM_DONE = 14;
207 private static final int CMD_NV_WRITE_ITEM = 15;
208 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
209 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
210 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700211 private static final int CMD_RESET_MODEM_CONFIG = 19;
212 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800213 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
214 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
215 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
216 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800217 private static final int CMD_SEND_ENVELOPE = 25;
218 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000219 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
220 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700221 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
222 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
223 private static final int CMD_EXCHANGE_SIM_IO = 31;
224 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800225 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
226 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700227 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700229 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
230 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700231 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
232 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
233 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700235 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
236 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
237 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
238 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700239 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
241 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000242 private static final int CMD_SWITCH_SLOTS = 50;
243 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700244 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
245 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
246 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
247 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
248 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
249 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
250 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
251 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700252 private static final int CMD_GET_ALL_CELL_INFO = 60;
253 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
254 private static final int CMD_GET_CELL_LOCATION = 62;
255 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700256 private static final int CMD_MODEM_REBOOT = 64;
257 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700258 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
259 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800260 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
261 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262 private static final int CMD_GET_MODEM_STATUS = 70;
263 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700264 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
265 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700266 private static final int CMD_ERASE_MODEM_CONFIG = 74;
267 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800269 // Parameters of select command.
270 private static final int SELECT_COMMAND = 0xA4;
271 private static final int SELECT_P1 = 0x04;
272 private static final int SELECT_P2 = 0;
273 private static final int SELECT_P3 = 0x10;
274
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;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800280 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700281 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private AppOpsManager mAppOps;
283 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800284 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700286 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
Derek Tan97ebb422014-09-05 16:55:38 -0700288 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
289 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800290 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800291 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700292
Michelecea4cf22018-12-21 15:00:11 -0800293 // String to store multi SIM allowed
294 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
295
Derek Tan740e1672017-06-27 14:56:27 -0700296 // The AID of ISD-R.
297 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
298
yinxub1bed742017-04-17 11:45:04 -0700299 private NetworkScanRequestTracker mNetworkScanRequestTracker;
300
David Kelly5e06a7f2018-03-12 14:10:59 +0000301 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
302 private static final int MANUFACTURER_CODE_LENGTH = 8;
303
Derek Tan89e89d42014-07-08 17:00:10 -0700304 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700305 * Experiment flag to enable erase modem config on reset network, default value is false
306 */
307 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
308 "reset_network_erase_modem_config_enabled";
309
310 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700311 * A request object to use for transmitting data to an ICC.
312 */
313 private static final class IccAPDUArgument {
314 public int channel, cla, command, p1, p2, p3;
315 public String data;
316
317 public IccAPDUArgument(int channel, int cla, int command,
318 int p1, int p2, int p3, String data) {
319 this.channel = channel;
320 this.cla = cla;
321 this.command = command;
322 this.p1 = p1;
323 this.p2 = p2;
324 this.p3 = p3;
325 this.data = data;
326 }
327 }
328
329 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700330 * A request object to use for transmitting data to an ICC.
331 */
332 private static final class ManualNetworkSelectionArgument {
333 public OperatorInfo operatorInfo;
334 public boolean persistSelection;
335
336 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
337 this.operatorInfo = operatorInfo;
338 this.persistSelection = persistSelection;
339 }
340 }
341
342 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
344 * request after sending. The main thread will notify the request when it is complete.
345 */
346 private static final class MainThreadRequest {
347 /** The argument to use for the request */
348 public Object argument;
349 /** The result of the request that is run on the main thread */
350 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800351 // The subscriber id that this request applies to. Defaults to
352 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
353 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
Nathan Harold92bed182018-10-12 18:16:49 -0700355 // In cases where subId is unavailable, the caller needs to specify the phone.
356 public Phone phone;
357
vagdeviaf9a5b92018-08-15 16:01:53 -0700358 public WorkSource workSource;
359
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 public MainThreadRequest(Object argument) {
361 this.argument = argument;
362 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800363
Nathan Harold92bed182018-10-12 18:16:49 -0700364 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
365 this.argument = argument;
366 if (phone != null) {
367 this.phone = phone;
368 }
369 this.workSource = workSource;
370 }
371
vagdeviaf9a5b92018-08-15 16:01:53 -0700372 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800373 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800374 if (subId != null) {
375 this.subId = subId;
376 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700377 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 }
380
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800381 private static final class IncomingThirdPartyCallArgs {
382 public final ComponentName component;
383 public final String callId;
384 public final String callerDisplayName;
385
386 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
387 String callerDisplayName) {
388 this.component = component;
389 this.callId = callId;
390 this.callerDisplayName = callerDisplayName;
391 }
392 }
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 /**
395 * A handler that processes messages on the main thread in the phone process. Since many
396 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
397 * inbound binder threads to the main thread in the phone process. The Binder thread
398 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
399 * on, which will be notified when the operation completes and will contain the result of the
400 * request.
401 *
402 * <p>If a MainThreadRequest object is provided in the msg.obj field,
403 * note that request.result must be set to something non-null for the calling thread to
404 * unblock.
405 */
406 private final class MainThreadHandler extends Handler {
407 @Override
408 public void handleMessage(Message msg) {
409 MainThreadRequest request;
410 Message onCompleted;
411 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800412 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800414 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
416 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700417 case CMD_HANDLE_USSD_REQUEST: {
418 request = (MainThreadRequest) msg.obj;
419 final Phone phone = getPhoneFromRequest(request);
420 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
421 String ussdRequest = ussdObject.first;
422 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 if (!isUssdApiAllowed(request.subId)) {
425 // Carrier does not support use of this API, return failure.
426 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
427 UssdResponse response = new UssdResponse(ussdRequest, null);
428 Bundle returnData = new Bundle();
429 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
430 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700431
Pengquan Menga1bb6272018-09-06 09:59:22 -0700432 request.result = true;
433 notifyRequester(request);
434 return;
435 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700436
Pengquan Menga1bb6272018-09-06 09:59:22 -0700437 try {
438 request.result = phone != null
439 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
440 } catch (CallStateException cse) {
441 request.result = false;
442 }
443 // Wake up the requesting thread
444 notifyRequester(request);
445 break;
pkanwar32d516d2016-10-14 19:37:38 -0700446 }
447
Yorke Lee716f67e2015-06-17 15:39:16 -0700448 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 final Phone phone = getPhoneFromRequest(request);
451 request.result = phone != null ?
452 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
453 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800462 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700463 if (uiccCard == null) {
464 loge("iccTransmitApduLogicalChannel: No UICC");
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700467 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
469 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 iccArgument.channel, iccArgument.cla, iccArgument.command,
472 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700474 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 break;
476
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 ar = (AsyncResult) msg.obj;
479 request = (MainThreadRequest) ar.userObj;
480 if (ar.exception == null && ar.result != null) {
481 request.result = ar.result;
482 } else {
483 request.result = new IccIoResult(0x6F, 0, (byte[])null);
484 if (ar.result == null) {
485 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800486 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800488 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 } else {
490 loge("iccTransmitApduLogicalChannel: Unknown exception");
491 }
492 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 break;
495
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
497 request = (MainThreadRequest) msg.obj;
498 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800499 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 if (uiccCard == null) {
501 loge("iccTransmitApduBasicChannel: No UICC");
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 } else {
505 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
506 request);
507 uiccCard.iccTransmitApduBasicChannel(
508 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
509 iccArgument.p3, iccArgument.data, onCompleted);
510 }
511 break;
512
513 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
514 ar = (AsyncResult) msg.obj;
515 request = (MainThreadRequest) ar.userObj;
516 if (ar.exception == null && ar.result != null) {
517 request.result = ar.result;
518 } else {
519 request.result = new IccIoResult(0x6F, 0, (byte[])null);
520 if (ar.result == null) {
521 loge("iccTransmitApduBasicChannel: Empty response");
522 } else if (ar.exception instanceof CommandException) {
523 loge("iccTransmitApduBasicChannel: CommandException: " +
524 ar.exception);
525 } else {
526 loge("iccTransmitApduBasicChannel: Unknown exception");
527 }
528 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 break;
531
532 case CMD_EXCHANGE_SIM_IO:
533 request = (MainThreadRequest) msg.obj;
534 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800535 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 if (uiccCard == null) {
537 loge("iccExchangeSimIO: No UICC");
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 } else {
541 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
542 request);
543 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
544 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
545 iccArgument.data, onCompleted);
546 }
547 break;
548
549 case EVENT_EXCHANGE_SIM_IO_DONE:
550 ar = (AsyncResult) msg.obj;
551 request = (MainThreadRequest) ar.userObj;
552 if (ar.exception == null && ar.result != null) {
553 request.result = ar.result;
554 } else {
555 request.result = new IccIoResult(0x6f, 0, (byte[])null);
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 case CMD_SEND_ENVELOPE:
561 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 if (uiccCard == null) {
564 loge("sendEnvelopeWithStatus: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
569 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
570 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800571 break;
572
573 case EVENT_SEND_ENVELOPE_DONE:
574 ar = (AsyncResult) msg.obj;
575 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700576 if (ar.exception == null && ar.result != null) {
577 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
580 if (ar.result == null) {
581 loge("sendEnvelopeWithStatus: Empty response");
582 } else if (ar.exception instanceof CommandException) {
583 loge("sendEnvelopeWithStatus: CommandException: " +
584 ar.exception);
585 } else {
586 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
587 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 break;
591
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 case CMD_OPEN_CHANNEL:
593 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800594 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800595 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 if (uiccCard == null) {
597 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800598 request.result = new IccOpenLogicalChannelResponse(-1,
599 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 } else {
602 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800603 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
604 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
608 case EVENT_OPEN_CHANNEL_DONE:
609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 int[] result = (int[]) ar.result;
614 int channelId = result[0];
615 byte[] selectResponse = null;
616 if (result.length > 1) {
617 selectResponse = new byte[result.length - 1];
618 for (int i = 1; i < result.length; ++i) {
619 selectResponse[i - 1] = (byte) result[i];
620 }
621 }
622 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 if (ar.result == null) {
626 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 if (ar.exception != null) {
629 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
630 }
631
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700632 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700633 if (ar.exception instanceof CommandException) {
634 CommandException.Error error =
635 ((CommandException) (ar.exception)).getCommandError();
636 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700637 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700638 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 }
641 }
642 openChannelResp = new IccOpenLogicalChannelResponse(
643 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700645 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case CMD_CLOSE_CHANNEL:
650 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800651 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 if (uiccCard == null) {
653 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900654 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 } else {
657 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
658 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
659 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 break;
661
662 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800663 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
664 break;
665
666 case CMD_NV_READ_ITEM:
667 request = (MainThreadRequest) msg.obj;
668 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800669 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
670 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800671 break;
672
673 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 ar = (AsyncResult) msg.obj;
675 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800676 if (ar.exception == null && ar.result != null) {
677 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800679 request.result = "";
680 if (ar.result == null) {
681 loge("nvReadItem: Empty response");
682 } else if (ar.exception instanceof CommandException) {
683 loge("nvReadItem: CommandException: " +
684 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800686 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 }
688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
Jake Hambye994d462014-02-03 13:10:13 -0800692 case CMD_NV_WRITE_ITEM:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
695 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700697 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_WRITE_ITEM_DONE:
701 handleNullReturnEvent(msg, "nvWriteItem");
702 break;
703
704 case CMD_NV_WRITE_CDMA_PRL:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800707 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
710 case EVENT_NV_WRITE_CDMA_PRL_DONE:
711 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
712 break;
713
chen xu6dac5ab2018-10-26 17:39:23 -0700714 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800715 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700716 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800717 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800718 break;
719
chen xu6dac5ab2018-10-26 17:39:23 -0700720 case EVENT_RESET_MODEM_CONFIG_DONE:
721 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800722 break;
723
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 case CMD_GET_PREFERRED_NETWORK_TYPE:
725 request = (MainThreadRequest) msg.obj;
726 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700727 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800728 break;
729
730 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
731 ar = (AsyncResult) msg.obj;
732 request = (MainThreadRequest) ar.userObj;
733 if (ar.exception == null && ar.result != null) {
734 request.result = ar.result; // Integer
735 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800736 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 if (ar.result == null) {
738 loge("getPreferredNetworkType: Empty response");
739 } else if (ar.exception instanceof CommandException) {
740 loge("getPreferredNetworkType: CommandException: " +
741 ar.exception);
742 } else {
743 loge("getPreferredNetworkType: Unknown exception");
744 }
745 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700746 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 break;
748
749 case CMD_SET_PREFERRED_NETWORK_TYPE:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
752 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700753 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 break;
755
756 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
757 handleNullReturnEvent(msg, "setPreferredNetworkType");
758 break;
759
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000760 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
761 request = (MainThreadRequest)msg.obj;
762 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000764 break;
765
766 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
767 ar = (AsyncResult)msg.obj;
768 request = (MainThreadRequest)ar.userObj;
769 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000771 break;
772
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800773 case CMD_SET_VOICEMAIL_NUMBER:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
776 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800777 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
778 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800779 break;
780
781 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
782 handleNullReturnEvent(msg, "setVoicemailNumber");
783 break;
784
Stuart Scott54788802015-03-30 13:18:01 -0700785 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
786 request = (MainThreadRequest) msg.obj;
787 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
788 request);
789 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
790 break;
791
792 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
793 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
794 break;
795
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 case CMD_PERFORM_NETWORK_SCAN:
797 request = (MainThreadRequest) msg.obj;
798 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
799 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
800 break;
801
802 case EVENT_PERFORM_NETWORK_SCAN_DONE:
803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 CellNetworkScanResult cellScanResult;
806 if (ar.exception == null && ar.result != null) {
807 cellScanResult = new CellNetworkScanResult(
808 CellNetworkScanResult.STATUS_SUCCESS,
809 (List<OperatorInfo>) ar.result);
810 } else {
811 if (ar.result == null) {
812 loge("getCellNetworkScanResults: Empty response");
813 }
814 if (ar.exception != null) {
815 loge("getCellNetworkScanResults: Exception: " + ar.exception);
816 }
817 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
818 if (ar.exception instanceof CommandException) {
819 CommandException.Error error =
820 ((CommandException) (ar.exception)).getCommandError();
821 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
822 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
823 } else if (error == CommandException.Error.GENERIC_FAILURE) {
824 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
825 }
826 }
827 cellScanResult = new CellNetworkScanResult(errorCode, null);
828 }
829 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700830 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 break;
832
833 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
834 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700835 ManualNetworkSelectionArgument selArg =
836 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
838 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700839 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
840 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
843 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
846 if (ar.exception == null) {
847 request.result = true;
848 } else {
849 request.result = false;
850 loge("setNetworkSelectionModeManual " + ar.exception);
851 }
852 notifyRequester(request);
853 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700854 break;
855
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700856 case CMD_GET_MODEM_ACTIVITY_INFO:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700859 if (defaultPhone != null) {
860 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
861 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700862 break;
863
864 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
865 ar = (AsyncResult) msg.obj;
866 request = (MainThreadRequest) ar.userObj;
867 if (ar.exception == null && ar.result != null) {
868 request.result = ar.result;
869 } else {
870 if (ar.result == null) {
871 loge("queryModemActivityInfo: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("queryModemActivityInfo: CommandException: " +
874 ar.exception);
875 } else {
876 loge("queryModemActivityInfo: Unknown exception");
877 }
878 }
Amit Mahajand4766222016-01-28 15:28:28 -0800879 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
880 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -0700881 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800882 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700883 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700884 break;
885
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 case CMD_SET_ALLOWED_CARRIERS:
887 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800888 CarrierRestrictionRules argument =
889 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800891 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 break;
893
894 case EVENT_SET_ALLOWED_CARRIERS_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result;
899 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800900 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
901 if (ar.exception instanceof CommandException) {
902 loge("setAllowedCarriers: CommandException: " + ar.exception);
903 CommandException.Error error =
904 ((CommandException) (ar.exception)).getCommandError();
905 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
906 request.result =
907 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
908 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 } else {
910 loge("setAllowedCarriers: Unknown exception");
911 }
912 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700913 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 break;
915
916 case CMD_GET_ALLOWED_CARRIERS:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800919 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 break;
921
922 case EVENT_GET_ALLOWED_CARRIERS_DONE:
923 ar = (AsyncResult) msg.obj;
924 request = (MainThreadRequest) ar.userObj;
925 if (ar.exception == null && ar.result != null) {
926 request.result = ar.result;
927 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800928 request.result = new IllegalStateException(
929 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700930 if (ar.result == null) {
931 loge("getAllowedCarriers: Empty response");
932 } else if (ar.exception instanceof CommandException) {
933 loge("getAllowedCarriers: CommandException: " +
934 ar.exception);
935 } else {
936 loge("getAllowedCarriers: Unknown exception");
937 }
938 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700940 break;
941
Nathan Haroldb3014052017-01-25 15:57:32 -0800942 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception == null && ar.result != null) {
946 request.result = ar.result;
947 } else {
948 request.result = new IllegalArgumentException(
949 "Failed to retrieve Forbidden Plmns");
950 if (ar.result == null) {
951 loge("getForbiddenPlmns: Empty response");
952 } else {
953 loge("getForbiddenPlmns: Unknown exception");
954 }
955 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800957 break;
958
959 case CMD_GET_FORBIDDEN_PLMNS:
960 request = (MainThreadRequest) msg.obj;
961 uiccCard = getUiccCardFromRequest(request);
962 if (uiccCard == null) {
963 loge("getForbiddenPlmns() UiccCard is null");
964 request.result = new IllegalArgumentException(
965 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700966 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800967 break;
968 }
969 Integer appType = (Integer) request.argument;
970 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
971 if (uiccApp == null) {
972 loge("getForbiddenPlmns() no app with specified type -- "
973 + appType);
974 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700975 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800976 break;
977 } else {
978 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
979 + " specified type -- " + appType);
980 }
981 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
982 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
983 onCompleted);
984 break;
985
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000986 case CMD_SWITCH_SLOTS:
987 request = (MainThreadRequest) msg.obj;
988 int[] physicalSlots = (int[]) request.argument;
989 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
990 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
991 break;
992
993 case EVENT_SWITCH_SLOTS_DONE:
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700997 notifyRequester(request);
998 break;
999 case CMD_GET_NETWORK_SELECTION_MODE:
1000 request = (MainThreadRequest) msg.obj;
1001 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1002 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1003 break;
1004
1005 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1006 ar = (AsyncResult) msg.obj;
1007 request = (MainThreadRequest) ar.userObj;
1008 if (ar.exception != null) {
1009 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1010 } else {
1011 int mode = ((int[]) ar.result)[0];
1012 if (mode == 0) {
1013 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1014 } else {
1015 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1016 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001017 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001018 notifyRequester(request);
1019 break;
1020 case CMD_GET_CDMA_ROAMING_MODE:
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1023 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1024 break;
1025 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 if (ar.exception != null) {
1029 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1030 } else {
1031 request.result = ((int[]) ar.result)[0];
1032 }
1033 notifyRequester(request);
1034 break;
1035 case CMD_SET_CDMA_ROAMING_MODE:
1036 request = (MainThreadRequest) msg.obj;
1037 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1038 int mode = (int) request.argument;
1039 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1040 break;
1041 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
1044 request.result = ar.exception == null;
1045 notifyRequester(request);
1046 break;
1047 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1050 int subscriptionMode = (int) request.argument;
1051 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1052 break;
1053 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
1056 request.result = ar.exception == null;
1057 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001058 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001059 case CMD_GET_ALL_CELL_INFO:
1060 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001062 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 case EVENT_GET_ALL_CELL_INFO_DONE:
1065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001067 // If a timeout occurs, the response will be null
1068 request.result = (ar.exception == null && ar.result != null)
1069 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001070 synchronized (request) {
1071 request.notifyAll();
1072 }
1073 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 case CMD_REQUEST_CELL_INFO_UPDATE:
1075 request = (MainThreadRequest) msg.obj;
1076 request.phone.requestCellInfoUpdate(request.workSource,
1077 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1078 break;
1079 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1080 ar = (AsyncResult) msg.obj;
1081 request = (MainThreadRequest) ar.userObj;
1082 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1083 try {
1084 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001086 cb.onError(
1087 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1088 ar.exception.getClass().getName(),
1089 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001092 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 } else {
1094 // use the result as returned
1095 cb.onCellInfo((List<CellInfo>) ar.result);
1096 }
1097 } catch (RemoteException re) {
1098 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1099 }
1100 break;
1101 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001102 request = (MainThreadRequest) msg.obj;
1103 WorkSource ws = (WorkSource) request.argument;
1104 Phone phone = getPhoneFromRequest(request);
1105 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1106 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001107 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 ar = (AsyncResult) msg.obj;
1109 request = (MainThreadRequest) ar.userObj;
1110 if (ar.exception == null) {
1111 request.result = ar.result;
1112 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001113 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001114 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1115 ? new CdmaCellLocation() : new GsmCellLocation();
1116 }
1117
1118 synchronized (request) {
1119 request.notifyAll();
1120 }
1121 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001122 case CMD_MODEM_REBOOT:
1123 request = (MainThreadRequest) msg.obj;
1124 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001125 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001126 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001127 case EVENT_CMD_MODEM_REBOOT_DONE:
1128 handleNullReturnEvent(msg, "rebootModem");
1129 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001130 case CMD_REQUEST_ENABLE_MODEM:
1131 request = (MainThreadRequest) msg.obj;
1132 boolean enable = (boolean) request.argument;
1133 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001134 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001135 PhoneConfigurationManager.getInstance()
1136 .enablePhone(request.phone, enable, onCompleted);
1137 break;
1138 case EVENT_ENABLE_MODEM_DONE:
1139 ar = (AsyncResult) msg.obj;
1140 request = (MainThreadRequest) ar.userObj;
1141 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001142 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001143 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001144 if ((boolean) request.result) {
1145 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1146 updateModemStateMetrics();
1147 } else {
1148 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1149 + ar.exception);
1150 }
1151 notifyRequester(request);
1152 break;
1153 case CMD_GET_MODEM_STATUS:
1154 request = (MainThreadRequest) msg.obj;
1155 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1156 PhoneConfigurationManager.getInstance()
1157 .getPhoneStatusFromModem(request.phone, onCompleted);
1158 break;
1159 case EVENT_GET_MODEM_STATUS_DONE:
1160 ar = (AsyncResult) msg.obj;
1161 request = (MainThreadRequest) ar.userObj;
1162 int id = request.phone.getPhoneId();
1163 if (ar.exception == null && ar.result != null) {
1164 request.result = ar.result;
1165 //update the cache as modem status has changed
1166 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1167 (boolean) request.result);
1168 } else {
1169 // Return true if modem status cannot be retrieved. For most cases,
1170 // modem status is on. And for older version modems, GET_MODEM_STATUS
1171 // and disable modem are not supported. Modem is always on.
1172 // TODO: this should be fixed in R to support a third
1173 // status UNKNOWN b/131631629
1174 request.result = true;
1175 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1176 + ar.exception);
1177 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001178 notifyRequester(request);
1179 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001180 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1181 ar = (AsyncResult) msg.obj;
1182 request = (MainThreadRequest) ar.userObj;
1183 if (ar.exception == null && ar.result != null) {
1184 request.result = ar.result;
1185 } else {
1186 request.result = -1;
1187 loge("Failed to set Forbidden Plmns");
1188 if (ar.result == null) {
1189 loge("setForbidenPlmns: Empty response");
1190 } else if (ar.exception != null) {
1191 loge("setForbiddenPlmns: Exception: " + ar.exception);
1192 request.result = -1;
1193 } else {
1194 loge("setForbiddenPlmns: Unknown exception");
1195 }
1196 }
1197 notifyRequester(request);
1198 break;
1199 case CMD_SET_FORBIDDEN_PLMNS:
1200 request = (MainThreadRequest) msg.obj;
1201 uiccCard = getUiccCardFromRequest(request);
1202 if (uiccCard == null) {
1203 loge("setForbiddenPlmns: UiccCard is null");
1204 request.result = -1;
1205 notifyRequester(request);
1206 break;
1207 }
1208 Pair<Integer, List<String>> setFplmnsArgs =
1209 (Pair<Integer, List<String>>) request.argument;
1210 appType = setFplmnsArgs.first;
1211 List<String> fplmns = setFplmnsArgs.second;
1212 uiccApp = uiccCard.getApplicationByType(appType);
1213 if (uiccApp == null) {
1214 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1215 request.result = -1;
1216 loge("Failed to get UICC App");
1217 notifyRequester(request);
1218 } else {
1219 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1220 ((SIMRecords) uiccApp.getIccRecords())
1221 .setForbiddenPlmns(onCompleted, fplmns);
1222 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001223 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001224 case CMD_ERASE_MODEM_CONFIG:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1227 defaultPhone.eraseModemConfig(onCompleted);
1228 break;
1229 case EVENT_ERASE_MODEM_CONFIG_DONE:
1230 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001231 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 default:
1233 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1234 break;
1235 }
1236 }
Jake Hambye994d462014-02-03 13:10:13 -08001237
Pengquan Menga1bb6272018-09-06 09:59:22 -07001238 private void notifyRequester(MainThreadRequest request) {
1239 synchronized (request) {
1240 request.notifyAll();
1241 }
1242 }
1243
Jake Hambye994d462014-02-03 13:10:13 -08001244 private void handleNullReturnEvent(Message msg, String command) {
1245 AsyncResult ar = (AsyncResult) msg.obj;
1246 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1247 if (ar.exception == null) {
1248 request.result = true;
1249 } else {
1250 request.result = false;
1251 if (ar.exception instanceof CommandException) {
1252 loge(command + ": CommandException: " + ar.exception);
1253 } else {
1254 loge(command + ": Unknown exception");
1255 }
1256 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001257 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 }
1260
1261 /**
1262 * Posts the specified command to be executed on the main thread,
1263 * waits for the request to complete, and returns the result.
1264 * @see #sendRequestAsync
1265 */
1266 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001267 return sendRequest(
1268 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001269 }
1270
1271 /**
1272 * Posts the specified command to be executed on the main thread,
1273 * waits for the request to complete, and returns the result.
1274 * @see #sendRequestAsync
1275 */
1276 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1277 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001278 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001279 }
1280
1281 /**
1282 * Posts the specified command to be executed on the main thread,
1283 * waits for the request to complete, and returns the result.
1284 * @see #sendRequestAsync
1285 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001286 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001287 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001288 }
1289
1290 /**
1291 * Posts the specified command to be executed on the main thread,
1292 * waits for the request to complete, and returns the result.
1293 * @see #sendRequestAsync
1294 */
Nathan Harold92bed182018-10-12 18:16:49 -07001295 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1296 return sendRequest(command, argument, subId, null, workSource);
1297 }
1298
1299 /**
1300 * Posts the specified command to be executed on the main thread,
1301 * waits for the request to complete, and returns the result.
1302 * @see #sendRequestAsync
1303 */
1304 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1305 return sendRequest(
1306 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1307 }
1308
1309 /**
1310 * Posts the specified command to be executed on the main thread,
1311 * waits for the request to complete, and returns the result.
1312 * @see #sendRequestAsync
1313 */
1314 private Object sendRequest(
1315 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1317 throw new RuntimeException("This method will deadlock if called from the main thread.");
1318 }
1319
Nathan Harold92bed182018-10-12 18:16:49 -07001320 MainThreadRequest request = null;
1321 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1322 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1323 } else if (phone != null) {
1324 request = new MainThreadRequest(argument, phone, workSource);
1325 } else {
1326 request = new MainThreadRequest(argument, subId, workSource);
1327 }
1328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 Message msg = mMainThreadHandler.obtainMessage(command, request);
1330 msg.sendToTarget();
1331
1332 // Wait for the request to complete
1333 synchronized (request) {
1334 while (request.result == null) {
1335 try {
1336 request.wait();
1337 } catch (InterruptedException e) {
1338 // Do nothing, go back and wait until the request is complete
1339 }
1340 }
1341 }
1342 return request.result;
1343 }
1344
1345 /**
1346 * Asynchronous ("fire and forget") version of sendRequest():
1347 * Posts the specified command to be executed on the main thread, and
1348 * returns immediately.
1349 * @see #sendRequest
1350 */
1351 private void sendRequestAsync(int command) {
1352 mMainThreadHandler.sendEmptyMessage(command);
1353 }
1354
1355 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001357 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 */
1359 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001360 sendRequestAsync(command, argument, null, null);
1361 }
1362
1363 /**
1364 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1365 * @see {@link #sendRequest(int,Object)}
1366 */
1367 private void sendRequestAsync(
1368 int command, Object argument, Phone phone, WorkSource workSource) {
1369 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001370 Message msg = mMainThreadHandler.obtainMessage(command, request);
1371 msg.sendToTarget();
1372 }
1373
1374 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 * Initialize the singleton PhoneInterfaceManager instance.
1376 * This is only done once, at startup, from PhoneApp.onCreate().
1377 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001378 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 synchronized (PhoneInterfaceManager.class) {
1380 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 } else {
1383 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1384 }
1385 return sInstance;
1386 }
1387 }
1388
1389 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001390 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001393 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001394 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1396 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001397 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001398 mTelephonySharedPreferences =
1399 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001400 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001401 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001402
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 publish();
1404 }
1405
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001406 private Phone getDefaultPhone() {
1407 Phone thePhone = getPhone(getDefaultSubscription());
1408 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1409 }
1410
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 private void publish() {
1412 if (DBG) log("publish: " + this);
1413
1414 ServiceManager.addService("phone", this);
1415 }
1416
Stuart Scott584921c2015-01-15 17:10:34 -08001417 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001418 if (request.phone != null) {
1419 return request.phone;
1420 } else {
1421 return getPhoneFromSubId(request.subId);
1422 }
1423 }
1424
1425 private Phone getPhoneFromSubId(int subId) {
1426 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1427 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001428 }
1429
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001430 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1431 Phone phone = getPhoneFromRequest(request);
1432 return phone == null ? null :
1433 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1434 }
1435
Wink Saville36469e72014-06-11 15:17:00 -07001436 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001437 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001438 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001441 private void sendEraseModemConfig(Phone phone) {
1442 if (phone != null) {
1443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1444 mApp, phone.getSubId(), "eraseModemConfig");
1445 final long identity = Binder.clearCallingIdentity();
1446 try {
1447 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1448 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1449 } finally {
1450 Binder.restoreCallingIdentity(identity);
1451 }
1452 }
1453 }
1454
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001457 }
1458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 if (DBG) log("dial: " + number);
1461 // No permission check needed here: This is just a wrapper around the
1462 // ACTION_DIAL intent, which is available to any app since it puts up
1463 // the UI before it does anything.
1464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001465 final long identity = Binder.clearCallingIdentity();
1466 try {
1467 String url = createTelUrl(number);
1468 if (url == null) {
1469 return;
1470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001472 // PENDING: should we just silently fail if phone is offhook or ringing?
1473 PhoneConstants.State state = mCM.getState(subId);
1474 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1475 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1476 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1477 mApp.startActivity(intent);
1478 }
1479 } finally {
1480 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482 }
1483
1484 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001485 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001486 }
1487
Wink Savilleb564aae2014-10-23 10:18:09 -07001488 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 if (DBG) log("call: " + number);
1490
1491 // This is just a wrapper around the ACTION_CALL intent, but we still
1492 // need to do a permission check since we're calling startActivity()
1493 // from the context of the phone app.
1494 enforceCallPermission();
1495
Jordan Liu1617b712019-07-10 15:06:26 -07001496 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 != AppOpsManager.MODE_ALLOWED) {
1498 return;
1499 }
1500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001501 final long identity = Binder.clearCallingIdentity();
1502 try {
1503 String url = createTelUrl(number);
1504 if (url == null) {
1505 return;
1506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001508 boolean isValid = false;
1509 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1510 if (slist != null) {
1511 for (SubscriptionInfo subInfoRecord : slist) {
1512 if (subInfoRecord.getSubscriptionId() == subId) {
1513 isValid = true;
1514 break;
1515 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001516 }
Wink Saville08874612014-08-31 19:19:58 -07001517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001518 if (!isValid) {
1519 return;
1520 }
Wink Saville08874612014-08-31 19:19:58 -07001521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001522 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1523 intent.putExtra(SUBSCRIPTION_KEY, subId);
1524 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1525 mApp.startActivity(intent);
1526 } finally {
1527 Binder.restoreCallingIdentity(identity);
1528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 }
1530
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001532 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001533 }
1534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001537 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1538 }
1539
1540 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001541 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001546 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1547 }
1548
1549 /** {@hide} */
1550 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001551 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001552 }
1553
Wink Savilleb564aae2014-10-23 10:18:09 -07001554 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001556
1557 final long identity = Binder.clearCallingIdentity();
1558 try {
1559 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1560 checkSimPin.start();
1561 return checkSimPin.unlockSim(null, pin);
1562 } finally {
1563 Binder.restoreCallingIdentity(identity);
1564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 }
1566
Wink Saville9de0f752013-10-22 19:04:03 -07001567 /** {@hide} */
1568 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001569 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001570 }
1571
Wink Savilleb564aae2014-10-23 10:18:09 -07001572 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001574
1575 final long identity = Binder.clearCallingIdentity();
1576 try {
1577 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1578 checkSimPuk.start();
1579 return checkSimPuk.unlockSim(puk, pin);
1580 } finally {
1581 Binder.restoreCallingIdentity(identity);
1582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
1585 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001586 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 * a synchronous one.
1588 */
1589 private static class UnlockSim extends Thread {
1590
1591 private final IccCard mSimCard;
1592
1593 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001594 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1595 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596
1597 // For replies from SimCard interface
1598 private Handler mHandler;
1599
1600 // For async handler to identify request type
1601 private static final int SUPPLY_PIN_COMPLETE = 100;
1602
1603 public UnlockSim(IccCard simCard) {
1604 mSimCard = simCard;
1605 }
1606
1607 @Override
1608 public void run() {
1609 Looper.prepare();
1610 synchronized (UnlockSim.this) {
1611 mHandler = new Handler() {
1612 @Override
1613 public void handleMessage(Message msg) {
1614 AsyncResult ar = (AsyncResult) msg.obj;
1615 switch (msg.what) {
1616 case SUPPLY_PIN_COMPLETE:
1617 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1618 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001619 mRetryCount = msg.arg1;
1620 if (ar.exception != null) {
1621 if (ar.exception instanceof CommandException &&
1622 ((CommandException)(ar.exception)).getCommandError()
1623 == CommandException.Error.PASSWORD_INCORRECT) {
1624 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1625 } else {
1626 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1627 }
1628 } else {
1629 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 mDone = true;
1632 UnlockSim.this.notifyAll();
1633 }
1634 break;
1635 }
1636 }
1637 };
1638 UnlockSim.this.notifyAll();
1639 }
1640 Looper.loop();
1641 }
1642
1643 /*
1644 * Use PIN or PUK to unlock SIM card
1645 *
1646 * If PUK is null, unlock SIM card with PIN
1647 *
1648 * If PUK is not null, unlock SIM card with PUK and set PIN code
1649 */
Wink Saville9de0f752013-10-22 19:04:03 -07001650 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651
1652 while (mHandler == null) {
1653 try {
1654 wait();
1655 } catch (InterruptedException e) {
1656 Thread.currentThread().interrupt();
1657 }
1658 }
1659 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1660
1661 if (puk == null) {
1662 mSimCard.supplyPin(pin, callback);
1663 } else {
1664 mSimCard.supplyPuk(puk, pin, callback);
1665 }
1666
1667 while (!mDone) {
1668 try {
1669 Log.d(LOG_TAG, "wait for done");
1670 wait();
1671 } catch (InterruptedException e) {
1672 // Restore the interrupted status
1673 Thread.currentThread().interrupt();
1674 }
1675 }
1676 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001677 int[] resultArray = new int[2];
1678 resultArray[0] = mResult;
1679 resultArray[1] = mRetryCount;
1680 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682 }
1683
1684 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001685 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001686
1687 }
1688
Wink Savilleb564aae2014-10-23 10:18:09 -07001689 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 // No permission check needed here: this call is harmless, and it's
1691 // needed for the ServiceState.requestStateUpdate() call (which is
1692 // already intentionally exposed to 3rd parties.)
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 phone.updateServiceLocation();
1698 }
1699 } finally {
1700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 }
1703
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001704 @Override
1705 public boolean isRadioOn(String callingPackage) {
1706 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001707 }
1708
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001709 @Override
1710 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001712 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001713 return false;
1714 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 return isRadioOnForSubscriber(subId);
1719 } finally {
1720 Binder.restoreCallingIdentity(identity);
1721 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001722 }
1723
1724 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001725 final long identity = Binder.clearCallingIdentity();
1726 try {
1727 final Phone phone = getPhone(subId);
1728 if (phone != null) {
1729 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1730 } else {
1731 return false;
1732 }
1733 } finally {
1734 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 }
1737
1738 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001739 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
Wink Saville36469e72014-06-11 15:17:00 -07001741
Wink Savilleb564aae2014-10-23 10:18:09 -07001742 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001744
1745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 final Phone phone = getPhone(subId);
1748 if (phone != null) {
1749 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1750 }
1751 } finally {
1752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001753 }
Wink Saville36469e72014-06-11 15:17:00 -07001754 }
1755
1756 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001757 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001758 }
1759
Wink Savilleb564aae2014-10-23 10:18:09 -07001760 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762
1763 final long identity = Binder.clearCallingIdentity();
1764 try {
1765 final Phone phone = getPhone(subId);
1766 if (phone == null) {
1767 return false;
1768 }
1769 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1770 toggleRadioOnOffForSubscriber(subId);
1771 }
1772 return true;
1773 } finally {
1774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 }
Wink Saville36469e72014-06-11 15:17:00 -07001777
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001778 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001779 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001780 /*
1781 * If any of the Radios are available, it will need to be
1782 * shutdown. So return true if any Radio is available.
1783 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784 final long identity = Binder.clearCallingIdentity();
1785 try {
1786 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1787 Phone phone = PhoneFactory.getPhone(i);
1788 if (phone != null && phone.isRadioAvailable()) return true;
1789 }
1790 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1791 return false;
1792 } finally {
1793 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001794 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001795 }
1796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001798 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 enforceModifyPermission();
1800
1801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1804 logv("Shutting down Phone " + i);
1805 shutdownRadioUsingPhoneId(i);
1806 }
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001809 }
1810 }
1811
1812 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001813 Phone phone = PhoneFactory.getPhone(phoneId);
1814 if (phone != null && phone.isRadioAvailable()) {
1815 phone.shutdownRadio();
1816 }
1817 }
1818
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001820 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001821
1822 final long identity = Binder.clearCallingIdentity();
1823 try {
1824 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1825 if (defaultPhone != null) {
1826 defaultPhone.setRadioPower(turnOn);
1827 return true;
1828 } else {
1829 loge("There's no default phone.");
1830 return false;
1831 }
1832 } finally {
1833 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001834 }
Wink Saville36469e72014-06-11 15:17:00 -07001835 }
1836
Wink Savilleb564aae2014-10-23 10:18:09 -07001837 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001839
1840 final long identity = Binder.clearCallingIdentity();
1841 try {
1842 final Phone phone = getPhone(subId);
1843 if (phone != null) {
1844 phone.setRadioPower(turnOn);
1845 return true;
1846 } else {
1847 return false;
1848 }
1849 } finally {
1850 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001851 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001852 }
1853
Wink Saville36469e72014-06-11 15:17:00 -07001854 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 public boolean enableDataConnectivity() {
1857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001858
1859 final long identity = Binder.clearCallingIdentity();
1860 try {
1861 int subId = mSubscriptionController.getDefaultDataSubId();
1862 final Phone phone = getPhone(subId);
1863 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001864 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001865 return true;
1866 } else {
1867 return false;
1868 }
1869 } finally {
1870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873
Wink Saville36469e72014-06-11 15:17:00 -07001874 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 public boolean disableDataConnectivity() {
1877 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878
1879 final long identity = Binder.clearCallingIdentity();
1880 try {
1881 int subId = mSubscriptionController.getDefaultDataSubId();
1882 final Phone phone = getPhone(subId);
1883 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001884 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 return true;
1886 } else {
1887 return false;
1888 }
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001895 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001896 final long identity = Binder.clearCallingIdentity();
1897 try {
1898 final Phone phone = getPhone(subId);
1899 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001900 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001901 } else {
1902 return false;
1903 }
1904 } finally {
1905 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908
1909 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001910 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001911 }
1912
pkanwarae03a6b2016-11-06 20:37:09 -08001913 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 enforceCallPermission();
1915
1916 final long identity = Binder.clearCallingIdentity();
1917 try {
1918 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1919 return;
1920 }
1921 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1922 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1923 } finally {
1924 Binder.restoreCallingIdentity(identity);
1925 }
pkanwar32d516d2016-10-14 19:37:38 -07001926 };
1927
Wink Savilleb564aae2014-10-23 10:18:09 -07001928 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930
1931 final long identity = Binder.clearCallingIdentity();
1932 try {
1933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1934 return false;
1935 }
1936 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1937 } finally {
1938 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 }
1941
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001943 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001944 }
1945
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001946 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001947 final long identity = Binder.clearCallingIdentity();
1948 try {
1949 Phone phone = PhoneFactory.getPhone(slotIndex);
1950 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1951 PhoneConstantConversions.convertCallState(phone.getState());
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001958 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001959 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1960 }
1961
1962 @Override
1963 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001964 final long identity = Binder.clearCallingIdentity();
1965 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001966 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967 if (phone != null) {
1968 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1969 } else {
1970 return PhoneConstantConversions.convertDataState(
1971 PhoneConstants.DataState.DISCONNECTED);
1972 }
1973 } finally {
1974 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 }
1977
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001979 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001980 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1981 }
1982
1983 @Override
1984 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001987 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988 if (phone != null) {
1989 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1990 } else {
1991 return TelephonyManager.DATA_ACTIVITY_NONE;
1992 }
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997
1998 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001999 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002000 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002001 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002002
2003 LocationAccessPolicy.LocationPermissionResult locationResult =
2004 LocationAccessPolicy.checkLocationPermission(mApp,
2005 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2006 .setCallingPackage(callingPackage)
2007 .setCallingPid(Binder.getCallingPid())
2008 .setCallingUid(Binder.getCallingUid())
2009 .setMethod("getCellLocation")
2010 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2011 .build());
2012 switch (locationResult) {
2013 case DENIED_HARD:
2014 throw new SecurityException("Not allowed to access cell location");
2015 case DENIED_SOFT:
2016 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002019 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 if (DBG_LOC) log("getCellLocation: is active user");
2023 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002024 int subId = mSubscriptionController.getDefaultDataSubId();
2025 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2026 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002027 return data;
2028 } finally {
2029 Binder.restoreCallingIdentity(identity);
2030 }
Svetoslav64fad262015-04-14 14:35:21 -07002031 }
2032
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 @Override
Jack Yu7c5d91a2019-09-26 11:48:33 -07002034 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2035 if (!TextUtils.isEmpty(callingPackage)) {
2036 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2038 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2039 return "";
2040 }
2041 }
2042
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002043 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2044 // registered cell info, so return a NULL country instead.
2045 final long identity = Binder.clearCallingIdentity();
2046 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002047 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2048 // Get default phone in this case.
2049 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2050 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002051 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002052 // Todo: fix this when we can get the actual cellular network info when the device
2053 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002054 if (TelephonyManager.NETWORK_TYPE_IWLAN
2055 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2056 return "";
2057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002058 Phone phone = PhoneFactory.getPhone(phoneId);
2059 if (phone != null) {
2060 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002061 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062 if (sst != null) {
2063 LocaleTracker lt = sst.getLocaleTracker();
2064 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002065 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2066 return lt.getCurrentCountry();
2067 } else if (emergencyNumberTracker != null) {
2068 return emergencyNumberTracker.getEmergencyCountryIso();
2069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002070 }
2071 }
2072 }
2073 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002074 } finally {
2075 Binder.restoreCallingIdentity(identity);
2076 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002077 }
2078
2079 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002081 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002082 }
2083
Sanket Padawe356d7632015-06-22 14:03:32 -07002084 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002085 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 mApp.enforceCallingOrSelfPermission(
2087 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002088
2089 final long identity = Binder.clearCallingIdentity();
2090 try {
2091 final Phone phone = getPhone(subId);
2092 if (phone != null) {
2093 phone.enableLocationUpdates();
2094 }
2095 } finally {
2096 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 }
2099
2100 @Override
2101 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002102 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002103 }
2104
Sanket Padawe356d7632015-06-22 14:03:32 -07002105 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002106 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 mApp.enforceCallingOrSelfPermission(
2108 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002109
2110 final long identity = Binder.clearCallingIdentity();
2111 try {
2112 final Phone phone = getPhone(subId);
2113 if (phone != null) {
2114 phone.disableLocationUpdates();
2115 }
2116 } finally {
2117 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 }
2120
Nathan Harold31d7ff32018-10-15 20:20:30 -07002121 /**
2122 * Returns the target SDK version number for a given package name.
2123 *
Nathan Haroldec184742019-07-10 17:04:16 -07002124 * This call MUST be invoked before clearing the calling UID.
2125 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002126 * @return target SDK if the package is found or INT_MAX.
2127 */
2128 private int getTargetSdk(String packageName) {
2129 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002130 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002131 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002132 if (ai != null) return ai.targetSdkVersion;
2133 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002134 loge("Failed to get package info for pkg="
2135 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002136 }
2137 return Integer.MAX_VALUE;
2138 }
2139
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 @Override
2141 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002142 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2143 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002144 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2145 throw new SecurityException(
2146 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2147 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002148
Jordan Liu1617b712019-07-10 15:06:26 -07002149 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2151 return null;
2152 }
Svetoslav64fad262015-04-14 14:35:21 -07002153
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002154 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155
Nathan Haroldf180aac2018-06-01 18:43:55 -07002156 List<CellInfo> info = getAllCellInfo(callingPackage);
2157 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158
Nathan Haroldf180aac2018-06-01 18:43:55 -07002159 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2160 for (CellInfo ci : info) {
2161 if (ci instanceof CellInfoGsm) {
2162 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2163 } else if (ci instanceof CellInfoWcdma) {
2164 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002167 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002170 private List<CellInfo> getCachedCellInfo() {
2171 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2172 for (Phone phone : PhoneFactory.getPhones()) {
2173 List<CellInfo> info = phone.getAllCellInfo();
2174 if (info != null) cellInfos.addAll(info);
2175 }
2176 return cellInfos;
2177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178
2179 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002180 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002181 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002182 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002183
2184 LocationAccessPolicy.LocationPermissionResult locationResult =
2185 LocationAccessPolicy.checkLocationPermission(mApp,
2186 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2187 .setCallingPackage(callingPackage)
2188 .setCallingPid(Binder.getCallingPid())
2189 .setCallingUid(Binder.getCallingUid())
2190 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002191 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002192 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2193 .build());
2194 switch (locationResult) {
2195 case DENIED_HARD:
2196 throw new SecurityException("Not allowed to access cell info");
2197 case DENIED_SOFT:
2198 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002201 final int targetSdk = getTargetSdk(callingPackage);
2202 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2203 return getCachedCellInfo();
2204 }
2205
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002206 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002207 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208 final long identity = Binder.clearCallingIdentity();
2209 try {
2210 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2211 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002212 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002213 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214 if (info != null) cellInfos.addAll(info);
2215 }
2216 return cellInfos;
2217 } finally {
2218 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220 }
2221
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002222 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002223 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2224 requestCellInfoUpdateInternal(
2225 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2226 }
2227
2228 @Override
2229 public void requestCellInfoUpdateWithWorkSource(
2230 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2231 enforceModifyPermission();
2232 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2233 }
2234
2235 private void requestCellInfoUpdateInternal(
2236 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002237 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002238 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002239
2240 LocationAccessPolicy.LocationPermissionResult locationResult =
2241 LocationAccessPolicy.checkLocationPermission(mApp,
2242 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2243 .setCallingPackage(callingPackage)
2244 .setCallingPid(Binder.getCallingPid())
2245 .setCallingUid(Binder.getCallingUid())
2246 .setMethod("requestCellInfoUpdate")
2247 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2248 .build());
2249 switch (locationResult) {
2250 case DENIED_HARD:
2251 throw new SecurityException("Not allowed to access cell info");
2252 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002253 try {
2254 cb.onCellInfo(new ArrayList<CellInfo>());
2255 } catch (RemoteException re) {
2256 // Drop without consequences
2257 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002258 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002259 }
2260
Nathan Harolda939a962019-05-09 10:13:47 -07002261
2262 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002263 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2264
2265 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2266 }
2267
2268 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002270 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002271 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002272
2273 final long identity = Binder.clearCallingIdentity();
2274 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002275 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276 } finally {
2277 Binder.restoreCallingIdentity(identity);
2278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280
Shishir Agrawala9f32182016-04-12 12:00:16 -07002281 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002282 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002283 Phone phone = PhoneFactory.getPhone(slotIndex);
2284 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002285 return null;
2286 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002287 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002288 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2289 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 return null;
2291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
2295 return phone.getImei();
2296 } finally {
2297 Binder.restoreCallingIdentity(identity);
2298 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002299 }
2300
2301 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002302 public String getTypeAllocationCodeForSlot(int slotIndex) {
2303 Phone phone = PhoneFactory.getPhone(slotIndex);
2304 String tac = null;
2305 if (phone != null) {
2306 String imei = phone.getImei();
2307 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2308 }
2309 return tac;
2310 }
2311
2312 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002313 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002314 Phone phone = PhoneFactory.getPhone(slotIndex);
2315 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002316 return null;
2317 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002318
Jeff Davidson913390f2018-02-23 17:11:49 -08002319 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002320 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2321 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002322 return null;
2323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 return phone.getMeid();
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
2330 }
Jack Yu2af8d712017-03-15 17:14:14 -07002331 }
2332
2333 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002334 public String getManufacturerCodeForSlot(int slotIndex) {
2335 Phone phone = PhoneFactory.getPhone(slotIndex);
2336 String manufacturerCode = null;
2337 if (phone != null) {
2338 String meid = phone.getMeid();
2339 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2340 }
2341 return manufacturerCode;
2342 }
2343
2344 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002345 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002346 Phone phone = PhoneFactory.getPhone(slotIndex);
2347 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002348 return null;
2349 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002350 int subId = phone.getSubId();
2351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2352 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2353 return null;
2354 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355
2356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 return phone.getDeviceSvn();
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
2361 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002362 }
2363
fionaxu43304da2017-11-27 22:51:16 -08002364 @Override
2365 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 final Phone phone = getPhone(subId);
2369 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2370 } finally {
2371 Binder.restoreCallingIdentity(identity);
2372 }
fionaxu43304da2017-11-27 22:51:16 -08002373 }
2374
2375 @Override
2376 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 final Phone phone = getPhone(subId);
2380 return phone == null ? null : phone.getCarrierName();
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
2383 }
fionaxu43304da2017-11-27 22:51:16 -08002384 }
2385
calvinpanffe225e2018-11-01 19:43:06 +08002386 @Override
chen xu0026ca62019-03-06 15:28:50 -08002387 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002392 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002393 } finally {
2394 Binder.restoreCallingIdentity(identity);
2395 }
2396 }
2397
2398 @Override
chen xu0026ca62019-03-06 15:28:50 -08002399 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002400 final long identity = Binder.clearCallingIdentity();
2401 try {
2402 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002403 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002404 } finally {
2405 Binder.restoreCallingIdentity(identity);
2406 }
2407 }
2408
chen xu651eec72018-11-11 19:03:44 -08002409 @Override
chen xu864e11c2018-12-06 22:10:03 -08002410 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2411 if (!isSubscriptionMccMnc) {
2412 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2413 }
chen xu651eec72018-11-11 19:03:44 -08002414 final Phone phone = PhoneFactory.getPhone(slotIndex);
2415 if (phone == null) {
2416 return TelephonyManager.UNKNOWN_CARRIER_ID;
2417 }
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
2420 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
2423 }
2424 }
2425
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 //
2427 // Internal helper methods.
2428 //
2429
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002430 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2432 *
2433 * @throws SecurityException if the caller does not have the required permission
2434 */
2435 private void enforceModifyPermission() {
2436 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2437 }
2438
Shuo Qianf2b2df42019-11-13 17:43:31 -08002439 private void enforceActiveEmergencySessionPermission() {
2440 mApp.enforceCallingOrSelfPermission(
2441 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2442 }
2443
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 /**
2445 * Make sure the caller has the CALL_PHONE permission.
2446 *
2447 * @throws SecurityException if the caller does not have the required permission
2448 */
2449 private void enforceCallPermission() {
2450 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2451 }
2452
paulhu423b5f22019-08-23 19:17:33 +08002453 private void enforceSettingsPermission() {
2454 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002455 }
2456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 private String createTelUrl(String number) {
2458 if (TextUtils.isEmpty(number)) {
2459 return null;
2460 }
2461
Jake Hambye994d462014-02-03 13:10:13 -08002462 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464
Ihab Awadf9e92732013-12-05 18:02:52 -08002465 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2467 }
2468
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002469 private static void logv(String msg) {
2470 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2471 }
2472
Ihab Awadf9e92732013-12-05 18:02:52 -08002473 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002474 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2475 }
2476
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002477 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002479 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002480 }
2481
Sanket Padawe356d7632015-06-22 14:03:32 -07002482 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002483 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 final long identity = Binder.clearCallingIdentity();
2485 try {
2486 final Phone phone = PhoneFactory.getPhone(slotIndex);
2487 if (phone == null) {
2488 return PhoneConstants.PHONE_TYPE_NONE;
2489 } else {
2490 return phone.getPhoneType();
2491 }
2492 } finally {
2493 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002494 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 }
2496
2497 /**
2498 * Returns the CDMA ERI icon index to display
2499 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002500 @Override
2501 public int getCdmaEriIconIndex(String callingPackage) {
2502 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002503 }
2504
Sanket Padawe356d7632015-06-22 14:03:32 -07002505 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002506 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002508 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002509 return -1;
2510 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511
2512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 final Phone phone = getPhone(subId);
2515 if (phone != null) {
2516 return phone.getCdmaEriIconIndex();
2517 } else {
2518 return -1;
2519 }
2520 } finally {
2521 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 }
2524
2525 /**
2526 * Returns the CDMA ERI icon mode,
2527 * 0 - ON
2528 * 1 - FLASHING
2529 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002530 @Override
2531 public int getCdmaEriIconMode(String callingPackage) {
2532 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002533 }
2534
Sanket Padawe356d7632015-06-22 14:03:32 -07002535 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002536 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002538 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002539 return -1;
2540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541
2542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 final Phone phone = getPhone(subId);
2545 if (phone != null) {
2546 return phone.getCdmaEriIconMode();
2547 } else {
2548 return -1;
2549 }
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554
2555 /**
2556 * Returns the CDMA ERI text,
2557 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002558 @Override
2559 public String getCdmaEriText(String callingPackage) {
2560 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002561 }
2562
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002564 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002566 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002567 return null;
2568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone phone = getPhone(subId);
2573 if (phone != null) {
2574 return phone.getCdmaEriText();
2575 } else {
2576 return null;
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 }
2582
2583 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002584 * Returns the CDMA MDN.
2585 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002586 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002587 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2589 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590
2591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002594 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 return phone.getLine1Number();
2596 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002597 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 return null;
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002602 }
2603 }
2604
2605 /**
2606 * Returns the CDMA MIN.
2607 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002609 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2611 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612
2613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 final Phone phone = getPhone(subId);
2616 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2617 return phone.getCdmaMin();
2618 } else {
2619 return null;
2620 }
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002623 }
2624 }
2625
Hall Liud892bec2018-11-30 14:51:45 -08002626 @Override
2627 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2628 INumberVerificationCallback callback, String callingPackage) {
2629 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2630 != PERMISSION_GRANTED) {
2631 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2632 }
2633 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2634
2635 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2636 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2637 throw new SecurityException("Calling package must be configured in the device config");
2638 }
2639
2640 if (range == null) {
2641 throw new NullPointerException("Range must be non-null");
2642 }
2643
2644 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002645 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002646
2647 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2648 }
2649
Junda Liuca05d5d2014-08-14 22:36:34 -07002650 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 * Returns true if CDMA provisioning needs to run.
2652 */
2653 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002656 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 } finally {
2658 Binder.restoreCallingIdentity(identity);
2659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 }
2661
2662 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002663 * Sets the voice mail number of a given subId.
2664 */
2665 @Override
2666 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002667 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668
2669 final long identity = Binder.clearCallingIdentity();
2670 try {
2671 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2672 new Pair<String, String>(alphaTag, number), new Integer(subId));
2673 return success;
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
2676 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002677 }
2678
Ta-wei Yen87c49842016-05-13 21:19:52 -07002679 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002680 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002682 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2683 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002684 if (!TextUtils.equals(callingPackage, systemDialer)) {
2685 throw new SecurityException("caller must be system dialer");
2686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2691 if (phoneAccountHandle == null) {
2692 return null;
2693 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002694 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002697 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002698 }
2699
2700 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002701 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002704 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002705 return null;
2706 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002708 final long identity = Binder.clearCallingIdentity();
2709 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002710 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002711 } finally {
2712 Binder.restoreCallingIdentity(identity);
2713 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002714 }
2715
2716 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002717 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2718 VisualVoicemailSmsFilterSettings settings) {
2719 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720
2721 final long identity = Binder.clearCallingIdentity();
2722 try {
2723 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002724 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 } finally {
2726 Binder.restoreCallingIdentity(identity);
2727 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002728 }
2729
2730 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002731 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733
2734 final long identity = Binder.clearCallingIdentity();
2735 try {
2736 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002737 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 } finally {
2739 Binder.restoreCallingIdentity(identity);
2740 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002741 }
2742
2743 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002744 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2745 String callingPackage, int subId) {
2746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002751 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752 } finally {
2753 Binder.restoreCallingIdentity(identity);
2754 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002755 }
2756
2757 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002758 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002759 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002764 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765 } finally {
2766 Binder.restoreCallingIdentity(identity);
2767 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002768 }
2769
2770 @Override
2771 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2772 String number, int port, String text, PendingIntent sentIntent) {
2773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002774 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002775 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002776 SmsController smsController = PhoneFactory.getSmsController();
2777 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2778 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002779 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002780
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002781 /**
fionaxu0152e512016-11-14 13:36:14 -08002782 * Sets the voice activation state of a given subId.
2783 */
2784 @Override
2785 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2787 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788
2789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 final Phone phone = getPhone(subId);
2792 if (phone != null) {
2793 phone.setVoiceActivationState(activationState);
2794 } else {
2795 loge("setVoiceActivationState fails with invalid subId: " + subId);
2796 }
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002799 }
2800 }
2801
2802 /**
2803 * Sets the data activation state of a given subId.
2804 */
2805 @Override
2806 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2808 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 final Phone phone = getPhone(subId);
2813 if (phone != null) {
2814 phone.setDataActivationState(activationState);
2815 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002816 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817 }
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002820 }
2821 }
2822
2823 /**
2824 * Returns the voice activation state of a given subId.
2825 */
2826 @Override
2827 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002828 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829
fionaxu0152e512016-11-14 13:36:14 -08002830 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 if (phone != null) {
2834 return phone.getVoiceActivationState();
2835 } else {
2836 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2837 }
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002840 }
2841 }
2842
2843 /**
2844 * Returns the data activation state of a given subId.
2845 */
2846 @Override
2847 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002848 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849
fionaxu0152e512016-11-14 13:36:14 -08002850 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 if (phone != null) {
2854 return phone.getDataActivationState();
2855 } else {
2856 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2857 }
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002860 }
2861 }
2862
2863 /**
Wink Saville36469e72014-06-11 15:17:00 -07002864 * Returns the unread count of voicemails for a subId
2865 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002866 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002867 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2868 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2869 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2870 return 0;
2871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 final long identity = Binder.clearCallingIdentity();
2873 try {
2874 final Phone phone = getPhone(subId);
2875 if (phone != null) {
2876 return phone.getVoiceMessageCount();
2877 } else {
2878 return 0;
2879 }
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
2884
2885 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002886 * returns true, if the device is in a state where both voice and data
2887 * are supported simultaneously. This can change based on location or network condition.
2888 */
2889 @Override
2890 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 final Phone phone = getPhone(subId);
2894 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
2897 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002898 }
2899
2900 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002901 * Send the dialer code if called from the current default dialer or the caller has
2902 * carrier privilege.
2903 * @param inputCode The dialer code to send
2904 */
2905 @Override
2906 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002907 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002908 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002909 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2910 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002911 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002912 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2913 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002915
2916 final long identity = Binder.clearCallingIdentity();
2917 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002918 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 } finally {
2920 Binder.restoreCallingIdentity(identity);
2921 }
fionaxu235cc5e2017-03-06 22:25:57 -08002922 }
2923
Pengquan Menga1bb6272018-09-06 09:59:22 -07002924 @Override
2925 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002926 if (!isActiveSubscription(subId)) {
2927 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2928 }
2929
Pengquan Menga1bb6272018-09-06 09:59:22 -07002930 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2931 }
2932
Brad Ebinger35c841c2018-10-01 10:40:55 -07002933 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002934 public boolean isInEmergencySmsMode() {
2935 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 for (Phone phone : PhoneFactory.getPhones()) {
2939 if (phone.isInEmergencySmsMode()) {
2940 return true;
2941 }
2942 }
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
2945 }
2946 return false;
2947 }
2948
2949 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002950 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2951 throws RemoteException {
2952 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002953 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2954 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2955 "IMS not available on device.");
2956 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002957 final long token = Binder.clearCallingIdentity();
2958 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002960 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002961 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002962 } catch (ImsException e) {
2963 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002964 } finally {
2965 Binder.restoreCallingIdentity(token);
2966 }
2967 }
2968
2969 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002970 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2971 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002972 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2973 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2974 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002975 final long token = Binder.clearCallingIdentity();
2976 try {
2977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2978 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2979 .removeRegistrationCallbackForSubscription(c, subId);
2980 } catch (ImsException e) {
2981 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2982 + "is inactive, ignoring unregister.");
2983 // If the subscription is no longer active, just return, since the callback
2984 // will already have been removed internally.
2985 } finally {
2986 Binder.restoreCallingIdentity(token);
2987 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 }
2989
Brad Ebinger774ba362019-10-22 17:36:18 -07002990 /**
2991 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2992 */
2993 @Override
2994 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2995 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2996 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2997 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2998 "IMS not available on device.");
2999 }
3000 final long token = Binder.clearCallingIdentity();
3001 try {
3002 Phone phone = getPhone(subId);
3003 if (phone == null) {
3004 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3005 + subId + "'");
3006 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3007 }
3008 phone.getImsRegistrationState(regState -> {
3009 try {
3010 consumer.accept((regState == null)
3011 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3012 } catch (RemoteException e) {
3013 // Ignore if the remote process is no longer available to call back.
3014 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3015 }
3016 });
3017 } finally {
3018 Binder.restoreCallingIdentity(token);
3019 }
3020 }
3021
3022 /**
3023 * Get the transport type for the IMS service registration state.
3024 */
3025 @Override
3026 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3027 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
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 Phone phone = getPhone(subId);
3035 if (phone == null) {
3036 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3037 + subId + "'");
3038 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3039 }
3040 phone.getImsRegistrationTech(regTech -> {
3041 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3042 int regTechConverted = (regTech == null)
3043 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3044 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3045 regTechConverted);
3046 try {
3047 consumer.accept(regTechConverted);
3048 } catch (RemoteException e) {
3049 // Ignore if the remote process is no longer available to call back.
3050 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3051 }
3052 });
3053 } finally {
3054 Binder.restoreCallingIdentity(token);
3055 }
3056 }
3057
Brad Ebinger35c841c2018-10-01 10:40:55 -07003058 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003059 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3060 throws RemoteException {
3061 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003062 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3063 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3064 "IMS not available on device.");
3065 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003066 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3067 final long token = Binder.clearCallingIdentity();
3068 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003069 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003070 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003071 } catch (ImsException e) {
3072 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 } finally {
3074 Binder.restoreCallingIdentity(token);
3075 }
3076 }
3077
3078 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003079 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3080 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003081 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3082 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3083 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003084
3085 final long token = Binder.clearCallingIdentity();
3086 try {
3087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3088 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003089 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003090 } catch (ImsException e) {
3091 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3092 + "is inactive, ignoring unregister.");
3093 // If the subscription is no longer active, just return, since the callback
3094 // will already have been removed internally.
3095 } finally {
3096 Binder.restoreCallingIdentity(token);
3097 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003098 }
3099
3100 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003101 public boolean isCapable(int subId, int capability, int regTech) {
3102 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3104 final long token = Binder.clearCallingIdentity();
3105 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003106 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003107 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003108 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3110 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003111 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003112 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3113 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003114 } finally {
3115 Binder.restoreCallingIdentity(token);
3116 }
3117 }
3118
3119 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003120 public boolean isAvailable(int subId, int capability, int regTech) {
3121 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 final long token = Binder.clearCallingIdentity();
3123 try {
3124 Phone phone = getPhone(subId);
3125 if (phone == null) return false;
3126 return phone.isImsCapabilityAvailable(capability, regTech);
3127 } finally {
3128 Binder.restoreCallingIdentity(token);
3129 }
3130 }
3131
Brad Ebinger77b832e2019-10-17 17:03:22 -07003132 /**
3133 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3134 * subscription.
3135 * @param subId The subscription to use to check the configuration.
3136 * @param callback The callback that will be used to send the result.
3137 * @param capability The MmTelFeature capability that will be used to send the result.
3138 * @param transportType The transport type of the MmTelFeature capability.
3139 */
3140 @Override
3141 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3142 int transportType) {
3143 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3144 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3145 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3146 "IMS not available on device.");
3147 }
3148 final long token = Binder.clearCallingIdentity();
3149 try {
3150 int slotId = getSlotIndex(subId);
3151 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3152 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3153 + subId + "'");
3154 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3155 }
3156 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3157 transportType, aBoolean -> {
3158 try {
3159 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3160 } catch (RemoteException e) {
3161 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3162 + "running. Ignore");
3163 }
3164 });
3165 } finally {
3166 Binder.restoreCallingIdentity(token);
3167 }
3168 }
3169
Brad Ebinger35c841c2018-10-01 10:40:55 -07003170 @Override
3171 public boolean isAdvancedCallingSettingEnabled(int subId) {
3172 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3173 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3174 final long token = Binder.clearCallingIdentity();
3175 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003176 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003177 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003178 } catch (ImsException e) {
3179 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003180 } finally {
3181 Binder.restoreCallingIdentity(token);
3182 }
3183 }
3184
3185 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003186 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003188 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003192 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003193 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003194 } catch (ImsException e) {
3195 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
3199 }
3200
3201 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003202 public boolean isVtSettingEnabled(int subId) {
3203 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003207 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3208 } catch (ImsException e) {
3209 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 } finally {
3211 Binder.restoreCallingIdentity(identity);
3212 }
3213 }
3214
3215 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003216 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003218 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003219 final long identity = Binder.clearCallingIdentity();
3220 try {
3221 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003222 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003223 } catch (ImsException e) {
3224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 } finally {
3226 Binder.restoreCallingIdentity(identity);
3227 }
3228 }
3229
3230 @Override
3231 public boolean isVoWiFiSettingEnabled(int subId) {
3232 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3233 final long identity = Binder.clearCallingIdentity();
3234 try {
3235 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003236 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003238 } catch (ImsException e) {
3239 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
3243 }
3244
3245 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003246 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003248 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003249 final long identity = Binder.clearCallingIdentity();
3250 try {
3251 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003252 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003253 } catch (ImsException e) {
3254 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 } finally {
3256 Binder.restoreCallingIdentity(identity);
3257 }
3258 }
3259
3260 @Override
3261 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3262 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003266 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003268 } catch (ImsException e) {
3269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 } finally {
3271 Binder.restoreCallingIdentity(identity);
3272 }
3273 }
3274
3275 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003276 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003278 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 final long identity = Binder.clearCallingIdentity();
3280 try {
3281 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003282 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003284 } catch (ImsException e) {
3285 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
3289 }
3290
3291 @Override
3292 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3294 "setVoWiFiNonPersistent");
3295 final long identity = Binder.clearCallingIdentity();
3296 try {
3297 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003298 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003299 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003300 } catch (ImsException e) {
3301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 } finally {
3303 Binder.restoreCallingIdentity(identity);
3304 }
3305 }
3306
3307 @Override
3308 public int getVoWiFiModeSetting(int subId) {
3309 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003313 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003314 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003315 } catch (ImsException e) {
3316 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
3320 }
3321
3322 @Override
3323 public void setVoWiFiModeSetting(int subId, int mode) {
3324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3325 "setVoWiFiModeSetting");
3326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003329 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003330 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003331 } catch (ImsException e) {
3332 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
3336 }
3337
3338 @Override
3339 public int getVoWiFiRoamingModeSetting(int subId) {
3340 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003344 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003346 } catch (ImsException e) {
3347 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003348 } finally {
3349 Binder.restoreCallingIdentity(identity);
3350 }
3351 }
3352
3353 @Override
3354 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3356 "setVoWiFiRoamingModeSetting");
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003360 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003361 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003362 } catch (ImsException e) {
3363 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003364 } finally {
3365 Binder.restoreCallingIdentity(identity);
3366 }
3367 }
3368
3369 @Override
3370 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3372 "setRttCapabilityEnabled");
3373 final long identity = Binder.clearCallingIdentity();
3374 try {
3375 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003376 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3377 } catch (ImsException e) {
3378 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003379 } finally {
3380 Binder.restoreCallingIdentity(identity);
3381 }
3382 }
3383
3384 @Override
3385 public boolean isTtyOverVolteEnabled(int subId) {
3386 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003390 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003392 } catch (ImsException e) {
3393 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 } finally {
3395 Binder.restoreCallingIdentity(identity);
3396 }
3397 }
3398
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003399 @Override
3400 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3401 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003405 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003406 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003407 } catch (ImsException e) {
3408 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003409 } finally {
3410 Binder.restoreCallingIdentity(identity);
3411 }
3412 }
3413
3414 @Override
3415 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3416 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3417 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003418 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3419 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3420 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003421 try {
3422 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003424 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003425 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003426 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3427 + "is inactive, ignoring unregister.");
3428 // If the subscription is no longer active, just return, since the callback will already
3429 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
3433 }
3434
3435 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003436 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3437 boolean isProvisioned) {
3438 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3439 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3440 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3441 }
3442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3443 "setProvisioningStatusForCapability");
3444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3447 Phone phone = getPhone(subId);
3448 if (phone == null) {
3449 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3450 + subId);
3451 return;
3452 }
3453 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3454 return;
3455 }
3456
3457 // this capability requires provisioning, route to the correct API.
3458 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3459 switch (capability) {
3460 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3461 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3462 ims.setVolteProvisioned(isProvisioned);
3463 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3464 ims.setWfcProvisioned(isProvisioned);
3465 }
3466 break;
3467 }
3468 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3469 // There is currently no difference in VT provisioning type.
3470 ims.setVtProvisioned(isProvisioned);
3471 break;
3472 }
3473 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3474 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3475 // change the capability of the feature instead if needed.
3476 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3477 == isProvisioned) {
3478 // No change in provisioning.
3479 return;
3480 }
3481 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3482 try {
3483 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003484 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003485 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3486 + ", Exception" + e.getMessage());
3487 }
3488 break;
3489 }
3490 default: {
3491 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3492 + capability + "', which does not require provisioning.");
3493 }
3494 }
3495
3496 } finally {
3497 Binder.restoreCallingIdentity(identity);
3498 }
3499 }
3500
3501 @Override
3502 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3503 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3504 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3505 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3506 }
3507 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3511 Phone phone = getPhone(subId);
3512 if (phone == null) {
3513 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3514 + subId);
3515 // We will fail with "true" as the provisioning status because this is the default
3516 // if we do not require provisioning.
3517 return true;
3518 }
3519
3520 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3521 return true;
3522 }
3523
3524 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3525 switch (capability) {
3526 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3527 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3528 return ims.isVolteProvisionedOnDevice();
3529 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3530 return ims.isWfcProvisionedOnDevice();
3531 }
3532 // This should never happen, since we are checking tech above to make sure it
3533 // is either LTE or IWLAN.
3534 throw new IllegalArgumentException("Invalid radio technology for voice "
3535 + "capability.");
3536 }
3537 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3538 // There is currently no difference in VT provisioning type.
3539 return ims.isVtProvisionedOnDevice();
3540 }
3541 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3542 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3543 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3544 }
3545 default: {
3546 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3547 + capability + "', which does not require provisioning.");
3548 }
3549 }
3550
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
3554 }
3555
3556 @Override
3557 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3558 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3559 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3560 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3561 }
3562 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3563 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3564 return (provisionedBits & capability) > 0;
3565 }
3566
3567 @Override
3568 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3569 boolean isProvisioned) {
3570 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3571 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3572 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3573 }
3574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3575 "setProvisioningStatusForCapability");
3576 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3577 // If the current provisioning status for capability already matches isProvisioned,
3578 // do nothing.
3579 if (((provisionedBits & capability) > 0) == isProvisioned) {
3580 return;
3581 }
3582 if (isProvisioned) {
3583 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3584 } else {
3585 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3586 }
3587 }
3588
3589 /**
3590 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3591 * technology. The bitfield should mirror the bitfield defined by
3592 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3593 */
3594 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3595 String key = getMmTelProvisioningKey(subId, tech);
3596 // Default is no capabilities are provisioned.
3597 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3598 }
3599
3600 /**
3601 * Sets the MmTel capability provisioning bitfield (defined by
3602 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3603 * technology specified.
3604 *
3605 * Note: This is a synchronous command and should not be called on UI thread.
3606 */
3607 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3608 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3609 String key = getMmTelProvisioningKey(subId, tech);
3610 editor.putInt(key, newField);
3611 editor.commit();
3612 }
3613
3614 private static String getMmTelProvisioningKey(int subId, int tech) {
3615 // resulting key is provision_ims_mmtel_{subId}_{tech}
3616 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3617 }
3618
3619 /**
3620 * Query CarrierConfig to see if the specified capability requires provisioning for the
3621 * carrier associated with the subscription id.
3622 */
3623 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3624 int capability) {
3625 CarrierConfigManager configManager = new CarrierConfigManager(context);
3626 PersistableBundle c = configManager.getConfigForSubId(subId);
3627 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003628 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003629 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3630 false);
3631 boolean requireVoiceVtProvisioning = c.getBoolean(
3632 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3633
3634 // First check to make sure that the capability requires provisioning.
3635 switch (capability) {
3636 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3637 // intentional fallthrough
3638 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3639 if (requireVoiceVtProvisioning) {
3640 // Voice and Video requires provisioning
3641 return true;
3642 }
3643 break;
3644 }
3645 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3646 if (requireUtProvisioning) {
3647 // UT requires provisioning
3648 return true;
3649 }
3650 break;
3651 }
3652 }
3653 return false;
3654 }
3655
3656 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003657 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003658 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3659 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3660 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003661 enforceReadPrivilegedPermission("getImsProvisioningInt");
3662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003665 int slotId = getSlotIndex(subId);
3666 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3667 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3668 + subId + "' for key:" + key);
3669 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3670 }
3671 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003672 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003673 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3674 + subId + "' for key:" + key);
3675 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
3679 }
3680
3681 @Override
3682 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003683 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3684 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3685 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003686 enforceReadPrivilegedPermission("getImsProvisioningString");
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003690 int slotId = getSlotIndex(subId);
3691 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3692 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3693 + subId + "' for key:" + key);
3694 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3695 }
3696 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003697 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003698 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3699 + subId + "' for key:" + key);
3700 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
3704 }
3705
3706 @Override
3707 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003708 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3709 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3710 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3712 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003716 int slotId = getSlotIndex(subId);
3717 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3718 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3719 + subId + "' for key:" + key);
3720 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3721 }
3722 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003723 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003724 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3725 + "' for key:" + key);
3726 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
3730 }
3731
3732 @Override
3733 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3735 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3736 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3738 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003742 int slotId = getSlotIndex(subId);
3743 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3744 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3745 + subId + "' for key:" + key);
3746 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3747 }
3748 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003749 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003750 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3751 + "' for key:" + key);
3752 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
3756 }
3757
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003759 int slotId = SubscriptionManager.getSlotIndex(subId);
3760 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003761 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3762 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 }
3764 return slotId;
3765 }
3766
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003767 private int getSlotIndex(int subId) {
3768 int slotId = SubscriptionManager.getSlotIndex(subId);
3769 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3770 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3771 }
3772 return slotId;
3773 }
3774
Wink Saville36469e72014-06-11 15:17:00 -07003775 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003776 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003777 */
3778 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003779 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003780 final int targetSdk = getTargetSdk(callingPackage);
3781 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3782 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3783 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003784 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3785 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003786 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3787 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 final Phone phone = getPhone(subId);
3792 if (phone != null) {
3793 return phone.getServiceState().getDataNetworkType();
3794 } else {
3795 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3796 }
3797 } finally {
3798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003800 }
3801
3802 /**
3803 * Returns the data network type
3804 */
3805 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003806 public int getDataNetworkType(String callingPackage) {
3807 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003808 }
3809
3810 /**
3811 * Returns the data network type for a subId
3812 */
3813 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003814 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003815 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003816 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003817 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3818 }
3819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 final Phone phone = getPhone(subId);
3823 if (phone != null) {
3824 return phone.getServiceState().getDataNetworkType();
3825 } else {
3826 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3827 }
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003831 }
3832
3833 /**
Wink Saville36469e72014-06-11 15:17:00 -07003834 * Returns the Voice network type for a subId
3835 */
3836 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003837 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003838 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003839 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003840 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3841 }
3842
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003843 final long identity = Binder.clearCallingIdentity();
3844 try {
3845 final Phone phone = getPhone(subId);
3846 if (phone != null) {
3847 return phone.getServiceState().getVoiceNetworkType();
3848 } else {
3849 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3850 }
3851 } finally {
3852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003854 }
3855
3856 /**
3857 * @return true if a ICC card is present
3858 */
3859 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003860 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003861 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3862 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003863 }
3864
3865 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003866 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003868 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003869 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 final Phone phone = PhoneFactory.getPhone(slotIndex);
3873 if (phone != null) {
3874 return phone.getIccCard().hasIccCard();
3875 } else {
3876 return false;
3877 }
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003881 }
3882
3883 /**
3884 * Return if the current radio is LTE on CDMA. This
3885 * is a tri-state return value as for a period of time
3886 * the mode may be unknown.
3887 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003888 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003889 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003890 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003891 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003892 @Override
3893 public int getLteOnCdmaMode(String callingPackage) {
3894 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003895 }
3896
Sanket Padawe356d7632015-06-22 14:03:32 -07003897 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003898 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003900 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003901 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3902 }
3903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 final Phone phone = getPhone(subId);
3907 if (phone == null) {
3908 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3909 } else {
3910 return phone.getLteOnCdmaMode();
3911 }
3912 } finally {
3913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003914 }
Wink Saville36469e72014-06-11 15:17:00 -07003915 }
3916
Wink Saville36469e72014-06-11 15:17:00 -07003917 /**
3918 * {@hide}
3919 * Returns Default subId, 0 in the case of single standby.
3920 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003921 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003922 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003923 }
3924
Shishir Agrawala9f32182016-04-12 12:00:16 -07003925 private int getSlotForDefaultSubscription() {
3926 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3927 }
3928
Wink Savilleb564aae2014-10-23 10:18:09 -07003929 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003930 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003931 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003932
Pengquan Menge92a50d2018-09-21 15:54:48 -07003933 private boolean isActiveSubscription(int subId) {
3934 return mSubscriptionController.isActiveSubId(subId);
3935 }
3936
Ihab Awadf2177b72013-11-25 13:33:23 -08003937 /**
3938 * @see android.telephony.TelephonyManager.WifiCallingChoices
3939 */
3940 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 final long identity = Binder.clearCallingIdentity();
3942 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003943 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3945 getWhenToMakeWifiCallsDefaultPreference());
3946 } finally {
3947 Binder.restoreCallingIdentity(identity);
3948 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003949 }
3950
3951 /**
3952 * @see android.telephony.TelephonyManager.WifiCallingChoices
3953 */
3954 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003958 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
3962 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003963 }
3964
Sailesh Nepald1e68152013-12-12 19:08:02 -08003965 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003966 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003967 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003968 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003969
Jordan Liu4c733742019-02-28 12:03:40 -08003970 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3971 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3972 if (phoneId == -1) {
3973 throw new IllegalArgumentException("Given slot index: " + slotIndex
3974 + " does not correspond to an active phone");
3975 }
3976 return PhoneFactory.getPhone(phoneId);
3977 }
3978
Shishir Agrawal566b7612013-10-28 14:41:00 -07003979 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003980 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3981 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3983 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003985 if (DBG) {
3986 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3987 }
3988 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3989 p2);
3990 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003991
Jordan Liu4c733742019-02-28 12:03:40 -08003992
3993 @Override
3994 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3995 int slotIndex, String callingPackage, String aid, int p2) {
3996 enforceModifyPermission();
3997 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3998 if (DBG) {
3999 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4000 }
4001 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4002 callingPackage, aid, p2);
4003 }
4004
4005 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4006 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 final long identity = Binder.clearCallingIdentity();
4008 try {
4009 if (TextUtils.equals(ISDR_AID, aid)) {
4010 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004011 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4012 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 if (bestComponent == null
4014 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4015 loge("The calling package is not allowed to access ISD-R.");
4016 throw new SecurityException(
4017 "The calling package is not allowed to access ISD-R.");
4018 }
Derek Tan740e1672017-06-27 14:56:27 -07004019 }
Derek Tan740e1672017-06-27 14:56:27 -07004020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004022 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4023 null /* workSource */);
4024 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025 return response;
4026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004029 }
4030
4031 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004032 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4034 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004035 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4036 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4037 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004038
Jordan Liu4c733742019-02-28 12:03:40 -08004039 @Override
4040 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4041 enforceModifyPermission();
4042 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4043 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4044 channel);
4045 }
4046
4047 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048 final long identity = Binder.clearCallingIdentity();
4049 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 if (channel < 0) {
4051 return false;
4052 }
Jordan Liu4c733742019-02-28 12:03:40 -08004053 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4054 null /* workSource */);
4055 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 return success;
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004059 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004060 }
4061
4062 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004063 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004064 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4066 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004067 if (DBG) {
4068 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4069 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4070 + p3 + " data=" + data);
4071 }
4072 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4073 command, p1, p2, p3, data);
4074 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004075
Jordan Liu4c733742019-02-28 12:03:40 -08004076 @Override
4077 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4078 int command, int p1, int p2, int p3, String data) {
4079 enforceModifyPermission();
4080 if (DBG) {
4081 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4082 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4083 + p3 + " data=" + data);
4084 }
4085 return iccTransmitApduLogicalChannelWithPermission(
4086 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4087 data);
4088 }
4089
4090 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4091 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 final long identity = Binder.clearCallingIdentity();
4093 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004094 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 return "";
4096 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004099 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4100 null /* workSource */);
4101 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103 // Append the returned status code to the end of the response payload.
4104 String s = Integer.toHexString(
4105 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4106 if (response.payload != null) {
4107 s = IccUtils.bytesToHexString(response.payload) + s;
4108 }
4109 return s;
4110 } finally {
4111 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004112 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004113 }
Jake Hambye994d462014-02-03 13:10:13 -08004114
Evan Charltonc66da362014-05-16 14:06:40 -07004115 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004116 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4117 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4119 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004121 if (DBG) {
4122 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4123 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4124 }
4125 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4126 cla, command, p1, p2, p3, data);
4127 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004128
Jordan Liu4c733742019-02-28 12:03:40 -08004129 @Override
4130 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4131 int command, int p1, int p2, int p3, String data) {
4132 enforceModifyPermission();
4133 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4134 if (DBG) {
4135 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4136 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4137 + " data=" + data);
4138 }
4139
4140 return iccTransmitApduBasicChannelWithPermission(
4141 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4142 p2, p3, data);
4143 }
4144
4145 // open APDU basic channel assuming the caller has sufficient permissions
4146 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4147 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4151 && TextUtils.equals(ISDR_AID, data)) {
4152 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004153 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4154 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004155 if (bestComponent == null
4156 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4157 loge("The calling package is not allowed to select ISD-R.");
4158 throw new SecurityException(
4159 "The calling package is not allowed to select ISD-R.");
4160 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004161 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004164 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4165 null /* workSource */);
4166 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004168 // Append the returned status code to the end of the response payload.
4169 String s = Integer.toHexString(
4170 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4171 if (response.payload != null) {
4172 s = IccUtils.bytesToHexString(response.payload) + s;
4173 }
4174 return s;
4175 } finally {
4176 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004177 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004178 }
4179
4180 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004181 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004182 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4184 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 if (DBG) {
4189 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4190 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4191 }
4192
4193 IccIoResult response =
4194 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4195 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4196 subId);
4197
4198 if (DBG) {
4199 log("Exchange SIM_IO [R]" + response);
4200 }
4201
4202 byte[] result = null;
4203 int length = 2;
4204 if (response.payload != null) {
4205 length = 2 + response.payload.length;
4206 result = new byte[length];
4207 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4208 } else {
4209 result = new byte[length];
4210 }
4211
4212 result[length - 1] = (byte) response.sw2;
4213 result[length - 2] = (byte) response.sw1;
4214 return result;
4215 } finally {
4216 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004217 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004218 }
4219
Nathan Haroldb3014052017-01-25 15:57:32 -08004220 /**
4221 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4222 * on a particular subscription
4223 */
sqianb6e41952018-03-12 14:54:01 -07004224 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4226 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4227 return null;
4228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229
4230 final long identity = Binder.clearCallingIdentity();
4231 try {
4232 if (appType != TelephonyManager.APPTYPE_USIM
4233 && appType != TelephonyManager.APPTYPE_SIM) {
4234 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4235 return null;
4236 }
4237 Object response = sendRequest(
4238 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4239 if (response instanceof String[]) {
4240 return (String[]) response;
4241 }
yincheng zhaod698b842019-09-06 17:06:54 -07004242 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004243 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004244 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004247 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004248 }
4249
yincheng zhaod698b842019-09-06 17:06:54 -07004250 /**
4251 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4252 * subscription.
4253 *
4254 * @param subId the id of the subscription.
4255 * @param appType the uicc app type, must be USIM or SIM.
4256 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4257 * @param callingPackage the op Package name.
4258 * @return number of fplmns that is successfully written to the SIM.
4259 */
4260 public int setForbiddenPlmns(
4261 int subId, int appType, List<String> fplmns, String callingPackage) {
4262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4263 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4264 if (DBG) logv("no permissions for setForbiddenplmns");
4265 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4266 }
4267 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4268 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4269 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4270 }
4271 if (fplmns == null) {
4272 throw new IllegalArgumentException("Fplmn List provided is null");
4273 }
4274 for (String fplmn : fplmns) {
4275 if (!CellIdentity.isValidPlmn(fplmn)) {
4276 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4277 }
4278 }
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 Object response = sendRequest(
4282 CMD_SET_FORBIDDEN_PLMNS,
4283 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4284 subId);
4285 return (int) response;
4286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
4289 }
4290
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004291 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004292 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4294 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 final long identity = Binder.clearCallingIdentity();
4297 try {
4298 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4299 if (response.payload == null) {
4300 return "";
4301 }
Evan Charltonc66da362014-05-16 14:06:40 -07004302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303 // Append the returned status code to the end of the response payload.
4304 String s = Integer.toHexString(
4305 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4306 s = IccUtils.bytesToHexString(response.payload) + s;
4307 return s;
4308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
Evan Charltonc66da362014-05-16 14:06:40 -07004311 }
4312
Jake Hambye994d462014-02-03 13:10:13 -08004313 /**
4314 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4315 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4316 *
4317 * @param itemID the ID of the item to read
4318 * @return the NV item as a String, or null on error.
4319 */
4320 @Override
4321 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4324 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325
4326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004329 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4331 return value;
4332 } finally {
4333 Binder.restoreCallingIdentity(identity);
4334 }
Jake Hambye994d462014-02-03 13:10:13 -08004335 }
4336
4337 /**
4338 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4339 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4340 *
4341 * @param itemID the ID of the item to read
4342 * @param itemValue the value to write, as a String
4343 * @return true on success; false on any failure
4344 */
4345 @Override
4346 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004347 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4349 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350
4351 final long identity = Binder.clearCallingIdentity();
4352 try {
4353 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4354 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004355 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4357 return success;
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
Jake Hambye994d462014-02-03 13:10:13 -08004361 }
4362
4363 /**
4364 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4365 * Used for device configuration by some CDMA operators.
4366 *
4367 * @param preferredRoamingList byte array containing the new PRL
4368 * @return true on success; false on any failure
4369 */
4370 @Override
4371 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4373 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374
4375 final long identity = Binder.clearCallingIdentity();
4376 try {
4377 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4378 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4379 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4380 return success;
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
Jake Hambye994d462014-02-03 13:10:13 -08004384 }
4385
4386 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004387 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004388 * Used for device configuration by some CDMA operators.
4389 *
chen xu6dac5ab2018-10-26 17:39:23 -07004390 * @param slotIndex - device slot.
4391 *
Jake Hambye994d462014-02-03 13:10:13 -08004392 * @return true on success; false on any failure
4393 */
4394 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004395 public boolean resetModemConfig(int slotIndex) {
4396 Phone phone = PhoneFactory.getPhone(slotIndex);
4397 if (phone != null) {
4398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4399 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400
chen xu6dac5ab2018-10-26 17:39:23 -07004401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4404 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4405 return success;
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 }
chen xu6dac5ab2018-10-26 17:39:23 -07004410 return false;
4411 }
4412
4413 /**
4414 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4415 *
4416 * @param slotIndex - device slot.
4417 *
4418 * @return true on success; false on any failure
4419 */
4420 @Override
4421 public boolean rebootModem(int slotIndex) {
4422 Phone phone = PhoneFactory.getPhone(slotIndex);
4423 if (phone != null) {
4424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4425 mApp, phone.getSubId(), "rebootModem");
4426
4427 final long identity = Binder.clearCallingIdentity();
4428 try {
4429 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4430 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4431 return success;
4432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
4435 }
4436 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004437 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004438
Svet Ganovb320e182015-04-16 12:30:10 -07004439 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004440 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004442 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004443 return new String[0];
4444 }
4445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 final long identity = Binder.clearCallingIdentity();
4447 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004448 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
Wink Saville36469e72014-06-11 15:17:00 -07004452 }
4453
Brad Ebinger51f743a2017-01-23 13:50:20 -08004454 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004455 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4456 * {@link #disableIms(int)}.
4457 * @param slotIndex device slot.
4458 */
4459 public void resetIms(int slotIndex) {
4460 enforceModifyPermission();
4461
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
4464 if (mImsResolver == null) {
4465 // may happen if the does not support IMS.
4466 return;
4467 }
4468 mImsResolver.disableIms(slotIndex);
4469 mImsResolver.enableIms(slotIndex);
4470 } finally {
4471 Binder.restoreCallingIdentity(identity);
4472 }
4473 }
4474
4475 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004476 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4477 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004478 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004479 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004480 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481
4482 final long identity = Binder.clearCallingIdentity();
4483 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004484 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004485 // may happen if the device does not support IMS.
4486 return;
4487 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004488 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004489 } finally {
4490 Binder.restoreCallingIdentity(identity);
4491 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004492 }
4493
4494 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004495 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4496 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004497 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004498 public void disableIms(int slotId) {
4499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500
4501 final long identity = Binder.clearCallingIdentity();
4502 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004503 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004504 // may happen if the device does not support IMS.
4505 return;
4506 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004507 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004511 }
4512
4513 /**
4514 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4515 * feature or {@link null} if the service is not available. If the feature is available, the
4516 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4517 */
4518 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004519 IImsServiceFeatureCallback callback) {
4520 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521
4522 final long identity = Binder.clearCallingIdentity();
4523 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004524 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004525 // may happen if the device does not support IMS.
4526 return null;
4527 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004528 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004532 }
4533
4534 /**
4535 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4536 * feature during emergency calling or {@link null} if the service is not available. If the
4537 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4538 * listener for feature updates.
4539 */
4540 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004542
4543 final long identity = Binder.clearCallingIdentity();
4544 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004545 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004546 // may happen if the device does not support IMS.
4547 return null;
4548 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004549 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004553 }
4554
Brad Ebinger5f64b052017-12-14 14:26:15 -08004555 /**
4556 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004557 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004558 */
4559 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4560 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561
4562 final long identity = Binder.clearCallingIdentity();
4563 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004564 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004565 // may happen if the device does not support IMS.
4566 return null;
4567 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004568 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569 } finally {
4570 Binder.restoreCallingIdentity(identity);
4571 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004572 }
4573
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004574 /**
4575 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004576 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004577 */
4578 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4579 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004580
4581 final long identity = Binder.clearCallingIdentity();
4582 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004583 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004584 // may happen if the device does not support IMS.
4585 return null;
4586 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004587 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 } finally {
4589 Binder.restoreCallingIdentity(identity);
4590 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004591 }
4592
Brad Ebinger884c07b2018-02-15 16:17:40 -08004593 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004594 * Sets the ImsService Package Name that Telephony will bind to.
4595 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004596 * @param slotIndex the slot ID that the ImsService should bind for.
4597 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004598 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004599 * @param featureTypes An integer array of feature types associated with a packageName.
4600 * @param packageName The name of the package that the current configuration will be replaced
4601 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004602 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004603 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004604 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4605 int[] featureTypes, String packageName) {
4606 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4607 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4609 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004610 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004612 final long identity = Binder.clearCallingIdentity();
4613 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004614 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004615 // may happen if the device does not support IMS.
4616 return false;
4617 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004618 Map<Integer, String> featureConfig = new HashMap<>();
4619 for (int featureType : featureTypes) {
4620 featureConfig.put(featureType, packageName);
4621 }
4622 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4623 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 } finally {
4625 Binder.restoreCallingIdentity(identity);
4626 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004627 }
4628
4629 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004630 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004631 *
4632 * @param slotId The slot that the ImsService is associated with.
4633 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4634 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004635 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004636 * @return the package name of the ImsService configuration.
4637 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004638 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4639 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004640 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004641 TelephonyPermissions
4642 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4643 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4644 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 final long identity = Binder.clearCallingIdentity();
4647 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004648 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004649 // may happen if the device does not support IMS.
4650 return "";
4651 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004652 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004653 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4654 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 } finally {
4656 Binder.restoreCallingIdentity(identity);
4657 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004658 }
4659
Brad Ebinger77b832e2019-10-17 17:03:22 -07004660 /**
4661 * Get the MmTelFeature state associated with the requested subscription id.
4662 * @param subId The subscription that the MmTelFeature is associated with.
4663 * @param callback A callback with an integer containing the
4664 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4665 */
4666 @Override
4667 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4668 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4669 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4670 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4671 "IMS not available on device.");
4672 }
4673 final long token = Binder.clearCallingIdentity();
4674 try {
4675 int slotId = getSlotIndex(subId);
4676 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4677 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4678 + subId + "'");
4679 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4680 }
4681 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4682 try {
4683 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4684 } catch (RemoteException e) {
4685 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4686 + "Ignore");
4687 }
4688 });
4689 } finally {
4690 Binder.restoreCallingIdentity(token);
4691 }
4692 }
4693
Wink Saville36469e72014-06-11 15:17:00 -07004694 public void setImsRegistrationState(boolean registered) {
4695 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696
4697 final long identity = Binder.clearCallingIdentity();
4698 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004699 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700 } finally {
4701 Binder.restoreCallingIdentity(identity);
4702 }
Wink Saville36469e72014-06-11 15:17:00 -07004703 }
4704
4705 /**
Stuart Scott54788802015-03-30 13:18:01 -07004706 * Set the network selection mode to automatic.
4707 *
4708 */
4709 @Override
4710 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4712 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004713
Pengquan Menge92a50d2018-09-21 15:54:48 -07004714 if (!isActiveSubscription(subId)) {
4715 return;
4716 }
4717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 final long identity = Binder.clearCallingIdentity();
4719 try {
4720 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4721 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4722 } finally {
4723 Binder.restoreCallingIdentity(identity);
4724 }
Stuart Scott54788802015-03-30 13:18:01 -07004725 }
4726
Pengquan Mengea84e042018-09-20 14:57:26 -07004727 /**
4728 * Ask the radio to connect to the input network and change selection mode to manual.
4729 *
4730 * @param subId the id of the subscription.
4731 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4732 * the operator to attach to.
4733 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4734 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4735 * normal network selection next time.
4736 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004737 */
4738 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004739 public boolean setNetworkSelectionModeManual(
4740 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4742 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004743
4744 if (!isActiveSubscription(subId)) {
4745 return false;
4746 }
4747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004748 final long identity = Binder.clearCallingIdentity();
4749 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004750 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004751 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004752 if (DBG) {
4753 log("setNetworkSelectionModeManual: subId: " + subId
4754 + " operator: " + operatorInfo);
4755 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004756 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004760 }
4761
4762 /**
4763 * Scans for available networks.
4764 */
4765 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004766 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4768 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004769 LocationAccessPolicy.LocationPermissionResult locationResult =
4770 LocationAccessPolicy.checkLocationPermission(mApp,
4771 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4772 .setCallingPackage(callingPackage)
4773 .setCallingPid(Binder.getCallingPid())
4774 .setCallingUid(Binder.getCallingUid())
4775 .setMethod("getCellNetworkScanResults")
4776 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4777 .build());
4778 switch (locationResult) {
4779 case DENIED_HARD:
4780 throw new SecurityException("Not allowed to access scan results -- location");
4781 case DENIED_SOFT:
4782 return null;
4783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784
Pengquan Menga1bb6272018-09-06 09:59:22 -07004785 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786 try {
4787 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004788 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790 } finally {
4791 Binder.restoreCallingIdentity(identity);
4792 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004793 }
4794
4795 /**
yinxub1bed742017-04-17 11:45:04 -07004796 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004797 *
yinxub1bed742017-04-17 11:45:04 -07004798 * @param subId id of the subscription
4799 * @param request contains the radio access networks with bands/channels to scan
4800 * @param messenger callback messenger for scan results or errors
4801 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004802 * @return the id of the requested scan which can be used to stop the scan.
4803 */
4804 @Override
4805 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004806 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4808 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004809 LocationAccessPolicy.LocationPermissionResult locationResult =
4810 LocationAccessPolicy.checkLocationPermission(mApp,
4811 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4812 .setCallingPackage(callingPackage)
4813 .setCallingPid(Binder.getCallingPid())
4814 .setCallingUid(Binder.getCallingUid())
4815 .setMethod("requestNetworkScan")
4816 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4817 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004818 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004819 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004820 if (e != null) {
4821 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4822 throw e;
4823 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004824 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004825 return TelephonyScanManager.INVALID_SCAN_ID;
4826 }
4827 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004828 }
Hall Liu912dfd32019-04-25 14:02:26 -07004829 int callingUid = Binder.getCallingUid();
4830 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 return mNetworkScanRequestTracker.startNetworkScan(
4834 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004835 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004836 } finally {
4837 Binder.restoreCallingIdentity(identity);
4838 }
yinxu504e1392017-04-12 16:03:22 -07004839 }
4840
Hall Liub2ac8ef2019-02-28 15:56:23 -08004841 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004842 NetworkScanRequest request, int subId) {
4843 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4844 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4845 boolean hasNetworkScanPermission =
4846 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4847 == PERMISSION_GRANTED;
4848
4849 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4850 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4851 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004852 }
4853
4854 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4855 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004856 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4857 return new SecurityException("Specific channels must not be"
4858 + " scanned without location access.");
4859 }
4860 }
4861 }
4862
Hall Liub2ac8ef2019-02-28 15:56:23 -08004863 return null;
4864 }
4865
yinxu504e1392017-04-12 16:03:22 -07004866 /**
4867 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004868 *
4869 * @param subId id of the subscription
4870 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004871 */
4872 @Override
4873 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4875 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876
Hall Liu912dfd32019-04-25 14:02:26 -07004877 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878 final long identity = Binder.clearCallingIdentity();
4879 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004880 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881 } finally {
4882 Binder.restoreCallingIdentity(identity);
4883 }
yinxu504e1392017-04-12 16:03:22 -07004884 }
4885
4886 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004887 * Get the calculated preferred network type.
4888 * Used for debugging incorrect network type.
4889 *
4890 * @return the preferred network type, defined in RILConstants.java.
4891 */
4892 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004893 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004894 final Phone defaultPhone = getDefaultPhone();
4895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4896 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004897 return RILConstants.PREFERRED_NETWORK_MODE;
4898 }
4899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004900 final long identity = Binder.clearCallingIdentity();
4901 try {
4902 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004903 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 } finally {
4905 Binder.restoreCallingIdentity(identity);
4906 }
Junda Liu84d15a22014-07-02 11:21:04 -07004907 }
4908
4909 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004910 * Get the preferred network type.
4911 * Used for device configuration by some CDMA operators.
4912 *
4913 * @return the preferred network type, defined in RILConstants.java.
4914 */
4915 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004916 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004917 TelephonyPermissions
4918 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4919 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004920
4921 final long identity = Binder.clearCallingIdentity();
4922 try {
4923 if (DBG) log("getPreferredNetworkType");
4924 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4925 int networkType = (result != null ? result[0] : -1);
4926 if (DBG) log("getPreferredNetworkType: " + networkType);
4927 return networkType;
4928 } finally {
4929 Binder.restoreCallingIdentity(identity);
4930 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004931 }
4932
4933 /**
4934 * Set the preferred network type.
4935 * Used for device configuration by some CDMA operators.
4936 *
4937 * @param networkType the preferred network type, defined in RILConstants.java.
4938 * @return true on success; false on any failure.
4939 */
4940 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004941 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4943 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944
4945 final long identity = Binder.clearCallingIdentity();
4946 try {
4947 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4948 Boolean success = (Boolean) sendRequest(
4949 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4950 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4951 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004952 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4954 }
4955 return success;
4956 } finally {
4957 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004958 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004959 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004960
4961 /**
Miaoa84611c2019-03-15 09:21:10 +08004962 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004963 *
Miaoa84611c2019-03-15 09:21:10 +08004964 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004965 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004966 * @hide
4967 */
4968 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004969 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004970 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004972 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 try {
Miaoa84611c2019-03-15 09:21:10 +08004974 if (phone != null) {
4975 return phone.hasMatchedTetherApnSetting();
4976 } else {
4977 return false;
4978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004979 } finally {
4980 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004981 }
Junda Liu475951f2014-11-07 16:45:03 -08004982 }
4983
4984 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004985 * Set mobile data enabled
4986 * Used by the user through settings etc to turn on/off mobile data
4987 *
4988 * @param enable {@code true} turn turn data on, else {@code false}
4989 */
4990 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004991 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4993 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994
4995 final long identity = Binder.clearCallingIdentity();
4996 try {
4997 int phoneId = mSubscriptionController.getPhoneId(subId);
4998 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4999 Phone phone = PhoneFactory.getPhone(phoneId);
5000 if (phone != null) {
5001 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005002 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005004 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005 }
5006 } finally {
5007 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005008 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005009 }
5010
5011 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005012 * Get the user enabled state of Mobile Data.
5013 *
5014 * TODO: remove and use isUserDataEnabled.
5015 * This can't be removed now because some vendor codes
5016 * calls through ITelephony directly while they should
5017 * use TelephonyManager.
5018 *
5019 * @return true on enabled
5020 */
5021 @Override
5022 public boolean getDataEnabled(int subId) {
5023 return isUserDataEnabled(subId);
5024 }
5025
5026 /**
5027 * Get whether mobile data is enabled per user setting.
5028 *
5029 * There are other factors deciding whether mobile data is actually enabled, but they are
5030 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005031 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005032 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005033 *
5034 * @return {@code true} if data is enabled else {@code false}
5035 */
5036 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005037 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005038 try {
5039 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5040 null);
5041 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5043 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005044 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045
5046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 int phoneId = mSubscriptionController.getPhoneId(subId);
5049 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5050 Phone phone = PhoneFactory.getPhone(phoneId);
5051 if (phone != null) {
5052 boolean retVal = phone.isUserDataEnabled();
5053 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5054 return retVal;
5055 } else {
5056 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5057 return false;
5058 }
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005061 }
5062 }
5063
5064 /**
5065 * Get whether mobile data is enabled.
5066 *
5067 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5068 * whether mobile data is actually enabled.
5069 *
5070 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5071 *
5072 * @return {@code true} if data is enabled else {@code false}
5073 */
5074 @Override
5075 public boolean isDataEnabled(int subId) {
5076 try {
5077 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5078 null);
5079 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5081 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005082 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083
5084 final long identity = Binder.clearCallingIdentity();
5085 try {
5086 int phoneId = mSubscriptionController.getPhoneId(subId);
5087 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5088 Phone phone = PhoneFactory.getPhone(phoneId);
5089 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005090 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5092 return retVal;
5093 } else {
5094 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5095 return false;
5096 }
5097 } finally {
5098 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005099 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005100 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005101
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005102 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5103 Phone phone) {
5104 //load access rules from carrier configs, and check those as well: b/139133814
5105 SubscriptionController subController = SubscriptionController.getInstance();
5106 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5107 || subController == null) return privilegeFromSim;
5108
5109 int uid = Binder.getCallingUid();
5110 PackageManager pkgMgr = phone.getContext().getPackageManager();
5111 String[] packages = pkgMgr.getPackagesForUid(uid);
5112
5113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5116 SubscriptionManager subManager = (SubscriptionManager)
5117 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5118 for (String pkg : packages) {
5119 if (subManager.canManageSubscription(subInfo, pkg)) {
5120 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5121 }
5122 }
5123 return privilegeFromSim;
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
5126 }
5127 }
5128
5129 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5130 String pkgName) {
5131 //load access rules from carrier configs, and check those as well: b/139133814
5132 SubscriptionController subController = SubscriptionController.getInstance();
5133 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5134 || subController == null) return privilegeFromSim;
5135
5136 final long identity = Binder.clearCallingIdentity();
5137 try {
5138 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5139 SubscriptionManager subManager = (SubscriptionManager)
5140 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5141 return subManager.canManageSubscription(subInfo, pkgName)
5142 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5143 } finally {
5144 Binder.restoreCallingIdentity(identity);
5145 }
5146 }
5147
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005148 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005149 public int getCarrierPrivilegeStatus(int subId) {
5150 final Phone phone = getPhone(subId);
5151 if (phone == null) {
5152 loge("getCarrierPrivilegeStatus: Invalid subId");
5153 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5154 }
5155 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005156 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005157 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005158 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5159 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005160
5161 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5162 card.getCarrierPrivilegeStatusForCurrentTransaction(
5163 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005164 }
Junda Liu29340342014-07-10 15:23:27 -07005165
5166 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005167 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5168 final Phone phone = getPhone(subId);
5169 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005170 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005171 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5172 }
5173 UiccProfile profile =
5174 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5175 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005176 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005177 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5178 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005179 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5180 profile.getCarrierPrivilegeStatusForUid(
5181 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005182 }
5183
5184 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005185 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5186 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005187 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005188 }
5189
5190 int phoneId = SubscriptionManager.getPhoneId(subId);
5191 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005192 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005193 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005194 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5195 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005196 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5197 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5198 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005199 }
5200
5201 @Override
5202 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005203 if (TextUtils.isEmpty(pkgName))
5204 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005205 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5206 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5207 UiccCard card = UiccController.getInstance().getUiccCard(i);
5208 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005209 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005210 continue;
5211 }
5212
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005213 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5214 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5215 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005216 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5217 break;
5218 }
5219 }
5220
5221 return result;
Junda Liu29340342014-07-10 15:23:27 -07005222 }
Derek Tan89e89d42014-07-08 17:00:10 -07005223
5224 @Override
Junda Liue64de782015-04-16 17:19:16 -07005225 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5226 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5227 loge("phoneId " + phoneId + " is not valid.");
5228 return null;
5229 }
5230 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005231 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005232 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005233 return null ;
5234 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005235 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005236 }
5237
Amith Yamasani6e118872016-02-19 12:53:51 -08005238 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005239 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005240 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005241 List<String> privilegedPackages = new ArrayList<>();
5242 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005243 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5244 // has UICC in that slot.
5245 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005246 if (card.hasCarrierPrivilegeRules()) {
5247 if (packages == null) {
5248 // Only check packages in user 0 for now
5249 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005250 PackageManager.MATCH_DISABLED_COMPONENTS
5251 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005252 | PackageManager.GET_SIGNING_CERTIFICATES,
5253 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005254 }
5255 for (int p = packages.size() - 1; p >= 0; p--) {
5256 PackageInfo pkgInfo = packages.get(p);
5257 if (pkgInfo != null && pkgInfo.packageName != null
5258 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005259 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005260 privilegedPackages.add(pkgInfo.packageName);
5261 }
5262 }
5263 }
5264 }
5265 return privilegedPackages;
5266 }
5267
chen xuf7e9fe82019-05-09 19:31:02 -07005268 @Override
5269 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005270 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5271
5272 final long identity = Binder.clearCallingIdentity();
5273
chen xuf7e9fe82019-05-09 19:31:02 -07005274 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005275 try {
5276 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5277 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5278 }
5279 } finally {
5280 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005281 }
5282 return privilegedPackages;
5283 }
5284
Wink Savilleb564aae2014-10-23 10:18:09 -07005285 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005286 final Phone phone = getPhone(subId);
5287 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005288 if (card == null) {
5289 loge("getIccId: No UICC");
5290 return null;
5291 }
5292 String iccId = card.getIccId();
5293 if (TextUtils.isEmpty(iccId)) {
5294 loge("getIccId: ICC ID is null or empty.");
5295 return null;
5296 }
5297 return iccId;
5298 }
5299
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005300 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005301 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5302 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005303 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5304 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306 final long identity = Binder.clearCallingIdentity();
5307 try {
5308 final String iccId = getIccId(subId);
5309 final Phone phone = getPhone(subId);
5310 if (phone == null) {
5311 return false;
5312 }
5313 final String subscriberId = phone.getSubscriberId();
5314
5315 if (DBG_MERGE) {
5316 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5317 + subscriberId + " to " + number);
5318 }
5319
5320 if (TextUtils.isEmpty(iccId)) {
5321 return false;
5322 }
5323
5324 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5325
5326 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5327 if (alphaTag == null) {
5328 editor.remove(alphaTagPrefKey);
5329 } else {
5330 editor.putString(alphaTagPrefKey, alphaTag);
5331 }
5332
5333 // Record both the line number and IMSI for this ICCID, since we need to
5334 // track all merged IMSIs based on line number
5335 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5336 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5337 if (number == null) {
5338 editor.remove(numberPrefKey);
5339 editor.remove(subscriberPrefKey);
5340 } else {
5341 editor.putString(numberPrefKey, number);
5342 editor.putString(subscriberPrefKey, subscriberId);
5343 }
5344
5345 editor.commit();
5346 return true;
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005349 }
Derek Tan7226c842014-07-02 17:42:23 -07005350 }
5351
5352 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005353 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005354 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005356 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005357 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005358 return null;
5359 }
Derek Tan97ebb422014-09-05 16:55:38 -07005360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 final long identity = Binder.clearCallingIdentity();
5362 try {
5363 String iccId = getIccId(subId);
5364 if (iccId != null) {
5365 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5366 if (DBG_MERGE) {
5367 log("getLine1NumberForDisplay returning "
5368 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5369 }
5370 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5373 return null;
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005376 }
Derek Tan7226c842014-07-02 17:42:23 -07005377 }
5378
5379 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005380 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005382 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005383 return null;
5384 }
Derek Tan97ebb422014-09-05 16:55:38 -07005385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
5388 String iccId = getIccId(subId);
5389 if (iccId != null) {
5390 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5391 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5392 }
5393 return null;
5394 } finally {
5395 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005396 }
Derek Tan7226c842014-07-02 17:42:23 -07005397 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005398
5399 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005400 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005401 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5402 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005404 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5405 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005406 return null;
5407 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005408
Jordan Liub49b04b2019-05-06 14:45:15 -07005409 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5410 // the process, where TelephonyManager was instantiated.
5411 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005412 final long identity = Binder.clearCallingIdentity();
5413 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005414 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 final TelephonyManager tele = TelephonyManager.from(context);
5416 final SubscriptionManager sub = SubscriptionManager.from(context);
5417
5418 // Figure out what subscribers are currently active
5419 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005420
Jordan Liub49b04b2019-05-06 14:45:15 -07005421 // Only consider subs which match the current subId
5422 // This logic can be simplified. See b/131189269 for progress.
5423 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005424 activeSubscriberIds.add(tele.getSubscriberId(subId));
5425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426
5427 // First pass, find a number override for an active subscriber
5428 String mergeNumber = null;
5429 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5430 for (String key : prefs.keySet()) {
5431 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5432 final String subscriberId = (String) prefs.get(key);
5433 if (activeSubscriberIds.contains(subscriberId)) {
5434 final String iccId = key.substring(
5435 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5436 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5437 mergeNumber = (String) prefs.get(numberKey);
5438 if (DBG_MERGE) {
5439 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5440 + " for active subscriber " + subscriberId);
5441 }
5442 if (!TextUtils.isEmpty(mergeNumber)) {
5443 break;
5444 }
5445 }
5446 }
5447 }
5448
5449 // Shortcut when no active merged subscribers
5450 if (TextUtils.isEmpty(mergeNumber)) {
5451 return null;
5452 }
5453
5454 // Second pass, find all subscribers under that line override
5455 final ArraySet<String> result = new ArraySet<>();
5456 for (String key : prefs.keySet()) {
5457 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5458 final String number = (String) prefs.get(key);
5459 if (mergeNumber.equals(number)) {
5460 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5461 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5462 final String subscriberId = (String) prefs.get(subscriberKey);
5463 if (!TextUtils.isEmpty(subscriberId)) {
5464 result.add(subscriberId);
5465 }
5466 }
5467 }
5468 }
5469
5470 final String[] resultArray = result.toArray(new String[result.size()]);
5471 Arrays.sort(resultArray);
5472 if (DBG_MERGE) {
5473 Slog.d(LOG_TAG,
5474 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5475 }
5476 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005477 } finally {
5478 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005479 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005480 }
5481
5482 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005483 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5484 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5485
5486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 final TelephonyManager telephonyManager = mApp.getSystemService(
5489 TelephonyManager.class);
5490 String subscriberId = telephonyManager.getSubscriberId(subId);
5491 if (subscriberId == null) {
5492 if (DBG) {
5493 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5494 + subId);
5495 }
5496 return null;
5497 }
5498
5499 final SubscriptionInfo info = SubscriptionController.getInstance()
5500 .getSubscriptionInfo(subId);
5501 final ParcelUuid groupUuid = info.getGroupUuid();
5502 // If it doesn't belong to any group, return just subscriberId of itself.
5503 if (groupUuid == null) {
5504 return new String[]{subscriberId};
5505 }
5506
5507 // Get all subscriberIds from the group.
5508 final List<String> mergedSubscriberIds = new ArrayList<>();
5509 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5510 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5511 for (SubscriptionInfo subInfo : groupInfos) {
5512 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5513 if (subscriberId != null) {
5514 mergedSubscriberIds.add(subscriberId);
5515 }
5516 }
5517
5518 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5519 } finally {
5520 Binder.restoreCallingIdentity(identity);
5521
5522 }
5523 }
5524
5525 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005526 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005527 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5528 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529
5530 final long identity = Binder.clearCallingIdentity();
5531 try {
5532 final Phone phone = getPhone(subId);
5533 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005537 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005538
5539 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005540 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005541 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5542 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005543 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544
5545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 final Phone phone = getPhone(subId);
5548 if (phone == null) {
5549 return false;
5550 }
5551 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5552 cdmaNonRoamingList);
5553 } finally {
5554 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005555 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005556 }
5557
5558 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005559 @Deprecated
5560 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5561 enforceModifyPermission();
5562
5563 int returnValue = 0;
5564 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005565 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005566 if(result.exception == null) {
5567 if (result.result != null) {
5568 byte[] responseData = (byte[])(result.result);
5569 if(responseData.length > oemResp.length) {
5570 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5571 responseData.length + "bytes. Buffer Size is " +
5572 oemResp.length + "bytes.");
5573 }
5574 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5575 returnValue = responseData.length;
5576 }
5577 } else {
5578 CommandException ex = (CommandException) result.exception;
5579 returnValue = ex.getCommandError().ordinal();
5580 if(returnValue > 0) returnValue *= -1;
5581 }
5582 } catch (RuntimeException e) {
5583 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5584 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5585 if(returnValue > 0) returnValue *= -1;
5586 }
5587
5588 return returnValue;
5589 }
5590
5591 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005592 public void setRadioCapability(RadioAccessFamily[] rafs) {
5593 try {
5594 ProxyController.getInstance().setRadioCapability(rafs);
5595 } catch (RuntimeException e) {
5596 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5597 }
5598 }
5599
5600 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005601 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005602 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005603 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005604 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005605 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 final long identity = Binder.clearCallingIdentity();
5608 try {
chen xub97461a2018-10-26 14:17:57 -07005609 TelephonyPermissions
5610 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5611 mApp, phone.getSubId(), "getRadioAccessFamily");
5612 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613 } finally {
5614 Binder.restoreCallingIdentity(identity);
5615 }
chen xub97461a2018-10-26 14:17:57 -07005616 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005617 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005618
5619 @Override
5620 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005621 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005622 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623
5624 final long identity = Binder.clearCallingIdentity();
5625 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005626 ImsManager.getInstance(defaultPhone.getContext(),
5627 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 } finally {
5629 Binder.restoreCallingIdentity(identity);
5630 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005631 }
5632
5633 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005634 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005635 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005637 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005638 return false;
5639 }
Svet Ganovb320e182015-04-16 12:30:10 -07005640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 // Check the user preference and the system-level IMS setting. Even if the user has
5644 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5645 // In the long run, we may instead need to check if there exists a connection service
5646 // which can support video calling.
5647 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005648 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 return imsManager.isVtEnabledByPlatform()
5650 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5651 && imsManager.isVtEnabledByUser();
5652 } finally {
5653 Binder.restoreCallingIdentity(identity);
5654 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005655 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005656
Andrew Leea1239f22015-03-02 17:44:07 -08005657 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5660 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5661 return false;
5662 }
5663
5664 final long identity = Binder.clearCallingIdentity();
5665 try {
5666 CarrierConfigManager configManager =
5667 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005668 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5670 } finally {
5671 Binder.restoreCallingIdentity(identity);
5672 }
Andrew Leea1239f22015-03-02 17:44:07 -08005673 }
5674
5675 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 public boolean isWorldPhone(int subId, String callingPackage) {
5677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5678 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5679 return false;
5680 }
5681
5682 final long identity = Binder.clearCallingIdentity();
5683 try {
5684 CarrierConfigManager configManager =
5685 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005686 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5688 } finally {
5689 Binder.restoreCallingIdentity(identity);
5690 }
Andrew Leea1239f22015-03-02 17:44:07 -08005691 }
5692
Andrew Lee9431b832015-03-09 18:46:45 -07005693 @Override
5694 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005695 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005696 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005697 }
5698
5699 @Override
5700 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 final long identity = Binder.clearCallingIdentity();
5702 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005703 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
Andrew Lee9431b832015-03-09 18:46:45 -07005707 }
5708
Hall Liuf6668912018-10-31 17:05:23 -07005709 /**
5710 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5711 * support for the feature and device firmware support.
5712 *
5713 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5714 */
5715 @Override
5716 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005718 final Phone phone = getPhone(subscriptionId);
5719 if (phone == null) {
5720 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5721 return false;
5722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005724 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5726 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005727 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 return isCarrierSupported && isDeviceSupported;
5729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Hall Liu98187582018-01-22 19:15:32 -08005732 }
5733
Hall Liuf6668912018-10-31 17:05:23 -07005734 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005735 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5736 * RTT setting, will return true if the device and carrier both support RTT.
5737 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005738 */
5739 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 final long identity = Binder.clearCallingIdentity();
5741 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005742 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005746 }
5747
Sanket Padawe7310cc72015-01-14 09:53:20 -08005748 /**
5749 * Returns the unique device ID of phone, for example, the IMEI for
5750 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5751 *
5752 * <p>Requires Permission:
5753 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5754 */
5755 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005756 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005757 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005758 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005759 return null;
5760 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005761 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005762 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5763 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005764 return null;
5765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 return phone.getDeviceId();
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005773 }
5774
Ping Sunc67b7c22016-03-02 19:16:45 +08005775 /**
5776 * {@hide}
5777 * Returns the IMS Registration Status on a particular subid
5778 *
5779 * @param subId
5780 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005781 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005782 Phone phone = getPhone(subId);
5783 if (phone != null) {
5784 return phone.isImsRegistered();
5785 } else {
5786 return false;
5787 }
5788 }
5789
Santos Cordon7a1885b2015-02-03 11:15:19 -08005790 @Override
5791 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005798 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005799
Tyler Gunnf70ed162019-04-03 15:28:53 -07005800 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005801 public int getSubIdForPhoneAccountHandle(
5802 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5804 callingPackage, "getSubIdForPhoneAccountHandle")) {
5805 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5806 }
5807 final long identity = Binder.clearCallingIdentity();
5808 try {
5809 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5810 } finally {
5811 Binder.restoreCallingIdentity(identity);
5812 }
5813 }
5814
5815 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005816 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5817 final long identity = Binder.clearCallingIdentity();
5818 try {
5819 Phone phone = getPhone(subscriptionId);
5820 if (phone == null) {
5821 return null;
5822 }
5823 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5824 } finally {
5825 Binder.restoreCallingIdentity(identity);
5826 }
5827 }
5828
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005829 /**
5830 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005831 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005832 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 final long identity = Binder.clearCallingIdentity();
5834 try {
5835 Phone phone = getPhone(subId);
5836 if (phone != null) {
5837 return phone.isWifiCallingEnabled();
5838 } else {
5839 return false;
5840 }
5841 } finally {
5842 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005843 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005844 }
5845
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005846 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005847 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005848 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005849 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 Phone phone = getPhone(subId);
5853 if (phone != null) {
5854 return phone.isVideoEnabled();
5855 } else {
5856 return false;
5857 }
5858 } finally {
5859 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005860 }
5861 }
5862
5863 /**
5864 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5865 * defined in {@link ImsRegistrationImplBase}.
5866 */
5867 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 final long identity = Binder.clearCallingIdentity();
5869 try {
5870 Phone phone = getPhone(subId);
5871 if (phone != null) {
5872 return phone.getImsRegistrationTech();
5873 } else {
5874 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5875 }
5876 } finally {
5877 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005878 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005879 }
5880
Stuart Scott8eef64f2015-04-08 15:13:54 -07005881 @Override
5882 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005883 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005884 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5885 return;
5886 }
5887
Svet Ganovcc087f82015-05-12 20:35:54 -07005888 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005889
Svet Ganovcc087f82015-05-12 20:35:54 -07005890 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005891 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5892 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005893 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005894 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005895 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005896 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5897 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005898 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005899 // There has been issues when Sms raw table somehow stores orphan
5900 // fragments. They lead to garbled message when new fragments come
5901 // in and combined with those stale ones. In case this happens again,
5902 // user can reset all network settings which will clean up this table.
5903 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005904 // Clean up IMS settings as well here.
5905 int slotId = getSlotIndex(subId);
5906 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5907 ImsManager.getInstance(mApp, slotId).factoryReset();
5908 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005909
5910 // Erase modem config if erase modem on network setting is enabled.
5911 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5912 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5913 if (configValue != null && Boolean.parseBoolean(configValue)) {
5914 sendEraseModemConfig(getDefaultPhone());
5915 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005916 } finally {
5917 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005918 }
5919 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005920
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005921 private void cleanUpSmsRawTable(Context context) {
5922 ContentResolver resolver = context.getContentResolver();
5923 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5924 resolver.delete(uri, null, null);
5925 }
5926
Narayan Kamath1c496c22015-04-16 14:40:19 +01005927 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005928 public String getSimLocaleForSubscriber(int subId) {
5929 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5930 final Phone phone = getPhone(subId);
5931 if (phone == null) {
5932 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005933 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 final long identity = Binder.clearCallingIdentity();
5936 try {
chen xu5d3637b2019-01-21 23:31:38 -08005937 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5938 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005939 if (info == null) {
5940 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5941 return null;
5942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 // Try and fetch the locale from the carrier properties or from the SIM language
5944 // preferences (EF-PL and EF-LI)...
5945 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005947 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5948 if (localeFromDefaultSim != null) {
5949 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5950 if (DBG) log("Using locale from subId: " + subId + " locale: "
5951 + localeFromDefaultSim);
5952 return localeFromDefaultSim.toLanguageTag();
5953 } else {
5954 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 }
5956 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 // The SIM language preferences only store a language (e.g. fr = French), not an
5959 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5960 // the SIM and carrier preferences does not include a country we add the country
5961 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08005962 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005964 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 return mccLocale.toLanguageTag();
5966 }
5967
5968 if (DBG) log("No locale found - returning null");
5969 return null;
5970 } finally {
5971 Binder.restoreCallingIdentity(identity);
5972 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005973 }
5974
5975 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005976 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005977 }
5978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 /**
5980 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5981 */
5982 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005983 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005984 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005985
Chenjie Yu1ba97252018-01-11 18:16:20 -08005986 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07005987 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005988
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005989 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005990 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5991 * representing the state of the modem.
5992 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005993 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5994 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005995 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005996 */
5997 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005998 public void requestModemActivityInfo(ResultReceiver result) {
5999 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001
6002 final long identity = Binder.clearCallingIdentity();
6003 try {
6004 ModemActivityInfo ret = null;
6005 synchronized (mLastModemActivityInfo) {
6006 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6007 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006008 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006009 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006011 int[] txTimeMs = info.getTransmitTimeMillis();
6012 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006014 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 }
6016 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006017 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6018 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 mLastModemActivityInfo.setIdleTimeMillis(
6020 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006021 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6022 mLastModemActivityInfo.setReceiveTimeMillis(
6023 info.getReceiveTimeMillis() + mLastModemActivityInfo
6024 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006025 }
Chen Xu13851032019-09-10 18:49:52 -07006026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6028 mLastModemActivityInfo.getSleepTimeMillis(),
6029 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006030 mLastModemActivityInfo.getTransmitTimeMillis(),
6031 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 Bundle bundle = new Bundle();
6034 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6035 result.send(0, bundle);
6036 } finally {
6037 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006038 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006039 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006040
Siddharth Rayb8114062018-06-17 15:02:38 -07006041 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6042 // less than total activity duration.
6043 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6044 if (info == null) {
6045 return false;
6046 }
6047 int activityDurationMs =
6048 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6049 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006050 int[] txTimeMs = info.getTransmitTimeMillis();
6051 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6052 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006053 }
6054 return (info.isValid()
6055 && (info.getSleepTimeMillis() <= activityDurationMs)
6056 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006057 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006058 && (totalTxTimeMs <= activityDurationMs));
6059 }
6060
Jack Yu85bd38a2015-11-09 11:34:32 -08006061 /**
6062 * {@hide}
6063 * Returns the service state information on specified subscription.
6064 */
6065 @Override
6066 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006068 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006069 return null;
6070 }
6071
Hall Liuf19c44f2018-11-27 14:38:17 -08006072 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6073 LocationAccessPolicy.checkLocationPermission(mApp,
6074 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6075 .setCallingPackage(callingPackage)
6076 .setCallingPid(Binder.getCallingPid())
6077 .setCallingUid(Binder.getCallingUid())
6078 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006079 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006080 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6081 .build());
6082
6083 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6084 LocationAccessPolicy.checkLocationPermission(mApp,
6085 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6086 .setCallingPackage(callingPackage)
6087 .setCallingPid(Binder.getCallingPid())
6088 .setCallingUid(Binder.getCallingUid())
6089 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006090 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006091 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6092 .build());
6093 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6094 boolean hasFinePermission =
6095 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6096 boolean hasCoarsePermission =
6097 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 final long identity = Binder.clearCallingIdentity();
6100 try {
6101 final Phone phone = getPhone(subId);
6102 if (phone == null) {
6103 return null;
6104 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006105
Hall Liuf19c44f2018-11-27 14:38:17 -08006106 ServiceState ss = phone.getServiceState();
6107
6108 // Scrub out the location info in ServiceState depending on what level of access
6109 // the caller has.
6110 if (hasFinePermission) return ss;
6111 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6112 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 } finally {
6114 Binder.restoreCallingIdentity(identity);
6115 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006116 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006117
6118 /**
6119 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6120 *
6121 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6122 * voicemail ringtone.
6123 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6124 * PhoneAccount.
6125 */
6126 @Override
6127 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 final long identity = Binder.clearCallingIdentity();
6129 try {
6130 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6131 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006132 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006139 }
6140
6141 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006142 * Sets the per-account voicemail ringtone.
6143 *
6144 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6145 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6146 *
6147 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6148 * voicemail ringtone.
6149 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6150 * PhoneAccount.
6151 */
6152 @Override
6153 public void setVoicemailRingtoneUri(String callingPackage,
6154 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006155 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006156 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006157 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6158 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6160 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6161 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163
6164 final long identity = Binder.clearCallingIdentity();
6165 try {
6166 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6167 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006168 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 }
6170 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006173 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006174 }
6175
6176 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006177 * Returns whether vibration is set for voicemail notification in Phone settings.
6178 *
6179 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6180 * voicemail vibration setting.
6181 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6182 */
6183 @Override
6184 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006185 final long identity = Binder.clearCallingIdentity();
6186 try {
6187 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6188 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006189 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6193 } finally {
6194 Binder.restoreCallingIdentity(identity);
6195 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006196 }
6197
Youhan Wange64578a2016-05-02 15:32:42 -07006198 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006199 * Sets the per-account voicemail vibration.
6200 *
6201 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6202 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6203 *
6204 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6205 * voicemail vibration setting.
6206 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6207 * specific PhoneAccount.
6208 */
6209 @Override
6210 public void setVoicemailVibrationEnabled(String callingPackage,
6211 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006212 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006213 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006214 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6215 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6217 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6218 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006219 }
6220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006221 final long identity = Binder.clearCallingIdentity();
6222 try {
6223 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6224 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006225 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226 }
6227 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6228 } finally {
6229 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006230 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006231 }
6232
6233 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006234 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6235 *
6236 * @throws SecurityException if the caller does not have the required permission
6237 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006238 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006239 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006240 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006241 }
6242
6243 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006244 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6245 * permission.
6246 *
6247 * @throws SecurityException if the caller does not have the required permission
6248 */
6249 private void enforceSendSmsPermission() {
6250 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6251 }
6252
6253 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006254 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006255 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006256 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006257 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006258 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 final long identity = Binder.clearCallingIdentity();
6260 try {
6261 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006262 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006263 if (componentName == null) {
6264 throw new SecurityException(
6265 "Caller not current active visual voicemail package[null]");
6266 }
6267 String vvmPackage = componentName.getPackageName();
6268 if (!callingPackage.equals(vvmPackage)) {
6269 throw new SecurityException("Caller not current active visual voicemail package["
6270 + vvmPackage + "]");
6271 }
6272 } finally {
6273 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006274 }
6275 }
6276
6277 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006278 * Return the application ID for the app type.
6279 *
6280 * @param subId the subscription ID that this request applies to.
6281 * @param appType the uicc app type.
6282 * @return Application ID for specificied app type, or null if no uicc.
6283 */
6284 @Override
6285 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006286 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006287 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288
6289 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006290 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291 if (phone == null) {
6292 return null;
6293 }
6294 String aid = null;
6295 try {
6296 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6297 .getApplicationByType(appType).getAid();
6298 } catch (Exception e) {
6299 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6300 }
6301 return aid;
6302 } finally {
6303 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006304 }
Youhan Wange64578a2016-05-02 15:32:42 -07006305 }
6306
Youhan Wang4001d252016-05-11 10:29:41 -07006307 /**
6308 * Return the Electronic Serial Number.
6309 *
6310 * @param subId the subscription ID that this request applies to.
6311 * @return ESN or null if error.
6312 */
6313 @Override
6314 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006315 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006316 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317
6318 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006319 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320 if (phone == null) {
6321 return null;
6322 }
6323 String esn = null;
6324 try {
6325 esn = phone.getEsn();
6326 } catch (Exception e) {
6327 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6328 }
6329 return esn;
6330 } finally {
6331 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006332 }
Youhan Wang4001d252016-05-11 10:29:41 -07006333 }
6334
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006335 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006336 * Return the Preferred Roaming List Version.
6337 *
6338 * @param subId the subscription ID that this request applies to.
6339 * @return PRLVersion or null if error.
6340 */
6341 @Override
6342 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006343 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006344 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345
6346 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006347 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 if (phone == null) {
6349 return null;
6350 }
6351 String cdmaPrlVersion = null;
6352 try {
6353 cdmaPrlVersion = phone.getCdmaPrlVersion();
6354 } catch (Exception e) {
6355 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6356 }
6357 return cdmaPrlVersion;
6358 } finally {
6359 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006360 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006361 }
6362
6363 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006364 * Get snapshot of Telephony histograms
6365 * @return List of Telephony histograms
6366 * @hide
6367 */
6368 @Override
6369 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6371 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372
6373 final long identity = Binder.clearCallingIdentity();
6374 try {
6375 return RIL.getTelephonyRILTimingHistograms();
6376 } finally {
6377 Binder.restoreCallingIdentity(identity);
6378 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006379 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006380
6381 /**
6382 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006383 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6384 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006385 * Require system privileges. In the future we may add this to carrier APIs.
6386 *
Michele Berionne482f8202018-11-27 18:57:59 -08006387 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006388 */
6389 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006390 @TelephonyManager.SetCarrierRestrictionResult
6391 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006392 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006393 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006394
Michele Berionne482f8202018-11-27 18:57:59 -08006395 if (carrierRestrictionRules == null) {
6396 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006397 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 final long identity = Binder.clearCallingIdentity();
6400 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006401 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006402 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 } finally {
6404 Binder.restoreCallingIdentity(identity);
6405 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006406 }
6407
6408 /**
6409 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006410 * Get the allowed carrier list and the excluded carrier list, including the priority between
6411 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006412 * Require system privileges. In the future we may add this to carrier APIs.
6413 *
Michele Berionne482f8202018-11-27 18:57:59 -08006414 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006415 */
6416 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006417 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006418 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006419 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420
6421 final long identity = Binder.clearCallingIdentity();
6422 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006423 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6424 if (response instanceof CarrierRestrictionRules) {
6425 return (CarrierRestrictionRules) response;
6426 }
6427 // Response is an Exception of some kind,
6428 // which is signalled to the user as a NULL retval
6429 return null;
6430 } catch (Exception e) {
6431 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6432 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006436 }
6437
fionaxu59545b42016-05-25 15:53:37 -07006438 /**
6439 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6440 * @param subId the subscription ID that this action applies to.
6441 * @param enabled control enable or disable metered apns.
6442 * {@hide}
6443 */
6444 @Override
6445 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6446 enforceModifyPermission();
6447 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448
6449 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006450 if (phone == null) {
6451 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6452 return;
6453 }
6454 try {
6455 phone.carrierActionSetMeteredApnsEnabled(enabled);
6456 } catch (Exception e) {
6457 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458 } finally {
6459 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006460 }
6461 }
6462
6463 /**
6464 * Action set from carrier signalling broadcast receivers to enable/disable radio
6465 * @param subId the subscription ID that this action applies to.
6466 * @param enabled control enable or disable radio.
6467 * {@hide}
6468 */
6469 @Override
6470 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6471 enforceModifyPermission();
6472 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473
6474 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006475 if (phone == null) {
6476 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6477 return;
6478 }
6479 try {
6480 phone.carrierActionSetRadioEnabled(enabled);
6481 } catch (Exception e) {
6482 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483 } finally {
6484 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006485 }
6486 }
6487
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006488 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006489 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6490 * network status based on which carrier apps could apply actions accordingly,
6491 * enable/disable default url handler for example.
6492 *
6493 * @param subId the subscription ID that this action applies to.
6494 * @param report control start/stop reporting the default network status.
6495 * {@hide}
6496 */
6497 @Override
6498 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6499 enforceModifyPermission();
6500 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501
6502 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006503 if (phone == null) {
6504 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6505 return;
6506 }
6507 try {
6508 phone.carrierActionReportDefaultNetworkStatus(report);
6509 } catch (Exception e) {
6510 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006511 } finally {
6512 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006513 }
6514 }
6515
6516 /**
fionaxud9622282017-07-17 17:51:30 -07006517 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6518 * @param subId the subscription ID that this action applies to.
6519 * {@hide}
6520 */
6521 @Override
6522 public void carrierActionResetAll(int subId) {
6523 enforceModifyPermission();
6524 final Phone phone = getPhone(subId);
6525 if (phone == null) {
6526 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6527 return;
6528 }
6529 try {
6530 phone.carrierActionResetAll();
6531 } catch (Exception e) {
6532 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6533 }
6534 }
6535
6536 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006537 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6538 * bug report is being generated.
6539 */
6540 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006541 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006542 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6543 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006544 writer.println("Permission Denial: can't dump Phone from pid="
6545 + Binder.getCallingPid()
6546 + ", uid=" + Binder.getCallingUid()
6547 + "without permission "
6548 + android.Manifest.permission.DUMP);
6549 return;
6550 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006551 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006552 }
Jack Yueb89b242016-06-22 13:27:47 -07006553
Brad Ebingerdac2f002018-04-03 15:17:52 -07006554 @Override
6555 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6556 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6557 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006558 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6559 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006560 }
6561
Jack Yueb89b242016-06-22 13:27:47 -07006562 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006563 * Get aggregated video call data usage since boot.
6564 *
6565 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6566 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006567 * {@hide}
6568 */
6569 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006570 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006571 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6572 null);
6573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 final long identity = Binder.clearCallingIdentity();
6575 try {
6576 // NetworkStatsService keeps tracking the active network interface and identity. It
6577 // records the delta with the corresponding network identity.
6578 // We just return the total video call data usage snapshot since boot.
6579 Phone phone = getPhone(subId);
6580 if (phone != null) {
6581 return phone.getVtDataUsage(perUidStats);
6582 }
6583 return null;
6584 } finally {
6585 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006586 }
Jack Yueb89b242016-06-22 13:27:47 -07006587 }
Jack Yu75ab2952016-07-08 14:29:33 -07006588
6589 /**
6590 * Policy control of data connection. Usually used when data limit is passed.
6591 * @param enabled True if enabling the data, otherwise disabling.
6592 * @param subId Subscription index
6593 * {@hide}
6594 */
6595 @Override
6596 public void setPolicyDataEnabled(boolean enabled, int subId) {
6597 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
6601 Phone phone = getPhone(subId);
6602 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006603 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 }
6605 } finally {
6606 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006607 }
6608 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006609
6610 /**
6611 * Get Client request stats
6612 * @return List of Client Request Stats
6613 * @hide
6614 */
6615 @Override
6616 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006618 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006619 return null;
6620 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006621 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 if (phone != null) {
6626 return phone.getClientRequestStats();
6627 }
6628
6629 return null;
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
6632 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006633 }
6634
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006635 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006636 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006637 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006638 }
Jack Yueb4124c2017-02-16 15:32:43 -08006639
6640 /**
Grace Chen70990072017-03-24 17:21:30 -07006641 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006642 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006643 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006644 * @param state State of SIM (power down, power up, pass through)
6645 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6646 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6647 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006648 *
6649 **/
6650 @Override
Grace Chen70990072017-03-24 17:21:30 -07006651 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006652 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006653 Phone phone = PhoneFactory.getPhone(slotIndex);
6654
vagdeviaf9a5b92018-08-15 16:01:53 -07006655 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006660 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006661 }
6662 } finally {
6663 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006664 }
6665 }
Shuo Qiandd210312017-04-12 22:11:33 +00006666
Tyler Gunn65d45c22017-06-05 11:22:26 -07006667 private boolean isUssdApiAllowed(int subId) {
6668 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006669 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006670 if (configManager == null) {
6671 return false;
6672 }
6673 PersistableBundle pb = configManager.getConfigForSubId(subId);
6674 if (pb == null) {
6675 return false;
6676 }
6677 return pb.getBoolean(
6678 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6679 }
6680
Shuo Qiandd210312017-04-12 22:11:33 +00006681 /**
6682 * Check if phone is in emergency callback mode
6683 * @return true if phone is in emergency callback mode
6684 * @param subId sub id
6685 */
goneil9c5f4872017-12-05 14:07:56 -08006686 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006687 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006688 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006689 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690
6691 final long identity = Binder.clearCallingIdentity();
6692 try {
6693 if (phone != null) {
6694 return phone.isInEcm();
6695 } else {
6696 return false;
6697 }
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006700 }
6701 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006702
6703 /**
6704 * Get the current signal strength information for the given subscription.
6705 * Because this information is not updated when the device is in a low power state
6706 * it should not be relied-upon to be current.
6707 * @param subId Subscription index
6708 * @return the most recent cached signal strength info from the modem
6709 */
6710 @Override
6711 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 final long identity = Binder.clearCallingIdentity();
6713 try {
6714 Phone p = getPhone(subId);
6715 if (p == null) {
6716 return null;
6717 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006719 return p.getSignalStrength();
6720 } finally {
6721 Binder.restoreCallingIdentity(identity);
6722 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006723 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006724
Pengquan Meng77b7f132018-08-22 14:49:57 -07006725 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006726 * Get the current modem radio state for the given slot.
6727 * @param slotIndex slot index.
6728 * @param callingPackage the name of the package making the call.
6729 * @return the current radio power state from the modem
6730 */
6731 @Override
6732 public int getRadioPowerState(int slotIndex, String callingPackage) {
6733 Phone phone = PhoneFactory.getPhone(slotIndex);
6734 if (phone != null) {
6735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6736 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6737 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6738 }
6739
6740 final long identity = Binder.clearCallingIdentity();
6741 try {
6742 return phone.getRadioPowerState();
6743 } finally {
6744 Binder.restoreCallingIdentity(identity);
6745 }
6746 }
6747 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6748 }
6749
6750 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006751 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6752 *
6753 * <p>Requires one of the following permissions:
6754 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6755 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6756 * privileges.
6757 *
6758 * @param subId subscription id
6759 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6760 * {@code false}.
6761 */
6762 @Override
6763 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006764 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6765 null /* message */);
6766
Pengquan Menga1bb6272018-09-06 09:59:22 -07006767 boolean isEnabled = false;
6768 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006769 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006770 Phone phone = getPhone(subId);
6771 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006772 } catch (Exception e) {
6773 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6774 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006775 } finally {
6776 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006777 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006778 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006779 }
6780
6781
6782 /**
6783 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6784 *
6785 * <p> Requires permission:
6786 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6787 * privileges.
6788 *
6789 * @param subId subscription id
6790 * @param isEnabled {@code true} means enable, {@code false} means disable.
6791 */
6792 @Override
6793 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6795 mApp, subId, "setDataRoamingEnabled");
6796
Pengquan Menga1bb6272018-09-06 09:59:22 -07006797 final long identity = Binder.clearCallingIdentity();
6798 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006799 Phone phone = getPhone(subId);
6800 if (phone != null) {
6801 phone.setDataRoamingEnabled(isEnabled);
6802 }
6803 } finally {
6804 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006805 }
6806 }
6807
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006808 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006809 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006810 TelephonyPermissions
6811 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006812 mApp, subId, "isManualNetworkSelectionAllowed");
6813
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006814 boolean isAllowed = true;
6815 final long identity = Binder.clearCallingIdentity();
6816 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006817 Phone phone = getPhone(subId);
6818 if (phone != null) {
6819 isAllowed = phone.isCspPlmnEnabled();
6820 }
6821 } finally {
6822 Binder.restoreCallingIdentity(identity);
6823 }
6824 return isAllowed;
6825 }
6826
6827 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006828 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006829 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006830 try {
6831 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006832 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006833 } catch (SecurityException e) {
6834 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6835 // has carrier privileges on an active UICC
6836 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6837 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006838 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006839 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006840 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006841
6842 final long identity = Binder.clearCallingIdentity();
6843 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006844 UiccController uiccController = UiccController.getInstance();
6845 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006846 if (hasReadPermission) {
6847 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006848 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006849
6850 // Remove private info if the caller doesn't have access
6851 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6852 for (UiccCardInfo cardInfo : cardInfos) {
6853 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6854 // is available
6855 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6856 if (card == null || card.getUiccProfile() == null) {
6857 // assume no access if the card or profile is unavailable
6858 filteredInfos.add(cardInfo.getUnprivileged());
6859 continue;
6860 }
6861 UiccProfile profile = card.getUiccProfile();
6862 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6863 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6864 filteredInfos.add(cardInfo);
6865 } else {
6866 filteredInfos.add(cardInfo.getUnprivileged());
6867 }
6868 }
6869 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006870 } finally {
6871 Binder.restoreCallingIdentity(identity);
6872 }
6873 }
6874
6875 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006876 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006877 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879 final long identity = Binder.clearCallingIdentity();
6880 try {
6881 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6882 if (slots == null) {
6883 Rlog.i(LOG_TAG, "slots is null.");
6884 return null;
6885 }
6886
6887 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6888 for (int i = 0; i < slots.length; i++) {
6889 UiccSlot slot = slots[i];
6890 if (slot == null) {
6891 continue;
6892 }
6893
Jordan Liu7be7e652019-05-06 18:55:02 +00006894 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 UiccCard card = slot.getUiccCard();
6896 if (card != null) {
6897 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006898 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006899 cardId = slot.getEid();
6900 if (TextUtils.isEmpty(cardId)) {
6901 cardId = slot.getIccId();
6902 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 }
6904
Jordan Liu857451f2019-05-09 16:35:35 -07006905 if (cardId != null) {
6906 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6907 // if cardId is an EID, it's all digits so this is fine
6908 cardId = IccUtils.stripTrailingFs(cardId);
6909 }
6910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 int cardState = 0;
6912 switch (slot.getCardState()) {
6913 case CARDSTATE_ABSENT:
6914 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6915 break;
6916 case CARDSTATE_PRESENT:
6917 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6918 break;
6919 case CARDSTATE_ERROR:
6920 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6921 break;
6922 case CARDSTATE_RESTRICTED:
6923 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6924 break;
6925 default:
6926 break;
6927
6928 }
6929
6930 infos[i] = new UiccSlotInfo(
6931 slot.isActive(),
6932 slot.isEuicc(),
6933 cardId,
6934 cardState,
6935 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006936 slot.isExtendedApduSupported(),
6937 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938 }
6939 return infos;
6940 } finally {
6941 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006942 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006943 }
6944
6945 @Override
6946 public boolean switchSlots(int[] physicalSlots) {
6947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948
6949 final long identity = Binder.clearCallingIdentity();
6950 try {
6951 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6952 } finally {
6953 Binder.restoreCallingIdentity(identity);
6954 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006955 }
Jack Yu4c988042018-02-27 15:30:01 -08006956
6957 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006958 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006959 final long identity = Binder.clearCallingIdentity();
6960 try {
6961 return UiccController.getInstance().getCardIdForDefaultEuicc();
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
6964 }
6965 }
6966
6967 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006968 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6969 enforceModifyPermission();
6970 final Phone phone = getPhone(subId);
6971 if (phone == null) {
6972 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6973 return;
6974 }
6975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006976 final long identity = Binder.clearCallingIdentity();
6977 try {
6978 phone.setRadioIndicationUpdateMode(filters, mode);
6979 } finally {
6980 Binder.restoreCallingIdentity(identity);
6981 }
Jack Yu4c988042018-02-27 15:30:01 -08006982 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006983
6984 /**
goneil47ffb6e2018-04-06 15:40:58 -07006985 * A test API to reload the UICC profile.
6986 *
6987 * <p>Requires that the calling app has permission
6988 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6989 * @hide
6990 */
6991 @Override
6992 public void refreshUiccProfile(int subId) {
6993 enforceModifyPermission();
6994
6995 final long identity = Binder.clearCallingIdentity();
6996 try {
6997 Phone phone = getPhone(subId);
6998 if (phone == null) {
6999 return;
7000 }
7001 UiccCard uiccCard = phone.getUiccCard();
7002 if (uiccCard == null) {
7003 return;
7004 }
7005 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7006 if (uiccProfile == null) {
7007 return;
7008 }
7009 uiccProfile.refresh();
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
7012 }
7013 }
7014
7015 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007016 * Returns false if the mobile data is disabled by default, otherwise return true.
7017 */
7018 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007019 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007020 }
7021
7022 /**
7023 * Returns true if the data roaming is enabled by default, i.e the system property
7024 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7025 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7026 */
7027 private boolean getDefaultDataRoamingEnabled(int subId) {
7028 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007029 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007030 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007031 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7032 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7033 return isDataRoamingEnabled;
7034 }
7035
7036 /**
7037 * Returns the default network type for the given {@code subId}, if the default network type is
7038 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7039 */
7040 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007041 List<Integer> list = TelephonyProperties.default_network();
7042 int phoneId = mSubscriptionController.getPhoneId(subId);
7043 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7044 return list.get(phoneId);
7045 }
7046 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007047 }
fionaxua13278b2018-03-21 00:08:13 -07007048
7049 @Override
7050 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007051 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007052 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053
7054 final long identity = Binder.clearCallingIdentity();
7055 try {
7056 final Phone phone = getPhone(subId);
7057 if (phone == null) {
7058 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7059 return;
7060 }
chen xueaba88a2019-03-15 13:15:10 -07007061 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7062 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 } finally {
7064 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007065 }
fionaxua13278b2018-03-21 00:08:13 -07007066 }
7067
7068 @Override
7069 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007070 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071
7072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 final Phone phone = getPhone(subId);
7075 if (phone == null) {
7076 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7077 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7078 }
7079 return phone.getCarrierIdListVersion();
7080 } finally {
7081 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007082 }
fionaxua13278b2018-03-21 00:08:13 -07007083 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007084
7085 @Override
7086 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7088 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7089 return -1;
7090 }
7091
7092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7095 } finally {
7096 Binder.restoreCallingIdentity(identity);
7097 }
7098 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007099
7100 @Override
7101 public int getCdmaRoamingMode(int subId) {
7102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7103 mApp, subId, "getCdmaRoamingMode");
7104
7105 final long identity = Binder.clearCallingIdentity();
7106 try {
7107 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7108 } finally {
7109 Binder.restoreCallingIdentity(identity);
7110 }
7111 }
7112
7113 @Override
7114 public boolean setCdmaRoamingMode(int subId, int mode) {
7115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7116 mApp, subId, "setCdmaRoamingMode");
7117
7118 final long identity = Binder.clearCallingIdentity();
7119 try {
7120 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7121 } finally {
7122 Binder.restoreCallingIdentity(identity);
7123 }
7124 }
7125
7126 @Override
7127 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7129 mApp, subId, "setCdmaSubscriptionMode");
7130
7131 final long identity = Binder.clearCallingIdentity();
7132 try {
7133 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7134 } finally {
7135 Binder.restoreCallingIdentity(identity);
7136 }
7137 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007138
sqianc5eccab2018-10-19 18:46:41 -07007139 @Override
sqian8c685422019-02-22 15:55:18 -08007140 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007141 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007142 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007143 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007144 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7145 }
7146 final long identity = Binder.clearCallingIdentity();
7147 try {
sqian854d44b2018-12-12 16:48:18 -08007148 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7149 for (Phone phone: PhoneFactory.getPhones()) {
7150 if (phone.getEmergencyNumberTracker() != null
7151 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7152 emergencyNumberListInternal.put(
7153 phone.getSubId(),
7154 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7155 }
sqian11b7a0e2018-12-05 18:48:28 -08007156 }
sqian854d44b2018-12-12 16:48:18 -08007157 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007158 } finally {
7159 Binder.restoreCallingIdentity(identity);
7160 }
sqianc5eccab2018-10-19 18:46:41 -07007161 }
7162
7163 @Override
sqian8c685422019-02-22 15:55:18 -08007164 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007165 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007166 if (!exactMatch) {
7167 TelephonyPermissions
7168 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007169 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007170 }
7171 final long identity = Binder.clearCallingIdentity();
7172 try {
sqian854d44b2018-12-12 16:48:18 -08007173 for (Phone phone: PhoneFactory.getPhones()) {
7174 if (phone.getEmergencyNumberTracker() != null
7175 && phone.getEmergencyNumberTracker() != null) {
7176 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7177 number, exactMatch)) {
7178 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007179 }
7180 }
sqian11b7a0e2018-12-05 18:48:28 -08007181 }
7182 return false;
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
7185 }
7186 }
7187
sqianf4ca7ed2019-01-15 18:32:07 -08007188 /**
7189 * Update emergency number list for test mode.
7190 */
7191 @Override
7192 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7194 "updateEmergencyNumberListTestMode");
7195
7196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 for (Phone phone: PhoneFactory.getPhones()) {
7199 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7200 if (tracker != null) {
7201 tracker.executeEmergencyNumberTestModeCommand(action, num);
7202 }
7203 }
7204 } finally {
7205 Binder.restoreCallingIdentity(identity);
7206 }
7207 }
7208
7209 /**
7210 * Get the full emergency number list for test mode.
7211 */
7212 @Override
7213 public List<String> getEmergencyNumberListTestMode() {
7214 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7215 "getEmergencyNumberListTestMode");
7216
7217 final long identity = Binder.clearCallingIdentity();
7218 try {
7219 Set<String> emergencyNumbers = new HashSet<>();
7220 for (Phone phone: PhoneFactory.getPhones()) {
7221 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7222 if (tracker != null) {
7223 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7224 emergencyNumbers.add(num.getNumber());
7225 }
7226 }
7227 }
7228 return new ArrayList<>(emergencyNumbers);
7229 } finally {
7230 Binder.restoreCallingIdentity(identity);
7231 }
7232 }
7233
chen xud6b45bd2018-10-30 22:27:10 -07007234 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007235 public int getEmergencyNumberDbVersion(int subId) {
7236 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7237
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 final Phone phone = getPhone(subId);
7241 if (phone == null) {
7242 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7243 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7244 }
7245 return phone.getEmergencyNumberDbVersion();
7246 } finally {
7247 Binder.restoreCallingIdentity(identity);
7248 }
7249 }
7250
7251 @Override
7252 public void notifyOtaEmergencyNumberDbInstalled() {
7253 enforceModifyPermission();
7254
7255 final long identity = Binder.clearCallingIdentity();
7256 try {
7257 for (Phone phone: PhoneFactory.getPhones()) {
7258 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7259 if (tracker != null) {
7260 tracker.updateOtaEmergencyNumberDatabase();
7261 }
7262 }
7263 } finally {
7264 Binder.restoreCallingIdentity(identity);
7265 }
7266 }
7267
7268 @Override
7269 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7270 enforceActiveEmergencySessionPermission();
7271
7272 final long identity = Binder.clearCallingIdentity();
7273 try {
7274 for (Phone phone: PhoneFactory.getPhones()) {
7275 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7276 if (tracker != null) {
7277 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7278 }
7279 }
7280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
7283 }
7284
7285 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007286 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7287 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7288 Phone phone = getPhone(subId);
7289 if (phone == null) {
7290 return null;
7291 }
7292 final long identity = Binder.clearCallingIdentity();
7293 try {
7294 UiccProfile profile = UiccController.getInstance()
7295 .getUiccProfileForPhone(phone.getPhoneId());
7296 if (profile != null) {
7297 return profile.getCertsFromCarrierPrivilegeAccessRules();
7298 }
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301 }
7302 return null;
7303 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007304
7305 /**
7306 * Enable or disable a modem stack.
7307 */
7308 @Override
7309 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7310 enforceModifyPermission();
7311
7312 final long identity = Binder.clearCallingIdentity();
7313 try {
7314 Phone phone = PhoneFactory.getPhone(slotIndex);
7315 if (phone == null) {
7316 return false;
7317 } else {
7318 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7319 }
7320 } finally {
7321 Binder.restoreCallingIdentity(identity);
7322 }
7323 }
Michelecea4cf22018-12-21 15:00:11 -08007324
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007325 /**
7326 * Whether a modem stack is enabled or not.
7327 */
7328 @Override
7329 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7330 Phone phone = PhoneFactory.getPhone(slotIndex);
7331 if (phone == null) return false;
7332
7333 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7334 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7335 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7336 }
7337
7338 final long identity = Binder.clearCallingIdentity();
7339 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007340 try {
7341 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7342 } catch (NoSuchElementException ex) {
7343 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7344 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007345 } finally {
7346 Binder.restoreCallingIdentity(identity);
7347 }
7348 }
7349
Michelecea4cf22018-12-21 15:00:11 -08007350 @Override
Michele0ea7d782019-03-19 14:58:42 -07007351 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007352 enforceModifyPermission();
7353
7354 final long identity = Binder.clearCallingIdentity();
7355 try {
7356 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007357 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007358 .commit();
7359 } finally {
7360 Binder.restoreCallingIdentity(identity);
7361 }
7362 }
7363
7364 @Override
Michele0ea7d782019-03-19 14:58:42 -07007365 @TelephonyManager.IsMultiSimSupportedResult
7366 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007368 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7369 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007370 }
Michelecea4cf22018-12-21 15:00:11 -08007371
7372 final long identity = Binder.clearCallingIdentity();
7373 try {
Michele0ea7d782019-03-19 14:58:42 -07007374 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007375 } finally {
7376 Binder.restoreCallingIdentity(identity);
7377 }
7378 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007379
Michele0ea7d782019-03-19 14:58:42 -07007380 @TelephonyManager.IsMultiSimSupportedResult
7381 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007382 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7383 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7384 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007385 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7386 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007387 }
7388 // Check if the hardware supports multisim functionality. If usage of multisim is not
7389 // supported by the modem, indicate that it is restricted.
7390 PhoneCapability staticCapability =
7391 mPhoneConfigurationManager.getStaticPhoneCapability();
7392 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007393 loge("isMultiSimSupportedInternal: no static configuration available");
7394 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007395 }
7396 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007397 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7398 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007399 }
7400 // Check if support of multiple SIMs is restricted by carrier
7401 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007402 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007403 }
7404
Michele0ea7d782019-03-19 14:58:42 -07007405 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007406 }
7407
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007408 /**
7409 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007410 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7411 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7412 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007413 * @param numOfSims number of active sims we want to switch to
7414 */
7415 @Override
7416 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007417 if (numOfSims == 1) {
7418 enforceModifyPermission();
7419 } else {
7420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7421 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7422 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007423 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007424
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007425 try {
Michele30b57b22019-03-01 12:01:14 -08007426 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007427 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007428 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7429 return;
7430 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007431 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7432 } finally {
7433 Binder.restoreCallingIdentity(identity);
7434 }
7435 }
7436
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007437 @Override
7438 public boolean isApplicationOnUicc(int subId, int appType) {
7439 enforceReadPrivilegedPermission("isApplicationOnUicc");
7440 Phone phone = getPhone(subId);
7441 if (phone == null) {
7442 return false;
7443 }
7444 final long identity = Binder.clearCallingIdentity();
7445 try {
7446 UiccCard uiccCard = phone.getUiccCard();
7447 if (uiccCard == null) {
7448 return false;
7449 }
7450 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7451 if (uiccProfile == null) {
7452 return false;
7453 }
7454 if (TelephonyManager.APPTYPE_SIM <= appType
7455 && appType <= TelephonyManager.APPTYPE_ISIM) {
7456 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7457 }
7458 return false;
7459 } finally {
7460 Binder.restoreCallingIdentity(identity);
7461 }
7462 }
7463
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007464 /**
chen xub4baa772019-04-03 10:23:41 -07007465 * Get whether making changes to modem configurations will trigger reboot.
7466 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007467 */
7468 @Override
chen xub4baa772019-04-03 10:23:41 -07007469 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7471 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7472 return false;
7473 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007474 final long identity = Binder.clearCallingIdentity();
7475 try {
7476 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7477 } finally {
7478 Binder.restoreCallingIdentity(identity);
7479 }
7480 }
7481
Nathan Harold29f5f052019-02-15 13:41:57 -08007482 private void updateModemStateMetrics() {
7483 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7484 // TODO: check the state for each modem if the api is ready.
7485 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7486 }
7487
Pengquan Meng3889a572019-01-23 11:16:29 -08007488 @Override
7489 public int[] getSlotsMapping() {
7490 enforceReadPrivilegedPermission("getSlotsMapping");
7491
7492 final long identity = Binder.clearCallingIdentity();
7493 try {
7494 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7495 // All logical slots should have a mapping to a physical slot.
7496 int[] logicalSlotsMapping = new int[phoneCount];
7497 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7498 for (int i = 0; i < slotInfos.length; i++) {
7499 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7500 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7501 }
7502 }
7503 return logicalSlotsMapping;
7504 } finally {
7505 Binder.restoreCallingIdentity(identity);
7506 }
7507 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007508
7509 /**
7510 * Get the IRadio HAL Version
7511 */
7512 @Override
7513 public int getRadioHalVersion() {
7514 Phone phone = getDefaultPhone();
7515 if (phone == null) return -1;
7516 HalVersion hv = phone.getHalVersion();
7517 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7518 return hv.major * 100 + hv.minor;
7519 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007520
7521 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007522 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7523 * corresponding network requests on a subId.
7524 *
7525 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007526 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007527 * 2) APN is un-metered for this subscription, or
7528 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7529 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7530 *
7531 * @return whether data is allowed for a apn type.
7532 *
7533 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007534 */
7535 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007536 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007537 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7538 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007539
7540 // Now that all security checks passes, perform the operation as ourselves.
7541 final long identity = Binder.clearCallingIdentity();
7542 try {
7543 Phone phone = getPhone(subId);
7544 if (phone == null) return false;
7545
Jack Yu41407ee2019-05-13 16:54:09 -07007546 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007547 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7548 } finally {
7549 Binder.restoreCallingIdentity(identity);
7550 }
7551 }
7552
7553 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007554 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007555 enforceReadPrivilegedPermission("isApnMetered");
7556
7557 // Now that all security checks passes, perform the operation as ourselves.
7558 final long identity = Binder.clearCallingIdentity();
7559 try {
7560 Phone phone = getPhone(subId);
7561 if (phone == null) return true; // By default return true.
7562
Jack Yu41407ee2019-05-13 16:54:09 -07007563 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
7567 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007568
7569 @Override
7570 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7571 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7572 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7573 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7574 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7575 }
7576 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7577 Intent intent = new Intent();
7578 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7579 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7580 // Bring up choose default SMS subscription dialog right now
7581 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7582 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7583 mApp.startActivity(intent);
7584 }
chen xud5ca2d52019-05-28 15:20:57 -07007585
7586 @Override
7587 public String getMmsUAProfUrl(int subId) {
7588 //TODO investigate if this API should require proper permission check in R b/133791609
7589 final long identity = Binder.clearCallingIdentity();
7590 try {
7591 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7592 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
7595 }
7596 }
7597
7598 @Override
7599 public String getMmsUserAgent(int subId) {
7600 //TODO investigate if this API should require proper permission check in R b/133791609
7601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7604 .getString(com.android.internal.R.string.config_mms_user_agent);
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
7607 }
7608 }
Jack Yub07d4972019-05-28 16:12:25 -07007609
7610 @Override
7611 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7612 enforceModifyPermission();
7613
7614 // Now that all security checks passes, perform the operation as ourselves.
7615 final long identity = Binder.clearCallingIdentity();
7616 try {
7617 Phone phone = getPhone(subId);
7618 if (phone == null) return false;
7619
7620 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
7624 }
7625
7626 @Override
7627 public boolean isDataAllowedInVoiceCall(int subId) {
7628 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7629
7630 // Now that all security checks passes, perform the operation as ourselves.
7631 final long identity = Binder.clearCallingIdentity();
7632 try {
7633 Phone phone = getPhone(subId);
7634 if (phone == null) return false;
7635
7636 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
7639 }
7640 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007641
7642 /**
7643 * Updates whether conference event pacakge handling is enabled.
7644 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7645 * otherwise.
7646 */
7647 @Override
7648 public void setCepEnabled(boolean isCepEnabled) {
7649 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7650
7651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7654 for (Phone phone : PhoneFactory.getPhones()) {
7655 Phone defaultPhone = phone.getImsPhone();
7656 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7657 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7658 ImsPhoneCallTracker imsPhoneCallTracker =
7659 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7660 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7661 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7662 + imsPhone.getMsisdn());
7663 }
7664 }
7665 } finally {
7666 Binder.restoreCallingIdentity(identity);
7667 }
7668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007669}