blob: c9525ff103b830696718012ea97f7ac476bcb185 [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;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070055import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070056import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070058import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070059import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070060import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070061import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080062import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070063import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070072import android.telephony.CellInfoGsm;
73import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070074import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070075import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070076import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070077import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080078import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070079import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070081import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080082import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080083import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070084import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080085import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070086import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070091import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080093import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080094import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000095import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070096import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070098import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -0700101import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700102import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700104import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700107import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800108import android.telephony.ims.aidl.IImsMmTelFeature;
109import android.telephony.ims.aidl.IImsRcsFeature;
110import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700111import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700112import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.feature.MmTelFeature;
114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700132import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800133import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800135import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700136import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100137import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700138import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700141import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800142import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700143import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700144import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700145import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700146import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700147import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700149import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700150import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800152import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700153import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800154import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700155import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800156import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700157import com.android.internal.telephony.imsphone.ImsPhone;
158import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800159import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900160import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800162import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700165import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000169import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700170import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800171import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700172import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800174import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700175import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700176import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800177
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700178import java.io.FileDescriptor;
179import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800182import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800183import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800184import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100185import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700187import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190/**
191 * Implementation of the ITelephony interface.
192 */
Santos Cordon117fee72014-05-16 17:56:12 -0700193public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 private static final String LOG_TAG = "PhoneInterfaceManager";
195 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
196 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
199 // Message codes used with mMainThreadHandler
200 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700201 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
202 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203 private static final int CMD_OPEN_CHANNEL = 9;
204 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
205 private static final int CMD_CLOSE_CHANNEL = 11;
206 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800207 private static final int CMD_NV_READ_ITEM = 13;
208 private static final int EVENT_NV_READ_ITEM_DONE = 14;
209 private static final int CMD_NV_WRITE_ITEM = 15;
210 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
211 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
212 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700213 private static final int CMD_RESET_MODEM_CONFIG = 19;
214 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800215 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
216 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
217 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
218 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800219 private static final int CMD_SEND_ENVELOPE = 25;
220 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000221 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
222 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700223 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
224 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
225 private static final int CMD_EXCHANGE_SIM_IO = 31;
226 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800227 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
228 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700229 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
230 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700231 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
232 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700233 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
234 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
235 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700237 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
238 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
239 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
240 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700241 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
243 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000244 private static final int CMD_SWITCH_SLOTS = 50;
245 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700246 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
247 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
248 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
249 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
250 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
251 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
252 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
253 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700254 private static final int CMD_GET_ALL_CELL_INFO = 60;
255 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
256 private static final int CMD_GET_CELL_LOCATION = 62;
257 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700258 private static final int CMD_MODEM_REBOOT = 64;
259 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700260 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
261 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800262 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
263 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700264 private static final int CMD_GET_MODEM_STATUS = 70;
265 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700266 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
267 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700268 private static final int CMD_ERASE_MODEM_CONFIG = 74;
269 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800271 // Parameters of select command.
272 private static final int SELECT_COMMAND = 0xA4;
273 private static final int SELECT_P1 = 0x04;
274 private static final int SELECT_P2 = 0;
275 private static final int SELECT_P3 = 0x10;
276
Pengquan Meng85728fb2018-03-12 16:31:21 -0700277 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
278 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
279 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
280
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281 /** The singleton instance. */
282 private static PhoneInterfaceManager sInstance;
283
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700286 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800287 private AppOpsManager mAppOps;
288 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800289 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800290 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700291 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
Derek Tan97ebb422014-09-05 16:55:38 -0700293 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
294 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800295 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800296 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700297
Michelecea4cf22018-12-21 15:00:11 -0800298 // String to store multi SIM allowed
299 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
300
Derek Tan740e1672017-06-27 14:56:27 -0700301 // The AID of ISD-R.
302 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
303
yinxub1bed742017-04-17 11:45:04 -0700304 private NetworkScanRequestTracker mNetworkScanRequestTracker;
305
David Kelly5e06a7f2018-03-12 14:10:59 +0000306 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
307 private static final int MANUFACTURER_CODE_LENGTH = 8;
308
Derek Tan89e89d42014-07-08 17:00:10 -0700309 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700310 * Experiment flag to enable erase modem config on reset network, default value is false
311 */
312 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
313 "reset_network_erase_modem_config_enabled";
314
315 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700316 * A request object to use for transmitting data to an ICC.
317 */
318 private static final class IccAPDUArgument {
319 public int channel, cla, command, p1, p2, p3;
320 public String data;
321
322 public IccAPDUArgument(int channel, int cla, int command,
323 int p1, int p2, int p3, String data) {
324 this.channel = channel;
325 this.cla = cla;
326 this.command = command;
327 this.p1 = p1;
328 this.p2 = p2;
329 this.p3 = p3;
330 this.data = data;
331 }
332 }
333
334 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700335 * A request object to use for transmitting data to an ICC.
336 */
337 private static final class ManualNetworkSelectionArgument {
338 public OperatorInfo operatorInfo;
339 public boolean persistSelection;
340
341 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
342 this.operatorInfo = operatorInfo;
343 this.persistSelection = persistSelection;
344 }
345 }
346
347 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
349 * request after sending. The main thread will notify the request when it is complete.
350 */
351 private static final class MainThreadRequest {
352 /** The argument to use for the request */
353 public Object argument;
354 /** The result of the request that is run on the main thread */
355 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800356 // The subscriber id that this request applies to. Defaults to
357 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
358 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Nathan Harold92bed182018-10-12 18:16:49 -0700360 // In cases where subId is unavailable, the caller needs to specify the phone.
361 public Phone phone;
362
vagdeviaf9a5b92018-08-15 16:01:53 -0700363 public WorkSource workSource;
364
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 public MainThreadRequest(Object argument) {
366 this.argument = argument;
367 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800368
Nathan Harold92bed182018-10-12 18:16:49 -0700369 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
370 this.argument = argument;
371 if (phone != null) {
372 this.phone = phone;
373 }
374 this.workSource = workSource;
375 }
376
vagdeviaf9a5b92018-08-15 16:01:53 -0700377 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800378 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800379 if (subId != null) {
380 this.subId = subId;
381 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700382 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 }
385
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800386 private static final class IncomingThirdPartyCallArgs {
387 public final ComponentName component;
388 public final String callId;
389 public final String callerDisplayName;
390
391 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
392 String callerDisplayName) {
393 this.component = component;
394 this.callId = callId;
395 this.callerDisplayName = callerDisplayName;
396 }
397 }
398
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 /**
400 * A handler that processes messages on the main thread in the phone process. Since many
401 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
402 * inbound binder threads to the main thread in the phone process. The Binder thread
403 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
404 * on, which will be notified when the operation completes and will contain the result of the
405 * request.
406 *
407 * <p>If a MainThreadRequest object is provided in the msg.obj field,
408 * note that request.result must be set to something non-null for the calling thread to
409 * unblock.
410 */
411 private final class MainThreadHandler extends Handler {
412 @Override
413 public void handleMessage(Message msg) {
414 MainThreadRequest request;
415 Message onCompleted;
416 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800417 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800419 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420
421 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700422 case CMD_HANDLE_USSD_REQUEST: {
423 request = (MainThreadRequest) msg.obj;
424 final Phone phone = getPhoneFromRequest(request);
425 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
426 String ussdRequest = ussdObject.first;
427 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700428
Pengquan Menga1bb6272018-09-06 09:59:22 -0700429 if (!isUssdApiAllowed(request.subId)) {
430 // Carrier does not support use of this API, return failure.
431 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
432 UssdResponse response = new UssdResponse(ussdRequest, null);
433 Bundle returnData = new Bundle();
434 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
435 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700436
Pengquan Menga1bb6272018-09-06 09:59:22 -0700437 request.result = true;
438 notifyRequester(request);
439 return;
440 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700441
Pengquan Menga1bb6272018-09-06 09:59:22 -0700442 try {
443 request.result = phone != null
444 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
445 } catch (CallStateException cse) {
446 request.result = false;
447 }
448 // Wake up the requesting thread
449 notifyRequester(request);
450 break;
pkanwar32d516d2016-10-14 19:37:38 -0700451 }
452
Yorke Lee716f67e2015-06-17 15:39:16 -0700453 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700455 final Phone phone = getPhoneFromRequest(request);
456 request.result = phone != null ?
457 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
458 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800467 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700468 if (uiccCard == null) {
469 loge("iccTransmitApduLogicalChannel: No UICC");
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700471 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700472 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
474 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700475 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 iccArgument.channel, iccArgument.cla, iccArgument.command,
477 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700479 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700480 break;
481
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700483 ar = (AsyncResult) msg.obj;
484 request = (MainThreadRequest) ar.userObj;
485 if (ar.exception == null && ar.result != null) {
486 request.result = ar.result;
487 } else {
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
489 if (ar.result == null) {
490 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800491 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700492 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800493 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 } else {
495 loge("iccTransmitApduLogicalChannel: Unknown exception");
496 }
497 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700498 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700499 break;
500
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
502 request = (MainThreadRequest) msg.obj;
503 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800504 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 if (uiccCard == null) {
506 loge("iccTransmitApduBasicChannel: No UICC");
507 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 } else {
510 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
511 request);
512 uiccCard.iccTransmitApduBasicChannel(
513 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
514 iccArgument.p3, iccArgument.data, onCompleted);
515 }
516 break;
517
518 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
519 ar = (AsyncResult) msg.obj;
520 request = (MainThreadRequest) ar.userObj;
521 if (ar.exception == null && ar.result != null) {
522 request.result = ar.result;
523 } else {
524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
525 if (ar.result == null) {
526 loge("iccTransmitApduBasicChannel: Empty response");
527 } else if (ar.exception instanceof CommandException) {
528 loge("iccTransmitApduBasicChannel: CommandException: " +
529 ar.exception);
530 } else {
531 loge("iccTransmitApduBasicChannel: Unknown exception");
532 }
533 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700534 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 break;
536
537 case CMD_EXCHANGE_SIM_IO:
538 request = (MainThreadRequest) msg.obj;
539 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800540 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 if (uiccCard == null) {
542 loge("iccExchangeSimIO: No UICC");
543 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 } else {
546 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
547 request);
548 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
549 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
550 iccArgument.data, onCompleted);
551 }
552 break;
553
554 case EVENT_EXCHANGE_SIM_IO_DONE:
555 ar = (AsyncResult) msg.obj;
556 request = (MainThreadRequest) ar.userObj;
557 if (ar.exception == null && ar.result != null) {
558 request.result = ar.result;
559 } else {
560 request.result = new IccIoResult(0x6f, 0, (byte[])null);
561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 break;
564
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 case CMD_SEND_ENVELOPE:
566 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800567 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 if (uiccCard == null) {
569 loge("sendEnvelopeWithStatus: No UICC");
570 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700571 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700572 } else {
573 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
574 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
575 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800576 break;
577
578 case EVENT_SEND_ENVELOPE_DONE:
579 ar = (AsyncResult) msg.obj;
580 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700581 if (ar.exception == null && ar.result != null) {
582 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800583 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700584 request.result = new IccIoResult(0x6F, 0, (byte[])null);
585 if (ar.result == null) {
586 loge("sendEnvelopeWithStatus: Empty response");
587 } else if (ar.exception instanceof CommandException) {
588 loge("sendEnvelopeWithStatus: CommandException: " +
589 ar.exception);
590 } else {
591 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
592 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800593 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800595 break;
596
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 case CMD_OPEN_CHANNEL:
598 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800599 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800600 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 if (uiccCard == null) {
602 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800603 request.result = new IccOpenLogicalChannelResponse(-1,
604 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700606 } else {
607 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800608 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
609 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700610 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 break;
612
613 case EVENT_OPEN_CHANNEL_DONE:
614 ar = (AsyncResult) msg.obj;
615 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 int[] result = (int[]) ar.result;
619 int channelId = result[0];
620 byte[] selectResponse = null;
621 if (result.length > 1) {
622 selectResponse = new byte[result.length - 1];
623 for (int i = 1; i < result.length; ++i) {
624 selectResponse[i - 1] = (byte) result[i];
625 }
626 }
627 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700628 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 if (ar.result == null) {
631 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 if (ar.exception != null) {
634 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
635 }
636
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700637 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700638 if (ar.exception instanceof CommandException) {
639 CommandException.Error error =
640 ((CommandException) (ar.exception)).getCommandError();
641 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700642 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700643 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700644 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 }
646 }
647 openChannelResp = new IccOpenLogicalChannelResponse(
648 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700650 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 break;
653
654 case CMD_CLOSE_CHANNEL:
655 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800656 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 if (uiccCard == null) {
658 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900659 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 } else {
662 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
663 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
664 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 break;
666
667 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800668 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
669 break;
670
671 case CMD_NV_READ_ITEM:
672 request = (MainThreadRequest) msg.obj;
673 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800674 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
675 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800676 break;
677
678 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 ar = (AsyncResult) msg.obj;
680 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800681 if (ar.exception == null && ar.result != null) {
682 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800684 request.result = "";
685 if (ar.result == null) {
686 loge("nvReadItem: Empty response");
687 } else if (ar.exception instanceof CommandException) {
688 loge("nvReadItem: CommandException: " +
689 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800691 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 }
693 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 break;
696
Jake Hambye994d462014-02-03 13:10:13 -0800697 case CMD_NV_WRITE_ITEM:
698 request = (MainThreadRequest) msg.obj;
699 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
700 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800701 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700702 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800703 break;
704
705 case EVENT_NV_WRITE_ITEM_DONE:
706 handleNullReturnEvent(msg, "nvWriteItem");
707 break;
708
709 case CMD_NV_WRITE_CDMA_PRL:
710 request = (MainThreadRequest) msg.obj;
711 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800712 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800713 break;
714
715 case EVENT_NV_WRITE_CDMA_PRL_DONE:
716 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
717 break;
718
chen xu6dac5ab2018-10-26 17:39:23 -0700719 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800720 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700721 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800722 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800723 break;
724
chen xu6dac5ab2018-10-26 17:39:23 -0700725 case EVENT_RESET_MODEM_CONFIG_DONE:
726 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800727 break;
728
Jake Hamby7c27be32014-03-03 13:25:59 -0800729 case CMD_GET_PREFERRED_NETWORK_TYPE:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700732 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800733 break;
734
735 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
736 ar = (AsyncResult) msg.obj;
737 request = (MainThreadRequest) ar.userObj;
738 if (ar.exception == null && ar.result != null) {
739 request.result = ar.result; // Integer
740 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800741 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800742 if (ar.result == null) {
743 loge("getPreferredNetworkType: Empty response");
744 } else if (ar.exception instanceof CommandException) {
745 loge("getPreferredNetworkType: CommandException: " +
746 ar.exception);
747 } else {
748 loge("getPreferredNetworkType: Unknown exception");
749 }
750 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700751 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800752 break;
753
754 case CMD_SET_PREFERRED_NETWORK_TYPE:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
757 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700758 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800759 break;
760
761 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
762 handleNullReturnEvent(msg, "setPreferredNetworkType");
763 break;
764
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000765 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
766 request = (MainThreadRequest)msg.obj;
767 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800768 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000769 break;
770
771 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
772 ar = (AsyncResult)msg.obj;
773 request = (MainThreadRequest)ar.userObj;
774 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700775 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000776 break;
777
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800778 case CMD_SET_VOICEMAIL_NUMBER:
779 request = (MainThreadRequest) msg.obj;
780 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
781 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800782 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
783 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800784 break;
785
786 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
787 handleNullReturnEvent(msg, "setVoicemailNumber");
788 break;
789
Stuart Scott54788802015-03-30 13:18:01 -0700790 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
793 request);
794 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
795 break;
796
797 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
798 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
799 break;
800
Shishir Agrawal302c8692015-06-19 13:49:39 -0700801 case CMD_PERFORM_NETWORK_SCAN:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
804 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
805 break;
806
807 case EVENT_PERFORM_NETWORK_SCAN_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
810 CellNetworkScanResult cellScanResult;
811 if (ar.exception == null && ar.result != null) {
812 cellScanResult = new CellNetworkScanResult(
813 CellNetworkScanResult.STATUS_SUCCESS,
814 (List<OperatorInfo>) ar.result);
815 } else {
816 if (ar.result == null) {
817 loge("getCellNetworkScanResults: Empty response");
818 }
819 if (ar.exception != null) {
820 loge("getCellNetworkScanResults: Exception: " + ar.exception);
821 }
822 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
823 if (ar.exception instanceof CommandException) {
824 CommandException.Error error =
825 ((CommandException) (ar.exception)).getCommandError();
826 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
827 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
828 } else if (error == CommandException.Error.GENERIC_FAILURE) {
829 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
830 }
831 }
832 cellScanResult = new CellNetworkScanResult(errorCode, null);
833 }
834 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700835 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700836 break;
837
838 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
839 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700840 ManualNetworkSelectionArgument selArg =
841 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700842 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
843 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700844 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
845 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700846 break;
847
848 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700849 ar = (AsyncResult) msg.obj;
850 request = (MainThreadRequest) ar.userObj;
851 if (ar.exception == null) {
852 request.result = true;
853 } else {
854 request.result = false;
855 loge("setNetworkSelectionModeManual " + ar.exception);
856 }
857 notifyRequester(request);
858 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700859 break;
860
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700861 case CMD_GET_MODEM_ACTIVITY_INFO:
862 request = (MainThreadRequest) msg.obj;
863 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700864 if (defaultPhone != null) {
865 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
866 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700867 break;
868
869 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null && ar.result != null) {
873 request.result = ar.result;
874 } else {
875 if (ar.result == null) {
876 loge("queryModemActivityInfo: Empty response");
877 } else if (ar.exception instanceof CommandException) {
878 loge("queryModemActivityInfo: CommandException: " +
879 ar.exception);
880 } else {
881 loge("queryModemActivityInfo: Unknown exception");
882 }
883 }
Amit Mahajand4766222016-01-28 15:28:28 -0800884 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
885 if (request.result == null) {
886 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
887 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700888 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700889 break;
890
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 case CMD_SET_ALLOWED_CARRIERS:
892 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800893 CarrierRestrictionRules argument =
894 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800896 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 break;
898
899 case EVENT_SET_ALLOWED_CARRIERS_DONE:
900 ar = (AsyncResult) msg.obj;
901 request = (MainThreadRequest) ar.userObj;
902 if (ar.exception == null && ar.result != null) {
903 request.result = ar.result;
904 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800905 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
906 if (ar.exception instanceof CommandException) {
907 loge("setAllowedCarriers: CommandException: " + ar.exception);
908 CommandException.Error error =
909 ((CommandException) (ar.exception)).getCommandError();
910 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
911 request.result =
912 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
913 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 } else {
915 loge("setAllowedCarriers: Unknown exception");
916 }
917 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700918 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700919 break;
920
921 case CMD_GET_ALLOWED_CARRIERS:
922 request = (MainThreadRequest) msg.obj;
923 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800924 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700925 break;
926
927 case EVENT_GET_ALLOWED_CARRIERS_DONE:
928 ar = (AsyncResult) msg.obj;
929 request = (MainThreadRequest) ar.userObj;
930 if (ar.exception == null && ar.result != null) {
931 request.result = ar.result;
932 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800933 request.result = new IllegalStateException(
934 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700935 if (ar.result == null) {
936 loge("getAllowedCarriers: Empty response");
937 } else if (ar.exception instanceof CommandException) {
938 loge("getAllowedCarriers: CommandException: " +
939 ar.exception);
940 } else {
941 loge("getAllowedCarriers: Unknown exception");
942 }
943 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700944 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700945 break;
946
Nathan Haroldb3014052017-01-25 15:57:32 -0800947 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
948 ar = (AsyncResult) msg.obj;
949 request = (MainThreadRequest) ar.userObj;
950 if (ar.exception == null && ar.result != null) {
951 request.result = ar.result;
952 } else {
953 request.result = new IllegalArgumentException(
954 "Failed to retrieve Forbidden Plmns");
955 if (ar.result == null) {
956 loge("getForbiddenPlmns: Empty response");
957 } else {
958 loge("getForbiddenPlmns: Unknown exception");
959 }
960 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700961 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800962 break;
963
964 case CMD_GET_FORBIDDEN_PLMNS:
965 request = (MainThreadRequest) msg.obj;
966 uiccCard = getUiccCardFromRequest(request);
967 if (uiccCard == null) {
968 loge("getForbiddenPlmns() UiccCard is null");
969 request.result = new IllegalArgumentException(
970 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700971 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800972 break;
973 }
974 Integer appType = (Integer) request.argument;
975 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
976 if (uiccApp == null) {
977 loge("getForbiddenPlmns() no app with specified type -- "
978 + appType);
979 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700980 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800981 break;
982 } else {
983 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
984 + " specified type -- " + appType);
985 }
986 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
987 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
988 onCompleted);
989 break;
990
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000991 case CMD_SWITCH_SLOTS:
992 request = (MainThreadRequest) msg.obj;
993 int[] physicalSlots = (int[]) request.argument;
994 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
995 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
996 break;
997
998 case EVENT_SWITCH_SLOTS_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001002 notifyRequester(request);
1003 break;
1004 case CMD_GET_NETWORK_SELECTION_MODE:
1005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1007 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1008 break;
1009
1010 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 if (ar.exception != null) {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1015 } else {
1016 int mode = ((int[]) ar.result)[0];
1017 if (mode == 0) {
1018 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1019 } else {
1020 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1021 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001022 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001023 notifyRequester(request);
1024 break;
1025 case CMD_GET_CDMA_ROAMING_MODE:
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1028 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1029 break;
1030 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1031 ar = (AsyncResult) msg.obj;
1032 request = (MainThreadRequest) ar.userObj;
1033 if (ar.exception != null) {
1034 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1035 } else {
1036 request.result = ((int[]) ar.result)[0];
1037 }
1038 notifyRequester(request);
1039 break;
1040 case CMD_SET_CDMA_ROAMING_MODE:
1041 request = (MainThreadRequest) msg.obj;
1042 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1043 int mode = (int) request.argument;
1044 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1045 break;
1046 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1047 ar = (AsyncResult) msg.obj;
1048 request = (MainThreadRequest) ar.userObj;
1049 request.result = ar.exception == null;
1050 notifyRequester(request);
1051 break;
1052 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1053 request = (MainThreadRequest) msg.obj;
1054 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1055 int subscriptionMode = (int) request.argument;
1056 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1057 break;
1058 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
1061 request.result = ar.exception == null;
1062 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001063 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 case CMD_GET_ALL_CELL_INFO:
1065 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001067 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001068 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 case EVENT_GET_ALL_CELL_INFO_DONE:
1070 ar = (AsyncResult) msg.obj;
1071 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001072 // If a timeout occurs, the response will be null
1073 request.result = (ar.exception == null && ar.result != null)
1074 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001075 synchronized (request) {
1076 request.notifyAll();
1077 }
1078 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 case CMD_REQUEST_CELL_INFO_UPDATE:
1080 request = (MainThreadRequest) msg.obj;
1081 request.phone.requestCellInfoUpdate(request.workSource,
1082 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1083 break;
1084 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1085 ar = (AsyncResult) msg.obj;
1086 request = (MainThreadRequest) ar.userObj;
1087 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1088 try {
1089 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001091 cb.onError(
1092 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1093 ar.exception.getClass().getName(),
1094 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001095 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001097 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001098 } else {
1099 // use the result as returned
1100 cb.onCellInfo((List<CellInfo>) ar.result);
1101 }
1102 } catch (RemoteException re) {
1103 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1104 }
1105 break;
1106 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 request = (MainThreadRequest) msg.obj;
1108 WorkSource ws = (WorkSource) request.argument;
1109 Phone phone = getPhoneFromRequest(request);
1110 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1111 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001113 ar = (AsyncResult) msg.obj;
1114 request = (MainThreadRequest) ar.userObj;
1115 if (ar.exception == null) {
1116 request.result = ar.result;
1117 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001118 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001119 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1120 ? new CdmaCellLocation() : new GsmCellLocation();
1121 }
1122
1123 synchronized (request) {
1124 request.notifyAll();
1125 }
1126 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001127 case CMD_MODEM_REBOOT:
1128 request = (MainThreadRequest) msg.obj;
1129 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001130 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001131 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001132 case EVENT_CMD_MODEM_REBOOT_DONE:
1133 handleNullReturnEvent(msg, "rebootModem");
1134 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001135 case CMD_REQUEST_ENABLE_MODEM:
1136 request = (MainThreadRequest) msg.obj;
1137 boolean enable = (boolean) request.argument;
1138 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001139 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001140 PhoneConfigurationManager.getInstance()
1141 .enablePhone(request.phone, enable, onCompleted);
1142 break;
1143 case EVENT_ENABLE_MODEM_DONE:
1144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
1146 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001147 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001148 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001149 if ((boolean) request.result) {
1150 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1151 updateModemStateMetrics();
1152 } else {
1153 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1154 + ar.exception);
1155 }
1156 notifyRequester(request);
1157 break;
1158 case CMD_GET_MODEM_STATUS:
1159 request = (MainThreadRequest) msg.obj;
1160 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1161 PhoneConfigurationManager.getInstance()
1162 .getPhoneStatusFromModem(request.phone, onCompleted);
1163 break;
1164 case EVENT_GET_MODEM_STATUS_DONE:
1165 ar = (AsyncResult) msg.obj;
1166 request = (MainThreadRequest) ar.userObj;
1167 int id = request.phone.getPhoneId();
1168 if (ar.exception == null && ar.result != null) {
1169 request.result = ar.result;
1170 //update the cache as modem status has changed
1171 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1172 (boolean) request.result);
1173 } else {
1174 // Return true if modem status cannot be retrieved. For most cases,
1175 // modem status is on. And for older version modems, GET_MODEM_STATUS
1176 // and disable modem are not supported. Modem is always on.
1177 // TODO: this should be fixed in R to support a third
1178 // status UNKNOWN b/131631629
1179 request.result = true;
1180 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1181 + ar.exception);
1182 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001183 notifyRequester(request);
1184 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001185 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1186 ar = (AsyncResult) msg.obj;
1187 request = (MainThreadRequest) ar.userObj;
1188 if (ar.exception == null && ar.result != null) {
1189 request.result = ar.result;
1190 } else {
1191 request.result = -1;
1192 loge("Failed to set Forbidden Plmns");
1193 if (ar.result == null) {
1194 loge("setForbidenPlmns: Empty response");
1195 } else if (ar.exception != null) {
1196 loge("setForbiddenPlmns: Exception: " + ar.exception);
1197 request.result = -1;
1198 } else {
1199 loge("setForbiddenPlmns: Unknown exception");
1200 }
1201 }
1202 notifyRequester(request);
1203 break;
1204 case CMD_SET_FORBIDDEN_PLMNS:
1205 request = (MainThreadRequest) msg.obj;
1206 uiccCard = getUiccCardFromRequest(request);
1207 if (uiccCard == null) {
1208 loge("setForbiddenPlmns: UiccCard is null");
1209 request.result = -1;
1210 notifyRequester(request);
1211 break;
1212 }
1213 Pair<Integer, List<String>> setFplmnsArgs =
1214 (Pair<Integer, List<String>>) request.argument;
1215 appType = setFplmnsArgs.first;
1216 List<String> fplmns = setFplmnsArgs.second;
1217 uiccApp = uiccCard.getApplicationByType(appType);
1218 if (uiccApp == null) {
1219 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1220 request.result = -1;
1221 loge("Failed to get UICC App");
1222 notifyRequester(request);
1223 } else {
1224 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1225 ((SIMRecords) uiccApp.getIccRecords())
1226 .setForbiddenPlmns(onCompleted, fplmns);
1227 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001228 case CMD_ERASE_MODEM_CONFIG:
1229 request = (MainThreadRequest) msg.obj;
1230 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1231 defaultPhone.eraseModemConfig(onCompleted);
1232 break;
1233 case EVENT_ERASE_MODEM_CONFIG_DONE:
1234 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001235 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 default:
1237 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1238 break;
1239 }
1240 }
Jake Hambye994d462014-02-03 13:10:13 -08001241
Pengquan Menga1bb6272018-09-06 09:59:22 -07001242 private void notifyRequester(MainThreadRequest request) {
1243 synchronized (request) {
1244 request.notifyAll();
1245 }
1246 }
1247
Jake Hambye994d462014-02-03 13:10:13 -08001248 private void handleNullReturnEvent(Message msg, String command) {
1249 AsyncResult ar = (AsyncResult) msg.obj;
1250 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1251 if (ar.exception == null) {
1252 request.result = true;
1253 } else {
1254 request.result = false;
1255 if (ar.exception instanceof CommandException) {
1256 loge(command + ": CommandException: " + ar.exception);
1257 } else {
1258 loge(command + ": Unknown exception");
1259 }
1260 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001261 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 }
1264
1265 /**
1266 * Posts the specified command to be executed on the main thread,
1267 * waits for the request to complete, and returns the result.
1268 * @see #sendRequestAsync
1269 */
1270 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001271 return sendRequest(
1272 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001273 }
1274
1275 /**
1276 * Posts the specified command to be executed on the main thread,
1277 * waits for the request to complete, and returns the result.
1278 * @see #sendRequestAsync
1279 */
1280 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1281 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001282 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001283 }
1284
1285 /**
1286 * Posts the specified command to be executed on the main thread,
1287 * waits for the request to complete, and returns the result.
1288 * @see #sendRequestAsync
1289 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001290 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001291 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001292 }
1293
1294 /**
1295 * Posts the specified command to be executed on the main thread,
1296 * waits for the request to complete, and returns the result.
1297 * @see #sendRequestAsync
1298 */
Nathan Harold92bed182018-10-12 18:16:49 -07001299 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1300 return sendRequest(command, argument, subId, null, workSource);
1301 }
1302
1303 /**
1304 * Posts the specified command to be executed on the main thread,
1305 * waits for the request to complete, and returns the result.
1306 * @see #sendRequestAsync
1307 */
1308 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1309 return sendRequest(
1310 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1311 }
1312
1313 /**
1314 * Posts the specified command to be executed on the main thread,
1315 * waits for the request to complete, and returns the result.
1316 * @see #sendRequestAsync
1317 */
1318 private Object sendRequest(
1319 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1321 throw new RuntimeException("This method will deadlock if called from the main thread.");
1322 }
1323
Nathan Harold92bed182018-10-12 18:16:49 -07001324 MainThreadRequest request = null;
1325 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1326 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1327 } else if (phone != null) {
1328 request = new MainThreadRequest(argument, phone, workSource);
1329 } else {
1330 request = new MainThreadRequest(argument, subId, workSource);
1331 }
1332
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 Message msg = mMainThreadHandler.obtainMessage(command, request);
1334 msg.sendToTarget();
1335
1336 // Wait for the request to complete
1337 synchronized (request) {
1338 while (request.result == null) {
1339 try {
1340 request.wait();
1341 } catch (InterruptedException e) {
1342 // Do nothing, go back and wait until the request is complete
1343 }
1344 }
1345 }
1346 return request.result;
1347 }
1348
1349 /**
1350 * Asynchronous ("fire and forget") version of sendRequest():
1351 * Posts the specified command to be executed on the main thread, and
1352 * returns immediately.
1353 * @see #sendRequest
1354 */
1355 private void sendRequestAsync(int command) {
1356 mMainThreadHandler.sendEmptyMessage(command);
1357 }
1358
1359 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001360 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001361 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001362 */
1363 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001364 sendRequestAsync(command, argument, null, null);
1365 }
1366
1367 /**
1368 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1369 * @see {@link #sendRequest(int,Object)}
1370 */
1371 private void sendRequestAsync(
1372 int command, Object argument, Phone phone, WorkSource workSource) {
1373 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001374 Message msg = mMainThreadHandler.obtainMessage(command, request);
1375 msg.sendToTarget();
1376 }
1377
1378 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 * Initialize the singleton PhoneInterfaceManager instance.
1380 * This is only done once, at startup, from PhoneApp.onCreate().
1381 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001382 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 synchronized (PhoneInterfaceManager.class) {
1384 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001385 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 } else {
1387 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1388 }
1389 return sInstance;
1390 }
1391 }
1392
1393 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001394 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001397 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001398 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1399 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001400 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001401 mTelephonySharedPreferences =
1402 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001403 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001404 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001405
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 publish();
1407 }
1408
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001409 private Phone getDefaultPhone() {
1410 Phone thePhone = getPhone(getDefaultSubscription());
1411 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1412 }
1413
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414 private void publish() {
1415 if (DBG) log("publish: " + this);
1416
1417 ServiceManager.addService("phone", this);
1418 }
1419
Stuart Scott584921c2015-01-15 17:10:34 -08001420 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001421 if (request.phone != null) {
1422 return request.phone;
1423 } else {
1424 return getPhoneFromSubId(request.subId);
1425 }
1426 }
1427
1428 private Phone getPhoneFromSubId(int subId) {
1429 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1430 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001431 }
1432
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001433 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1434 Phone phone = getPhoneFromRequest(request);
1435 return phone == null ? null :
1436 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1437 }
1438
Wink Saville36469e72014-06-11 15:17:00 -07001439 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001440 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001441 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001444 private void sendEraseModemConfig(Phone phone) {
1445 if (phone != null) {
1446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1447 mApp, phone.getSubId(), "eraseModemConfig");
1448 final long identity = Binder.clearCallingIdentity();
1449 try {
1450 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1451 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1452 } finally {
1453 Binder.restoreCallingIdentity(identity);
1454 }
1455 }
1456 }
1457
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001459 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001460 }
1461
Wink Savilleb564aae2014-10-23 10:18:09 -07001462 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001463 if (DBG) log("dial: " + number);
1464 // No permission check needed here: This is just a wrapper around the
1465 // ACTION_DIAL intent, which is available to any app since it puts up
1466 // the UI before it does anything.
1467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001468 final long identity = Binder.clearCallingIdentity();
1469 try {
1470 String url = createTelUrl(number);
1471 if (url == null) {
1472 return;
1473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001475 // PENDING: should we just silently fail if phone is offhook or ringing?
1476 PhoneConstants.State state = mCM.getState(subId);
1477 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1478 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1479 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1480 mApp.startActivity(intent);
1481 }
1482 } finally {
1483 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484 }
1485 }
1486
1487 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001488 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001489 }
1490
Wink Savilleb564aae2014-10-23 10:18:09 -07001491 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001492 if (DBG) log("call: " + number);
1493
1494 // This is just a wrapper around the ACTION_CALL intent, but we still
1495 // need to do a permission check since we're calling startActivity()
1496 // from the context of the phone app.
1497 enforceCallPermission();
1498
Jordan Liu1617b712019-07-10 15:06:26 -07001499 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 != AppOpsManager.MODE_ALLOWED) {
1501 return;
1502 }
1503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001504 final long identity = Binder.clearCallingIdentity();
1505 try {
1506 String url = createTelUrl(number);
1507 if (url == null) {
1508 return;
1509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001511 boolean isValid = false;
1512 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1513 if (slist != null) {
1514 for (SubscriptionInfo subInfoRecord : slist) {
1515 if (subInfoRecord.getSubscriptionId() == subId) {
1516 isValid = true;
1517 break;
1518 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001519 }
Wink Saville08874612014-08-31 19:19:58 -07001520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001521 if (!isValid) {
1522 return;
1523 }
Wink Saville08874612014-08-31 19:19:58 -07001524
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001525 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1526 intent.putExtra(SUBSCRIPTION_KEY, subId);
1527 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1528 mApp.startActivity(intent);
1529 } finally {
1530 Binder.restoreCallingIdentity(identity);
1531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 }
1533
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001535 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001536 }
1537
Wink Savilleb564aae2014-10-23 10:18:09 -07001538 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001540 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1541 }
1542
1543 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001544 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001545 }
1546
Wink Savilleb564aae2014-10-23 10:18:09 -07001547 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001548 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001549 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1550 }
1551
1552 /** {@hide} */
1553 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001554 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001555 }
1556
Wink Savilleb564aae2014-10-23 10:18:09 -07001557 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001559
1560 final long identity = Binder.clearCallingIdentity();
1561 try {
1562 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1563 checkSimPin.start();
1564 return checkSimPin.unlockSim(null, pin);
1565 } finally {
1566 Binder.restoreCallingIdentity(identity);
1567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 }
1569
Wink Saville9de0f752013-10-22 19:04:03 -07001570 /** {@hide} */
1571 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001572 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001573 }
1574
Wink Savilleb564aae2014-10-23 10:18:09 -07001575 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001577
1578 final long identity = Binder.clearCallingIdentity();
1579 try {
1580 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1581 checkSimPuk.start();
1582 return checkSimPuk.unlockSim(puk, pin);
1583 } finally {
1584 Binder.restoreCallingIdentity(identity);
1585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 }
1587
1588 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001589 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 * a synchronous one.
1591 */
1592 private static class UnlockSim extends Thread {
1593
1594 private final IccCard mSimCard;
1595
1596 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001597 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1598 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599
1600 // For replies from SimCard interface
1601 private Handler mHandler;
1602
1603 // For async handler to identify request type
1604 private static final int SUPPLY_PIN_COMPLETE = 100;
1605
1606 public UnlockSim(IccCard simCard) {
1607 mSimCard = simCard;
1608 }
1609
1610 @Override
1611 public void run() {
1612 Looper.prepare();
1613 synchronized (UnlockSim.this) {
1614 mHandler = new Handler() {
1615 @Override
1616 public void handleMessage(Message msg) {
1617 AsyncResult ar = (AsyncResult) msg.obj;
1618 switch (msg.what) {
1619 case SUPPLY_PIN_COMPLETE:
1620 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1621 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001622 mRetryCount = msg.arg1;
1623 if (ar.exception != null) {
1624 if (ar.exception instanceof CommandException &&
1625 ((CommandException)(ar.exception)).getCommandError()
1626 == CommandException.Error.PASSWORD_INCORRECT) {
1627 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1628 } else {
1629 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1630 }
1631 } else {
1632 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 mDone = true;
1635 UnlockSim.this.notifyAll();
1636 }
1637 break;
1638 }
1639 }
1640 };
1641 UnlockSim.this.notifyAll();
1642 }
1643 Looper.loop();
1644 }
1645
1646 /*
1647 * Use PIN or PUK to unlock SIM card
1648 *
1649 * If PUK is null, unlock SIM card with PIN
1650 *
1651 * If PUK is not null, unlock SIM card with PUK and set PIN code
1652 */
Wink Saville9de0f752013-10-22 19:04:03 -07001653 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654
1655 while (mHandler == null) {
1656 try {
1657 wait();
1658 } catch (InterruptedException e) {
1659 Thread.currentThread().interrupt();
1660 }
1661 }
1662 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1663
1664 if (puk == null) {
1665 mSimCard.supplyPin(pin, callback);
1666 } else {
1667 mSimCard.supplyPuk(puk, pin, callback);
1668 }
1669
1670 while (!mDone) {
1671 try {
1672 Log.d(LOG_TAG, "wait for done");
1673 wait();
1674 } catch (InterruptedException e) {
1675 // Restore the interrupted status
1676 Thread.currentThread().interrupt();
1677 }
1678 }
1679 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001680 int[] resultArray = new int[2];
1681 resultArray[0] = mResult;
1682 resultArray[1] = mRetryCount;
1683 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 }
1685 }
1686
1687 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001688 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001689
1690 }
1691
Wink Savilleb564aae2014-10-23 10:18:09 -07001692 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 // No permission check needed here: this call is harmless, and it's
1694 // needed for the ServiceState.requestStateUpdate() call (which is
1695 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 final Phone phone = getPhone(subId);
1699 if (phone != null) {
1700 phone.updateServiceLocation();
1701 }
1702 } finally {
1703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001707 @Override
1708 public boolean isRadioOn(String callingPackage) {
1709 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001710 }
1711
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001712 @Override
1713 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001715 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001716 return false;
1717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001718
1719 final long identity = Binder.clearCallingIdentity();
1720 try {
1721 return isRadioOnForSubscriber(subId);
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
1724 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001725 }
1726
1727 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001728 final long identity = Binder.clearCallingIdentity();
1729 try {
1730 final Phone phone = getPhone(subId);
1731 if (phone != null) {
1732 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1733 } else {
1734 return false;
1735 }
1736 } finally {
1737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 }
1740
1741 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001742 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
Wink Saville36469e72014-06-11 15:17:00 -07001744
Wink Savilleb564aae2014-10-23 10:18:09 -07001745 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001747
1748 final long identity = Binder.clearCallingIdentity();
1749 try {
1750 final Phone phone = getPhone(subId);
1751 if (phone != null) {
1752 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1753 }
1754 } finally {
1755 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001756 }
Wink Saville36469e72014-06-11 15:17:00 -07001757 }
1758
1759 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001760 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001761 }
1762
Wink Savilleb564aae2014-10-23 10:18:09 -07001763 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001764 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001765
1766 final long identity = Binder.clearCallingIdentity();
1767 try {
1768 final Phone phone = getPhone(subId);
1769 if (phone == null) {
1770 return false;
1771 }
1772 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1773 toggleRadioOnOffForSubscriber(subId);
1774 }
1775 return true;
1776 } finally {
1777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 }
Wink Saville36469e72014-06-11 15:17:00 -07001780
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001781 public boolean needMobileRadioShutdown() {
1782 /*
1783 * If any of the Radios are available, it will need to be
1784 * shutdown. So return true if any Radio is available.
1785 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 final long identity = Binder.clearCallingIdentity();
1787 try {
1788 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1789 Phone phone = PhoneFactory.getPhone(i);
1790 if (phone != null && phone.isRadioAvailable()) return true;
1791 }
1792 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1793 return false;
1794 } finally {
1795 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001796 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001797 }
1798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001800 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 enforceModifyPermission();
1802
1803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1806 logv("Shutting down Phone " + i);
1807 shutdownRadioUsingPhoneId(i);
1808 }
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 }
1812 }
1813
1814 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001815 Phone phone = PhoneFactory.getPhone(phoneId);
1816 if (phone != null && phone.isRadioAvailable()) {
1817 phone.shutdownRadio();
1818 }
1819 }
1820
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001823
1824 final long identity = Binder.clearCallingIdentity();
1825 try {
1826 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1827 if (defaultPhone != null) {
1828 defaultPhone.setRadioPower(turnOn);
1829 return true;
1830 } else {
1831 loge("There's no default phone.");
1832 return false;
1833 }
1834 } finally {
1835 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001836 }
Wink Saville36469e72014-06-11 15:17:00 -07001837 }
1838
Wink Savilleb564aae2014-10-23 10:18:09 -07001839 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001841
1842 final long identity = Binder.clearCallingIdentity();
1843 try {
1844 final Phone phone = getPhone(subId);
1845 if (phone != null) {
1846 phone.setRadioPower(turnOn);
1847 return true;
1848 } else {
1849 return false;
1850 }
1851 } finally {
1852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 }
1855
Wink Saville36469e72014-06-11 15:17:00 -07001856 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 public boolean enableDataConnectivity() {
1859 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001860
1861 final long identity = Binder.clearCallingIdentity();
1862 try {
1863 int subId = mSubscriptionController.getDefaultDataSubId();
1864 final Phone phone = getPhone(subId);
1865 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001866 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001867 return true;
1868 } else {
1869 return false;
1870 }
1871 } finally {
1872 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 }
1875
Wink Saville36469e72014-06-11 15:17:00 -07001876 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001877 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 public boolean disableDataConnectivity() {
1879 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880
1881 final long identity = Binder.clearCallingIdentity();
1882 try {
1883 int subId = mSubscriptionController.getDefaultDataSubId();
1884 final Phone phone = getPhone(subId);
1885 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001886 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001887 return true;
1888 } else {
1889 return false;
1890 }
1891 } finally {
1892 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 }
1895
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001897 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898 final long identity = Binder.clearCallingIdentity();
1899 try {
1900 final Phone phone = getPhone(subId);
1901 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001902 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001903 } else {
1904 return false;
1905 }
1906 } finally {
1907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 }
1910
1911 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001912 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001913 }
1914
pkanwarae03a6b2016-11-06 20:37:09 -08001915 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001916 enforceCallPermission();
1917
1918 final long identity = Binder.clearCallingIdentity();
1919 try {
1920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1921 return;
1922 }
1923 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1924 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1925 } finally {
1926 Binder.restoreCallingIdentity(identity);
1927 }
pkanwar32d516d2016-10-14 19:37:38 -07001928 };
1929
Wink Savilleb564aae2014-10-23 10:18:09 -07001930 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001932
1933 final long identity = Binder.clearCallingIdentity();
1934 try {
1935 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1936 return false;
1937 }
1938 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001945 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001946 }
1947
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001948 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 Phone phone = PhoneFactory.getPhone(slotIndex);
1952 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1953 PhoneConstantConversions.convertCallState(phone.getState());
1954 } finally {
1955 Binder.restoreCallingIdentity(identity);
1956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 }
1958
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001960 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001961 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1962 }
1963
1964 @Override
1965 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 final long identity = Binder.clearCallingIdentity();
1967 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001968 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001969 if (phone != null) {
1970 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1971 } else {
1972 return PhoneConstantConversions.convertDataState(
1973 PhoneConstants.DataState.DISCONNECTED);
1974 }
1975 } finally {
1976 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979
Sanket Padawe356d7632015-06-22 14:03:32 -07001980 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001981 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001982 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1983 }
1984
1985 @Override
1986 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987 final long identity = Binder.clearCallingIdentity();
1988 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001989 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001990 if (phone != null) {
1991 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1992 } else {
1993 return TelephonyManager.DATA_ACTIVITY_NONE;
1994 }
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 }
1999
2000 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002001 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002002 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002003 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002004
2005 LocationAccessPolicy.LocationPermissionResult locationResult =
2006 LocationAccessPolicy.checkLocationPermission(mApp,
2007 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2008 .setCallingPackage(callingPackage)
2009 .setCallingPid(Binder.getCallingPid())
2010 .setCallingUid(Binder.getCallingUid())
2011 .setMethod("getCellLocation")
2012 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2013 .build());
2014 switch (locationResult) {
2015 case DENIED_HARD:
2016 throw new SecurityException("Not allowed to access cell location");
2017 case DENIED_SOFT:
2018 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 }
2020
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002021 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 if (DBG_LOC) log("getCellLocation: is active user");
2025 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002026 int subId = mSubscriptionController.getDefaultDataSubId();
2027 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2028 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002029 return data;
2030 } finally {
2031 Binder.restoreCallingIdentity(identity);
2032 }
Svetoslav64fad262015-04-14 14:35:21 -07002033 }
2034
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002035 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002036 public String getNetworkCountryIsoForPhone(int phoneId) {
2037 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2038 // registered cell info, so return a NULL country instead.
2039 final long identity = Binder.clearCallingIdentity();
2040 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002041 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2042 // Get default phone in this case.
2043 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2044 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002045 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002046 // Todo: fix this when we can get the actual cellular network info when the device
2047 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002048 if (TelephonyManager.NETWORK_TYPE_IWLAN
2049 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2050 return "";
2051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002052 Phone phone = PhoneFactory.getPhone(phoneId);
2053 if (phone != null) {
2054 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002055 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002056 if (sst != null) {
2057 LocaleTracker lt = sst.getLocaleTracker();
2058 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002059 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2060 return lt.getCurrentCountry();
2061 } else if (emergencyNumberTracker != null) {
2062 return emergencyNumberTracker.getEmergencyCountryIso();
2063 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002064 }
2065 }
2066 }
2067 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002068 } finally {
2069 Binder.restoreCallingIdentity(identity);
2070 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002071 }
2072
2073 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002075 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002076 }
2077
Sanket Padawe356d7632015-06-22 14:03:32 -07002078 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002079 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 mApp.enforceCallingOrSelfPermission(
2081 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002082
2083 final long identity = Binder.clearCallingIdentity();
2084 try {
2085 final Phone phone = getPhone(subId);
2086 if (phone != null) {
2087 phone.enableLocationUpdates();
2088 }
2089 } finally {
2090 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 }
2093
2094 @Override
2095 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002096 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002097 }
2098
Sanket Padawe356d7632015-06-22 14:03:32 -07002099 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002100 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 mApp.enforceCallingOrSelfPermission(
2102 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103
2104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 final Phone phone = getPhone(subId);
2107 if (phone != null) {
2108 phone.disableLocationUpdates();
2109 }
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114
Nathan Harold31d7ff32018-10-15 20:20:30 -07002115 /**
2116 * Returns the target SDK version number for a given package name.
2117 *
Nathan Haroldec184742019-07-10 17:04:16 -07002118 * This call MUST be invoked before clearing the calling UID.
2119 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002120 * @return target SDK if the package is found or INT_MAX.
2121 */
2122 private int getTargetSdk(String packageName) {
2123 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002124 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002125 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002126 if (ai != null) return ai.targetSdkVersion;
2127 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002128 loge("Failed to get package info for pkg="
2129 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002130 }
2131 return Integer.MAX_VALUE;
2132 }
2133
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 @Override
2135 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002136 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2137 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002138 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2139 throw new SecurityException(
2140 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2141 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002142
Jordan Liu1617b712019-07-10 15:06:26 -07002143 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2145 return null;
2146 }
Svetoslav64fad262015-04-14 14:35:21 -07002147
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002148 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149
Nathan Haroldf180aac2018-06-01 18:43:55 -07002150 List<CellInfo> info = getAllCellInfo(callingPackage);
2151 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152
Nathan Haroldf180aac2018-06-01 18:43:55 -07002153 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2154 for (CellInfo ci : info) {
2155 if (ci instanceof CellInfoGsm) {
2156 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2157 } else if (ci instanceof CellInfoWcdma) {
2158 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002161 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 }
2163
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002164 private List<CellInfo> getCachedCellInfo() {
2165 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2166 for (Phone phone : PhoneFactory.getPhones()) {
2167 List<CellInfo> info = phone.getAllCellInfo();
2168 if (info != null) cellInfos.addAll(info);
2169 }
2170 return cellInfos;
2171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172
2173 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002174 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002175 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002176 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002177
2178 LocationAccessPolicy.LocationPermissionResult locationResult =
2179 LocationAccessPolicy.checkLocationPermission(mApp,
2180 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2181 .setCallingPackage(callingPackage)
2182 .setCallingPid(Binder.getCallingPid())
2183 .setCallingUid(Binder.getCallingUid())
2184 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002185 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002186 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2187 .build());
2188 switch (locationResult) {
2189 case DENIED_HARD:
2190 throw new SecurityException("Not allowed to access cell info");
2191 case DENIED_SOFT:
2192 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 }
2194
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002195 final int targetSdk = getTargetSdk(callingPackage);
2196 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2197 return getCachedCellInfo();
2198 }
2199
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002200 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002201 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002202 final long identity = Binder.clearCallingIdentity();
2203 try {
2204 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2205 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002206 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002207 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208 if (info != null) cellInfos.addAll(info);
2209 }
2210 return cellInfos;
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 }
2214 }
2215
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002216 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002217 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2218 requestCellInfoUpdateInternal(
2219 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2220 }
2221
2222 @Override
2223 public void requestCellInfoUpdateWithWorkSource(
2224 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2225 enforceModifyPermission();
2226 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2227 }
2228
2229 private void requestCellInfoUpdateInternal(
2230 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002231 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002232 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002233
2234 LocationAccessPolicy.LocationPermissionResult locationResult =
2235 LocationAccessPolicy.checkLocationPermission(mApp,
2236 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2237 .setCallingPackage(callingPackage)
2238 .setCallingPid(Binder.getCallingPid())
2239 .setCallingUid(Binder.getCallingUid())
2240 .setMethod("requestCellInfoUpdate")
2241 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2242 .build());
2243 switch (locationResult) {
2244 case DENIED_HARD:
2245 throw new SecurityException("Not allowed to access cell info");
2246 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002247 try {
2248 cb.onCellInfo(new ArrayList<CellInfo>());
2249 } catch (RemoteException re) {
2250 // Drop without consequences
2251 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002252 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002253 }
2254
Nathan Harolda939a962019-05-09 10:13:47 -07002255
2256 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002257 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2258
2259 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2260 }
2261
2262 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002264 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002265 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002266
2267 final long identity = Binder.clearCallingIdentity();
2268 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002269 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002270 } finally {
2271 Binder.restoreCallingIdentity(identity);
2272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
Shishir Agrawala9f32182016-04-12 12:00:16 -07002275 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002276 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002277 Phone phone = PhoneFactory.getPhone(slotIndex);
2278 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002279 return null;
2280 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002281 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002282 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2283 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002284 return null;
2285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 return phone.getImei();
2290 } finally {
2291 Binder.restoreCallingIdentity(identity);
2292 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002293 }
2294
2295 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002296 public String getTypeAllocationCodeForSlot(int slotIndex) {
2297 Phone phone = PhoneFactory.getPhone(slotIndex);
2298 String tac = null;
2299 if (phone != null) {
2300 String imei = phone.getImei();
2301 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2302 }
2303 return tac;
2304 }
2305
2306 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002307 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002308 Phone phone = PhoneFactory.getPhone(slotIndex);
2309 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002310 return null;
2311 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002312
Jeff Davidson913390f2018-02-23 17:11:49 -08002313 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002314 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2315 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002316 return null;
2317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002318
2319 final long identity = Binder.clearCallingIdentity();
2320 try {
2321 return phone.getMeid();
2322 } finally {
2323 Binder.restoreCallingIdentity(identity);
2324 }
Jack Yu2af8d712017-03-15 17:14:14 -07002325 }
2326
2327 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002328 public String getManufacturerCodeForSlot(int slotIndex) {
2329 Phone phone = PhoneFactory.getPhone(slotIndex);
2330 String manufacturerCode = null;
2331 if (phone != null) {
2332 String meid = phone.getMeid();
2333 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2334 }
2335 return manufacturerCode;
2336 }
2337
2338 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002339 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002340 Phone phone = PhoneFactory.getPhone(slotIndex);
2341 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002342 return null;
2343 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002344 int subId = phone.getSubId();
2345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2346 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2347 return null;
2348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002349
2350 final long identity = Binder.clearCallingIdentity();
2351 try {
2352 return phone.getDeviceSvn();
2353 } finally {
2354 Binder.restoreCallingIdentity(identity);
2355 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002356 }
2357
fionaxu43304da2017-11-27 22:51:16 -08002358 @Override
2359 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 final Phone phone = getPhone(subId);
2363 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2364 } finally {
2365 Binder.restoreCallingIdentity(identity);
2366 }
fionaxu43304da2017-11-27 22:51:16 -08002367 }
2368
2369 @Override
2370 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = getPhone(subId);
2374 return phone == null ? null : phone.getCarrierName();
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
2377 }
fionaxu43304da2017-11-27 22:51:16 -08002378 }
2379
calvinpanffe225e2018-11-01 19:43:06 +08002380 @Override
chen xu0026ca62019-03-06 15:28:50 -08002381 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 final Phone phone = getPhone(subId);
2385 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002386 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002387 } finally {
2388 Binder.restoreCallingIdentity(identity);
2389 }
2390 }
2391
2392 @Override
chen xu0026ca62019-03-06 15:28:50 -08002393 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002397 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002398 } finally {
2399 Binder.restoreCallingIdentity(identity);
2400 }
2401 }
2402
chen xu651eec72018-11-11 19:03:44 -08002403 @Override
chen xu864e11c2018-12-06 22:10:03 -08002404 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2405 if (!isSubscriptionMccMnc) {
2406 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2407 }
chen xu651eec72018-11-11 19:03:44 -08002408 final Phone phone = PhoneFactory.getPhone(slotIndex);
2409 if (phone == null) {
2410 return TelephonyManager.UNKNOWN_CARRIER_ID;
2411 }
2412 final long identity = Binder.clearCallingIdentity();
2413 try {
2414 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2415 } finally {
2416 Binder.restoreCallingIdentity(identity);
2417 }
2418 }
2419
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 //
2421 // Internal helper methods.
2422 //
2423
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002424 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2426 *
2427 * @throws SecurityException if the caller does not have the required permission
2428 */
2429 private void enforceModifyPermission() {
2430 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2431 }
2432
Shuo Qianf2b2df42019-11-13 17:43:31 -08002433 private void enforceActiveEmergencySessionPermission() {
2434 mApp.enforceCallingOrSelfPermission(
2435 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2436 }
2437
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002438 /**
2439 * Make sure the caller has the CALL_PHONE permission.
2440 *
2441 * @throws SecurityException if the caller does not have the required permission
2442 */
2443 private void enforceCallPermission() {
2444 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2445 }
2446
paulhu423b5f22019-08-23 19:17:33 +08002447 private void enforceSettingsPermission() {
2448 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002449 }
2450
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 private String createTelUrl(String number) {
2452 if (TextUtils.isEmpty(number)) {
2453 return null;
2454 }
2455
Jake Hambye994d462014-02-03 13:10:13 -08002456 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458
Ihab Awadf9e92732013-12-05 18:02:52 -08002459 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2461 }
2462
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002463 private static void logv(String msg) {
2464 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2465 }
2466
Ihab Awadf9e92732013-12-05 18:02:52 -08002467 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2469 }
2470
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002471 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002472 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002473 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002474 }
2475
Sanket Padawe356d7632015-06-22 14:03:32 -07002476 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002477 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 final Phone phone = PhoneFactory.getPhone(slotIndex);
2481 if (phone == null) {
2482 return PhoneConstants.PHONE_TYPE_NONE;
2483 } else {
2484 return phone.getPhoneType();
2485 }
2486 } finally {
2487 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490
2491 /**
2492 * Returns the CDMA ERI icon index to display
2493 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002494 @Override
2495 public int getCdmaEriIconIndex(String callingPackage) {
2496 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002497 }
2498
Sanket Padawe356d7632015-06-22 14:03:32 -07002499 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002500 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002502 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002503 return -1;
2504 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = getPhone(subId);
2509 if (phone != null) {
2510 return phone.getCdmaEriIconIndex();
2511 } else {
2512 return -1;
2513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
2519 /**
2520 * Returns the CDMA ERI icon mode,
2521 * 0 - ON
2522 * 1 - FLASHING
2523 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002524 @Override
2525 public int getCdmaEriIconMode(String callingPackage) {
2526 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002527 }
2528
Sanket Padawe356d7632015-06-22 14:03:32 -07002529 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002530 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002532 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002533 return -1;
2534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535
2536 final long identity = Binder.clearCallingIdentity();
2537 try {
2538 final Phone phone = getPhone(subId);
2539 if (phone != null) {
2540 return phone.getCdmaEriIconMode();
2541 } else {
2542 return -1;
2543 }
2544 } finally {
2545 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 }
2548
2549 /**
2550 * Returns the CDMA ERI text,
2551 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002552 @Override
2553 public String getCdmaEriText(String callingPackage) {
2554 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002555 }
2556
Sanket Padawe356d7632015-06-22 14:03:32 -07002557 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002558 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002560 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002561 return null;
2562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563
2564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 final Phone phone = getPhone(subId);
2567 if (phone != null) {
2568 return phone.getCdmaEriText();
2569 } else {
2570 return null;
2571 }
2572 } finally {
2573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 }
2576
2577 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002578 * Returns the CDMA MDN.
2579 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002580 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002581 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2583 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002584
2585 final long identity = Binder.clearCallingIdentity();
2586 try {
2587 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002588 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002589 return phone.getLine1Number();
2590 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002591 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592 return null;
2593 }
2594 } finally {
2595 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002596 }
2597 }
2598
2599 /**
2600 * Returns the CDMA MIN.
2601 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002602 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002603 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2605 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606
2607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 final Phone phone = getPhone(subId);
2610 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2611 return phone.getCdmaMin();
2612 } else {
2613 return null;
2614 }
2615 } finally {
2616 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002617 }
2618 }
2619
Hall Liud892bec2018-11-30 14:51:45 -08002620 @Override
2621 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2622 INumberVerificationCallback callback, String callingPackage) {
2623 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2624 != PERMISSION_GRANTED) {
2625 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2626 }
2627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2628
2629 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2630 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2631 throw new SecurityException("Calling package must be configured in the device config");
2632 }
2633
2634 if (range == null) {
2635 throw new NullPointerException("Range must be non-null");
2636 }
2637
2638 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002639 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002640
2641 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2642 }
2643
Junda Liuca05d5d2014-08-14 22:36:34 -07002644 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 * Returns true if CDMA provisioning needs to run.
2646 */
2647 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 final long identity = Binder.clearCallingIdentity();
2649 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002650 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 } finally {
2652 Binder.restoreCallingIdentity(identity);
2653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 }
2655
2656 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002657 * Sets the voice mail number of a given subId.
2658 */
2659 @Override
2660 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002661 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662
2663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2666 new Pair<String, String>(alphaTag, number), new Integer(subId));
2667 return success;
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
2670 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002671 }
2672
Ta-wei Yen87c49842016-05-13 21:19:52 -07002673 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002674 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2675 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002676 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2677 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002678 if (!TextUtils.equals(callingPackage, systemDialer)) {
2679 throw new SecurityException("caller must be system dialer");
2680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2685 if (phoneAccountHandle == null) {
2686 return null;
2687 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002688 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 } finally {
2690 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002691 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002692 }
2693
2694 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002695 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002698 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002699 return null;
2700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002702 final long identity = Binder.clearCallingIdentity();
2703 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002704 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002705 } finally {
2706 Binder.restoreCallingIdentity(identity);
2707 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002708 }
2709
2710 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002711 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2712 VisualVoicemailSmsFilterSettings settings) {
2713 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714
2715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002718 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 } finally {
2720 Binder.restoreCallingIdentity(identity);
2721 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002722 }
2723
2724 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002725 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2726 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727
2728 final long identity = Binder.clearCallingIdentity();
2729 try {
2730 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002731 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 } finally {
2733 Binder.restoreCallingIdentity(identity);
2734 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002735 }
2736
2737 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002738 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2739 String callingPackage, int subId) {
2740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741
2742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002745 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746 } finally {
2747 Binder.restoreCallingIdentity(identity);
2748 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002749 }
2750
2751 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002752 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002753 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754
2755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002758 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 } finally {
2760 Binder.restoreCallingIdentity(identity);
2761 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002762 }
2763
2764 @Override
2765 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2766 String number, int port, String text, PendingIntent sentIntent) {
2767 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002768 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002769 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002770 SmsController smsController = PhoneFactory.getSmsController();
2771 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2772 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002773 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002774
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002775 /**
fionaxu0152e512016-11-14 13:36:14 -08002776 * Sets the voice activation state of a given subId.
2777 */
2778 @Override
2779 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2781 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 final Phone phone = getPhone(subId);
2786 if (phone != null) {
2787 phone.setVoiceActivationState(activationState);
2788 } else {
2789 loge("setVoiceActivationState fails with invalid subId: " + subId);
2790 }
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002793 }
2794 }
2795
2796 /**
2797 * Sets the data activation state of a given subId.
2798 */
2799 @Override
2800 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2802 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 final Phone phone = getPhone(subId);
2807 if (phone != null) {
2808 phone.setDataActivationState(activationState);
2809 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002810 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002814 }
2815 }
2816
2817 /**
2818 * Returns the voice activation state of a given subId.
2819 */
2820 @Override
2821 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002822 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823
fionaxu0152e512016-11-14 13:36:14 -08002824 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 if (phone != null) {
2828 return phone.getVoiceActivationState();
2829 } else {
2830 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2831 }
2832 } finally {
2833 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002834 }
2835 }
2836
2837 /**
2838 * Returns the data activation state of a given subId.
2839 */
2840 @Override
2841 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002842 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843
fionaxu0152e512016-11-14 13:36:14 -08002844 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 if (phone != null) {
2848 return phone.getDataActivationState();
2849 } else {
2850 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2851 }
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002854 }
2855 }
2856
2857 /**
Wink Saville36469e72014-06-11 15:17:00 -07002858 * Returns the unread count of voicemails for a subId
2859 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002861 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2863 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2864 return 0;
2865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866 final long identity = Binder.clearCallingIdentity();
2867 try {
2868 final Phone phone = getPhone(subId);
2869 if (phone != null) {
2870 return phone.getVoiceMessageCount();
2871 } else {
2872 return 0;
2873 }
2874 } finally {
2875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877 }
2878
2879 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002880 * returns true, if the device is in a state where both voice and data
2881 * are supported simultaneously. This can change based on location or network condition.
2882 */
2883 @Override
2884 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 final Phone phone = getPhone(subId);
2888 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
2891 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002892 }
2893
2894 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002895 * Send the dialer code if called from the current default dialer or the caller has
2896 * carrier privilege.
2897 * @param inputCode The dialer code to send
2898 */
2899 @Override
2900 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002901 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002903 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2904 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002905 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002906 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2907 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002908 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909
2910 final long identity = Binder.clearCallingIdentity();
2911 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002912 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002913 } finally {
2914 Binder.restoreCallingIdentity(identity);
2915 }
fionaxu235cc5e2017-03-06 22:25:57 -08002916 }
2917
Pengquan Menga1bb6272018-09-06 09:59:22 -07002918 @Override
2919 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002920 if (!isActiveSubscription(subId)) {
2921 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2922 }
2923
Pengquan Menga1bb6272018-09-06 09:59:22 -07002924 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2925 }
2926
Brad Ebinger35c841c2018-10-01 10:40:55 -07002927 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002928 public boolean isInEmergencySmsMode() {
2929 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 for (Phone phone : PhoneFactory.getPhones()) {
2933 if (phone.isInEmergencySmsMode()) {
2934 return true;
2935 }
2936 }
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
2940 return false;
2941 }
2942
2943 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002944 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2945 throws RemoteException {
2946 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002947 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2948 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2949 "IMS not available on device.");
2950 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002951 final long token = Binder.clearCallingIdentity();
2952 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002953 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002954 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002955 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002956 } catch (ImsException e) {
2957 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002958 } finally {
2959 Binder.restoreCallingIdentity(token);
2960 }
2961 }
2962
2963 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002964 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2965 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002966 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2967 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2968 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002969 final long token = Binder.clearCallingIdentity();
2970 try {
2971 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2972 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2973 .removeRegistrationCallbackForSubscription(c, subId);
2974 } catch (ImsException e) {
2975 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2976 + "is inactive, ignoring unregister.");
2977 // If the subscription is no longer active, just return, since the callback
2978 // will already have been removed internally.
2979 } finally {
2980 Binder.restoreCallingIdentity(token);
2981 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002982 }
2983
Brad Ebinger774ba362019-10-22 17:36:18 -07002984 /**
2985 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2986 */
2987 @Override
2988 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2989 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2990 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2991 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2992 "IMS not available on device.");
2993 }
2994 final long token = Binder.clearCallingIdentity();
2995 try {
2996 Phone phone = getPhone(subId);
2997 if (phone == null) {
2998 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2999 + subId + "'");
3000 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3001 }
3002 phone.getImsRegistrationState(regState -> {
3003 try {
3004 consumer.accept((regState == null)
3005 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3006 } catch (RemoteException e) {
3007 // Ignore if the remote process is no longer available to call back.
3008 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3009 }
3010 });
3011 } finally {
3012 Binder.restoreCallingIdentity(token);
3013 }
3014 }
3015
3016 /**
3017 * Get the transport type for the IMS service registration state.
3018 */
3019 @Override
3020 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3021 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3022 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3023 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3024 "IMS not available on device.");
3025 }
3026 final long token = Binder.clearCallingIdentity();
3027 try {
3028 Phone phone = getPhone(subId);
3029 if (phone == null) {
3030 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3031 + subId + "'");
3032 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3033 }
3034 phone.getImsRegistrationTech(regTech -> {
3035 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3036 int regTechConverted = (regTech == null)
3037 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3038 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3039 regTechConverted);
3040 try {
3041 consumer.accept(regTechConverted);
3042 } catch (RemoteException e) {
3043 // Ignore if the remote process is no longer available to call back.
3044 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3045 }
3046 });
3047 } finally {
3048 Binder.restoreCallingIdentity(token);
3049 }
3050 }
3051
Brad Ebinger35c841c2018-10-01 10:40:55 -07003052 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003053 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3054 throws RemoteException {
3055 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003056 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3057 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3058 "IMS not available on device.");
3059 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3061 final long token = Binder.clearCallingIdentity();
3062 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003063 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003064 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003065 } catch (ImsException e) {
3066 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003067 } finally {
3068 Binder.restoreCallingIdentity(token);
3069 }
3070 }
3071
3072 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003073 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3074 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003075 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3076 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3077 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003078
3079 final long token = Binder.clearCallingIdentity();
3080 try {
3081 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3082 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003083 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003084 } catch (ImsException e) {
3085 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3086 + "is inactive, ignoring unregister.");
3087 // If the subscription is no longer active, just return, since the callback
3088 // will already have been removed internally.
3089 } finally {
3090 Binder.restoreCallingIdentity(token);
3091 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003092 }
3093
3094 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003095 public boolean isCapable(int subId, int capability, int regTech) {
3096 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003097 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3098 final long token = Binder.clearCallingIdentity();
3099 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003100 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003101 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003102 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3104 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003105 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003106 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3107 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 } finally {
3109 Binder.restoreCallingIdentity(token);
3110 }
3111 }
3112
3113 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003114 public boolean isAvailable(int subId, int capability, int regTech) {
3115 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003116 final long token = Binder.clearCallingIdentity();
3117 try {
3118 Phone phone = getPhone(subId);
3119 if (phone == null) return false;
3120 return phone.isImsCapabilityAvailable(capability, regTech);
3121 } finally {
3122 Binder.restoreCallingIdentity(token);
3123 }
3124 }
3125
Brad Ebinger77b832e2019-10-17 17:03:22 -07003126 /**
3127 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3128 * subscription.
3129 * @param subId The subscription to use to check the configuration.
3130 * @param callback The callback that will be used to send the result.
3131 * @param capability The MmTelFeature capability that will be used to send the result.
3132 * @param transportType The transport type of the MmTelFeature capability.
3133 */
3134 @Override
3135 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3136 int transportType) {
3137 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3138 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3139 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3140 "IMS not available on device.");
3141 }
3142 final long token = Binder.clearCallingIdentity();
3143 try {
3144 int slotId = getSlotIndex(subId);
3145 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3146 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3147 + subId + "'");
3148 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3149 }
3150 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3151 transportType, aBoolean -> {
3152 try {
3153 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3154 } catch (RemoteException e) {
3155 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3156 + "running. Ignore");
3157 }
3158 });
3159 } finally {
3160 Binder.restoreCallingIdentity(token);
3161 }
3162 }
3163
Brad Ebinger35c841c2018-10-01 10:40:55 -07003164 @Override
3165 public boolean isAdvancedCallingSettingEnabled(int subId) {
3166 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3167 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3168 final long token = Binder.clearCallingIdentity();
3169 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003170 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003171 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003172 } catch (ImsException e) {
3173 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003174 } finally {
3175 Binder.restoreCallingIdentity(token);
3176 }
3177 }
3178
3179 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003180 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003182 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003183 final long identity = Binder.clearCallingIdentity();
3184 try {
3185 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003186 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003187 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003188 } catch (ImsException e) {
3189 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003190 } finally {
3191 Binder.restoreCallingIdentity(identity);
3192 }
3193 }
3194
3195 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003196 public boolean isVtSettingEnabled(int subId) {
3197 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003198 final long identity = Binder.clearCallingIdentity();
3199 try {
3200 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003201 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3202 } catch (ImsException e) {
3203 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
3207 }
3208
3209 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003210 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003212 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 final long identity = Binder.clearCallingIdentity();
3214 try {
3215 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003216 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003217 } catch (ImsException e) {
3218 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
3222 }
3223
3224 @Override
3225 public boolean isVoWiFiSettingEnabled(int subId) {
3226 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003230 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003231 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003232 } catch (ImsException e) {
3233 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
3237 }
3238
3239 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003240 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003242 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003246 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003247 } catch (ImsException e) {
3248 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003249 } finally {
3250 Binder.restoreCallingIdentity(identity);
3251 }
3252 }
3253
3254 @Override
3255 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3256 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003260 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003262 } catch (ImsException e) {
3263 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003264 } finally {
3265 Binder.restoreCallingIdentity(identity);
3266 }
3267 }
3268
3269 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003270 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003272 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 final long identity = Binder.clearCallingIdentity();
3274 try {
3275 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003276 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003277 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003278 } catch (ImsException e) {
3279 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
3283 }
3284
3285 @Override
3286 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3288 "setVoWiFiNonPersistent");
3289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003292 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003293 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003294 } catch (ImsException e) {
3295 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
3299 }
3300
3301 @Override
3302 public int getVoWiFiModeSetting(int subId) {
3303 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003307 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003308 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003309 } catch (ImsException e) {
3310 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003311 } finally {
3312 Binder.restoreCallingIdentity(identity);
3313 }
3314 }
3315
3316 @Override
3317 public void setVoWiFiModeSetting(int subId, int mode) {
3318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3319 "setVoWiFiModeSetting");
3320 final long identity = Binder.clearCallingIdentity();
3321 try {
3322 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003323 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003324 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003325 } catch (ImsException e) {
3326 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003327 } finally {
3328 Binder.restoreCallingIdentity(identity);
3329 }
3330 }
3331
3332 @Override
3333 public int getVoWiFiRoamingModeSetting(int subId) {
3334 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003338 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003339 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003340 } catch (ImsException e) {
3341 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
3345 }
3346
3347 @Override
3348 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3350 "setVoWiFiRoamingModeSetting");
3351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003354 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003355 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003356 } catch (ImsException e) {
3357 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003358 } finally {
3359 Binder.restoreCallingIdentity(identity);
3360 }
3361 }
3362
3363 @Override
3364 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3366 "setRttCapabilityEnabled");
3367 final long identity = Binder.clearCallingIdentity();
3368 try {
3369 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003370 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3371 } catch (ImsException e) {
3372 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003373 } finally {
3374 Binder.restoreCallingIdentity(identity);
3375 }
3376 }
3377
3378 @Override
3379 public boolean isTtyOverVolteEnabled(int subId) {
3380 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003384 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003385 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003386 } catch (ImsException e) {
3387 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003388 } finally {
3389 Binder.restoreCallingIdentity(identity);
3390 }
3391 }
3392
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003393 @Override
3394 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3395 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3396 final long identity = Binder.clearCallingIdentity();
3397 try {
3398 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003399 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003400 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003401 } catch (ImsException e) {
3402 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003403 } finally {
3404 Binder.restoreCallingIdentity(identity);
3405 }
3406 }
3407
3408 @Override
3409 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3410 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3411 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003412 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3413 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3414 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003415 try {
3416 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003417 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003418 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003419 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003420 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3421 + "is inactive, ignoring unregister.");
3422 // If the subscription is no longer active, just return, since the callback will already
3423 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
3429 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003430 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3431 boolean isProvisioned) {
3432 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3433 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3434 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3435 }
3436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3437 "setProvisioningStatusForCapability");
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3441 Phone phone = getPhone(subId);
3442 if (phone == null) {
3443 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3444 + subId);
3445 return;
3446 }
3447 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3448 return;
3449 }
3450
3451 // this capability requires provisioning, route to the correct API.
3452 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3453 switch (capability) {
3454 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3455 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3456 ims.setVolteProvisioned(isProvisioned);
3457 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3458 ims.setWfcProvisioned(isProvisioned);
3459 }
3460 break;
3461 }
3462 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3463 // There is currently no difference in VT provisioning type.
3464 ims.setVtProvisioned(isProvisioned);
3465 break;
3466 }
3467 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3468 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3469 // change the capability of the feature instead if needed.
3470 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3471 == isProvisioned) {
3472 // No change in provisioning.
3473 return;
3474 }
3475 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3476 try {
3477 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003478 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003479 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3480 + ", Exception" + e.getMessage());
3481 }
3482 break;
3483 }
3484 default: {
3485 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3486 + capability + "', which does not require provisioning.");
3487 }
3488 }
3489
3490 } finally {
3491 Binder.restoreCallingIdentity(identity);
3492 }
3493 }
3494
3495 @Override
3496 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3497 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3498 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3499 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3500 }
3501 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3505 Phone phone = getPhone(subId);
3506 if (phone == null) {
3507 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3508 + subId);
3509 // We will fail with "true" as the provisioning status because this is the default
3510 // if we do not require provisioning.
3511 return true;
3512 }
3513
3514 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3515 return true;
3516 }
3517
3518 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3519 switch (capability) {
3520 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3521 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3522 return ims.isVolteProvisionedOnDevice();
3523 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3524 return ims.isWfcProvisionedOnDevice();
3525 }
3526 // This should never happen, since we are checking tech above to make sure it
3527 // is either LTE or IWLAN.
3528 throw new IllegalArgumentException("Invalid radio technology for voice "
3529 + "capability.");
3530 }
3531 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3532 // There is currently no difference in VT provisioning type.
3533 return ims.isVtProvisionedOnDevice();
3534 }
3535 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3536 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3537 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3538 }
3539 default: {
3540 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3541 + capability + "', which does not require provisioning.");
3542 }
3543 }
3544
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
3548 }
3549
3550 @Override
3551 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3552 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3553 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3554 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3555 }
3556 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3557 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3558 return (provisionedBits & capability) > 0;
3559 }
3560
3561 @Override
3562 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3563 boolean isProvisioned) {
3564 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3565 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3566 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3567 }
3568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3569 "setProvisioningStatusForCapability");
3570 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3571 // If the current provisioning status for capability already matches isProvisioned,
3572 // do nothing.
3573 if (((provisionedBits & capability) > 0) == isProvisioned) {
3574 return;
3575 }
3576 if (isProvisioned) {
3577 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3578 } else {
3579 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3580 }
3581 }
3582
3583 /**
3584 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3585 * technology. The bitfield should mirror the bitfield defined by
3586 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3587 */
3588 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3589 String key = getMmTelProvisioningKey(subId, tech);
3590 // Default is no capabilities are provisioned.
3591 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3592 }
3593
3594 /**
3595 * Sets the MmTel capability provisioning bitfield (defined by
3596 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3597 * technology specified.
3598 *
3599 * Note: This is a synchronous command and should not be called on UI thread.
3600 */
3601 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3602 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3603 String key = getMmTelProvisioningKey(subId, tech);
3604 editor.putInt(key, newField);
3605 editor.commit();
3606 }
3607
3608 private static String getMmTelProvisioningKey(int subId, int tech) {
3609 // resulting key is provision_ims_mmtel_{subId}_{tech}
3610 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3611 }
3612
3613 /**
3614 * Query CarrierConfig to see if the specified capability requires provisioning for the
3615 * carrier associated with the subscription id.
3616 */
3617 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3618 int capability) {
3619 CarrierConfigManager configManager = new CarrierConfigManager(context);
3620 PersistableBundle c = configManager.getConfigForSubId(subId);
3621 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003622 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003623 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3624 false);
3625 boolean requireVoiceVtProvisioning = c.getBoolean(
3626 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3627
3628 // First check to make sure that the capability requires provisioning.
3629 switch (capability) {
3630 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3631 // intentional fallthrough
3632 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3633 if (requireVoiceVtProvisioning) {
3634 // Voice and Video requires provisioning
3635 return true;
3636 }
3637 break;
3638 }
3639 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3640 if (requireUtProvisioning) {
3641 // UT requires provisioning
3642 return true;
3643 }
3644 break;
3645 }
3646 }
3647 return false;
3648 }
3649
3650 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003651 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003652 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3653 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3654 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003655 enforceReadPrivilegedPermission("getImsProvisioningInt");
3656 final long identity = Binder.clearCallingIdentity();
3657 try {
3658 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003659 int slotId = getSlotIndex(subId);
3660 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3661 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3662 + subId + "' for key:" + key);
3663 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3664 }
3665 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003666 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003667 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3668 + subId + "' for key:" + key);
3669 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003670 } finally {
3671 Binder.restoreCallingIdentity(identity);
3672 }
3673 }
3674
3675 @Override
3676 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003677 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3678 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3679 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003680 enforceReadPrivilegedPermission("getImsProvisioningString");
3681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003684 int slotId = getSlotIndex(subId);
3685 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3686 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3687 + subId + "' for key:" + key);
3688 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3689 }
3690 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003691 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003692 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3693 + subId + "' for key:" + key);
3694 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003695 } finally {
3696 Binder.restoreCallingIdentity(identity);
3697 }
3698 }
3699
3700 @Override
3701 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003702 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3703 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3704 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3706 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003710 int slotId = getSlotIndex(subId);
3711 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3712 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3713 + subId + "' for key:" + key);
3714 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3715 }
3716 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003717 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003718 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3719 + "' for key:" + key);
3720 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
3724 }
3725
3726 @Override
3727 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003728 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3729 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3730 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3732 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003736 int slotId = getSlotIndex(subId);
3737 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3738 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3739 + subId + "' for key:" + key);
3740 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3741 }
3742 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003743 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003744 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3745 + "' for key:" + key);
3746 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
3750 }
3751
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003752 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003753 int slotId = SubscriptionManager.getSlotIndex(subId);
3754 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003755 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3756 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 }
3758 return slotId;
3759 }
3760
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003761 private int getSlotIndex(int subId) {
3762 int slotId = SubscriptionManager.getSlotIndex(subId);
3763 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3764 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3765 }
3766 return slotId;
3767 }
3768
Wink Saville36469e72014-06-11 15:17:00 -07003769 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003770 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003771 */
3772 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003773 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003774 final int targetSdk = getTargetSdk(callingPackage);
3775 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3776 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3777 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003778 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3779 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003780 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3781 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783 final long identity = Binder.clearCallingIdentity();
3784 try {
3785 final Phone phone = getPhone(subId);
3786 if (phone != null) {
3787 return phone.getServiceState().getDataNetworkType();
3788 } else {
3789 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3790 }
3791 } finally {
3792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003794 }
3795
3796 /**
3797 * Returns the data network type
3798 */
3799 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003800 public int getDataNetworkType(String callingPackage) {
3801 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003802 }
3803
3804 /**
3805 * Returns the data network type for a subId
3806 */
3807 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003808 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003810 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003811 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3812 }
3813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 final Phone phone = getPhone(subId);
3817 if (phone != null) {
3818 return phone.getServiceState().getDataNetworkType();
3819 } else {
3820 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3821 }
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003825 }
3826
3827 /**
Wink Saville36469e72014-06-11 15:17:00 -07003828 * Returns the Voice network type for a subId
3829 */
3830 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003831 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003832 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003833 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003834 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3835 }
3836
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 final Phone phone = getPhone(subId);
3840 if (phone != null) {
3841 return phone.getServiceState().getVoiceNetworkType();
3842 } else {
3843 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3844 }
3845 } finally {
3846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003848 }
3849
3850 /**
3851 * @return true if a ICC card is present
3852 */
3853 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003854 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003855 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3856 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003857 }
3858
3859 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003860 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003861 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003862 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003863 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864 final long identity = Binder.clearCallingIdentity();
3865 try {
3866 final Phone phone = PhoneFactory.getPhone(slotIndex);
3867 if (phone != null) {
3868 return phone.getIccCard().hasIccCard();
3869 } else {
3870 return false;
3871 }
3872 } finally {
3873 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003875 }
3876
3877 /**
3878 * Return if the current radio is LTE on CDMA. This
3879 * is a tri-state return value as for a period of time
3880 * the mode may be unknown.
3881 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003882 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003883 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003884 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003885 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003886 @Override
3887 public int getLteOnCdmaMode(String callingPackage) {
3888 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003889 }
3890
Sanket Padawe356d7632015-06-22 14:03:32 -07003891 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003892 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003894 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003895 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3896 }
3897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898 final long identity = Binder.clearCallingIdentity();
3899 try {
3900 final Phone phone = getPhone(subId);
3901 if (phone == null) {
3902 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3903 } else {
3904 return phone.getLteOnCdmaMode();
3905 }
3906 } finally {
3907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003908 }
Wink Saville36469e72014-06-11 15:17:00 -07003909 }
3910
Wink Saville36469e72014-06-11 15:17:00 -07003911 /**
3912 * {@hide}
3913 * Returns Default subId, 0 in the case of single standby.
3914 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003915 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003916 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003917 }
3918
Shishir Agrawala9f32182016-04-12 12:00:16 -07003919 private int getSlotForDefaultSubscription() {
3920 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3921 }
3922
Wink Savilleb564aae2014-10-23 10:18:09 -07003923 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003924 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003925 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003926
Pengquan Menge92a50d2018-09-21 15:54:48 -07003927 private boolean isActiveSubscription(int subId) {
3928 return mSubscriptionController.isActiveSubId(subId);
3929 }
3930
Ihab Awadf2177b72013-11-25 13:33:23 -08003931 /**
3932 * @see android.telephony.TelephonyManager.WifiCallingChoices
3933 */
3934 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003935 final long identity = Binder.clearCallingIdentity();
3936 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003937 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3939 getWhenToMakeWifiCallsDefaultPreference());
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
3942 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003943 }
3944
3945 /**
3946 * @see android.telephony.TelephonyManager.WifiCallingChoices
3947 */
3948 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003952 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3954 } finally {
3955 Binder.restoreCallingIdentity(identity);
3956 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003957 }
3958
Sailesh Nepald1e68152013-12-12 19:08:02 -08003959 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003960 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003961 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003962 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003963
Jordan Liu4c733742019-02-28 12:03:40 -08003964 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3965 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3966 if (phoneId == -1) {
3967 throw new IllegalArgumentException("Given slot index: " + slotIndex
3968 + " does not correspond to an active phone");
3969 }
3970 return PhoneFactory.getPhone(phoneId);
3971 }
3972
Shishir Agrawal566b7612013-10-28 14:41:00 -07003973 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003974 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3975 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3977 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003979 if (DBG) {
3980 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3981 }
3982 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3983 p2);
3984 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003985
Jordan Liu4c733742019-02-28 12:03:40 -08003986
3987 @Override
3988 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3989 int slotIndex, String callingPackage, String aid, int p2) {
3990 enforceModifyPermission();
3991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3992 if (DBG) {
3993 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3994 }
3995 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3996 callingPackage, aid, p2);
3997 }
3998
3999 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4000 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 if (TextUtils.equals(ISDR_AID, aid)) {
4004 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004005 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4006 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 if (bestComponent == null
4008 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4009 loge("The calling package is not allowed to access ISD-R.");
4010 throw new SecurityException(
4011 "The calling package is not allowed to access ISD-R.");
4012 }
Derek Tan740e1672017-06-27 14:56:27 -07004013 }
Derek Tan740e1672017-06-27 14:56:27 -07004014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004016 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4017 null /* workSource */);
4018 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004019 return response;
4020 } finally {
4021 Binder.restoreCallingIdentity(identity);
4022 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004023 }
4024
4025 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004026 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4028 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004029 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4030 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4031 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004032
Jordan Liu4c733742019-02-28 12:03:40 -08004033 @Override
4034 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4035 enforceModifyPermission();
4036 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4037 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4038 channel);
4039 }
4040
4041 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 final long identity = Binder.clearCallingIdentity();
4043 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044 if (channel < 0) {
4045 return false;
4046 }
Jordan Liu4c733742019-02-28 12:03:40 -08004047 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4048 null /* workSource */);
4049 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 return success;
4051 } finally {
4052 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004053 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004054 }
4055
4056 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004057 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004058 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4060 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004061 if (DBG) {
4062 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4063 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4064 + p3 + " data=" + data);
4065 }
4066 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4067 command, p1, p2, p3, data);
4068 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004069
Jordan Liu4c733742019-02-28 12:03:40 -08004070 @Override
4071 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4072 int command, int p1, int p2, int p3, String data) {
4073 enforceModifyPermission();
4074 if (DBG) {
4075 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4076 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4077 + p3 + " data=" + data);
4078 }
4079 return iccTransmitApduLogicalChannelWithPermission(
4080 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4081 data);
4082 }
4083
4084 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4085 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 final long identity = Binder.clearCallingIdentity();
4087 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004088 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089 return "";
4090 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004093 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4094 null /* workSource */);
4095 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 // Append the returned status code to the end of the response payload.
4098 String s = Integer.toHexString(
4099 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4100 if (response.payload != null) {
4101 s = IccUtils.bytesToHexString(response.payload) + s;
4102 }
4103 return s;
4104 } finally {
4105 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004106 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004107 }
Jake Hambye994d462014-02-03 13:10:13 -08004108
Evan Charltonc66da362014-05-16 14:06:40 -07004109 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004110 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4111 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4113 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004115 if (DBG) {
4116 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4117 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4118 }
4119 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4120 cla, command, p1, p2, p3, data);
4121 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004122
Jordan Liu4c733742019-02-28 12:03:40 -08004123 @Override
4124 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4125 int command, int p1, int p2, int p3, String data) {
4126 enforceModifyPermission();
4127 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4128 if (DBG) {
4129 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4130 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4131 + " data=" + data);
4132 }
4133
4134 return iccTransmitApduBasicChannelWithPermission(
4135 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4136 p2, p3, data);
4137 }
4138
4139 // open APDU basic channel assuming the caller has sufficient permissions
4140 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4141 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4145 && TextUtils.equals(ISDR_AID, data)) {
4146 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004147 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4148 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 if (bestComponent == null
4150 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4151 loge("The calling package is not allowed to select ISD-R.");
4152 throw new SecurityException(
4153 "The calling package is not allowed to select ISD-R.");
4154 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004155 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004158 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4159 null /* workSource */);
4160 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 // Append the returned status code to the end of the response payload.
4163 String s = Integer.toHexString(
4164 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4165 if (response.payload != null) {
4166 s = IccUtils.bytesToHexString(response.payload) + s;
4167 }
4168 return s;
4169 } finally {
4170 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004171 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004172 }
4173
4174 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004175 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004176 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4178 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 if (DBG) {
4183 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4184 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4185 }
4186
4187 IccIoResult response =
4188 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4189 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4190 subId);
4191
4192 if (DBG) {
4193 log("Exchange SIM_IO [R]" + response);
4194 }
4195
4196 byte[] result = null;
4197 int length = 2;
4198 if (response.payload != null) {
4199 length = 2 + response.payload.length;
4200 result = new byte[length];
4201 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4202 } else {
4203 result = new byte[length];
4204 }
4205
4206 result[length - 1] = (byte) response.sw2;
4207 result[length - 2] = (byte) response.sw1;
4208 return result;
4209 } finally {
4210 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004211 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004212 }
4213
Nathan Haroldb3014052017-01-25 15:57:32 -08004214 /**
4215 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4216 * on a particular subscription
4217 */
sqianb6e41952018-03-12 14:54:01 -07004218 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4220 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4221 return null;
4222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004223
4224 final long identity = Binder.clearCallingIdentity();
4225 try {
4226 if (appType != TelephonyManager.APPTYPE_USIM
4227 && appType != TelephonyManager.APPTYPE_SIM) {
4228 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4229 return null;
4230 }
4231 Object response = sendRequest(
4232 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4233 if (response instanceof String[]) {
4234 return (String[]) response;
4235 }
yincheng zhaod698b842019-09-06 17:06:54 -07004236 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004237 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004238 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004241 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004242 }
4243
yincheng zhaod698b842019-09-06 17:06:54 -07004244 /**
4245 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4246 * subscription.
4247 *
4248 * @param subId the id of the subscription.
4249 * @param appType the uicc app type, must be USIM or SIM.
4250 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4251 * @param callingPackage the op Package name.
4252 * @return number of fplmns that is successfully written to the SIM.
4253 */
4254 public int setForbiddenPlmns(
4255 int subId, int appType, List<String> fplmns, String callingPackage) {
4256 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4257 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4258 if (DBG) logv("no permissions for setForbiddenplmns");
4259 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4260 }
4261 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4262 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4263 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4264 }
4265 if (fplmns == null) {
4266 throw new IllegalArgumentException("Fplmn List provided is null");
4267 }
4268 for (String fplmn : fplmns) {
4269 if (!CellIdentity.isValidPlmn(fplmn)) {
4270 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4271 }
4272 }
4273 final long identity = Binder.clearCallingIdentity();
4274 try {
4275 Object response = sendRequest(
4276 CMD_SET_FORBIDDEN_PLMNS,
4277 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4278 subId);
4279 return (int) response;
4280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
4283 }
4284
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004285 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004286 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4288 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4293 if (response.payload == null) {
4294 return "";
4295 }
Evan Charltonc66da362014-05-16 14:06:40 -07004296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297 // Append the returned status code to the end of the response payload.
4298 String s = Integer.toHexString(
4299 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4300 s = IccUtils.bytesToHexString(response.payload) + s;
4301 return s;
4302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
Evan Charltonc66da362014-05-16 14:06:40 -07004305 }
4306
Jake Hambye994d462014-02-03 13:10:13 -08004307 /**
4308 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4309 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4310 *
4311 * @param itemID the ID of the item to read
4312 * @return the NV item as a String, or null on error.
4313 */
4314 @Override
4315 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004316 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4318 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319
4320 final long identity = Binder.clearCallingIdentity();
4321 try {
4322 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004323 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4325 return value;
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
Jake Hambye994d462014-02-03 13:10:13 -08004329 }
4330
4331 /**
4332 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4333 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4334 *
4335 * @param itemID the ID of the item to read
4336 * @param itemValue the value to write, as a String
4337 * @return true on success; false on any failure
4338 */
4339 @Override
4340 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004341 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4343 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004344
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4348 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004349 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4351 return success;
4352 } finally {
4353 Binder.restoreCallingIdentity(identity);
4354 }
Jake Hambye994d462014-02-03 13:10:13 -08004355 }
4356
4357 /**
4358 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4359 * Used for device configuration by some CDMA operators.
4360 *
4361 * @param preferredRoamingList byte array containing the new PRL
4362 * @return true on success; false on any failure
4363 */
4364 @Override
4365 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4367 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368
4369 final long identity = Binder.clearCallingIdentity();
4370 try {
4371 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4372 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4373 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4374 return success;
4375 } finally {
4376 Binder.restoreCallingIdentity(identity);
4377 }
Jake Hambye994d462014-02-03 13:10:13 -08004378 }
4379
4380 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004381 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004382 * Used for device configuration by some CDMA operators.
4383 *
chen xu6dac5ab2018-10-26 17:39:23 -07004384 * @param slotIndex - device slot.
4385 *
Jake Hambye994d462014-02-03 13:10:13 -08004386 * @return true on success; false on any failure
4387 */
4388 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004389 public boolean resetModemConfig(int slotIndex) {
4390 Phone phone = PhoneFactory.getPhone(slotIndex);
4391 if (phone != null) {
4392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4393 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004394
chen xu6dac5ab2018-10-26 17:39:23 -07004395 final long identity = Binder.clearCallingIdentity();
4396 try {
4397 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4398 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4399 return success;
4400 } finally {
4401 Binder.restoreCallingIdentity(identity);
4402 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 }
chen xu6dac5ab2018-10-26 17:39:23 -07004404 return false;
4405 }
4406
4407 /**
4408 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4409 *
4410 * @param slotIndex - device slot.
4411 *
4412 * @return true on success; false on any failure
4413 */
4414 @Override
4415 public boolean rebootModem(int slotIndex) {
4416 Phone phone = PhoneFactory.getPhone(slotIndex);
4417 if (phone != null) {
4418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4419 mApp, phone.getSubId(), "rebootModem");
4420
4421 final long identity = Binder.clearCallingIdentity();
4422 try {
4423 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4424 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4425 return success;
4426 } finally {
4427 Binder.restoreCallingIdentity(identity);
4428 }
4429 }
4430 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004431 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004432
Svet Ganovb320e182015-04-16 12:30:10 -07004433 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004434 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004435 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004436 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004437 return new String[0];
4438 }
4439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 final long identity = Binder.clearCallingIdentity();
4441 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004442 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
Wink Saville36469e72014-06-11 15:17:00 -07004446 }
4447
Brad Ebinger51f743a2017-01-23 13:50:20 -08004448 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004449 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4450 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004451 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004452 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004453 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004454
4455 final long identity = Binder.clearCallingIdentity();
4456 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004457 ImsResolver resolver = PhoneFactory.getImsResolver();
4458 if (resolver == null) {
4459 // may happen if the device does not support IMS.
4460 return;
4461 }
4462 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004466 }
4467
4468 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004469 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4470 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004471 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004472 public void disableIms(int slotId) {
4473 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004477 ImsResolver resolver = PhoneFactory.getImsResolver();
4478 if (resolver == null) {
4479 // may happen if the device does not support IMS.
4480 return;
4481 }
4482 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004486 }
4487
4488 /**
4489 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4490 * feature or {@link null} if the service is not available. If the feature is available, the
4491 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4492 */
4493 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004494 IImsServiceFeatureCallback callback) {
4495 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496
4497 final long identity = Binder.clearCallingIdentity();
4498 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004499 ImsResolver resolver = PhoneFactory.getImsResolver();
4500 if (resolver == null) {
4501 // may happen if the device does not support IMS.
4502 return null;
4503 }
4504 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004505 } finally {
4506 Binder.restoreCallingIdentity(identity);
4507 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004508 }
4509
4510 /**
4511 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4512 * feature during emergency calling or {@link null} if the service is not available. If the
4513 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4514 * listener for feature updates.
4515 */
4516 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4517 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518
4519 final long identity = Binder.clearCallingIdentity();
4520 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004521 ImsResolver resolver = PhoneFactory.getImsResolver();
4522 if (resolver == null) {
4523 // may happen if the device does not support IMS.
4524 return null;
4525 }
4526 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004527 } finally {
4528 Binder.restoreCallingIdentity(identity);
4529 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004530 }
4531
Brad Ebinger5f64b052017-12-14 14:26:15 -08004532 /**
4533 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004534 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004535 */
4536 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4537 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538
4539 final long identity = Binder.clearCallingIdentity();
4540 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004541 ImsResolver resolver = PhoneFactory.getImsResolver();
4542 if (resolver == null) {
4543 // may happen if the device does not support IMS.
4544 return null;
4545 }
4546 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004550 }
4551
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004552 /**
4553 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004554 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004555 */
4556 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004558
4559 final long identity = Binder.clearCallingIdentity();
4560 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004561 ImsResolver resolver = PhoneFactory.getImsResolver();
4562 if (resolver == null) {
4563 // may happen if the device does not support IMS.
4564 return null;
4565 }
4566 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004567 } finally {
4568 Binder.restoreCallingIdentity(identity);
4569 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004570 }
4571
Brad Ebinger884c07b2018-02-15 16:17:40 -08004572 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004573 * Sets the ImsService Package Name that Telephony will bind to.
4574 *
4575 * @param slotId the slot ID that the ImsService should bind for.
4576 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4577 * ImsService is the device default ImsService.
4578 * @param packageName The package name of the application that contains the ImsService to bind
4579 * to.
4580 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4581 * @hide
4582 */
4583 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004584 int[] subIds = SubscriptionManager.getSubId(slotId);
4585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4586 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4587 "setImsService");
4588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 final long identity = Binder.clearCallingIdentity();
4590 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004591 ImsResolver resolver = PhoneFactory.getImsResolver();
4592 if (resolver == null) {
4593 // may happen if the device does not support IMS.
4594 return false;
4595 }
4596 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4597 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004601 }
4602
4603 /**
4604 * Return the ImsService configuration.
4605 *
4606 * @param slotId The slot that the ImsService is associated with.
4607 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4608 * the device default.
4609 * @return the package name of the ImsService configuration.
4610 */
4611 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004612 int[] subIds = SubscriptionManager.getSubId(slotId);
4613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4614 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4615 "getImsService");
4616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004617 final long identity = Binder.clearCallingIdentity();
4618 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004619 ImsResolver resolver = PhoneFactory.getImsResolver();
4620 if (resolver == null) {
4621 // may happen if the device does not support IMS.
4622 return "";
4623 }
4624 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 } finally {
4626 Binder.restoreCallingIdentity(identity);
4627 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004628 }
4629
Brad Ebinger77b832e2019-10-17 17:03:22 -07004630 /**
4631 * Get the MmTelFeature state associated with the requested subscription id.
4632 * @param subId The subscription that the MmTelFeature is associated with.
4633 * @param callback A callback with an integer containing the
4634 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4635 */
4636 @Override
4637 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4638 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4639 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4640 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4641 "IMS not available on device.");
4642 }
4643 final long token = Binder.clearCallingIdentity();
4644 try {
4645 int slotId = getSlotIndex(subId);
4646 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4647 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4648 + subId + "'");
4649 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4650 }
4651 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4652 try {
4653 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4654 } catch (RemoteException e) {
4655 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4656 + "Ignore");
4657 }
4658 });
4659 } finally {
4660 Binder.restoreCallingIdentity(token);
4661 }
4662 }
4663
Wink Saville36469e72014-06-11 15:17:00 -07004664 public void setImsRegistrationState(boolean registered) {
4665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666
4667 final long identity = Binder.clearCallingIdentity();
4668 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004669 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670 } finally {
4671 Binder.restoreCallingIdentity(identity);
4672 }
Wink Saville36469e72014-06-11 15:17:00 -07004673 }
4674
4675 /**
Stuart Scott54788802015-03-30 13:18:01 -07004676 * Set the network selection mode to automatic.
4677 *
4678 */
4679 @Override
4680 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4682 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683
Pengquan Menge92a50d2018-09-21 15:54:48 -07004684 if (!isActiveSubscription(subId)) {
4685 return;
4686 }
4687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 final long identity = Binder.clearCallingIdentity();
4689 try {
4690 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4691 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
Stuart Scott54788802015-03-30 13:18:01 -07004695 }
4696
Pengquan Mengea84e042018-09-20 14:57:26 -07004697 /**
4698 * Ask the radio to connect to the input network and change selection mode to manual.
4699 *
4700 * @param subId the id of the subscription.
4701 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4702 * the operator to attach to.
4703 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4704 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4705 * normal network selection next time.
4706 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004707 */
4708 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004709 public boolean setNetworkSelectionModeManual(
4710 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4712 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004713
4714 if (!isActiveSubscription(subId)) {
4715 return false;
4716 }
4717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 final long identity = Binder.clearCallingIdentity();
4719 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004720 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004722 if (DBG) {
4723 log("setNetworkSelectionModeManual: subId: " + subId
4724 + " operator: " + operatorInfo);
4725 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004730 }
4731
4732 /**
4733 * Scans for available networks.
4734 */
4735 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004736 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4738 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004739 LocationAccessPolicy.LocationPermissionResult locationResult =
4740 LocationAccessPolicy.checkLocationPermission(mApp,
4741 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4742 .setCallingPackage(callingPackage)
4743 .setCallingPid(Binder.getCallingPid())
4744 .setCallingUid(Binder.getCallingUid())
4745 .setMethod("getCellNetworkScanResults")
4746 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4747 .build());
4748 switch (locationResult) {
4749 case DENIED_HARD:
4750 throw new SecurityException("Not allowed to access scan results -- location");
4751 case DENIED_SOFT:
4752 return null;
4753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004754
Pengquan Menga1bb6272018-09-06 09:59:22 -07004755 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004756 try {
4757 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004758 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 } finally {
4761 Binder.restoreCallingIdentity(identity);
4762 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004763 }
4764
4765 /**
yinxub1bed742017-04-17 11:45:04 -07004766 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004767 *
yinxub1bed742017-04-17 11:45:04 -07004768 * @param subId id of the subscription
4769 * @param request contains the radio access networks with bands/channels to scan
4770 * @param messenger callback messenger for scan results or errors
4771 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004772 * @return the id of the requested scan which can be used to stop the scan.
4773 */
4774 @Override
4775 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004776 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4778 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004779 LocationAccessPolicy.LocationPermissionResult locationResult =
4780 LocationAccessPolicy.checkLocationPermission(mApp,
4781 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4782 .setCallingPackage(callingPackage)
4783 .setCallingPid(Binder.getCallingPid())
4784 .setCallingUid(Binder.getCallingUid())
4785 .setMethod("requestNetworkScan")
4786 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4787 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004788 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004789 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004790 if (e != null) {
4791 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4792 throw e;
4793 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004794 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004795 return TelephonyScanManager.INVALID_SCAN_ID;
4796 }
4797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798 }
Hall Liu912dfd32019-04-25 14:02:26 -07004799 int callingUid = Binder.getCallingUid();
4800 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004801 final long identity = Binder.clearCallingIdentity();
4802 try {
4803 return mNetworkScanRequestTracker.startNetworkScan(
4804 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004805 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004806 } finally {
4807 Binder.restoreCallingIdentity(identity);
4808 }
yinxu504e1392017-04-12 16:03:22 -07004809 }
4810
Hall Liub2ac8ef2019-02-28 15:56:23 -08004811 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004812 NetworkScanRequest request, int subId) {
4813 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4814 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4815 boolean hasNetworkScanPermission =
4816 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4817 == PERMISSION_GRANTED;
4818
4819 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4820 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4821 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004822 }
4823
4824 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4825 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004826 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4827 return new SecurityException("Specific channels must not be"
4828 + " scanned without location access.");
4829 }
4830 }
4831 }
4832
Hall Liub2ac8ef2019-02-28 15:56:23 -08004833 return null;
4834 }
4835
yinxu504e1392017-04-12 16:03:22 -07004836 /**
4837 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004838 *
4839 * @param subId id of the subscription
4840 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004841 */
4842 @Override
4843 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4845 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004846
Hall Liu912dfd32019-04-25 14:02:26 -07004847 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848 final long identity = Binder.clearCallingIdentity();
4849 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004850 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 } finally {
4852 Binder.restoreCallingIdentity(identity);
4853 }
yinxu504e1392017-04-12 16:03:22 -07004854 }
4855
4856 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004857 * Get the calculated preferred network type.
4858 * Used for debugging incorrect network type.
4859 *
4860 * @return the preferred network type, defined in RILConstants.java.
4861 */
4862 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004863 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004864 final Phone defaultPhone = getDefaultPhone();
4865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4866 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004867 return RILConstants.PREFERRED_NETWORK_MODE;
4868 }
4869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004873 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 } finally {
4875 Binder.restoreCallingIdentity(identity);
4876 }
Junda Liu84d15a22014-07-02 11:21:04 -07004877 }
4878
4879 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004880 * Get the preferred network type.
4881 * Used for device configuration by some CDMA operators.
4882 *
4883 * @return the preferred network type, defined in RILConstants.java.
4884 */
4885 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004886 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004887 TelephonyPermissions
4888 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4889 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890
4891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 if (DBG) log("getPreferredNetworkType");
4894 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4895 int networkType = (result != null ? result[0] : -1);
4896 if (DBG) log("getPreferredNetworkType: " + networkType);
4897 return networkType;
4898 } finally {
4899 Binder.restoreCallingIdentity(identity);
4900 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004901 }
4902
4903 /**
4904 * Set the preferred network type.
4905 * Used for device configuration by some CDMA operators.
4906 *
4907 * @param networkType the preferred network type, defined in RILConstants.java.
4908 * @return true on success; false on any failure.
4909 */
4910 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004911 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4913 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914
4915 final long identity = Binder.clearCallingIdentity();
4916 try {
4917 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4918 Boolean success = (Boolean) sendRequest(
4919 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4920 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4921 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004922 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4924 }
4925 return success;
4926 } finally {
4927 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004928 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004929 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004930
4931 /**
Miaoa84611c2019-03-15 09:21:10 +08004932 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004933 *
Miaoa84611c2019-03-15 09:21:10 +08004934 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004935 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004936 * @hide
4937 */
4938 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004939 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004940 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004941 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004942 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 try {
Miaoa84611c2019-03-15 09:21:10 +08004944 if (phone != null) {
4945 return phone.hasMatchedTetherApnSetting();
4946 } else {
4947 return false;
4948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 } finally {
4950 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004951 }
Junda Liu475951f2014-11-07 16:45:03 -08004952 }
4953
4954 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004955 * Set mobile data enabled
4956 * Used by the user through settings etc to turn on/off mobile data
4957 *
4958 * @param enable {@code true} turn turn data on, else {@code false}
4959 */
4960 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004961 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4963 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964
4965 final long identity = Binder.clearCallingIdentity();
4966 try {
4967 int phoneId = mSubscriptionController.getPhoneId(subId);
4968 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4969 Phone phone = PhoneFactory.getPhone(phoneId);
4970 if (phone != null) {
4971 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004972 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004974 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975 }
4976 } finally {
4977 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004978 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004979 }
4980
4981 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004982 * Get the user enabled state of Mobile Data.
4983 *
4984 * TODO: remove and use isUserDataEnabled.
4985 * This can't be removed now because some vendor codes
4986 * calls through ITelephony directly while they should
4987 * use TelephonyManager.
4988 *
4989 * @return true on enabled
4990 */
4991 @Override
4992 public boolean getDataEnabled(int subId) {
4993 return isUserDataEnabled(subId);
4994 }
4995
4996 /**
4997 * Get whether mobile data is enabled per user setting.
4998 *
4999 * There are other factors deciding whether mobile data is actually enabled, but they are
5000 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005001 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005002 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005003 *
5004 * @return {@code true} if data is enabled else {@code false}
5005 */
5006 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005007 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005008 try {
5009 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5010 null);
5011 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5013 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015
5016 final long identity = Binder.clearCallingIdentity();
5017 try {
5018 int phoneId = mSubscriptionController.getPhoneId(subId);
5019 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5020 Phone phone = PhoneFactory.getPhone(phoneId);
5021 if (phone != null) {
5022 boolean retVal = phone.isUserDataEnabled();
5023 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5024 return retVal;
5025 } else {
5026 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5027 return false;
5028 }
5029 } finally {
5030 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005031 }
5032 }
5033
5034 /**
5035 * Get whether mobile data is enabled.
5036 *
5037 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5038 * whether mobile data is actually enabled.
5039 *
5040 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5041 *
5042 * @return {@code true} if data is enabled else {@code false}
5043 */
5044 @Override
5045 public boolean isDataEnabled(int subId) {
5046 try {
5047 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5048 null);
5049 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5051 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053
5054 final long identity = Binder.clearCallingIdentity();
5055 try {
5056 int phoneId = mSubscriptionController.getPhoneId(subId);
5057 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5058 Phone phone = PhoneFactory.getPhone(phoneId);
5059 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005060 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5062 return retVal;
5063 } else {
5064 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5065 return false;
5066 }
5067 } finally {
5068 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005069 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005070 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005071
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005072 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5073 Phone phone) {
5074 //load access rules from carrier configs, and check those as well: b/139133814
5075 SubscriptionController subController = SubscriptionController.getInstance();
5076 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5077 || subController == null) return privilegeFromSim;
5078
5079 int uid = Binder.getCallingUid();
5080 PackageManager pkgMgr = phone.getContext().getPackageManager();
5081 String[] packages = pkgMgr.getPackagesForUid(uid);
5082
5083 final long identity = Binder.clearCallingIdentity();
5084 try {
5085 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5086 SubscriptionManager subManager = (SubscriptionManager)
5087 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5088 for (String pkg : packages) {
5089 if (subManager.canManageSubscription(subInfo, pkg)) {
5090 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5091 }
5092 }
5093 return privilegeFromSim;
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
5097 }
5098
5099 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5100 String pkgName) {
5101 //load access rules from carrier configs, and check those as well: b/139133814
5102 SubscriptionController subController = SubscriptionController.getInstance();
5103 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5104 || subController == null) return privilegeFromSim;
5105
5106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5109 SubscriptionManager subManager = (SubscriptionManager)
5110 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5111 return subManager.canManageSubscription(subInfo, pkgName)
5112 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5113 } finally {
5114 Binder.restoreCallingIdentity(identity);
5115 }
5116 }
5117
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005118 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005119 public int getCarrierPrivilegeStatus(int subId) {
5120 final Phone phone = getPhone(subId);
5121 if (phone == null) {
5122 loge("getCarrierPrivilegeStatus: Invalid subId");
5123 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5124 }
5125 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005126 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005127 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005128 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5129 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005130
5131 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5132 card.getCarrierPrivilegeStatusForCurrentTransaction(
5133 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005134 }
Junda Liu29340342014-07-10 15:23:27 -07005135
5136 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005137 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5138 final Phone phone = getPhone(subId);
5139 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005140 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005141 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5142 }
5143 UiccProfile profile =
5144 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5145 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005146 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005147 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5148 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005149 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5150 profile.getCarrierPrivilegeStatusForUid(
5151 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005152 }
5153
5154 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005155 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5156 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005157 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005158 }
5159
5160 int phoneId = SubscriptionManager.getPhoneId(subId);
5161 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005162 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005163 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005164 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5165 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005166 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5167 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5168 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005169 }
5170
5171 @Override
5172 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005173 if (TextUtils.isEmpty(pkgName))
5174 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005175 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5176 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5177 UiccCard card = UiccController.getInstance().getUiccCard(i);
5178 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005179 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005180 continue;
5181 }
5182
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005183 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5184 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5185 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005186 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5187 break;
5188 }
5189 }
5190
5191 return result;
Junda Liu29340342014-07-10 15:23:27 -07005192 }
Derek Tan89e89d42014-07-08 17:00:10 -07005193
5194 @Override
Junda Liue64de782015-04-16 17:19:16 -07005195 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5196 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5197 loge("phoneId " + phoneId + " is not valid.");
5198 return null;
5199 }
5200 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005201 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005202 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005203 return null ;
5204 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005205 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005206 }
5207
Amith Yamasani6e118872016-02-19 12:53:51 -08005208 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005209 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005210 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005211 List<String> privilegedPackages = new ArrayList<>();
5212 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005213 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5214 // has UICC in that slot.
5215 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005216 if (card.hasCarrierPrivilegeRules()) {
5217 if (packages == null) {
5218 // Only check packages in user 0 for now
5219 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005220 PackageManager.MATCH_DISABLED_COMPONENTS
5221 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005222 | PackageManager.GET_SIGNING_CERTIFICATES,
5223 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005224 }
5225 for (int p = packages.size() - 1; p >= 0; p--) {
5226 PackageInfo pkgInfo = packages.get(p);
5227 if (pkgInfo != null && pkgInfo.packageName != null
5228 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005229 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005230 privilegedPackages.add(pkgInfo.packageName);
5231 }
5232 }
5233 }
5234 }
5235 return privilegedPackages;
5236 }
5237
chen xuf7e9fe82019-05-09 19:31:02 -07005238 @Override
5239 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5240 List<String> privilegedPackages = new ArrayList<>();
5241 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5242 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5243 }
5244 return privilegedPackages;
5245 }
5246
Wink Savilleb564aae2014-10-23 10:18:09 -07005247 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005248 final Phone phone = getPhone(subId);
5249 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005250 if (card == null) {
5251 loge("getIccId: No UICC");
5252 return null;
5253 }
5254 String iccId = card.getIccId();
5255 if (TextUtils.isEmpty(iccId)) {
5256 loge("getIccId: ICC ID is null or empty.");
5257 return null;
5258 }
5259 return iccId;
5260 }
5261
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005262 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005263 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5264 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005265 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5266 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 final long identity = Binder.clearCallingIdentity();
5269 try {
5270 final String iccId = getIccId(subId);
5271 final Phone phone = getPhone(subId);
5272 if (phone == null) {
5273 return false;
5274 }
5275 final String subscriberId = phone.getSubscriberId();
5276
5277 if (DBG_MERGE) {
5278 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5279 + subscriberId + " to " + number);
5280 }
5281
5282 if (TextUtils.isEmpty(iccId)) {
5283 return false;
5284 }
5285
5286 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5287
5288 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5289 if (alphaTag == null) {
5290 editor.remove(alphaTagPrefKey);
5291 } else {
5292 editor.putString(alphaTagPrefKey, alphaTag);
5293 }
5294
5295 // Record both the line number and IMSI for this ICCID, since we need to
5296 // track all merged IMSIs based on line number
5297 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5298 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5299 if (number == null) {
5300 editor.remove(numberPrefKey);
5301 editor.remove(subscriberPrefKey);
5302 } else {
5303 editor.putString(numberPrefKey, number);
5304 editor.putString(subscriberPrefKey, subscriberId);
5305 }
5306
5307 editor.commit();
5308 return true;
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005311 }
Derek Tan7226c842014-07-02 17:42:23 -07005312 }
5313
5314 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005315 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005316 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005318 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005319 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005320 return null;
5321 }
Derek Tan97ebb422014-09-05 16:55:38 -07005322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 final long identity = Binder.clearCallingIdentity();
5324 try {
5325 String iccId = getIccId(subId);
5326 if (iccId != null) {
5327 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5328 if (DBG_MERGE) {
5329 log("getLine1NumberForDisplay returning "
5330 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5331 }
5332 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5335 return null;
5336 } finally {
5337 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005338 }
Derek Tan7226c842014-07-02 17:42:23 -07005339 }
5340
5341 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005342 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005344 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005345 return null;
5346 }
Derek Tan97ebb422014-09-05 16:55:38 -07005347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 final long identity = Binder.clearCallingIdentity();
5349 try {
5350 String iccId = getIccId(subId);
5351 if (iccId != null) {
5352 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5353 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5354 }
5355 return null;
5356 } finally {
5357 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005358 }
Derek Tan7226c842014-07-02 17:42:23 -07005359 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005360
5361 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005362 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005363 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5364 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005366 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5367 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005368 return null;
5369 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005370
Jordan Liub49b04b2019-05-06 14:45:15 -07005371 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5372 // the process, where TelephonyManager was instantiated.
5373 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005374 final long identity = Binder.clearCallingIdentity();
5375 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005376 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 final TelephonyManager tele = TelephonyManager.from(context);
5378 final SubscriptionManager sub = SubscriptionManager.from(context);
5379
5380 // Figure out what subscribers are currently active
5381 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382
Jordan Liub49b04b2019-05-06 14:45:15 -07005383 // Only consider subs which match the current subId
5384 // This logic can be simplified. See b/131189269 for progress.
5385 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005386 activeSubscriberIds.add(tele.getSubscriberId(subId));
5387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388
5389 // First pass, find a number override for an active subscriber
5390 String mergeNumber = null;
5391 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5392 for (String key : prefs.keySet()) {
5393 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5394 final String subscriberId = (String) prefs.get(key);
5395 if (activeSubscriberIds.contains(subscriberId)) {
5396 final String iccId = key.substring(
5397 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5398 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5399 mergeNumber = (String) prefs.get(numberKey);
5400 if (DBG_MERGE) {
5401 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5402 + " for active subscriber " + subscriberId);
5403 }
5404 if (!TextUtils.isEmpty(mergeNumber)) {
5405 break;
5406 }
5407 }
5408 }
5409 }
5410
5411 // Shortcut when no active merged subscribers
5412 if (TextUtils.isEmpty(mergeNumber)) {
5413 return null;
5414 }
5415
5416 // Second pass, find all subscribers under that line override
5417 final ArraySet<String> result = new ArraySet<>();
5418 for (String key : prefs.keySet()) {
5419 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5420 final String number = (String) prefs.get(key);
5421 if (mergeNumber.equals(number)) {
5422 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5423 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5424 final String subscriberId = (String) prefs.get(subscriberKey);
5425 if (!TextUtils.isEmpty(subscriberId)) {
5426 result.add(subscriberId);
5427 }
5428 }
5429 }
5430 }
5431
5432 final String[] resultArray = result.toArray(new String[result.size()]);
5433 Arrays.sort(resultArray);
5434 if (DBG_MERGE) {
5435 Slog.d(LOG_TAG,
5436 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5437 }
5438 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005439 } finally {
5440 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005441 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005442 }
5443
5444 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005445 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5446 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5447
5448 final long identity = Binder.clearCallingIdentity();
5449 try {
5450 final TelephonyManager telephonyManager = mApp.getSystemService(
5451 TelephonyManager.class);
5452 String subscriberId = telephonyManager.getSubscriberId(subId);
5453 if (subscriberId == null) {
5454 if (DBG) {
5455 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5456 + subId);
5457 }
5458 return null;
5459 }
5460
5461 final SubscriptionInfo info = SubscriptionController.getInstance()
5462 .getSubscriptionInfo(subId);
5463 final ParcelUuid groupUuid = info.getGroupUuid();
5464 // If it doesn't belong to any group, return just subscriberId of itself.
5465 if (groupUuid == null) {
5466 return new String[]{subscriberId};
5467 }
5468
5469 // Get all subscriberIds from the group.
5470 final List<String> mergedSubscriberIds = new ArrayList<>();
5471 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5472 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5473 for (SubscriptionInfo subInfo : groupInfos) {
5474 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5475 if (subscriberId != null) {
5476 mergedSubscriberIds.add(subscriberId);
5477 }
5478 }
5479
5480 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483
5484 }
5485 }
5486
5487 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005488 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005489 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5490 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491
5492 final long identity = Binder.clearCallingIdentity();
5493 try {
5494 final Phone phone = getPhone(subId);
5495 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5496 } finally {
5497 Binder.restoreCallingIdentity(identity);
5498 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005499 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005500
5501 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005502 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005503 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5504 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005505 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 final Phone phone = getPhone(subId);
5510 if (phone == null) {
5511 return false;
5512 }
5513 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5514 cdmaNonRoamingList);
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005517 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005518 }
5519
5520 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005521 @Deprecated
5522 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5523 enforceModifyPermission();
5524
5525 int returnValue = 0;
5526 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005527 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005528 if(result.exception == null) {
5529 if (result.result != null) {
5530 byte[] responseData = (byte[])(result.result);
5531 if(responseData.length > oemResp.length) {
5532 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5533 responseData.length + "bytes. Buffer Size is " +
5534 oemResp.length + "bytes.");
5535 }
5536 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5537 returnValue = responseData.length;
5538 }
5539 } else {
5540 CommandException ex = (CommandException) result.exception;
5541 returnValue = ex.getCommandError().ordinal();
5542 if(returnValue > 0) returnValue *= -1;
5543 }
5544 } catch (RuntimeException e) {
5545 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5546 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5547 if(returnValue > 0) returnValue *= -1;
5548 }
5549
5550 return returnValue;
5551 }
5552
5553 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005554 public void setRadioCapability(RadioAccessFamily[] rafs) {
5555 try {
5556 ProxyController.getInstance().setRadioCapability(rafs);
5557 } catch (RuntimeException e) {
5558 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5559 }
5560 }
5561
5562 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005563 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005564 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005565 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005566 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005567 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569 final long identity = Binder.clearCallingIdentity();
5570 try {
chen xub97461a2018-10-26 14:17:57 -07005571 TelephonyPermissions
5572 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5573 mApp, phone.getSubId(), "getRadioAccessFamily");
5574 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 } finally {
5576 Binder.restoreCallingIdentity(identity);
5577 }
chen xub97461a2018-10-26 14:17:57 -07005578 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005579 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005580
5581 @Override
5582 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005583 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005584 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585
5586 final long identity = Binder.clearCallingIdentity();
5587 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005588 ImsManager.getInstance(defaultPhone.getContext(),
5589 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005593 }
5594
5595 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005596 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005597 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005599 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005600 return false;
5601 }
Svet Ganovb320e182015-04-16 12:30:10 -07005602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 // Check the user preference and the system-level IMS setting. Even if the user has
5606 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5607 // In the long run, we may instead need to check if there exists a connection service
5608 // which can support video calling.
5609 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005610 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 return imsManager.isVtEnabledByPlatform()
5612 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5613 && imsManager.isVtEnabledByUser();
5614 } finally {
5615 Binder.restoreCallingIdentity(identity);
5616 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005617 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005618
Andrew Leea1239f22015-03-02 17:44:07 -08005619 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5622 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5623 return false;
5624 }
5625
5626 final long identity = Binder.clearCallingIdentity();
5627 try {
5628 CarrierConfigManager configManager =
5629 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005630 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005631 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5632 } finally {
5633 Binder.restoreCallingIdentity(identity);
5634 }
Andrew Leea1239f22015-03-02 17:44:07 -08005635 }
5636
5637 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 public boolean isWorldPhone(int subId, String callingPackage) {
5639 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5640 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5641 return false;
5642 }
5643
5644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 CarrierConfigManager configManager =
5647 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005648 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5650 } finally {
5651 Binder.restoreCallingIdentity(identity);
5652 }
Andrew Leea1239f22015-03-02 17:44:07 -08005653 }
5654
Andrew Lee9431b832015-03-09 18:46:45 -07005655 @Override
5656 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005657 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005658 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005659 }
5660
5661 @Override
5662 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 final long identity = Binder.clearCallingIdentity();
5664 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005665 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
Andrew Lee9431b832015-03-09 18:46:45 -07005669 }
5670
Hall Liuf6668912018-10-31 17:05:23 -07005671 /**
5672 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5673 * support for the feature and device firmware support.
5674 *
5675 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5676 */
5677 @Override
5678 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005680 final Phone phone = getPhone(subscriptionId);
5681 if (phone == null) {
5682 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5683 return false;
5684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005686 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5688 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005689 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 return isCarrierSupported && isDeviceSupported;
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
Hall Liu98187582018-01-22 19:15:32 -08005694 }
5695
Hall Liuf6668912018-10-31 17:05:23 -07005696 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005697 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5698 * RTT setting, will return true if the device and carrier both support RTT.
5699 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005700 */
5701 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 final long identity = Binder.clearCallingIdentity();
5703 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005704 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005708 }
5709
Sanket Padawe7310cc72015-01-14 09:53:20 -08005710 /**
5711 * Returns the unique device ID of phone, for example, the IMEI for
5712 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5713 *
5714 * <p>Requires Permission:
5715 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5716 */
5717 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005718 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005719 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005720 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005721 return null;
5722 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005723 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005724 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5725 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005726 return null;
5727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728
5729 final long identity = Binder.clearCallingIdentity();
5730 try {
5731 return phone.getDeviceId();
5732 } finally {
5733 Binder.restoreCallingIdentity(identity);
5734 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005735 }
5736
Ping Sunc67b7c22016-03-02 19:16:45 +08005737 /**
5738 * {@hide}
5739 * Returns the IMS Registration Status on a particular subid
5740 *
5741 * @param subId
5742 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005743 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005744 Phone phone = getPhone(subId);
5745 if (phone != null) {
5746 return phone.isImsRegistered();
5747 } else {
5748 return false;
5749 }
5750 }
5751
Santos Cordon7a1885b2015-02-03 11:15:19 -08005752 @Override
5753 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 final long identity = Binder.clearCallingIdentity();
5755 try {
5756 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005760 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005761
Tyler Gunnf70ed162019-04-03 15:28:53 -07005762 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005763 public int getSubIdForPhoneAccountHandle(
5764 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5766 callingPackage, "getSubIdForPhoneAccountHandle")) {
5767 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5768 }
5769 final long identity = Binder.clearCallingIdentity();
5770 try {
5771 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
5775 }
5776
5777 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005778 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5779 final long identity = Binder.clearCallingIdentity();
5780 try {
5781 Phone phone = getPhone(subscriptionId);
5782 if (phone == null) {
5783 return null;
5784 }
5785 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
5789 }
5790
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005791 /**
5792 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005793 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005794 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 final long identity = Binder.clearCallingIdentity();
5796 try {
5797 Phone phone = getPhone(subId);
5798 if (phone != null) {
5799 return phone.isWifiCallingEnabled();
5800 } else {
5801 return false;
5802 }
5803 } finally {
5804 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005805 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005806 }
5807
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005808 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005809 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005810 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005811 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812 final long identity = Binder.clearCallingIdentity();
5813 try {
5814 Phone phone = getPhone(subId);
5815 if (phone != null) {
5816 return phone.isVideoEnabled();
5817 } else {
5818 return false;
5819 }
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005822 }
5823 }
5824
5825 /**
5826 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5827 * defined in {@link ImsRegistrationImplBase}.
5828 */
5829 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 final long identity = Binder.clearCallingIdentity();
5831 try {
5832 Phone phone = getPhone(subId);
5833 if (phone != null) {
5834 return phone.getImsRegistrationTech();
5835 } else {
5836 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5837 }
5838 } finally {
5839 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005840 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005841 }
5842
Stuart Scott8eef64f2015-04-08 15:13:54 -07005843 @Override
5844 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005845 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005846 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5847 return;
5848 }
5849
Svet Ganovcc087f82015-05-12 20:35:54 -07005850 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005851
Svet Ganovcc087f82015-05-12 20:35:54 -07005852 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005853 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5854 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005855 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005856 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005857 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005858 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5859 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005860 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005861 // There has been issues when Sms raw table somehow stores orphan
5862 // fragments. They lead to garbled message when new fragments come
5863 // in and combined with those stale ones. In case this happens again,
5864 // user can reset all network settings which will clean up this table.
5865 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005866 // Clean up IMS settings as well here.
5867 int slotId = getSlotIndex(subId);
5868 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5869 ImsManager.getInstance(mApp, slotId).factoryReset();
5870 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005871
5872 // Erase modem config if erase modem on network setting is enabled.
5873 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5874 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5875 if (configValue != null && Boolean.parseBoolean(configValue)) {
5876 sendEraseModemConfig(getDefaultPhone());
5877 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005878 } finally {
5879 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005880 }
5881 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005882
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005883 private void cleanUpSmsRawTable(Context context) {
5884 ContentResolver resolver = context.getContentResolver();
5885 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5886 resolver.delete(uri, null, null);
5887 }
5888
Narayan Kamath1c496c22015-04-16 14:40:19 +01005889 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005890 public String getSimLocaleForSubscriber(int subId) {
5891 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5892 final Phone phone = getPhone(subId);
5893 if (phone == null) {
5894 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005895 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 final long identity = Binder.clearCallingIdentity();
5898 try {
chen xu5d3637b2019-01-21 23:31:38 -08005899 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5900 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005901 if (info == null) {
5902 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5903 return null;
5904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905 // Try and fetch the locale from the carrier properties or from the SIM language
5906 // preferences (EF-PL and EF-LI)...
5907 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005909 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5910 if (localeFromDefaultSim != null) {
5911 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5912 if (DBG) log("Using locale from subId: " + subId + " locale: "
5913 + localeFromDefaultSim);
5914 return localeFromDefaultSim.toLanguageTag();
5915 } else {
5916 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917 }
5918 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 // The SIM language preferences only store a language (e.g. fr = French), not an
5921 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5922 // the SIM and carrier preferences does not include a country we add the country
5923 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005924 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005926 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927 return mccLocale.toLanguageTag();
5928 }
5929
5930 if (DBG) log("No locale found - returning null");
5931 return null;
5932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005935 }
5936
5937 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005938 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005939 }
5940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 /**
5942 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5943 */
5944 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005945 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005946 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005947
Chenjie Yu1ba97252018-01-11 18:16:20 -08005948 private final ModemActivityInfo mLastModemActivityInfo =
5949 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5950
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005951 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005952 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5953 * representing the state of the modem.
5954 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005955 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5956 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005957 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005958 */
5959 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005960 public void requestModemActivityInfo(ResultReceiver result) {
5961 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005962 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963
5964 final long identity = Binder.clearCallingIdentity();
5965 try {
5966 ModemActivityInfo ret = null;
5967 synchronized (mLastModemActivityInfo) {
5968 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5969 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005970 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005971 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5973 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005974 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5975 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 }
5977 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005978 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5979 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 mLastModemActivityInfo.setIdleTimeMillis(
5981 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5982 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5983 mLastModemActivityInfo.setRxTimeMillis(
5984 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5985 mLastModemActivityInfo.setEnergyUsed(
5986 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5989 mLastModemActivityInfo.getSleepTimeMillis(),
5990 mLastModemActivityInfo.getIdleTimeMillis(),
5991 mLastModemActivityInfo.getTxTimeMillis(),
5992 mLastModemActivityInfo.getRxTimeMillis(),
5993 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 Bundle bundle = new Bundle();
5996 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5997 result.send(0, bundle);
5998 } finally {
5999 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006000 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006001 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006002
Siddharth Rayb8114062018-06-17 15:02:38 -07006003 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6004 // less than total activity duration.
6005 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6006 if (info == null) {
6007 return false;
6008 }
6009 int activityDurationMs =
6010 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6011 int totalTxTimeMs = 0;
6012 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
6013 totalTxTimeMs += info.getTxTimeMillis()[i];
6014 }
6015 return (info.isValid()
6016 && (info.getSleepTimeMillis() <= activityDurationMs)
6017 && (info.getIdleTimeMillis() <= activityDurationMs)
6018 && (info.getRxTimeMillis() <= activityDurationMs)
6019 && (totalTxTimeMs <= activityDurationMs));
6020 }
6021
Jack Yu85bd38a2015-11-09 11:34:32 -08006022 /**
6023 * {@hide}
6024 * Returns the service state information on specified subscription.
6025 */
6026 @Override
6027 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006028 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006029 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006030 return null;
6031 }
6032
Hall Liuf19c44f2018-11-27 14:38:17 -08006033 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6034 LocationAccessPolicy.checkLocationPermission(mApp,
6035 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6036 .setCallingPackage(callingPackage)
6037 .setCallingPid(Binder.getCallingPid())
6038 .setCallingUid(Binder.getCallingUid())
6039 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006040 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006041 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6042 .build());
6043
6044 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6045 LocationAccessPolicy.checkLocationPermission(mApp,
6046 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6047 .setCallingPackage(callingPackage)
6048 .setCallingPid(Binder.getCallingPid())
6049 .setCallingUid(Binder.getCallingUid())
6050 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006051 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006052 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6053 .build());
6054 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6055 boolean hasFinePermission =
6056 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6057 boolean hasCoarsePermission =
6058 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 final long identity = Binder.clearCallingIdentity();
6061 try {
6062 final Phone phone = getPhone(subId);
6063 if (phone == null) {
6064 return null;
6065 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006066
Hall Liuf19c44f2018-11-27 14:38:17 -08006067 ServiceState ss = phone.getServiceState();
6068
6069 // Scrub out the location info in ServiceState depending on what level of access
6070 // the caller has.
6071 if (hasFinePermission) return ss;
6072 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6073 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006077 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006078
6079 /**
6080 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6081 *
6082 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6083 * voicemail ringtone.
6084 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6085 * PhoneAccount.
6086 */
6087 @Override
6088 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 final long identity = Binder.clearCallingIdentity();
6090 try {
6091 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6092 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006093 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
6099 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006100 }
6101
6102 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006103 * Sets the per-account voicemail ringtone.
6104 *
6105 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6106 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6107 *
6108 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6109 * voicemail ringtone.
6110 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6111 * PhoneAccount.
6112 */
6113 @Override
6114 public void setVoicemailRingtoneUri(String callingPackage,
6115 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006116 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006117 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006118 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6119 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6121 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6122 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124
6125 final long identity = Binder.clearCallingIdentity();
6126 try {
6127 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6128 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006129 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130 }
6131 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6132 } finally {
6133 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006134 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006135 }
6136
6137 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006138 * Returns whether vibration is set for voicemail notification in Phone settings.
6139 *
6140 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6141 * voicemail vibration setting.
6142 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6143 */
6144 @Override
6145 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006146 final long identity = Binder.clearCallingIdentity();
6147 try {
6148 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6149 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006150 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6154 } finally {
6155 Binder.restoreCallingIdentity(identity);
6156 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006157 }
6158
Youhan Wange64578a2016-05-02 15:32:42 -07006159 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006160 * Sets the per-account voicemail vibration.
6161 *
6162 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6163 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6164 *
6165 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6166 * voicemail vibration setting.
6167 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6168 * specific PhoneAccount.
6169 */
6170 @Override
6171 public void setVoicemailVibrationEnabled(String callingPackage,
6172 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006173 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006174 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006175 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6176 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6178 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6179 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006180 }
6181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6185 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006186 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187 }
6188 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6189 } finally {
6190 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006191 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006192 }
6193
6194 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006195 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6196 *
6197 * @throws SecurityException if the caller does not have the required permission
6198 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006199 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006200 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006201 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006202 }
6203
6204 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006205 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6206 * permission.
6207 *
6208 * @throws SecurityException if the caller does not have the required permission
6209 */
6210 private void enforceSendSmsPermission() {
6211 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6212 }
6213
6214 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006215 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006216 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006217 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006218 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006219 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 final long identity = Binder.clearCallingIdentity();
6221 try {
6222 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006223 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 if (componentName == null) {
6225 throw new SecurityException(
6226 "Caller not current active visual voicemail package[null]");
6227 }
6228 String vvmPackage = componentName.getPackageName();
6229 if (!callingPackage.equals(vvmPackage)) {
6230 throw new SecurityException("Caller not current active visual voicemail package["
6231 + vvmPackage + "]");
6232 }
6233 } finally {
6234 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006235 }
6236 }
6237
6238 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006239 * Return the application ID for the app type.
6240 *
6241 * @param subId the subscription ID that this request applies to.
6242 * @param appType the uicc app type.
6243 * @return Application ID for specificied app type, or null if no uicc.
6244 */
6245 @Override
6246 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006247 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006248 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249
6250 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006251 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252 if (phone == null) {
6253 return null;
6254 }
6255 String aid = null;
6256 try {
6257 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6258 .getApplicationByType(appType).getAid();
6259 } catch (Exception e) {
6260 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6261 }
6262 return aid;
6263 } finally {
6264 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006265 }
Youhan Wange64578a2016-05-02 15:32:42 -07006266 }
6267
Youhan Wang4001d252016-05-11 10:29:41 -07006268 /**
6269 * Return the Electronic Serial Number.
6270 *
6271 * @param subId the subscription ID that this request applies to.
6272 * @return ESN or null if error.
6273 */
6274 @Override
6275 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006276 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006277 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278
6279 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006280 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281 if (phone == null) {
6282 return null;
6283 }
6284 String esn = null;
6285 try {
6286 esn = phone.getEsn();
6287 } catch (Exception e) {
6288 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6289 }
6290 return esn;
6291 } finally {
6292 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006293 }
Youhan Wang4001d252016-05-11 10:29:41 -07006294 }
6295
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006296 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006297 * Return the Preferred Roaming List Version.
6298 *
6299 * @param subId the subscription ID that this request applies to.
6300 * @return PRLVersion or null if error.
6301 */
6302 @Override
6303 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006304 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006305 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306
6307 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006308 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 if (phone == null) {
6310 return null;
6311 }
6312 String cdmaPrlVersion = null;
6313 try {
6314 cdmaPrlVersion = phone.getCdmaPrlVersion();
6315 } catch (Exception e) {
6316 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6317 }
6318 return cdmaPrlVersion;
6319 } finally {
6320 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006321 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006322 }
6323
6324 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006325 * Get snapshot of Telephony histograms
6326 * @return List of Telephony histograms
6327 * @hide
6328 */
6329 @Override
6330 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6332 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333
6334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 return RIL.getTelephonyRILTimingHistograms();
6337 } finally {
6338 Binder.restoreCallingIdentity(identity);
6339 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006340 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006341
6342 /**
6343 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006344 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6345 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006346 * Require system privileges. In the future we may add this to carrier APIs.
6347 *
Michele Berionne482f8202018-11-27 18:57:59 -08006348 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006349 */
6350 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006351 @TelephonyManager.SetCarrierRestrictionResult
6352 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006353 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006355
Michele Berionne482f8202018-11-27 18:57:59 -08006356 if (carrierRestrictionRules == null) {
6357 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006358 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360 final long identity = Binder.clearCallingIdentity();
6361 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006362 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006363 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 } finally {
6365 Binder.restoreCallingIdentity(identity);
6366 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006367 }
6368
6369 /**
6370 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006371 * Get the allowed carrier list and the excluded carrier list, including the priority between
6372 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006373 * Require system privileges. In the future we may add this to carrier APIs.
6374 *
Michele Berionne482f8202018-11-27 18:57:59 -08006375 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006376 */
6377 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006378 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006379 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006380 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381
6382 final long identity = Binder.clearCallingIdentity();
6383 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006384 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6385 if (response instanceof CarrierRestrictionRules) {
6386 return (CarrierRestrictionRules) response;
6387 }
6388 // Response is an Exception of some kind,
6389 // which is signalled to the user as a NULL retval
6390 return null;
6391 } catch (Exception e) {
6392 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6393 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006397 }
6398
fionaxu59545b42016-05-25 15:53:37 -07006399 /**
6400 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6401 * @param subId the subscription ID that this action applies to.
6402 * @param enabled control enable or disable metered apns.
6403 * {@hide}
6404 */
6405 @Override
6406 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6407 enforceModifyPermission();
6408 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409
6410 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006411 if (phone == null) {
6412 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6413 return;
6414 }
6415 try {
6416 phone.carrierActionSetMeteredApnsEnabled(enabled);
6417 } catch (Exception e) {
6418 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 } finally {
6420 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006421 }
6422 }
6423
6424 /**
6425 * Action set from carrier signalling broadcast receivers to enable/disable radio
6426 * @param subId the subscription ID that this action applies to.
6427 * @param enabled control enable or disable radio.
6428 * {@hide}
6429 */
6430 @Override
6431 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6432 enforceModifyPermission();
6433 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434
6435 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006436 if (phone == null) {
6437 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6438 return;
6439 }
6440 try {
6441 phone.carrierActionSetRadioEnabled(enabled);
6442 } catch (Exception e) {
6443 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444 } finally {
6445 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006446 }
6447 }
6448
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006449 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006450 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6451 * network status based on which carrier apps could apply actions accordingly,
6452 * enable/disable default url handler for example.
6453 *
6454 * @param subId the subscription ID that this action applies to.
6455 * @param report control start/stop reporting the default network status.
6456 * {@hide}
6457 */
6458 @Override
6459 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6460 enforceModifyPermission();
6461 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462
6463 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006464 if (phone == null) {
6465 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6466 return;
6467 }
6468 try {
6469 phone.carrierActionReportDefaultNetworkStatus(report);
6470 } catch (Exception e) {
6471 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 } finally {
6473 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006474 }
6475 }
6476
6477 /**
fionaxud9622282017-07-17 17:51:30 -07006478 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6479 * @param subId the subscription ID that this action applies to.
6480 * {@hide}
6481 */
6482 @Override
6483 public void carrierActionResetAll(int subId) {
6484 enforceModifyPermission();
6485 final Phone phone = getPhone(subId);
6486 if (phone == null) {
6487 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6488 return;
6489 }
6490 try {
6491 phone.carrierActionResetAll();
6492 } catch (Exception e) {
6493 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6494 }
6495 }
6496
6497 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006498 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6499 * bug report is being generated.
6500 */
6501 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006502 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006503 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6504 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006505 writer.println("Permission Denial: can't dump Phone from pid="
6506 + Binder.getCallingPid()
6507 + ", uid=" + Binder.getCallingUid()
6508 + "without permission "
6509 + android.Manifest.permission.DUMP);
6510 return;
6511 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006512 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006513 }
Jack Yueb89b242016-06-22 13:27:47 -07006514
Brad Ebingerdac2f002018-04-03 15:17:52 -07006515 @Override
6516 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6517 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6518 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006519 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6520 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006521 }
6522
Jack Yueb89b242016-06-22 13:27:47 -07006523 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006524 * Get aggregated video call data usage since boot.
6525 *
6526 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6527 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006528 * {@hide}
6529 */
6530 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006531 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006532 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6533 null);
6534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535 final long identity = Binder.clearCallingIdentity();
6536 try {
6537 // NetworkStatsService keeps tracking the active network interface and identity. It
6538 // records the delta with the corresponding network identity.
6539 // We just return the total video call data usage snapshot since boot.
6540 Phone phone = getPhone(subId);
6541 if (phone != null) {
6542 return phone.getVtDataUsage(perUidStats);
6543 }
6544 return null;
6545 } finally {
6546 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006547 }
Jack Yueb89b242016-06-22 13:27:47 -07006548 }
Jack Yu75ab2952016-07-08 14:29:33 -07006549
6550 /**
6551 * Policy control of data connection. Usually used when data limit is passed.
6552 * @param enabled True if enabling the data, otherwise disabling.
6553 * @param subId Subscription index
6554 * {@hide}
6555 */
6556 @Override
6557 public void setPolicyDataEnabled(boolean enabled, int subId) {
6558 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559
6560 final long identity = Binder.clearCallingIdentity();
6561 try {
6562 Phone phone = getPhone(subId);
6563 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006564 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 }
6566 } finally {
6567 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006568 }
6569 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006570
6571 /**
6572 * Get Client request stats
6573 * @return List of Client Request Stats
6574 * @hide
6575 */
6576 @Override
6577 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006578 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006579 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006580 return null;
6581 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006582 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584 final long identity = Binder.clearCallingIdentity();
6585 try {
6586 if (phone != null) {
6587 return phone.getClientRequestStats();
6588 }
6589
6590 return null;
6591 } finally {
6592 Binder.restoreCallingIdentity(identity);
6593 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006594 }
6595
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006596 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006597 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006598 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006599 }
Jack Yueb4124c2017-02-16 15:32:43 -08006600
6601 /**
Grace Chen70990072017-03-24 17:21:30 -07006602 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006603 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006604 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006605 * @param state State of SIM (power down, power up, pass through)
6606 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6607 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6608 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006609 *
6610 **/
6611 @Override
Grace Chen70990072017-03-24 17:21:30 -07006612 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006613 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006614 Phone phone = PhoneFactory.getPhone(slotIndex);
6615
vagdeviaf9a5b92018-08-15 16:01:53 -07006616 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618 final long identity = Binder.clearCallingIdentity();
6619 try {
6620 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006621 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 }
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006625 }
6626 }
Shuo Qiandd210312017-04-12 22:11:33 +00006627
Tyler Gunn65d45c22017-06-05 11:22:26 -07006628 private boolean isUssdApiAllowed(int subId) {
6629 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006630 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006631 if (configManager == null) {
6632 return false;
6633 }
6634 PersistableBundle pb = configManager.getConfigForSubId(subId);
6635 if (pb == null) {
6636 return false;
6637 }
6638 return pb.getBoolean(
6639 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6640 }
6641
Shuo Qiandd210312017-04-12 22:11:33 +00006642 /**
6643 * Check if phone is in emergency callback mode
6644 * @return true if phone is in emergency callback mode
6645 * @param subId sub id
6646 */
goneil9c5f4872017-12-05 14:07:56 -08006647 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006648 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006649 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006650 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006651
6652 final long identity = Binder.clearCallingIdentity();
6653 try {
6654 if (phone != null) {
6655 return phone.isInEcm();
6656 } else {
6657 return false;
6658 }
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006661 }
6662 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006663
6664 /**
6665 * Get the current signal strength information for the given subscription.
6666 * Because this information is not updated when the device is in a low power state
6667 * it should not be relied-upon to be current.
6668 * @param subId Subscription index
6669 * @return the most recent cached signal strength info from the modem
6670 */
6671 @Override
6672 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 final long identity = Binder.clearCallingIdentity();
6674 try {
6675 Phone p = getPhone(subId);
6676 if (p == null) {
6677 return null;
6678 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 return p.getSignalStrength();
6681 } finally {
6682 Binder.restoreCallingIdentity(identity);
6683 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006684 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006685
Pengquan Meng77b7f132018-08-22 14:49:57 -07006686 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006687 * Get the current modem radio state for the given slot.
6688 * @param slotIndex slot index.
6689 * @param callingPackage the name of the package making the call.
6690 * @return the current radio power state from the modem
6691 */
6692 @Override
6693 public int getRadioPowerState(int slotIndex, String callingPackage) {
6694 Phone phone = PhoneFactory.getPhone(slotIndex);
6695 if (phone != null) {
6696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6697 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6698 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6699 }
6700
6701 final long identity = Binder.clearCallingIdentity();
6702 try {
6703 return phone.getRadioPowerState();
6704 } finally {
6705 Binder.restoreCallingIdentity(identity);
6706 }
6707 }
6708 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6709 }
6710
6711 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006712 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6713 *
6714 * <p>Requires one of the following permissions:
6715 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6716 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6717 * privileges.
6718 *
6719 * @param subId subscription id
6720 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6721 * {@code false}.
6722 */
6723 @Override
6724 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006725 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6726 null /* message */);
6727
Pengquan Menga1bb6272018-09-06 09:59:22 -07006728 boolean isEnabled = false;
6729 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006730 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006731 Phone phone = getPhone(subId);
6732 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006733 } catch (Exception e) {
6734 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6735 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006736 } finally {
6737 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006738 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006739 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006740 }
6741
6742
6743 /**
6744 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6745 *
6746 * <p> Requires permission:
6747 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6748 * privileges.
6749 *
6750 * @param subId subscription id
6751 * @param isEnabled {@code true} means enable, {@code false} means disable.
6752 */
6753 @Override
6754 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6756 mApp, subId, "setDataRoamingEnabled");
6757
Pengquan Menga1bb6272018-09-06 09:59:22 -07006758 final long identity = Binder.clearCallingIdentity();
6759 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006760 Phone phone = getPhone(subId);
6761 if (phone != null) {
6762 phone.setDataRoamingEnabled(isEnabled);
6763 }
6764 } finally {
6765 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006766 }
6767 }
6768
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006769 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006770 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006771 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6772 mApp, subId, "isManualNetworkSelectionAllowed");
6773
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006774 boolean isAllowed = true;
6775 final long identity = Binder.clearCallingIdentity();
6776 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006777 Phone phone = getPhone(subId);
6778 if (phone != null) {
6779 isAllowed = phone.isCspPlmnEnabled();
6780 }
6781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
6784 return isAllowed;
6785 }
6786
6787 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006788 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006789 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006790 try {
6791 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006792 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006793 } catch (SecurityException e) {
6794 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6795 // has carrier privileges on an active UICC
6796 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6797 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006798 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006799 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006800 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006801
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006804 UiccController uiccController = UiccController.getInstance();
6805 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006806 if (hasReadPermission) {
6807 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006808 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006809
6810 // Remove private info if the caller doesn't have access
6811 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6812 for (UiccCardInfo cardInfo : cardInfos) {
6813 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6814 // is available
6815 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6816 if (card == null || card.getUiccProfile() == null) {
6817 // assume no access if the card or profile is unavailable
6818 filteredInfos.add(cardInfo.getUnprivileged());
6819 continue;
6820 }
6821 UiccProfile profile = card.getUiccProfile();
6822 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6823 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6824 filteredInfos.add(cardInfo);
6825 } else {
6826 filteredInfos.add(cardInfo.getUnprivileged());
6827 }
6828 }
6829 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006830 } finally {
6831 Binder.restoreCallingIdentity(identity);
6832 }
6833 }
6834
6835 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006836 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006837 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 final long identity = Binder.clearCallingIdentity();
6840 try {
6841 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6842 if (slots == null) {
6843 Rlog.i(LOG_TAG, "slots is null.");
6844 return null;
6845 }
6846
6847 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6848 for (int i = 0; i < slots.length; i++) {
6849 UiccSlot slot = slots[i];
6850 if (slot == null) {
6851 continue;
6852 }
6853
Jordan Liu7be7e652019-05-06 18:55:02 +00006854 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855 UiccCard card = slot.getUiccCard();
6856 if (card != null) {
6857 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006858 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006859 cardId = slot.getEid();
6860 if (TextUtils.isEmpty(cardId)) {
6861 cardId = slot.getIccId();
6862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 }
6864
Jordan Liu857451f2019-05-09 16:35:35 -07006865 if (cardId != null) {
6866 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6867 // if cardId is an EID, it's all digits so this is fine
6868 cardId = IccUtils.stripTrailingFs(cardId);
6869 }
6870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 int cardState = 0;
6872 switch (slot.getCardState()) {
6873 case CARDSTATE_ABSENT:
6874 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6875 break;
6876 case CARDSTATE_PRESENT:
6877 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6878 break;
6879 case CARDSTATE_ERROR:
6880 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6881 break;
6882 case CARDSTATE_RESTRICTED:
6883 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6884 break;
6885 default:
6886 break;
6887
6888 }
6889
6890 infos[i] = new UiccSlotInfo(
6891 slot.isActive(),
6892 slot.isEuicc(),
6893 cardId,
6894 cardState,
6895 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006896 slot.isExtendedApduSupported(),
6897 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898 }
6899 return infos;
6900 } finally {
6901 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006902 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006903 }
6904
6905 @Override
6906 public boolean switchSlots(int[] physicalSlots) {
6907 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006908
6909 final long identity = Binder.clearCallingIdentity();
6910 try {
6911 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006915 }
Jack Yu4c988042018-02-27 15:30:01 -08006916
6917 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006918 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006919 final long identity = Binder.clearCallingIdentity();
6920 try {
6921 return UiccController.getInstance().getCardIdForDefaultEuicc();
6922 } finally {
6923 Binder.restoreCallingIdentity(identity);
6924 }
6925 }
6926
6927 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006928 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6929 enforceModifyPermission();
6930 final Phone phone = getPhone(subId);
6931 if (phone == null) {
6932 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6933 return;
6934 }
6935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936 final long identity = Binder.clearCallingIdentity();
6937 try {
6938 phone.setRadioIndicationUpdateMode(filters, mode);
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
6941 }
Jack Yu4c988042018-02-27 15:30:01 -08006942 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006943
6944 /**
goneil47ffb6e2018-04-06 15:40:58 -07006945 * A test API to reload the UICC profile.
6946 *
6947 * <p>Requires that the calling app has permission
6948 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6949 * @hide
6950 */
6951 @Override
6952 public void refreshUiccProfile(int subId) {
6953 enforceModifyPermission();
6954
6955 final long identity = Binder.clearCallingIdentity();
6956 try {
6957 Phone phone = getPhone(subId);
6958 if (phone == null) {
6959 return;
6960 }
6961 UiccCard uiccCard = phone.getUiccCard();
6962 if (uiccCard == null) {
6963 return;
6964 }
6965 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6966 if (uiccProfile == null) {
6967 return;
6968 }
6969 uiccProfile.refresh();
6970 } finally {
6971 Binder.restoreCallingIdentity(identity);
6972 }
6973 }
6974
6975 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006976 * Returns false if the mobile data is disabled by default, otherwise return true.
6977 */
6978 private boolean getDefaultDataEnabled() {
6979 return "true".equalsIgnoreCase(
6980 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6981 }
6982
6983 /**
6984 * Returns true if the data roaming is enabled by default, i.e the system property
6985 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6986 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6987 */
6988 private boolean getDefaultDataRoamingEnabled(int subId) {
6989 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006990 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006991 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6992 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6993 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6994 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6995 return isDataRoamingEnabled;
6996 }
6997
6998 /**
6999 * Returns the default network type for the given {@code subId}, if the default network type is
7000 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7001 */
7002 private int getDefaultNetworkType(int subId) {
7003 return Integer.parseInt(
7004 TelephonyManager.getTelephonyProperty(
7005 mSubscriptionController.getPhoneId(subId),
7006 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
7007 String.valueOf(Phone.PREFERRED_NT_MODE)));
7008 }
fionaxua13278b2018-03-21 00:08:13 -07007009
7010 @Override
7011 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007012 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007013 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014
7015 final long identity = Binder.clearCallingIdentity();
7016 try {
7017 final Phone phone = getPhone(subId);
7018 if (phone == null) {
7019 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7020 return;
7021 }
chen xueaba88a2019-03-15 13:15:10 -07007022 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7023 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 } finally {
7025 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007026 }
fionaxua13278b2018-03-21 00:08:13 -07007027 }
7028
7029 @Override
7030 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007031 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032
7033 final long identity = Binder.clearCallingIdentity();
7034 try {
7035 final Phone phone = getPhone(subId);
7036 if (phone == null) {
7037 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7038 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7039 }
7040 return phone.getCarrierIdListVersion();
7041 } finally {
7042 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007043 }
fionaxua13278b2018-03-21 00:08:13 -07007044 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007045
7046 @Override
7047 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7049 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7050 return -1;
7051 }
7052
7053 final long identity = Binder.clearCallingIdentity();
7054 try {
7055 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7056 } finally {
7057 Binder.restoreCallingIdentity(identity);
7058 }
7059 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007060
7061 @Override
7062 public int getCdmaRoamingMode(int subId) {
7063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7064 mApp, subId, "getCdmaRoamingMode");
7065
7066 final long identity = Binder.clearCallingIdentity();
7067 try {
7068 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7069 } finally {
7070 Binder.restoreCallingIdentity(identity);
7071 }
7072 }
7073
7074 @Override
7075 public boolean setCdmaRoamingMode(int subId, int mode) {
7076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7077 mApp, subId, "setCdmaRoamingMode");
7078
7079 final long identity = Binder.clearCallingIdentity();
7080 try {
7081 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7082 } finally {
7083 Binder.restoreCallingIdentity(identity);
7084 }
7085 }
7086
7087 @Override
7088 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7090 mApp, subId, "setCdmaSubscriptionMode");
7091
7092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7095 } finally {
7096 Binder.restoreCallingIdentity(identity);
7097 }
7098 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007099
sqianc5eccab2018-10-19 18:46:41 -07007100 @Override
sqian8c685422019-02-22 15:55:18 -08007101 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007102 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007104 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007105 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7106 }
7107 final long identity = Binder.clearCallingIdentity();
7108 try {
sqian854d44b2018-12-12 16:48:18 -08007109 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7110 for (Phone phone: PhoneFactory.getPhones()) {
7111 if (phone.getEmergencyNumberTracker() != null
7112 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7113 emergencyNumberListInternal.put(
7114 phone.getSubId(),
7115 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7116 }
sqian11b7a0e2018-12-05 18:48:28 -08007117 }
sqian854d44b2018-12-12 16:48:18 -08007118 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007119 } finally {
7120 Binder.restoreCallingIdentity(identity);
7121 }
sqianc5eccab2018-10-19 18:46:41 -07007122 }
7123
7124 @Override
sqian8c685422019-02-22 15:55:18 -08007125 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007126 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007127 if (!exactMatch) {
7128 TelephonyPermissions
7129 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007130 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007131 }
7132 final long identity = Binder.clearCallingIdentity();
7133 try {
sqian854d44b2018-12-12 16:48:18 -08007134 for (Phone phone: PhoneFactory.getPhones()) {
7135 if (phone.getEmergencyNumberTracker() != null
7136 && phone.getEmergencyNumberTracker() != null) {
7137 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7138 number, exactMatch)) {
7139 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007140 }
7141 }
sqian11b7a0e2018-12-05 18:48:28 -08007142 }
7143 return false;
7144 } finally {
7145 Binder.restoreCallingIdentity(identity);
7146 }
7147 }
7148
sqianf4ca7ed2019-01-15 18:32:07 -08007149 /**
7150 * Update emergency number list for test mode.
7151 */
7152 @Override
7153 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7154 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7155 "updateEmergencyNumberListTestMode");
7156
7157 final long identity = Binder.clearCallingIdentity();
7158 try {
7159 for (Phone phone: PhoneFactory.getPhones()) {
7160 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7161 if (tracker != null) {
7162 tracker.executeEmergencyNumberTestModeCommand(action, num);
7163 }
7164 }
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167 }
7168 }
7169
7170 /**
7171 * Get the full emergency number list for test mode.
7172 */
7173 @Override
7174 public List<String> getEmergencyNumberListTestMode() {
7175 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7176 "getEmergencyNumberListTestMode");
7177
7178 final long identity = Binder.clearCallingIdentity();
7179 try {
7180 Set<String> emergencyNumbers = new HashSet<>();
7181 for (Phone phone: PhoneFactory.getPhones()) {
7182 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7183 if (tracker != null) {
7184 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7185 emergencyNumbers.add(num.getNumber());
7186 }
7187 }
7188 }
7189 return new ArrayList<>(emergencyNumbers);
7190 } finally {
7191 Binder.restoreCallingIdentity(identity);
7192 }
7193 }
7194
chen xud6b45bd2018-10-30 22:27:10 -07007195 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007196 public int getEmergencyNumberDbVersion(int subId) {
7197 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7198
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 final Phone phone = getPhone(subId);
7202 if (phone == null) {
7203 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7204 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7205 }
7206 return phone.getEmergencyNumberDbVersion();
7207 } finally {
7208 Binder.restoreCallingIdentity(identity);
7209 }
7210 }
7211
7212 @Override
7213 public void notifyOtaEmergencyNumberDbInstalled() {
7214 enforceModifyPermission();
7215
7216 final long identity = Binder.clearCallingIdentity();
7217 try {
7218 for (Phone phone: PhoneFactory.getPhones()) {
7219 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7220 if (tracker != null) {
7221 tracker.updateOtaEmergencyNumberDatabase();
7222 }
7223 }
7224 } finally {
7225 Binder.restoreCallingIdentity(identity);
7226 }
7227 }
7228
7229 @Override
7230 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7231 enforceActiveEmergencySessionPermission();
7232
7233 final long identity = Binder.clearCallingIdentity();
7234 try {
7235 for (Phone phone: PhoneFactory.getPhones()) {
7236 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7237 if (tracker != null) {
7238 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7239 }
7240 }
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
7244 }
7245
7246 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007247 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7248 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7249 Phone phone = getPhone(subId);
7250 if (phone == null) {
7251 return null;
7252 }
7253 final long identity = Binder.clearCallingIdentity();
7254 try {
7255 UiccProfile profile = UiccController.getInstance()
7256 .getUiccProfileForPhone(phone.getPhoneId());
7257 if (profile != null) {
7258 return profile.getCertsFromCarrierPrivilegeAccessRules();
7259 }
7260 } finally {
7261 Binder.restoreCallingIdentity(identity);
7262 }
7263 return null;
7264 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007265
7266 /**
7267 * Enable or disable a modem stack.
7268 */
7269 @Override
7270 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7271 enforceModifyPermission();
7272
7273 final long identity = Binder.clearCallingIdentity();
7274 try {
7275 Phone phone = PhoneFactory.getPhone(slotIndex);
7276 if (phone == null) {
7277 return false;
7278 } else {
7279 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7280 }
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
7283 }
7284 }
Michelecea4cf22018-12-21 15:00:11 -08007285
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007286 /**
7287 * Whether a modem stack is enabled or not.
7288 */
7289 @Override
7290 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7291 Phone phone = PhoneFactory.getPhone(slotIndex);
7292 if (phone == null) return false;
7293
7294 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7295 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7296 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7297 }
7298
7299 final long identity = Binder.clearCallingIdentity();
7300 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007301 try {
7302 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7303 } catch (NoSuchElementException ex) {
7304 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7305 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007306 } finally {
7307 Binder.restoreCallingIdentity(identity);
7308 }
7309 }
7310
Michelecea4cf22018-12-21 15:00:11 -08007311 @Override
Michele0ea7d782019-03-19 14:58:42 -07007312 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007313 enforceModifyPermission();
7314
7315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007318 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007319 .commit();
7320 } finally {
7321 Binder.restoreCallingIdentity(identity);
7322 }
7323 }
7324
7325 @Override
Michele0ea7d782019-03-19 14:58:42 -07007326 @TelephonyManager.IsMultiSimSupportedResult
7327 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007328 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007329 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7330 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007331 }
Michelecea4cf22018-12-21 15:00:11 -08007332
7333 final long identity = Binder.clearCallingIdentity();
7334 try {
Michele0ea7d782019-03-19 14:58:42 -07007335 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
7339 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007340
Michele0ea7d782019-03-19 14:58:42 -07007341 @TelephonyManager.IsMultiSimSupportedResult
7342 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007343 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7344 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7345 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007346 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7347 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007348 }
7349 // Check if the hardware supports multisim functionality. If usage of multisim is not
7350 // supported by the modem, indicate that it is restricted.
7351 PhoneCapability staticCapability =
7352 mPhoneConfigurationManager.getStaticPhoneCapability();
7353 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007354 loge("isMultiSimSupportedInternal: no static configuration available");
7355 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007356 }
7357 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007358 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7359 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007360 }
7361 // Check if support of multiple SIMs is restricted by carrier
7362 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007363 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007364 }
7365
Michele0ea7d782019-03-19 14:58:42 -07007366 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007367 }
7368
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007369 /**
7370 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007371 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7372 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7373 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007374 * @param numOfSims number of active sims we want to switch to
7375 */
7376 @Override
7377 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007378 if (numOfSims == 1) {
7379 enforceModifyPermission();
7380 } else {
7381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7382 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7383 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007384 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007385
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007386 try {
Michele30b57b22019-03-01 12:01:14 -08007387 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007388 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007389 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7390 return;
7391 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007392 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7393 } finally {
7394 Binder.restoreCallingIdentity(identity);
7395 }
7396 }
7397
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007398 @Override
7399 public boolean isApplicationOnUicc(int subId, int appType) {
7400 enforceReadPrivilegedPermission("isApplicationOnUicc");
7401 Phone phone = getPhone(subId);
7402 if (phone == null) {
7403 return false;
7404 }
7405 final long identity = Binder.clearCallingIdentity();
7406 try {
7407 UiccCard uiccCard = phone.getUiccCard();
7408 if (uiccCard == null) {
7409 return false;
7410 }
7411 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7412 if (uiccProfile == null) {
7413 return false;
7414 }
7415 if (TelephonyManager.APPTYPE_SIM <= appType
7416 && appType <= TelephonyManager.APPTYPE_ISIM) {
7417 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7418 }
7419 return false;
7420 } finally {
7421 Binder.restoreCallingIdentity(identity);
7422 }
7423 }
7424
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007425 /**
chen xub4baa772019-04-03 10:23:41 -07007426 * Get whether making changes to modem configurations will trigger reboot.
7427 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007428 */
7429 @Override
chen xub4baa772019-04-03 10:23:41 -07007430 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7431 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7432 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7433 return false;
7434 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007435 final long identity = Binder.clearCallingIdentity();
7436 try {
7437 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
7441 }
7442
Nathan Harold29f5f052019-02-15 13:41:57 -08007443 private void updateModemStateMetrics() {
7444 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7445 // TODO: check the state for each modem if the api is ready.
7446 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7447 }
7448
Pengquan Meng3889a572019-01-23 11:16:29 -08007449 @Override
7450 public int[] getSlotsMapping() {
7451 enforceReadPrivilegedPermission("getSlotsMapping");
7452
7453 final long identity = Binder.clearCallingIdentity();
7454 try {
7455 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7456 // All logical slots should have a mapping to a physical slot.
7457 int[] logicalSlotsMapping = new int[phoneCount];
7458 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7459 for (int i = 0; i < slotInfos.length; i++) {
7460 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7461 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7462 }
7463 }
7464 return logicalSlotsMapping;
7465 } finally {
7466 Binder.restoreCallingIdentity(identity);
7467 }
7468 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007469
7470 /**
7471 * Get the IRadio HAL Version
7472 */
7473 @Override
7474 public int getRadioHalVersion() {
7475 Phone phone = getDefaultPhone();
7476 if (phone == null) return -1;
7477 HalVersion hv = phone.getHalVersion();
7478 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7479 return hv.major * 100 + hv.minor;
7480 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007481
7482 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007483 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7484 * corresponding network requests on a subId.
7485 *
7486 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007487 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007488 * 2) APN is un-metered for this subscription, or
7489 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7490 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7491 *
7492 * @return whether data is allowed for a apn type.
7493 *
7494 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007495 */
7496 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007497 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007498 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7499 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007500
7501 // Now that all security checks passes, perform the operation as ourselves.
7502 final long identity = Binder.clearCallingIdentity();
7503 try {
7504 Phone phone = getPhone(subId);
7505 if (phone == null) return false;
7506
Jack Yu41407ee2019-05-13 16:54:09 -07007507 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007508 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
7512 }
7513
7514 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007515 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007516 enforceReadPrivilegedPermission("isApnMetered");
7517
7518 // Now that all security checks passes, perform the operation as ourselves.
7519 final long identity = Binder.clearCallingIdentity();
7520 try {
7521 Phone phone = getPhone(subId);
7522 if (phone == null) return true; // By default return true.
7523
Jack Yu41407ee2019-05-13 16:54:09 -07007524 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
7528 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007529
7530 @Override
changbetty363e8ac2019-12-06 18:16:37 +08007531 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7532 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7533 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7534 if (iccRecords == null) {
7535 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7536 return false;
7537 }
7538 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7539 }
7540
7541 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007542 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7543 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7544 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7545 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7546 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7547 }
7548 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7549 Intent intent = new Intent();
7550 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7551 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7552 // Bring up choose default SMS subscription dialog right now
7553 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7554 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7555 mApp.startActivity(intent);
7556 }
chen xud5ca2d52019-05-28 15:20:57 -07007557
7558 @Override
7559 public String getMmsUAProfUrl(int subId) {
7560 //TODO investigate if this API should require proper permission check in R b/133791609
7561 final long identity = Binder.clearCallingIdentity();
7562 try {
7563 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7564 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7565 } finally {
7566 Binder.restoreCallingIdentity(identity);
7567 }
7568 }
7569
7570 @Override
7571 public String getMmsUserAgent(int subId) {
7572 //TODO investigate if this API should require proper permission check in R b/133791609
7573 final long identity = Binder.clearCallingIdentity();
7574 try {
7575 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7576 .getString(com.android.internal.R.string.config_mms_user_agent);
7577 } finally {
7578 Binder.restoreCallingIdentity(identity);
7579 }
7580 }
Jack Yub07d4972019-05-28 16:12:25 -07007581
7582 @Override
7583 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7584 enforceModifyPermission();
7585
7586 // Now that all security checks passes, perform the operation as ourselves.
7587 final long identity = Binder.clearCallingIdentity();
7588 try {
7589 Phone phone = getPhone(subId);
7590 if (phone == null) return false;
7591
7592 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
7595 }
7596 }
7597
7598 @Override
7599 public boolean isDataAllowedInVoiceCall(int subId) {
7600 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7601
7602 // Now that all security checks passes, perform the operation as ourselves.
7603 final long identity = Binder.clearCallingIdentity();
7604 try {
7605 Phone phone = getPhone(subId);
7606 if (phone == null) return false;
7607
7608 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7609 } finally {
7610 Binder.restoreCallingIdentity(identity);
7611 }
7612 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007613
7614 /**
7615 * Updates whether conference event pacakge handling is enabled.
7616 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7617 * otherwise.
7618 */
7619 @Override
7620 public void setCepEnabled(boolean isCepEnabled) {
7621 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7622
7623 final long identity = Binder.clearCallingIdentity();
7624 try {
7625 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7626 for (Phone phone : PhoneFactory.getPhones()) {
7627 Phone defaultPhone = phone.getImsPhone();
7628 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7629 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7630 ImsPhoneCallTracker imsPhoneCallTracker =
7631 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7632 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7633 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7634 + imsPhone.getMsisdn());
7635 }
7636 }
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
7639 }
7640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007641}