blob: 722a32b7588e7b327f240b65a9af6a824e0afb81 [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
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Tyler Gunn327a9722019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070047import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080048import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070049import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070051import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070052import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070054import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070055import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070056import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080057import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070058import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080059import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080060import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070061import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070062import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080063import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070065import android.telephony.CellInfoGsm;
66import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070067import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070068import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070069import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070070import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080071import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070072import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080073import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070074import android.telephony.NetworkScanRequest;
Michelebcb01bc2019-02-04 11:36:23 -080075import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080076import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070077import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080078import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080081import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070082import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080083import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080088import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000089import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070090import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080094import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080096import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070097import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080098import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070099import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800100import android.telephony.ims.aidl.IImsMmTelFeature;
101import android.telephony.ims.aidl.IImsRcsFeature;
102import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800104import android.telephony.ims.feature.MmTelFeature;
105import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800106import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800110import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800112
Brad Ebinger4c460712018-10-01 10:40:55 -0700113import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700114import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800115import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700117import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700118import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800119import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700120import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800123import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800124import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800126import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700127import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100128import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700129import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700130import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700132import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800133import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700134import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700135import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700136import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700137import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700138import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800140import com.android.internal.telephony.SmsApplication;
141import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800142import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800143import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800144import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700145import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800146import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800147import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.uicc.IccIoResult;
149import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800150import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700151import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800152import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800154import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000155import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700156import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800157import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700158import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800159import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700160import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700161import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800162
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700163import java.io.FileDescriptor;
164import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800165import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800167import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800168import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800169import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800170import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800171import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100172import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800173import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800174import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175
176/**
177 * Implementation of the ITelephony interface.
178 */
Santos Cordon117fee72014-05-16 17:56:12 -0700179public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180 private static final String LOG_TAG = "PhoneInterfaceManager";
181 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
182 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184
185 // Message codes used with mMainThreadHandler
186 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700187 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
188 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189 private static final int CMD_OPEN_CHANNEL = 9;
190 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
191 private static final int CMD_CLOSE_CHANNEL = 11;
192 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800193 private static final int CMD_NV_READ_ITEM = 13;
194 private static final int EVENT_NV_READ_ITEM_DONE = 14;
195 private static final int CMD_NV_WRITE_ITEM = 15;
196 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
197 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
198 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700199 private static final int CMD_RESET_MODEM_CONFIG = 19;
200 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800201 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
202 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
203 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
204 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800205 private static final int CMD_SEND_ENVELOPE = 25;
206 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000207 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
208 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700209 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
210 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
211 private static final int CMD_EXCHANGE_SIM_IO = 31;
212 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800213 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
214 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700215 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
216 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700217 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
218 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700219 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
220 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
221 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
222 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700223 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
224 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
225 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
226 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700227 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800228 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
229 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000230 private static final int CMD_SWITCH_SLOTS = 50;
231 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700232 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
233 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
234 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
235 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
236 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
237 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
238 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
239 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700240 private static final int CMD_GET_ALL_CELL_INFO = 60;
241 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
242 private static final int CMD_GET_CELL_LOCATION = 62;
243 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700244 private static final int CMD_MODEM_REBOOT = 64;
245 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700246 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
247 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800248 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
249 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800251 // Parameters of select command.
252 private static final int SELECT_COMMAND = 0xA4;
253 private static final int SELECT_P1 = 0x04;
254 private static final int SELECT_P2 = 0;
255 private static final int SELECT_P3 = 0x10;
256
Pengquan Meng85728fb2018-03-12 16:31:21 -0700257 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
258 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
259 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
260
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261 /** The singleton instance. */
262 private static PhoneInterfaceManager sInstance;
263
Wink Saville3ab207e2014-11-20 13:07:20 -0800264 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800265 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700266 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800267 private AppOpsManager mAppOps;
268 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800269 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800270 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700271 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272
Derek Tan97ebb422014-09-05 16:55:38 -0700273 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
274 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800275 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800276 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700277
Micheled3107c52018-12-21 15:00:11 -0800278 // String to store multi SIM allowed
279 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
280
Derek Tan740e1672017-06-27 14:56:27 -0700281 // The AID of ISD-R.
282 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
283
yinxub1bed742017-04-17 11:45:04 -0700284 private NetworkScanRequestTracker mNetworkScanRequestTracker;
285
David Kelly5e06a7f2018-03-12 14:10:59 +0000286 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
287 private static final int MANUFACTURER_CODE_LENGTH = 8;
288
Derek Tan89e89d42014-07-08 17:00:10 -0700289 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700290 * A request object to use for transmitting data to an ICC.
291 */
292 private static final class IccAPDUArgument {
293 public int channel, cla, command, p1, p2, p3;
294 public String data;
295
296 public IccAPDUArgument(int channel, int cla, int command,
297 int p1, int p2, int p3, String data) {
298 this.channel = channel;
299 this.cla = cla;
300 this.command = command;
301 this.p1 = p1;
302 this.p2 = p2;
303 this.p3 = p3;
304 this.data = data;
305 }
306 }
307
308 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700309 * A request object to use for transmitting data to an ICC.
310 */
311 private static final class ManualNetworkSelectionArgument {
312 public OperatorInfo operatorInfo;
313 public boolean persistSelection;
314
315 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
316 this.operatorInfo = operatorInfo;
317 this.persistSelection = persistSelection;
318 }
319 }
320
321 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
323 * request after sending. The main thread will notify the request when it is complete.
324 */
325 private static final class MainThreadRequest {
326 /** The argument to use for the request */
327 public Object argument;
328 /** The result of the request that is run on the main thread */
329 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800330 // The subscriber id that this request applies to. Defaults to
331 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
332 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333
Nathan Harold92bed182018-10-12 18:16:49 -0700334 // In cases where subId is unavailable, the caller needs to specify the phone.
335 public Phone phone;
336
vagdevie435a3e2018-08-15 16:01:53 -0700337 public WorkSource workSource;
338
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 public MainThreadRequest(Object argument) {
340 this.argument = argument;
341 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800342
Nathan Harold92bed182018-10-12 18:16:49 -0700343 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
344 this.argument = argument;
345 if (phone != null) {
346 this.phone = phone;
347 }
348 this.workSource = workSource;
349 }
350
vagdevie435a3e2018-08-15 16:01:53 -0700351 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800352 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800353 if (subId != null) {
354 this.subId = subId;
355 }
vagdevie435a3e2018-08-15 16:01:53 -0700356 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 }
359
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800360 private static final class IncomingThirdPartyCallArgs {
361 public final ComponentName component;
362 public final String callId;
363 public final String callerDisplayName;
364
365 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
366 String callerDisplayName) {
367 this.component = component;
368 this.callId = callId;
369 this.callerDisplayName = callerDisplayName;
370 }
371 }
372
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 /**
374 * A handler that processes messages on the main thread in the phone process. Since many
375 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
376 * inbound binder threads to the main thread in the phone process. The Binder thread
377 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
378 * on, which will be notified when the operation completes and will contain the result of the
379 * request.
380 *
381 * <p>If a MainThreadRequest object is provided in the msg.obj field,
382 * note that request.result must be set to something non-null for the calling thread to
383 * unblock.
384 */
385 private final class MainThreadHandler extends Handler {
386 @Override
387 public void handleMessage(Message msg) {
388 MainThreadRequest request;
389 Message onCompleted;
390 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800391 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700392 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800393 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394
395 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700396 case CMD_HANDLE_USSD_REQUEST: {
397 request = (MainThreadRequest) msg.obj;
398 final Phone phone = getPhoneFromRequest(request);
399 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
400 String ussdRequest = ussdObject.first;
401 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700402
Pengquan Meng0c05b502018-09-06 09:59:22 -0700403 if (!isUssdApiAllowed(request.subId)) {
404 // Carrier does not support use of this API, return failure.
405 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
406 UssdResponse response = new UssdResponse(ussdRequest, null);
407 Bundle returnData = new Bundle();
408 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
409 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700410
Pengquan Meng0c05b502018-09-06 09:59:22 -0700411 request.result = true;
412 notifyRequester(request);
413 return;
414 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700415
Pengquan Meng0c05b502018-09-06 09:59:22 -0700416 try {
417 request.result = phone != null
418 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
419 } catch (CallStateException cse) {
420 request.result = false;
421 }
422 // Wake up the requesting thread
423 notifyRequester(request);
424 break;
pkanwar32d516d2016-10-14 19:37:38 -0700425 }
426
Yorke Lee716f67e2015-06-17 15:39:16 -0700427 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700429 final Phone phone = getPhoneFromRequest(request);
430 request.result = phone != null ?
431 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
432 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700434 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800441 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700442 if (uiccCard == null) {
443 loge("iccTransmitApduLogicalChannel: No UICC");
444 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700445 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700446 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
448 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700449 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 iccArgument.channel, iccArgument.cla, iccArgument.command,
451 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 break;
455
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700457 ar = (AsyncResult) msg.obj;
458 request = (MainThreadRequest) ar.userObj;
459 if (ar.exception == null && ar.result != null) {
460 request.result = ar.result;
461 } else {
462 request.result = new IccIoResult(0x6F, 0, (byte[])null);
463 if (ar.result == null) {
464 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800465 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800467 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700468 } else {
469 loge("iccTransmitApduLogicalChannel: Unknown exception");
470 }
471 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700472 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 break;
474
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
476 request = (MainThreadRequest) msg.obj;
477 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800478 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 if (uiccCard == null) {
480 loge("iccTransmitApduBasicChannel: No UICC");
481 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700482 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 } else {
484 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
485 request);
486 uiccCard.iccTransmitApduBasicChannel(
487 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
488 iccArgument.p3, iccArgument.data, onCompleted);
489 }
490 break;
491
492 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
493 ar = (AsyncResult) msg.obj;
494 request = (MainThreadRequest) ar.userObj;
495 if (ar.exception == null && ar.result != null) {
496 request.result = ar.result;
497 } else {
498 request.result = new IccIoResult(0x6F, 0, (byte[])null);
499 if (ar.result == null) {
500 loge("iccTransmitApduBasicChannel: Empty response");
501 } else if (ar.exception instanceof CommandException) {
502 loge("iccTransmitApduBasicChannel: CommandException: " +
503 ar.exception);
504 } else {
505 loge("iccTransmitApduBasicChannel: Unknown exception");
506 }
507 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700508 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 break;
510
511 case CMD_EXCHANGE_SIM_IO:
512 request = (MainThreadRequest) msg.obj;
513 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800514 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 if (uiccCard == null) {
516 loge("iccExchangeSimIO: No UICC");
517 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700518 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 } else {
520 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
521 request);
522 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
523 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
524 iccArgument.data, onCompleted);
525 }
526 break;
527
528 case EVENT_EXCHANGE_SIM_IO_DONE:
529 ar = (AsyncResult) msg.obj;
530 request = (MainThreadRequest) ar.userObj;
531 if (ar.exception == null && ar.result != null) {
532 request.result = ar.result;
533 } else {
534 request.result = new IccIoResult(0x6f, 0, (byte[])null);
535 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700536 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 break;
538
Derek Tan4d5e5c12014-02-04 11:54:58 -0800539 case CMD_SEND_ENVELOPE:
540 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800541 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 if (uiccCard == null) {
543 loge("sendEnvelopeWithStatus: No UICC");
544 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700545 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 } else {
547 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
548 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
549 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 break;
551
552 case EVENT_SEND_ENVELOPE_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700558 request.result = new IccIoResult(0x6F, 0, (byte[])null);
559 if (ar.result == null) {
560 loge("sendEnvelopeWithStatus: Empty response");
561 } else if (ar.exception instanceof CommandException) {
562 loge("sendEnvelopeWithStatus: CommandException: " +
563 ar.exception);
564 } else {
565 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
566 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800567 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700568 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800569 break;
570
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 case CMD_OPEN_CHANNEL:
572 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800573 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800574 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700575 if (uiccCard == null) {
576 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800577 request.result = new IccOpenLogicalChannelResponse(-1,
578 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 } else {
581 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800582 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
583 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 break;
586
587 case EVENT_OPEN_CHANNEL_DONE:
588 ar = (AsyncResult) msg.obj;
589 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 int[] result = (int[]) ar.result;
593 int channelId = result[0];
594 byte[] selectResponse = null;
595 if (result.length > 1) {
596 selectResponse = new byte[result.length - 1];
597 for (int i = 1; i < result.length; ++i) {
598 selectResponse[i - 1] = (byte) result[i];
599 }
600 }
601 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700602 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 if (ar.result == null) {
605 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 if (ar.exception != null) {
608 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
609 }
610
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700611 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700612 if (ar.exception instanceof CommandException) {
613 CommandException.Error error =
614 ((CommandException) (ar.exception)).getCommandError();
615 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700616 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700617 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700618 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 }
620 }
621 openChannelResp = new IccOpenLogicalChannelResponse(
622 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700624 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 break;
627
628 case CMD_CLOSE_CHANNEL:
629 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800630 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 if (uiccCard == null) {
632 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900633 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
637 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
638 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 break;
640
641 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800642 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
643 break;
644
645 case CMD_NV_READ_ITEM:
646 request = (MainThreadRequest) msg.obj;
647 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800648 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
649 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800650 break;
651
652 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 ar = (AsyncResult) msg.obj;
654 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800655 if (ar.exception == null && ar.result != null) {
656 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800658 request.result = "";
659 if (ar.result == null) {
660 loge("nvReadItem: Empty response");
661 } else if (ar.exception instanceof CommandException) {
662 loge("nvReadItem: CommandException: " +
663 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800665 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 }
667 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 break;
670
Jake Hambye994d462014-02-03 13:10:13 -0800671 case CMD_NV_WRITE_ITEM:
672 request = (MainThreadRequest) msg.obj;
673 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
674 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800675 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700676 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800677 break;
678
679 case EVENT_NV_WRITE_ITEM_DONE:
680 handleNullReturnEvent(msg, "nvWriteItem");
681 break;
682
683 case CMD_NV_WRITE_CDMA_PRL:
684 request = (MainThreadRequest) msg.obj;
685 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800686 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800687 break;
688
689 case EVENT_NV_WRITE_CDMA_PRL_DONE:
690 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
691 break;
692
chen xu1cc0abe2018-10-26 17:39:23 -0700693 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800694 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700695 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800696 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
chen xu1cc0abe2018-10-26 17:39:23 -0700699 case EVENT_RESET_MODEM_CONFIG_DONE:
700 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
Jake Hamby7c27be32014-03-03 13:25:59 -0800703 case CMD_GET_PREFERRED_NETWORK_TYPE:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700706 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800707 break;
708
709 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
710 ar = (AsyncResult) msg.obj;
711 request = (MainThreadRequest) ar.userObj;
712 if (ar.exception == null && ar.result != null) {
713 request.result = ar.result; // Integer
714 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800715 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 if (ar.result == null) {
717 loge("getPreferredNetworkType: Empty response");
718 } else if (ar.exception instanceof CommandException) {
719 loge("getPreferredNetworkType: CommandException: " +
720 ar.exception);
721 } else {
722 loge("getPreferredNetworkType: Unknown exception");
723 }
724 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700725 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 break;
727
728 case CMD_SET_PREFERRED_NETWORK_TYPE:
729 request = (MainThreadRequest) msg.obj;
730 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
731 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700732 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800733 break;
734
735 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
736 handleNullReturnEvent(msg, "setPreferredNetworkType");
737 break;
738
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000739 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
740 request = (MainThreadRequest)msg.obj;
741 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800742 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000743 break;
744
745 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
746 ar = (AsyncResult)msg.obj;
747 request = (MainThreadRequest)ar.userObj;
748 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700749 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000750 break;
751
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800752 case CMD_SET_VOICEMAIL_NUMBER:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
755 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800756 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
757 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800758 break;
759
760 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
761 handleNullReturnEvent(msg, "setVoicemailNumber");
762 break;
763
Stuart Scott54788802015-03-30 13:18:01 -0700764 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
765 request = (MainThreadRequest) msg.obj;
766 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
767 request);
768 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
769 break;
770
771 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
772 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
773 break;
774
Shishir Agrawal302c8692015-06-19 13:49:39 -0700775 case CMD_PERFORM_NETWORK_SCAN:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
778 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
779 break;
780
781 case EVENT_PERFORM_NETWORK_SCAN_DONE:
782 ar = (AsyncResult) msg.obj;
783 request = (MainThreadRequest) ar.userObj;
784 CellNetworkScanResult cellScanResult;
785 if (ar.exception == null && ar.result != null) {
786 cellScanResult = new CellNetworkScanResult(
787 CellNetworkScanResult.STATUS_SUCCESS,
788 (List<OperatorInfo>) ar.result);
789 } else {
790 if (ar.result == null) {
791 loge("getCellNetworkScanResults: Empty response");
792 }
793 if (ar.exception != null) {
794 loge("getCellNetworkScanResults: Exception: " + ar.exception);
795 }
796 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
797 if (ar.exception instanceof CommandException) {
798 CommandException.Error error =
799 ((CommandException) (ar.exception)).getCommandError();
800 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
801 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
802 } else if (error == CommandException.Error.GENERIC_FAILURE) {
803 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
804 }
805 }
806 cellScanResult = new CellNetworkScanResult(errorCode, null);
807 }
808 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700809 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 break;
811
812 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
813 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700814 ManualNetworkSelectionArgument selArg =
815 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700816 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
817 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700818 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
819 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700820 break;
821
822 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
825 if (ar.exception == null) {
826 request.result = true;
827 } else {
828 request.result = false;
829 loge("setNetworkSelectionModeManual " + ar.exception);
830 }
831 notifyRequester(request);
832 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 break;
834
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700835 case CMD_GET_MODEM_ACTIVITY_INFO:
836 request = (MainThreadRequest) msg.obj;
837 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisc56281c2019-04-03 14:18:34 -0700838 if (defaultPhone != null) {
839 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
840 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700841 break;
842
843 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
846 if (ar.exception == null && ar.result != null) {
847 request.result = ar.result;
848 } else {
849 if (ar.result == null) {
850 loge("queryModemActivityInfo: Empty response");
851 } else if (ar.exception instanceof CommandException) {
852 loge("queryModemActivityInfo: CommandException: " +
853 ar.exception);
854 } else {
855 loge("queryModemActivityInfo: Unknown exception");
856 }
857 }
Amit Mahajand4766222016-01-28 15:28:28 -0800858 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
859 if (request.result == null) {
860 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
861 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700862 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700863 break;
864
Meng Wang1a7c35a2016-05-05 20:56:15 -0700865 case CMD_SET_ALLOWED_CARRIERS:
866 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800867 CarrierRestrictionRules argument =
868 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800870 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700871 break;
872
873 case EVENT_SET_ALLOWED_CARRIERS_DONE:
874 ar = (AsyncResult) msg.obj;
875 request = (MainThreadRequest) ar.userObj;
876 if (ar.exception == null && ar.result != null) {
877 request.result = ar.result;
878 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800879 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
880 if (ar.exception instanceof CommandException) {
881 loge("setAllowedCarriers: CommandException: " + ar.exception);
882 CommandException.Error error =
883 ((CommandException) (ar.exception)).getCommandError();
884 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
885 request.result =
886 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
887 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 } else {
889 loge("setAllowedCarriers: Unknown exception");
890 }
891 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700892 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 break;
894
895 case CMD_GET_ALLOWED_CARRIERS:
896 request = (MainThreadRequest) msg.obj;
897 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800898 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700899 break;
900
901 case EVENT_GET_ALLOWED_CARRIERS_DONE:
902 ar = (AsyncResult) msg.obj;
903 request = (MainThreadRequest) ar.userObj;
904 if (ar.exception == null && ar.result != null) {
905 request.result = ar.result;
906 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800907 request.result = new IllegalStateException(
908 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 if (ar.result == null) {
910 loge("getAllowedCarriers: Empty response");
911 } else if (ar.exception instanceof CommandException) {
912 loge("getAllowedCarriers: CommandException: " +
913 ar.exception);
914 } else {
915 loge("getAllowedCarriers: Unknown exception");
916 }
917 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700918 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700919 break;
920
Nathan Haroldb3014052017-01-25 15:57:32 -0800921 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
922 ar = (AsyncResult) msg.obj;
923 request = (MainThreadRequest) ar.userObj;
924 if (ar.exception == null && ar.result != null) {
925 request.result = ar.result;
926 } else {
927 request.result = new IllegalArgumentException(
928 "Failed to retrieve Forbidden Plmns");
929 if (ar.result == null) {
930 loge("getForbiddenPlmns: Empty response");
931 } else {
932 loge("getForbiddenPlmns: Unknown exception");
933 }
934 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700935 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800936 break;
937
938 case CMD_GET_FORBIDDEN_PLMNS:
939 request = (MainThreadRequest) msg.obj;
940 uiccCard = getUiccCardFromRequest(request);
941 if (uiccCard == null) {
942 loge("getForbiddenPlmns() UiccCard is null");
943 request.result = new IllegalArgumentException(
944 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700945 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800946 break;
947 }
948 Integer appType = (Integer) request.argument;
949 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
950 if (uiccApp == null) {
951 loge("getForbiddenPlmns() no app with specified type -- "
952 + appType);
953 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700954 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800955 break;
956 } else {
957 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
958 + " specified type -- " + appType);
959 }
960 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
961 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
962 onCompleted);
963 break;
964
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000965 case CMD_SWITCH_SLOTS:
966 request = (MainThreadRequest) msg.obj;
967 int[] physicalSlots = (int[]) request.argument;
968 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
969 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
970 break;
971
972 case EVENT_SWITCH_SLOTS_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700976 notifyRequester(request);
977 break;
978 case CMD_GET_NETWORK_SELECTION_MODE:
979 request = (MainThreadRequest) msg.obj;
980 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
981 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
982 break;
983
984 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception != null) {
988 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
989 } else {
990 int mode = ((int[]) ar.result)[0];
991 if (mode == 0) {
992 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
993 } else {
994 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
995 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000996 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700997 notifyRequester(request);
998 break;
999 case CMD_GET_CDMA_ROAMING_MODE:
1000 request = (MainThreadRequest) msg.obj;
1001 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1002 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1003 break;
1004 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
1007 if (ar.exception != null) {
1008 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1009 } else {
1010 request.result = ((int[]) ar.result)[0];
1011 }
1012 notifyRequester(request);
1013 break;
1014 case CMD_SET_CDMA_ROAMING_MODE:
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1017 int mode = (int) request.argument;
1018 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1019 break;
1020 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 request.result = ar.exception == null;
1024 notifyRequester(request);
1025 break;
1026 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1027 request = (MainThreadRequest) msg.obj;
1028 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1029 int subscriptionMode = (int) request.argument;
1030 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1031 break;
1032 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1033 ar = (AsyncResult) msg.obj;
1034 request = (MainThreadRequest) ar.userObj;
1035 request.result = ar.exception == null;
1036 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001037 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001038 case CMD_GET_ALL_CELL_INFO:
1039 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001040 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001041 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001042 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001043 case EVENT_GET_ALL_CELL_INFO_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001046 // If a timeout occurs, the response will be null
1047 request.result = (ar.exception == null && ar.result != null)
1048 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 synchronized (request) {
1050 request.notifyAll();
1051 }
1052 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001053 case CMD_REQUEST_CELL_INFO_UPDATE:
1054 request = (MainThreadRequest) msg.obj;
1055 request.phone.requestCellInfoUpdate(request.workSource,
1056 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1057 break;
1058 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
1061 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1062 try {
1063 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001065 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1066 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001067 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001069 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001070 } else {
1071 // use the result as returned
1072 cb.onCellInfo((List<CellInfo>) ar.result);
1073 }
1074 } catch (RemoteException re) {
1075 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1076 }
1077 break;
1078 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001079 request = (MainThreadRequest) msg.obj;
1080 WorkSource ws = (WorkSource) request.argument;
1081 Phone phone = getPhoneFromRequest(request);
1082 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1083 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001085 ar = (AsyncResult) msg.obj;
1086 request = (MainThreadRequest) ar.userObj;
1087 if (ar.exception == null) {
1088 request.result = ar.result;
1089 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001091 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1092 ? new CdmaCellLocation() : new GsmCellLocation();
1093 }
1094
1095 synchronized (request) {
1096 request.notifyAll();
1097 }
1098 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001099 case CMD_MODEM_REBOOT:
1100 request = (MainThreadRequest) msg.obj;
1101 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001102 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001103 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001104 case EVENT_CMD_MODEM_REBOOT_DONE:
1105 handleNullReturnEvent(msg, "rebootModem");
1106 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001107 case CMD_REQUEST_ENABLE_MODEM:
1108 request = (MainThreadRequest) msg.obj;
1109 boolean enable = (boolean) request.argument;
1110 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001111 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001112 PhoneConfigurationManager.getInstance()
1113 .enablePhone(request.phone, enable, onCompleted);
1114 break;
1115 case EVENT_ENABLE_MODEM_DONE:
1116 ar = (AsyncResult) msg.obj;
1117 request = (MainThreadRequest) ar.userObj;
1118 request.result = (ar.exception == null);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001119 //update the cache as modem status has changed
1120 mPhoneConfigurationManager.addToPhoneStatusCache(
1121 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001122 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001123 notifyRequester(request);
1124 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001125 default:
1126 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1127 break;
1128 }
1129 }
Jake Hambye994d462014-02-03 13:10:13 -08001130
Pengquan Meng0c05b502018-09-06 09:59:22 -07001131 private void notifyRequester(MainThreadRequest request) {
1132 synchronized (request) {
1133 request.notifyAll();
1134 }
1135 }
1136
Jake Hambye994d462014-02-03 13:10:13 -08001137 private void handleNullReturnEvent(Message msg, String command) {
1138 AsyncResult ar = (AsyncResult) msg.obj;
1139 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1140 if (ar.exception == null) {
1141 request.result = true;
1142 } else {
1143 request.result = false;
1144 if (ar.exception instanceof CommandException) {
1145 loge(command + ": CommandException: " + ar.exception);
1146 } else {
1147 loge(command + ": Unknown exception");
1148 }
1149 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001150 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001152 }
1153
1154 /**
1155 * Posts the specified command to be executed on the main thread,
1156 * waits for the request to complete, and returns the result.
1157 * @see #sendRequestAsync
1158 */
1159 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001160 return sendRequest(
1161 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001162 }
1163
1164 /**
1165 * Posts the specified command to be executed on the main thread,
1166 * waits for the request to complete, and returns the result.
1167 * @see #sendRequestAsync
1168 */
1169 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1170 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001171 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001172 }
1173
1174 /**
1175 * Posts the specified command to be executed on the main thread,
1176 * waits for the request to complete, and returns the result.
1177 * @see #sendRequestAsync
1178 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001179 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001180 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001181 }
1182
1183 /**
1184 * Posts the specified command to be executed on the main thread,
1185 * waits for the request to complete, and returns the result.
1186 * @see #sendRequestAsync
1187 */
Nathan Harold92bed182018-10-12 18:16:49 -07001188 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1189 return sendRequest(command, argument, subId, null, workSource);
1190 }
1191
1192 /**
1193 * Posts the specified command to be executed on the main thread,
1194 * waits for the request to complete, and returns the result.
1195 * @see #sendRequestAsync
1196 */
1197 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1198 return sendRequest(
1199 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1200 }
1201
1202 /**
1203 * Posts the specified command to be executed on the main thread,
1204 * waits for the request to complete, and returns the result.
1205 * @see #sendRequestAsync
1206 */
1207 private Object sendRequest(
1208 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001209 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1210 throw new RuntimeException("This method will deadlock if called from the main thread.");
1211 }
1212
Nathan Harold92bed182018-10-12 18:16:49 -07001213 MainThreadRequest request = null;
1214 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1215 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1216 } else if (phone != null) {
1217 request = new MainThreadRequest(argument, phone, workSource);
1218 } else {
1219 request = new MainThreadRequest(argument, subId, workSource);
1220 }
1221
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 Message msg = mMainThreadHandler.obtainMessage(command, request);
1223 msg.sendToTarget();
1224
1225 // Wait for the request to complete
1226 synchronized (request) {
1227 while (request.result == null) {
1228 try {
1229 request.wait();
1230 } catch (InterruptedException e) {
1231 // Do nothing, go back and wait until the request is complete
1232 }
1233 }
1234 }
1235 return request.result;
1236 }
1237
1238 /**
1239 * Asynchronous ("fire and forget") version of sendRequest():
1240 * Posts the specified command to be executed on the main thread, and
1241 * returns immediately.
1242 * @see #sendRequest
1243 */
1244 private void sendRequestAsync(int command) {
1245 mMainThreadHandler.sendEmptyMessage(command);
1246 }
1247
1248 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001249 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001250 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001251 */
1252 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001253 sendRequestAsync(command, argument, null, null);
1254 }
1255
1256 /**
1257 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1258 * @see {@link #sendRequest(int,Object)}
1259 */
1260 private void sendRequestAsync(
1261 int command, Object argument, Phone phone, WorkSource workSource) {
1262 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001263 Message msg = mMainThreadHandler.obtainMessage(command, request);
1264 msg.sendToTarget();
1265 }
1266
1267 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 * Initialize the singleton PhoneInterfaceManager instance.
1269 * This is only done once, at startup, from PhoneApp.onCreate().
1270 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001271 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 synchronized (PhoneInterfaceManager.class) {
1273 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001274 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001275 } else {
1276 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1277 }
1278 return sInstance;
1279 }
1280 }
1281
1282 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001283 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001286 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001287 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1288 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001289 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001290 mTelephonySharedPreferences =
1291 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001292 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001293 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001294
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001295 publish();
1296 }
1297
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001298 private Phone getDefaultPhone() {
1299 Phone thePhone = getPhone(getDefaultSubscription());
1300 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1301 }
1302
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 private void publish() {
1304 if (DBG) log("publish: " + this);
1305
1306 ServiceManager.addService("phone", this);
1307 }
1308
Stuart Scott584921c2015-01-15 17:10:34 -08001309 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001310 if (request.phone != null) {
1311 return request.phone;
1312 } else {
1313 return getPhoneFromSubId(request.subId);
1314 }
1315 }
1316
1317 private Phone getPhoneFromSubId(int subId) {
1318 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1319 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001320 }
1321
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001322 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1323 Phone phone = getPhoneFromRequest(request);
1324 return phone == null ? null :
1325 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1326 }
1327
Wink Saville36469e72014-06-11 15:17:00 -07001328 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001329 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001330 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332
1333 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001334 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001335 }
1336
Wink Savilleb564aae2014-10-23 10:18:09 -07001337 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001338 if (DBG) log("dial: " + number);
1339 // No permission check needed here: This is just a wrapper around the
1340 // ACTION_DIAL intent, which is available to any app since it puts up
1341 // the UI before it does anything.
1342
Malcolm Chend965c8b2018-02-28 15:00:40 -08001343 final long identity = Binder.clearCallingIdentity();
1344 try {
1345 String url = createTelUrl(number);
1346 if (url == null) {
1347 return;
1348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349
Malcolm Chend965c8b2018-02-28 15:00:40 -08001350 // PENDING: should we just silently fail if phone is offhook or ringing?
1351 PhoneConstants.State state = mCM.getState(subId);
1352 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1353 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1354 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1355 mApp.startActivity(intent);
1356 }
1357 } finally {
1358 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 }
1360 }
1361
1362 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001363 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001364 }
1365
Wink Savilleb564aae2014-10-23 10:18:09 -07001366 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001367 if (DBG) log("call: " + number);
1368
1369 // This is just a wrapper around the ACTION_CALL intent, but we still
1370 // need to do a permission check since we're calling startActivity()
1371 // from the context of the phone app.
1372 enforceCallPermission();
1373
1374 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1375 != AppOpsManager.MODE_ALLOWED) {
1376 return;
1377 }
1378
Malcolm Chend965c8b2018-02-28 15:00:40 -08001379 final long identity = Binder.clearCallingIdentity();
1380 try {
1381 String url = createTelUrl(number);
1382 if (url == null) {
1383 return;
1384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385
Malcolm Chend965c8b2018-02-28 15:00:40 -08001386 boolean isValid = false;
1387 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1388 if (slist != null) {
1389 for (SubscriptionInfo subInfoRecord : slist) {
1390 if (subInfoRecord.getSubscriptionId() == subId) {
1391 isValid = true;
1392 break;
1393 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001394 }
Wink Saville08874612014-08-31 19:19:58 -07001395 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001396 if (!isValid) {
1397 return;
1398 }
Wink Saville08874612014-08-31 19:19:58 -07001399
Malcolm Chend965c8b2018-02-28 15:00:40 -08001400 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1401 intent.putExtra(SUBSCRIPTION_KEY, subId);
1402 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1403 mApp.startActivity(intent);
1404 } finally {
1405 Binder.restoreCallingIdentity(identity);
1406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 }
1408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001410 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001411 }
1412
Wink Savilleb564aae2014-10-23 10:18:09 -07001413 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001414 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001415 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1416 }
1417
1418 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001419 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001420 }
1421
Wink Savilleb564aae2014-10-23 10:18:09 -07001422 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001423 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001424 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1425 }
1426
1427 /** {@hide} */
1428 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001429 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001430 }
1431
Wink Savilleb564aae2014-10-23 10:18:09 -07001432 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001434
1435 final long identity = Binder.clearCallingIdentity();
1436 try {
1437 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1438 checkSimPin.start();
1439 return checkSimPin.unlockSim(null, pin);
1440 } finally {
1441 Binder.restoreCallingIdentity(identity);
1442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443 }
1444
Wink Saville9de0f752013-10-22 19:04:03 -07001445 /** {@hide} */
1446 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001447 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001448 }
1449
Wink Savilleb564aae2014-10-23 10:18:09 -07001450 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001452
1453 final long identity = Binder.clearCallingIdentity();
1454 try {
1455 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1456 checkSimPuk.start();
1457 return checkSimPuk.unlockSim(puk, pin);
1458 } finally {
1459 Binder.restoreCallingIdentity(identity);
1460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 }
1462
1463 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001464 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 * a synchronous one.
1466 */
1467 private static class UnlockSim extends Thread {
1468
1469 private final IccCard mSimCard;
1470
1471 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001472 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1473 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474
1475 // For replies from SimCard interface
1476 private Handler mHandler;
1477
1478 // For async handler to identify request type
1479 private static final int SUPPLY_PIN_COMPLETE = 100;
1480
1481 public UnlockSim(IccCard simCard) {
1482 mSimCard = simCard;
1483 }
1484
1485 @Override
1486 public void run() {
1487 Looper.prepare();
1488 synchronized (UnlockSim.this) {
1489 mHandler = new Handler() {
1490 @Override
1491 public void handleMessage(Message msg) {
1492 AsyncResult ar = (AsyncResult) msg.obj;
1493 switch (msg.what) {
1494 case SUPPLY_PIN_COMPLETE:
1495 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1496 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001497 mRetryCount = msg.arg1;
1498 if (ar.exception != null) {
1499 if (ar.exception instanceof CommandException &&
1500 ((CommandException)(ar.exception)).getCommandError()
1501 == CommandException.Error.PASSWORD_INCORRECT) {
1502 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1503 } else {
1504 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1505 }
1506 } else {
1507 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 mDone = true;
1510 UnlockSim.this.notifyAll();
1511 }
1512 break;
1513 }
1514 }
1515 };
1516 UnlockSim.this.notifyAll();
1517 }
1518 Looper.loop();
1519 }
1520
1521 /*
1522 * Use PIN or PUK to unlock SIM card
1523 *
1524 * If PUK is null, unlock SIM card with PIN
1525 *
1526 * If PUK is not null, unlock SIM card with PUK and set PIN code
1527 */
Wink Saville9de0f752013-10-22 19:04:03 -07001528 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529
1530 while (mHandler == null) {
1531 try {
1532 wait();
1533 } catch (InterruptedException e) {
1534 Thread.currentThread().interrupt();
1535 }
1536 }
1537 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1538
1539 if (puk == null) {
1540 mSimCard.supplyPin(pin, callback);
1541 } else {
1542 mSimCard.supplyPuk(puk, pin, callback);
1543 }
1544
1545 while (!mDone) {
1546 try {
1547 Log.d(LOG_TAG, "wait for done");
1548 wait();
1549 } catch (InterruptedException e) {
1550 // Restore the interrupted status
1551 Thread.currentThread().interrupt();
1552 }
1553 }
1554 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001555 int[] resultArray = new int[2];
1556 resultArray[0] = mResult;
1557 resultArray[1] = mRetryCount;
1558 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 }
1560 }
1561
1562 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001563 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001564
1565 }
1566
Wink Savilleb564aae2014-10-23 10:18:09 -07001567 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 // No permission check needed here: this call is harmless, and it's
1569 // needed for the ServiceState.requestStateUpdate() call (which is
1570 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001571 final long identity = Binder.clearCallingIdentity();
1572 try {
1573 final Phone phone = getPhone(subId);
1574 if (phone != null) {
1575 phone.updateServiceLocation();
1576 }
1577 } finally {
1578 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 }
1581
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001582 @Override
1583 public boolean isRadioOn(String callingPackage) {
1584 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001585 }
1586
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001587 @Override
1588 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001590 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001591 return false;
1592 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001593
1594 final long identity = Binder.clearCallingIdentity();
1595 try {
1596 return isRadioOnForSubscriber(subId);
1597 } finally {
1598 Binder.restoreCallingIdentity(identity);
1599 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001600 }
1601
1602 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001603 final long identity = Binder.clearCallingIdentity();
1604 try {
1605 final Phone phone = getPhone(subId);
1606 if (phone != null) {
1607 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1608 } else {
1609 return false;
1610 }
1611 } finally {
1612 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 }
1615
1616 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001617 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 }
Wink Saville36469e72014-06-11 15:17:00 -07001619
Wink Savilleb564aae2014-10-23 10:18:09 -07001620 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001622
1623 final long identity = Binder.clearCallingIdentity();
1624 try {
1625 final Phone phone = getPhone(subId);
1626 if (phone != null) {
1627 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1628 }
1629 } finally {
1630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001631 }
Wink Saville36469e72014-06-11 15:17:00 -07001632 }
1633
1634 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001635 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001636 }
1637
Wink Savilleb564aae2014-10-23 10:18:09 -07001638 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001639 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001640
1641 final long identity = Binder.clearCallingIdentity();
1642 try {
1643 final Phone phone = getPhone(subId);
1644 if (phone == null) {
1645 return false;
1646 }
1647 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1648 toggleRadioOnOffForSubscriber(subId);
1649 }
1650 return true;
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 }
Wink Saville36469e72014-06-11 15:17:00 -07001655
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001656 public boolean needMobileRadioShutdown() {
1657 /*
1658 * If any of the Radios are available, it will need to be
1659 * shutdown. So return true if any Radio is available.
1660 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001661 final long identity = Binder.clearCallingIdentity();
1662 try {
1663 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1664 Phone phone = PhoneFactory.getPhone(i);
1665 if (phone != null && phone.isRadioAvailable()) return true;
1666 }
1667 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1668 return false;
1669 } finally {
1670 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001671 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001672 }
1673
Malcolm Chend965c8b2018-02-28 15:00:40 -08001674 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001675 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001676 enforceModifyPermission();
1677
1678 final long identity = Binder.clearCallingIdentity();
1679 try {
1680 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1681 logv("Shutting down Phone " + i);
1682 shutdownRadioUsingPhoneId(i);
1683 }
1684 } finally {
1685 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001686 }
1687 }
1688
1689 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001690 Phone phone = PhoneFactory.getPhone(phoneId);
1691 if (phone != null && phone.isRadioAvailable()) {
1692 phone.shutdownRadio();
1693 }
1694 }
1695
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001697 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001698
1699 final long identity = Binder.clearCallingIdentity();
1700 try {
1701 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1702 if (defaultPhone != null) {
1703 defaultPhone.setRadioPower(turnOn);
1704 return true;
1705 } else {
1706 loge("There's no default phone.");
1707 return false;
1708 }
1709 } finally {
1710 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001711 }
Wink Saville36469e72014-06-11 15:17:00 -07001712 }
1713
Wink Savilleb564aae2014-10-23 10:18:09 -07001714 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 final Phone phone = getPhone(subId);
1720 if (phone != null) {
1721 phone.setRadioPower(turnOn);
1722 return true;
1723 } else {
1724 return false;
1725 }
1726 } finally {
1727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 }
1730
Wink Saville36469e72014-06-11 15:17:00 -07001731 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001732 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 public boolean enableDataConnectivity() {
1734 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001735
1736 final long identity = Binder.clearCallingIdentity();
1737 try {
1738 int subId = mSubscriptionController.getDefaultDataSubId();
1739 final Phone phone = getPhone(subId);
1740 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001741 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001742 return true;
1743 } else {
1744 return false;
1745 }
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
1750
Wink Saville36469e72014-06-11 15:17:00 -07001751 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001752 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 public boolean disableDataConnectivity() {
1754 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001755
1756 final long identity = Binder.clearCallingIdentity();
1757 try {
1758 int subId = mSubscriptionController.getDefaultDataSubId();
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001761 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001762 return true;
1763 } else {
1764 return false;
1765 }
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001772 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001773 final long identity = Binder.clearCallingIdentity();
1774 try {
1775 final Phone phone = getPhone(subId);
1776 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001777 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001778 } else {
1779 return false;
1780 }
1781 } finally {
1782 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 }
1785
1786 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001787 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001788 }
1789
pkanwarae03a6b2016-11-06 20:37:09 -08001790 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001791 enforceCallPermission();
1792
1793 final long identity = Binder.clearCallingIdentity();
1794 try {
1795 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1796 return;
1797 }
1798 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1799 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1800 } finally {
1801 Binder.restoreCallingIdentity(identity);
1802 }
pkanwar32d516d2016-10-14 19:37:38 -07001803 };
1804
Wink Savilleb564aae2014-10-23 10:18:09 -07001805 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001807
1808 final long identity = Binder.clearCallingIdentity();
1809 try {
1810 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1811 return false;
1812 }
1813 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1814 } finally {
1815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 }
1818
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001820 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001821 }
1822
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001823 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001824 final long identity = Binder.clearCallingIdentity();
1825 try {
1826 Phone phone = PhoneFactory.getPhone(slotIndex);
1827 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1828 PhoneConstantConversions.convertCallState(phone.getState());
1829 } finally {
1830 Binder.restoreCallingIdentity(identity);
1831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 }
1833
Sanket Padawe356d7632015-06-22 14:03:32 -07001834 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001836 final long identity = Binder.clearCallingIdentity();
1837 try {
1838 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1839 if (phone != null) {
1840 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1841 } else {
1842 return PhoneConstantConversions.convertDataState(
1843 PhoneConstants.DataState.DISCONNECTED);
1844 }
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 }
1849
Sanket Padawe356d7632015-06-22 14:03:32 -07001850 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1855 if (phone != null) {
1856 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1857 } else {
1858 return TelephonyManager.DATA_ACTIVITY_NONE;
1859 }
1860 } finally {
1861 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 }
1864
1865 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001866 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001867 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001868 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001869
1870 LocationAccessPolicy.LocationPermissionResult locationResult =
1871 LocationAccessPolicy.checkLocationPermission(mApp,
1872 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1873 .setCallingPackage(callingPackage)
1874 .setCallingPid(Binder.getCallingPid())
1875 .setCallingUid(Binder.getCallingUid())
1876 .setMethod("getCellLocation")
1877 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1878 .build());
1879 switch (locationResult) {
1880 case DENIED_HARD:
1881 throw new SecurityException("Not allowed to access cell location");
1882 case DENIED_SOFT:
1883 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001886 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001887 final long identity = Binder.clearCallingIdentity();
1888 try {
1889 if (DBG_LOC) log("getCellLocation: is active user");
1890 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001891 int subId = mSubscriptionController.getDefaultDataSubId();
1892 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1893 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001894 return data;
1895 } finally {
1896 Binder.restoreCallingIdentity(identity);
1897 }
Svetoslav64fad262015-04-14 14:35:21 -07001898 }
1899
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001901 public String getNetworkCountryIsoForPhone(int phoneId) {
1902 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1903 // registered cell info, so return a NULL country instead.
1904 final long identity = Binder.clearCallingIdentity();
1905 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001906 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1907 // Get default phone in this case.
1908 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1909 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001910 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001911 // Todo: fix this when we can get the actual cellular network info when the device
1912 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001913 if (TelephonyManager.NETWORK_TYPE_IWLAN
1914 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1915 return "";
1916 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001917 Phone phone = PhoneFactory.getPhone(phoneId);
1918 if (phone != null) {
1919 ServiceStateTracker sst = phone.getServiceStateTracker();
1920 if (sst != null) {
1921 LocaleTracker lt = sst.getLocaleTracker();
1922 if (lt != null) {
1923 return lt.getCurrentCountry();
1924 }
1925 }
1926 }
1927 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001928 } finally {
1929 Binder.restoreCallingIdentity(identity);
1930 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001931 }
1932
1933 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001935 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001936 }
1937
Sanket Padawe356d7632015-06-22 14:03:32 -07001938 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001939 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 mApp.enforceCallingOrSelfPermission(
1941 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001942
1943 final long identity = Binder.clearCallingIdentity();
1944 try {
1945 final Phone phone = getPhone(subId);
1946 if (phone != null) {
1947 phone.enableLocationUpdates();
1948 }
1949 } finally {
1950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
1953
1954 @Override
1955 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001956 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001957 }
1958
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001960 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961 mApp.enforceCallingOrSelfPermission(
1962 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001963
1964 final long identity = Binder.clearCallingIdentity();
1965 try {
1966 final Phone phone = getPhone(subId);
1967 if (phone != null) {
1968 phone.disableLocationUpdates();
1969 }
1970 } finally {
1971 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 }
1974
Nathan Harold31d7ff32018-10-15 20:20:30 -07001975 /**
1976 * Returns the target SDK version number for a given package name.
1977 *
1978 * @return target SDK if the package is found or INT_MAX.
1979 */
1980 private int getTargetSdk(String packageName) {
1981 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001982 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1983 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001984 if (ai != null) return ai.targetSdkVersion;
1985 } catch (PackageManager.NameNotFoundException unexpected) {
1986 }
1987 return Integer.MAX_VALUE;
1988 }
1989
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 @Override
1991 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001992 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1993 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001994 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1995 throw new SecurityException(
1996 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1997 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001998
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2000 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2001 return null;
2002 }
Svetoslav64fad262015-04-14 14:35:21 -07002003
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002004 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005
Nathan Haroldf180aac2018-06-01 18:43:55 -07002006 List<CellInfo> info = getAllCellInfo(callingPackage);
2007 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008
Nathan Haroldf180aac2018-06-01 18:43:55 -07002009 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2010 for (CellInfo ci : info) {
2011 if (ci instanceof CellInfoGsm) {
2012 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2013 } else if (ci instanceof CellInfoWcdma) {
2014 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002017 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 }
2019
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002020 private List<CellInfo> getCachedCellInfo() {
2021 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2022 for (Phone phone : PhoneFactory.getPhones()) {
2023 List<CellInfo> info = phone.getAllCellInfo();
2024 if (info != null) cellInfos.addAll(info);
2025 }
2026 return cellInfos;
2027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028
2029 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002030 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002031 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002032 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002033
2034 LocationAccessPolicy.LocationPermissionResult locationResult =
2035 LocationAccessPolicy.checkLocationPermission(mApp,
2036 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2037 .setCallingPackage(callingPackage)
2038 .setCallingPid(Binder.getCallingPid())
2039 .setCallingUid(Binder.getCallingUid())
2040 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002041 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002042 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2043 .build());
2044 switch (locationResult) {
2045 case DENIED_HARD:
2046 throw new SecurityException("Not allowed to access cell info");
2047 case DENIED_SOFT:
2048 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 }
2050
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002051 final int targetSdk = getTargetSdk(callingPackage);
2052 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2053 return getCachedCellInfo();
2054 }
2055
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002056 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002057 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002058 final long identity = Binder.clearCallingIdentity();
2059 try {
2060 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2061 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002062 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002063 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002064 if (info != null) cellInfos.addAll(info);
2065 }
2066 return cellInfos;
2067 } finally {
2068 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 }
2070 }
2071
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002072 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002073 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2074 requestCellInfoUpdateInternal(
2075 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2076 }
2077
2078 @Override
2079 public void requestCellInfoUpdateWithWorkSource(
2080 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2081 enforceModifyPermission();
2082 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2083 }
2084
2085 private void requestCellInfoUpdateInternal(
2086 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002087 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002088 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002089
2090 LocationAccessPolicy.LocationPermissionResult locationResult =
2091 LocationAccessPolicy.checkLocationPermission(mApp,
2092 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2093 .setCallingPackage(callingPackage)
2094 .setCallingPid(Binder.getCallingPid())
2095 .setCallingUid(Binder.getCallingUid())
2096 .setMethod("requestCellInfoUpdate")
2097 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2098 .build());
2099 switch (locationResult) {
2100 case DENIED_HARD:
2101 throw new SecurityException("Not allowed to access cell info");
2102 case DENIED_SOFT:
2103 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002104 }
2105
2106 final Phone phone = getPhone(subId);
2107 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2108
2109 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2110 }
2111
2112 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002114 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002115 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002116
2117 final long identity = Binder.clearCallingIdentity();
2118 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002119 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002120 } finally {
2121 Binder.restoreCallingIdentity(identity);
2122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 }
2124
Shishir Agrawala9f32182016-04-12 12:00:16 -07002125 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002126 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002127 Phone phone = PhoneFactory.getPhone(slotIndex);
2128 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002129 return null;
2130 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002131 int subId = phone.getSubId();
2132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2133 mApp, subId, callingPackage, "getImeiForSlot")) {
2134 return null;
2135 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002136
2137 final long identity = Binder.clearCallingIdentity();
2138 try {
2139 return phone.getImei();
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
2142 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002143 }
2144
2145 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002146 public String getTypeAllocationCodeForSlot(int slotIndex) {
2147 Phone phone = PhoneFactory.getPhone(slotIndex);
2148 String tac = null;
2149 if (phone != null) {
2150 String imei = phone.getImei();
2151 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2152 }
2153 return tac;
2154 }
2155
2156 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002157 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002158 Phone phone = PhoneFactory.getPhone(slotIndex);
2159 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002160 return null;
2161 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002162
Jeff Davidson913390f2018-02-23 17:11:49 -08002163 int subId = phone.getSubId();
2164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2165 mApp, subId, callingPackage, "getMeidForSlot")) {
2166 return null;
2167 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002168
2169 final long identity = Binder.clearCallingIdentity();
2170 try {
2171 return phone.getMeid();
2172 } finally {
2173 Binder.restoreCallingIdentity(identity);
2174 }
Jack Yu2af8d712017-03-15 17:14:14 -07002175 }
2176
2177 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002178 public String getManufacturerCodeForSlot(int slotIndex) {
2179 Phone phone = PhoneFactory.getPhone(slotIndex);
2180 String manufacturerCode = null;
2181 if (phone != null) {
2182 String meid = phone.getMeid();
2183 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2184 }
2185 return manufacturerCode;
2186 }
2187
2188 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002189 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002190 Phone phone = PhoneFactory.getPhone(slotIndex);
2191 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002192 return null;
2193 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002194 int subId = phone.getSubId();
2195 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2196 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2197 return null;
2198 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002199
2200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 return phone.getDeviceSvn();
2203 } finally {
2204 Binder.restoreCallingIdentity(identity);
2205 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002206 }
2207
fionaxu43304da2017-11-27 22:51:16 -08002208 @Override
2209 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002210 final long identity = Binder.clearCallingIdentity();
2211 try {
2212 final Phone phone = getPhone(subId);
2213 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
2216 }
fionaxu43304da2017-11-27 22:51:16 -08002217 }
2218
2219 @Override
2220 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002221 final long identity = Binder.clearCallingIdentity();
2222 try {
2223 final Phone phone = getPhone(subId);
2224 return phone == null ? null : phone.getCarrierName();
2225 } finally {
2226 Binder.restoreCallingIdentity(identity);
2227 }
fionaxu43304da2017-11-27 22:51:16 -08002228 }
2229
calvinpaneed9ae82018-11-01 19:43:06 +08002230 @Override
chen xua31f22b2019-03-06 15:28:50 -08002231 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002232 final long identity = Binder.clearCallingIdentity();
2233 try {
2234 final Phone phone = getPhone(subId);
2235 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002236 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002237 } finally {
2238 Binder.restoreCallingIdentity(identity);
2239 }
2240 }
2241
2242 @Override
chen xua31f22b2019-03-06 15:28:50 -08002243 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002247 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002248 } finally {
2249 Binder.restoreCallingIdentity(identity);
2250 }
2251 }
2252
chen xu02581692018-11-11 19:03:44 -08002253 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002254 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2255 if (!isSubscriptionMccMnc) {
2256 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2257 }
chen xu02581692018-11-11 19:03:44 -08002258 final Phone phone = PhoneFactory.getPhone(slotIndex);
2259 if (phone == null) {
2260 return TelephonyManager.UNKNOWN_CARRIER_ID;
2261 }
2262 final long identity = Binder.clearCallingIdentity();
2263 try {
2264 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
2267 }
2268 }
2269
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 //
2271 // Internal helper methods.
2272 //
2273
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002274 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2276 *
2277 * @throws SecurityException if the caller does not have the required permission
2278 */
2279 private void enforceModifyPermission() {
2280 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2281 }
2282
2283 /**
2284 * Make sure the caller has the CALL_PHONE permission.
2285 *
2286 * @throws SecurityException if the caller does not have the required permission
2287 */
2288 private void enforceCallPermission() {
2289 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2290 }
2291
Stuart Scott8eef64f2015-04-08 15:13:54 -07002292 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002293 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002294 "ConnectivityService");
2295 }
2296
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 private String createTelUrl(String number) {
2298 if (TextUtils.isEmpty(number)) {
2299 return null;
2300 }
2301
Jake Hambye994d462014-02-03 13:10:13 -08002302 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 }
2304
Ihab Awadf9e92732013-12-05 18:02:52 -08002305 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2307 }
2308
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002309 private static void logv(String msg) {
2310 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2311 }
2312
Ihab Awadf9e92732013-12-05 18:02:52 -08002313 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2315 }
2316
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002317 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002319 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002320 }
2321
Sanket Padawe356d7632015-06-22 14:03:32 -07002322 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002323 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002324 final long identity = Binder.clearCallingIdentity();
2325 try {
2326 final Phone phone = PhoneFactory.getPhone(slotIndex);
2327 if (phone == null) {
2328 return PhoneConstants.PHONE_TYPE_NONE;
2329 } else {
2330 return phone.getPhoneType();
2331 }
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 }
2336
2337 /**
2338 * Returns the CDMA ERI icon index to display
2339 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002340 @Override
2341 public int getCdmaEriIconIndex(String callingPackage) {
2342 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002343 }
2344
Sanket Padawe356d7632015-06-22 14:03:32 -07002345 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002346 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002348 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002349 return -1;
2350 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002351
2352 final long identity = Binder.clearCallingIdentity();
2353 try {
2354 final Phone phone = getPhone(subId);
2355 if (phone != null) {
2356 return phone.getCdmaEriIconIndex();
2357 } else {
2358 return -1;
2359 }
2360 } finally {
2361 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002362 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 }
2364
2365 /**
2366 * Returns the CDMA ERI icon mode,
2367 * 0 - ON
2368 * 1 - FLASHING
2369 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002370 @Override
2371 public int getCdmaEriIconMode(String callingPackage) {
2372 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002373 }
2374
Sanket Padawe356d7632015-06-22 14:03:32 -07002375 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002376 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002378 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002379 return -1;
2380 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002381
2382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 final Phone phone = getPhone(subId);
2385 if (phone != null) {
2386 return phone.getCdmaEriIconMode();
2387 } else {
2388 return -1;
2389 }
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 }
2394
2395 /**
2396 * Returns the CDMA ERI text,
2397 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002398 @Override
2399 public String getCdmaEriText(String callingPackage) {
2400 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002401 }
2402
Sanket Padawe356d7632015-06-22 14:03:32 -07002403 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002404 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002405 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002406 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002407 return null;
2408 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002409
2410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 final Phone phone = getPhone(subId);
2413 if (phone != null) {
2414 return phone.getCdmaEriText();
2415 } else {
2416 return null;
2417 }
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 }
2422
2423 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002424 * Returns the CDMA MDN.
2425 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002426 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002427 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2429 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002430
2431 final long identity = Binder.clearCallingIdentity();
2432 try {
2433 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002434 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002435 return phone.getLine1Number();
2436 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002437 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002438 return null;
2439 }
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002442 }
2443 }
2444
2445 /**
2446 * Returns the CDMA MIN.
2447 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002448 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002449 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2451 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 final Phone phone = getPhone(subId);
2456 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2457 return phone.getCdmaMin();
2458 } else {
2459 return null;
2460 }
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002463 }
2464 }
2465
Hall Liud892bec2018-11-30 14:51:45 -08002466 @Override
2467 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2468 INumberVerificationCallback callback, String callingPackage) {
2469 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2470 != PERMISSION_GRANTED) {
2471 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2472 }
2473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2474
2475 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2476 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2477 throw new SecurityException("Calling package must be configured in the device config");
2478 }
2479
2480 if (range == null) {
2481 throw new NullPointerException("Range must be non-null");
2482 }
2483
2484 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002485 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002486
2487 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2488 }
2489
Junda Liuca05d5d2014-08-14 22:36:34 -07002490 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 * Returns true if CDMA provisioning needs to run.
2492 */
2493 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002494 final long identity = Binder.clearCallingIdentity();
2495 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002496 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002497 } finally {
2498 Binder.restoreCallingIdentity(identity);
2499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
2502 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002503 * Sets the voice mail number of a given subId.
2504 */
2505 @Override
2506 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002507 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2512 new Pair<String, String>(alphaTag, number), new Integer(subId));
2513 return success;
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
2516 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002517 }
2518
Ta-wei Yen87c49842016-05-13 21:19:52 -07002519 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002520 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2521 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002522 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002523 if (!TextUtils.equals(callingPackage, systemDialer)) {
2524 throw new SecurityException("caller must be system dialer");
2525 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002526
2527 final long identity = Binder.clearCallingIdentity();
2528 try {
2529 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2530 if (phoneAccountHandle == null) {
2531 return null;
2532 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002533 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002534 } finally {
2535 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002536 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002537 }
2538
2539 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002540 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002541 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002543 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002544 return null;
2545 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002546
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002547 final long identity = Binder.clearCallingIdentity();
2548 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002549 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002550 } finally {
2551 Binder.restoreCallingIdentity(identity);
2552 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002553 }
2554
2555 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002556 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2557 VisualVoicemailSmsFilterSettings settings) {
2558 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002559
2560 final long identity = Binder.clearCallingIdentity();
2561 try {
2562 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002563 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002564 } finally {
2565 Binder.restoreCallingIdentity(identity);
2566 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002567 }
2568
2569 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002570 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2571 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002572
2573 final long identity = Binder.clearCallingIdentity();
2574 try {
2575 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002576 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002577 } finally {
2578 Binder.restoreCallingIdentity(identity);
2579 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002580 }
2581
2582 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002583 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2584 String callingPackage, int subId) {
2585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002586
2587 final long identity = Binder.clearCallingIdentity();
2588 try {
2589 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002590 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002591 } finally {
2592 Binder.restoreCallingIdentity(identity);
2593 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002594 }
2595
2596 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002597 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002598 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002599
2600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002603 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002604 } finally {
2605 Binder.restoreCallingIdentity(identity);
2606 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002607 }
2608
2609 @Override
2610 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2611 String number, int port, String text, PendingIntent sentIntent) {
2612 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002613 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002614 enforceSendSmsPermission();
2615 // Make the calls as the phone process.
2616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2619 if (port == 0) {
2620 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2621 sentIntent, null, false);
2622 } else {
2623 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2624 smsManager.sendDataMessageWithSelfPermissions(number, null,
2625 (short) port, data, sentIntent, null);
2626 }
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
2629 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002630 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002631 /**
fionaxu0152e512016-11-14 13:36:14 -08002632 * Sets the voice activation state of a given subId.
2633 */
2634 @Override
2635 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2637 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 final Phone phone = getPhone(subId);
2642 if (phone != null) {
2643 phone.setVoiceActivationState(activationState);
2644 } else {
2645 loge("setVoiceActivationState fails with invalid subId: " + subId);
2646 }
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002649 }
2650 }
2651
2652 /**
2653 * Sets the data activation state of a given subId.
2654 */
2655 @Override
2656 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2658 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002659
2660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 final Phone phone = getPhone(subId);
2663 if (phone != null) {
2664 phone.setDataActivationState(activationState);
2665 } else {
2666 loge("setVoiceActivationState fails with invalid subId: " + subId);
2667 }
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002670 }
2671 }
2672
2673 /**
2674 * Returns the voice activation state of a given subId.
2675 */
2676 @Override
2677 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002678 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002679
fionaxu0152e512016-11-14 13:36:14 -08002680 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 if (phone != null) {
2684 return phone.getVoiceActivationState();
2685 } else {
2686 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2687 }
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002690 }
2691 }
2692
2693 /**
2694 * Returns the data activation state of a given subId.
2695 */
2696 @Override
2697 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002698 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002699
fionaxu0152e512016-11-14 13:36:14 -08002700 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 if (phone != null) {
2704 return phone.getDataActivationState();
2705 } else {
2706 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2707 }
2708 } finally {
2709 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002710 }
2711 }
2712
2713 /**
Wink Saville36469e72014-06-11 15:17:00 -07002714 * Returns the unread count of voicemails for a subId
2715 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002716 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002717 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2719 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2720 return 0;
2721 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 final Phone phone = getPhone(subId);
2725 if (phone != null) {
2726 return phone.getVoiceMessageCount();
2727 } else {
2728 return 0;
2729 }
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733 }
2734
2735 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002736 * returns true, if the device is in a state where both voice and data
2737 * are supported simultaneously. This can change based on location or network condition.
2738 */
2739 @Override
2740 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 final Phone phone = getPhone(subId);
2744 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
2747 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002748 }
2749
2750 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002751 * Send the dialer code if called from the current default dialer or the caller has
2752 * carrier privilege.
2753 * @param inputCode The dialer code to send
2754 */
2755 @Override
2756 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002757 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002758 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002759 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2760 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002761 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002762 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2763 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002764 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002765
2766 final long identity = Binder.clearCallingIdentity();
2767 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002768 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002769 } finally {
2770 Binder.restoreCallingIdentity(identity);
2771 }
fionaxu235cc5e2017-03-06 22:25:57 -08002772 }
2773
2774 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002775 * Returns the data network type.
2776 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 *
2778 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2779 */
2780 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002781 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 final Phone phone = getPhone(getDefaultSubscription());
2785 if (phone != null) {
2786 return phone.getServiceState().getDataNetworkType();
2787 } else {
2788 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2789 }
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002792 }
Wink Saville36469e72014-06-11 15:17:00 -07002793 }
2794
Pengquan Meng0c05b502018-09-06 09:59:22 -07002795 @Override
2796 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002797 if (!isActiveSubscription(subId)) {
2798 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2799 }
2800
Pengquan Meng0c05b502018-09-06 09:59:22 -07002801 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2802 }
2803
Brad Ebinger4c460712018-10-01 10:40:55 -07002804 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002805 public boolean isInEmergencySmsMode() {
2806 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 for (Phone phone : PhoneFactory.getPhones()) {
2810 if (phone.isInEmergencySmsMode()) {
2811 return true;
2812 }
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
2816 }
2817 return false;
2818 }
2819
2820 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002821 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2822 throws RemoteException {
2823 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002824 final long token = Binder.clearCallingIdentity();
2825 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002826 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002827 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002828 .addRegistrationCallbackForSubscription(c, subId);
2829 } finally {
2830 Binder.restoreCallingIdentity(token);
2831 }
2832 }
2833
2834 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002835 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2836 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002837 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2838 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2839 }
2840 Binder.withCleanCallingIdentity(() -> {
2841 try {
2842 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002843 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002844 .removeRegistrationCallbackForSubscription(c, subId);
2845 } catch (IllegalArgumentException e) {
2846 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2847 + "is inactive, ignoring unregister.");
2848 // If the subscription is no longer active, just return, since the callback
2849 // will already have been removed internally.
2850 }
2851 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002852 }
2853
2854 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002855 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2856 throws RemoteException {
2857 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2859 final long token = Binder.clearCallingIdentity();
2860 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002861 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002862 .addCapabilitiesCallbackForSubscription(c, subId);
2863 } finally {
2864 Binder.restoreCallingIdentity(token);
2865 }
2866 }
2867
2868 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002869 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2870 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002871
2872 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2873 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2874 }
2875 Binder.withCleanCallingIdentity(() -> {
2876 try {
2877 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002878 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002879 .removeCapabilitiesCallbackForSubscription(c, subId);
2880 } catch (IllegalArgumentException e) {
2881 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2882 + "is inactive, ignoring unregister.");
2883 // If the subscription is no longer active, just return, since the callback
2884 // will already have been removed internally.
2885 }
2886 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002887 }
2888
2889 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002890 public boolean isCapable(int subId, int capability, int regTech) {
2891 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002892 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2893 final long token = Binder.clearCallingIdentity();
2894 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002895 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002896 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2897 } catch (ImsException e) {
2898 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2899 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002900 } catch (IllegalArgumentException e) {
2901 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2902 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002903 } finally {
2904 Binder.restoreCallingIdentity(token);
2905 }
2906 }
2907
2908 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002909 public boolean isAvailable(int subId, int capability, int regTech) {
2910 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002911 final long token = Binder.clearCallingIdentity();
2912 try {
2913 Phone phone = getPhone(subId);
2914 if (phone == null) return false;
2915 return phone.isImsCapabilityAvailable(capability, regTech);
2916 } finally {
2917 Binder.restoreCallingIdentity(token);
2918 }
2919 }
2920
2921 @Override
2922 public boolean isAdvancedCallingSettingEnabled(int subId) {
2923 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2925 final long token = Binder.clearCallingIdentity();
2926 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002927 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002928 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2929 } finally {
2930 Binder.restoreCallingIdentity(token);
2931 }
2932 }
2933
2934 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002935 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002937 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002941 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002942 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
2945 }
2946 }
2947
2948 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002949 public boolean isVtSettingEnabled(int subId) {
2950 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002954 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002955 getSlotIndexOrException(subId)).isVtEnabledByUser();
2956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
2959 }
2960
2961 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002962 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002964 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002968 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
2972 }
2973
2974 @Override
2975 public boolean isVoWiFiSettingEnabled(int subId) {
2976 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002980 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002981 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2982 } finally {
2983 Binder.restoreCallingIdentity(identity);
2984 }
2985 }
2986
2987 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002988 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002990 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002991 final long identity = Binder.clearCallingIdentity();
2992 try {
2993 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002994 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
2998 }
2999
3000 @Override
3001 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3002 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003006 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003007 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
3011 }
3012
3013 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003014 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003016 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003020 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003021 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
3025 }
3026
3027 @Override
3028 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3030 "setVoWiFiNonPersistent");
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003034 boolean isRoaming = TelephonyManager.from(
3035 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003036 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003037 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
3041 }
3042
3043 @Override
3044 public int getVoWiFiModeSetting(int subId) {
3045 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003049 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003050 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
3054 }
3055
3056 @Override
3057 public void setVoWiFiModeSetting(int subId, int mode) {
3058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3059 "setVoWiFiModeSetting");
3060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003063 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003064 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 @Override
3071 public int getVoWiFiRoamingModeSetting(int subId) {
3072 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003076 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003077 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
3081 }
3082
3083 @Override
3084 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3086 "setVoWiFiRoamingModeSetting");
3087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003090 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003091 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
3095 }
3096
3097 @Override
3098 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3100 "setRttCapabilityEnabled");
3101 final long identity = Binder.clearCallingIdentity();
3102 try {
3103 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003104 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003105 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
3109 }
3110
3111 @Override
3112 public boolean isTtyOverVolteEnabled(int subId) {
3113 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003117 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003118 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003124 @Override
3125 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3126 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3127 final long identity = Binder.clearCallingIdentity();
3128 try {
3129 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003130 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003131 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
3137 @Override
3138 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3139 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3140 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003141 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3142 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3143 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003144 try {
3145 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003146 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003147 .removeProvisioningCallbackForSubscription(callback, subId);
3148 } catch (IllegalArgumentException e) {
3149 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3150 + "is inactive, ignoring unregister.");
3151 // If the subscription is no longer active, just return, since the callback will already
3152 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
3156 }
3157
3158 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003159 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3160 boolean isProvisioned) {
3161 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3162 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3163 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3164 }
3165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3166 "setProvisioningStatusForCapability");
3167 final long identity = Binder.clearCallingIdentity();
3168 try {
3169 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3170 Phone phone = getPhone(subId);
3171 if (phone == null) {
3172 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3173 + subId);
3174 return;
3175 }
3176 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3177 return;
3178 }
3179
3180 // this capability requires provisioning, route to the correct API.
3181 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3182 switch (capability) {
3183 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3184 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3185 ims.setVolteProvisioned(isProvisioned);
3186 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3187 ims.setWfcProvisioned(isProvisioned);
3188 }
3189 break;
3190 }
3191 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3192 // There is currently no difference in VT provisioning type.
3193 ims.setVtProvisioned(isProvisioned);
3194 break;
3195 }
3196 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3197 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3198 // change the capability of the feature instead if needed.
3199 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3200 == isProvisioned) {
3201 // No change in provisioning.
3202 return;
3203 }
3204 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3205 try {
3206 ims.changeMmTelCapability(capability, tech, isProvisioned);
3207 } catch (ImsException e) {
3208 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3209 + ", Exception" + e.getMessage());
3210 }
3211 break;
3212 }
3213 default: {
3214 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3215 + capability + "', which does not require provisioning.");
3216 }
3217 }
3218
3219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
3222 }
3223
3224 @Override
3225 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3226 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3227 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3228 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3229 }
3230 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3231 final long identity = Binder.clearCallingIdentity();
3232 try {
3233 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3234 Phone phone = getPhone(subId);
3235 if (phone == null) {
3236 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3237 + subId);
3238 // We will fail with "true" as the provisioning status because this is the default
3239 // if we do not require provisioning.
3240 return true;
3241 }
3242
3243 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3244 return true;
3245 }
3246
3247 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3248 switch (capability) {
3249 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3250 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3251 return ims.isVolteProvisionedOnDevice();
3252 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3253 return ims.isWfcProvisionedOnDevice();
3254 }
3255 // This should never happen, since we are checking tech above to make sure it
3256 // is either LTE or IWLAN.
3257 throw new IllegalArgumentException("Invalid radio technology for voice "
3258 + "capability.");
3259 }
3260 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3261 // There is currently no difference in VT provisioning type.
3262 return ims.isVtProvisionedOnDevice();
3263 }
3264 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3265 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3266 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3267 }
3268 default: {
3269 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3270 + capability + "', which does not require provisioning.");
3271 }
3272 }
3273
3274 } finally {
3275 Binder.restoreCallingIdentity(identity);
3276 }
3277 }
3278
3279 @Override
3280 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3281 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3282 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3283 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3284 }
3285 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3286 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3287 return (provisionedBits & capability) > 0;
3288 }
3289
3290 @Override
3291 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3292 boolean isProvisioned) {
3293 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3294 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3295 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3296 }
3297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3298 "setProvisioningStatusForCapability");
3299 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3300 // If the current provisioning status for capability already matches isProvisioned,
3301 // do nothing.
3302 if (((provisionedBits & capability) > 0) == isProvisioned) {
3303 return;
3304 }
3305 if (isProvisioned) {
3306 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3307 } else {
3308 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3309 }
3310 }
3311
3312 /**
3313 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3314 * technology. The bitfield should mirror the bitfield defined by
3315 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3316 */
3317 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3318 String key = getMmTelProvisioningKey(subId, tech);
3319 // Default is no capabilities are provisioned.
3320 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3321 }
3322
3323 /**
3324 * Sets the MmTel capability provisioning bitfield (defined by
3325 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3326 * technology specified.
3327 *
3328 * Note: This is a synchronous command and should not be called on UI thread.
3329 */
3330 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3331 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3332 String key = getMmTelProvisioningKey(subId, tech);
3333 editor.putInt(key, newField);
3334 editor.commit();
3335 }
3336
3337 private static String getMmTelProvisioningKey(int subId, int tech) {
3338 // resulting key is provision_ims_mmtel_{subId}_{tech}
3339 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3340 }
3341
3342 /**
3343 * Query CarrierConfig to see if the specified capability requires provisioning for the
3344 * carrier associated with the subscription id.
3345 */
3346 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3347 int capability) {
3348 CarrierConfigManager configManager = new CarrierConfigManager(context);
3349 PersistableBundle c = configManager.getConfigForSubId(subId);
3350 boolean requireUtProvisioning = c.getBoolean(
3351 // By default, this config is true (even if there is no SIM). We also check to make
3352 // sure the subscription needs provisioning here, so we do not need to check for
3353 // the no-SIM case, where we would normally shortcut this to false.
3354 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3355 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3356 false);
3357 boolean requireVoiceVtProvisioning = c.getBoolean(
3358 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3359
3360 // First check to make sure that the capability requires provisioning.
3361 switch (capability) {
3362 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3363 // intentional fallthrough
3364 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3365 if (requireVoiceVtProvisioning) {
3366 // Voice and Video requires provisioning
3367 return true;
3368 }
3369 break;
3370 }
3371 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3372 if (requireUtProvisioning) {
3373 // UT requires provisioning
3374 return true;
3375 }
3376 break;
3377 }
3378 }
3379 return false;
3380 }
3381
3382 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003383 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003384 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3385 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3386 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003387 enforceReadPrivilegedPermission("getImsProvisioningInt");
3388 final long identity = Binder.clearCallingIdentity();
3389 try {
3390 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003391 int slotId = getSlotIndex(subId);
3392 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3393 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3394 + subId + "' for key:" + key);
3395 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3396 }
3397 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003398 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003399 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3400 + subId + "' for key:" + key);
3401 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003402 } finally {
3403 Binder.restoreCallingIdentity(identity);
3404 }
3405 }
3406
3407 @Override
3408 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003409 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3410 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3411 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003412 enforceReadPrivilegedPermission("getImsProvisioningString");
3413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003416 int slotId = getSlotIndex(subId);
3417 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3418 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3419 + subId + "' for key:" + key);
3420 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3421 }
3422 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003423 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003424 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3425 + subId + "' for key:" + key);
3426 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
3430 }
3431
3432 @Override
3433 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003434 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3435 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3436 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3438 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003439 final long identity = Binder.clearCallingIdentity();
3440 try {
3441 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003442 int slotId = getSlotIndex(subId);
3443 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3444 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3445 + subId + "' for key:" + key);
3446 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3447 }
3448 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003449 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003450 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3451 + "' for key:" + key);
3452 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
3456 }
3457
3458 @Override
3459 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003460 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3461 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3462 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3464 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003465 final long identity = Binder.clearCallingIdentity();
3466 try {
3467 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003468 int slotId = getSlotIndex(subId);
3469 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3470 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3471 + subId + "' for key:" + key);
3472 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3473 }
3474 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003475 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003476 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3477 + "' for key:" + key);
3478 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
3482 }
3483
Brad Ebinger4c460712018-10-01 10:40:55 -07003484 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3485 int slotId = SubscriptionManager.getSlotIndex(subId);
3486 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003487 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003488 }
3489 return slotId;
3490 }
3491
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003492 private int getSlotIndex(int subId) {
3493 int slotId = SubscriptionManager.getSlotIndex(subId);
3494 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3495 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3496 }
3497 return slotId;
3498 }
3499
Wink Saville36469e72014-06-11 15:17:00 -07003500 /**
3501 * Returns the network type for a subId
3502 */
3503 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003504 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003506 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003507 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3508 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003509
Malcolm Chend965c8b2018-02-28 15:00:40 -08003510 final long identity = Binder.clearCallingIdentity();
3511 try {
3512 final Phone phone = getPhone(subId);
3513 if (phone != null) {
3514 return phone.getServiceState().getDataNetworkType();
3515 } else {
3516 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3517 }
3518 } finally {
3519 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 }
3522
3523 /**
3524 * Returns the data network type
3525 */
3526 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003527 public int getDataNetworkType(String callingPackage) {
3528 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003529 }
3530
3531 /**
3532 * Returns the data network type for a subId
3533 */
3534 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003536 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003537 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003538 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3539 }
3540
Malcolm Chend965c8b2018-02-28 15:00:40 -08003541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 final Phone phone = getPhone(subId);
3544 if (phone != null) {
3545 return phone.getServiceState().getDataNetworkType();
3546 } else {
3547 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3548 }
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003552 }
3553
3554 /**
Wink Saville36469e72014-06-11 15:17:00 -07003555 * Returns the Voice network type for a subId
3556 */
3557 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003558 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003560 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003561 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3562 }
3563
Malcolm Chend965c8b2018-02-28 15:00:40 -08003564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 final Phone phone = getPhone(subId);
3567 if (phone != null) {
3568 return phone.getServiceState().getVoiceNetworkType();
3569 } else {
3570 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3571 }
3572 } finally {
3573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003575 }
3576
3577 /**
3578 * @return true if a ICC card is present
3579 */
3580 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003581 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003582 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3583 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003584 }
3585
3586 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003587 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003588 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003589 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003590 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 final Phone phone = PhoneFactory.getPhone(slotIndex);
3594 if (phone != null) {
3595 return phone.getIccCard().hasIccCard();
3596 } else {
3597 return false;
3598 }
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003602 }
3603
3604 /**
3605 * Return if the current radio is LTE on CDMA. This
3606 * is a tri-state return value as for a period of time
3607 * the mode may be unknown.
3608 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003609 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003611 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003612 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003613 @Override
3614 public int getLteOnCdmaMode(String callingPackage) {
3615 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003616 }
3617
Sanket Padawe356d7632015-06-22 14:03:32 -07003618 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003619 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003621 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003622 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3623 }
3624
Malcolm Chend965c8b2018-02-28 15:00:40 -08003625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 final Phone phone = getPhone(subId);
3628 if (phone == null) {
3629 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3630 } else {
3631 return phone.getLteOnCdmaMode();
3632 }
3633 } finally {
3634 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003635 }
Wink Saville36469e72014-06-11 15:17:00 -07003636 }
3637
Wink Saville36469e72014-06-11 15:17:00 -07003638 /**
3639 * {@hide}
3640 * Returns Default subId, 0 in the case of single standby.
3641 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003642 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003643 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003644 }
3645
Shishir Agrawala9f32182016-04-12 12:00:16 -07003646 private int getSlotForDefaultSubscription() {
3647 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3648 }
3649
Wink Savilleb564aae2014-10-23 10:18:09 -07003650 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003651 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003652 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003653
Pengquan Meng466e2482018-09-21 15:54:48 -07003654 private boolean isActiveSubscription(int subId) {
3655 return mSubscriptionController.isActiveSubId(subId);
3656 }
3657
Ihab Awadf2177b72013-11-25 13:33:23 -08003658 /**
3659 * @see android.telephony.TelephonyManager.WifiCallingChoices
3660 */
3661 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003664 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003665 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3666 getWhenToMakeWifiCallsDefaultPreference());
3667 } finally {
3668 Binder.restoreCallingIdentity(identity);
3669 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003670 }
3671
3672 /**
3673 * @see android.telephony.TelephonyManager.WifiCallingChoices
3674 */
3675 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003679 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003680 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003684 }
3685
Sailesh Nepald1e68152013-12-12 19:08:02 -08003686 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003687 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003688 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003689 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003690
Jordan Liu73b078d2019-02-28 12:03:40 -08003691 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3692 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3693 if (phoneId == -1) {
3694 throw new IllegalArgumentException("Given slot index: " + slotIndex
3695 + " does not correspond to an active phone");
3696 }
3697 return PhoneFactory.getPhone(phoneId);
3698 }
3699
Shishir Agrawal566b7612013-10-28 14:41:00 -07003700 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003701 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3702 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3704 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003705 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003706 if (DBG) {
3707 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3708 }
3709 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3710 p2);
3711 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003712
Jordan Liu73b078d2019-02-28 12:03:40 -08003713
3714 @Override
3715 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3716 int slotIndex, String callingPackage, String aid, int p2) {
3717 enforceModifyPermission();
3718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3719 if (DBG) {
3720 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3721 }
3722 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3723 callingPackage, aid, p2);
3724 }
3725
3726 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3727 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003728 final long identity = Binder.clearCallingIdentity();
3729 try {
3730 if (TextUtils.equals(ISDR_AID, aid)) {
3731 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003732 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3733 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003734 if (bestComponent == null
3735 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3736 loge("The calling package is not allowed to access ISD-R.");
3737 throw new SecurityException(
3738 "The calling package is not allowed to access ISD-R.");
3739 }
Derek Tan740e1672017-06-27 14:56:27 -07003740 }
Derek Tan740e1672017-06-27 14:56:27 -07003741
Malcolm Chend965c8b2018-02-28 15:00:40 -08003742 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003743 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3744 null /* workSource */);
3745 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003746 return response;
3747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003750 }
3751
3752 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003753 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3755 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003756 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3757 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3758 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003759
Jordan Liu73b078d2019-02-28 12:03:40 -08003760 @Override
3761 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3762 enforceModifyPermission();
3763 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3764 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3765 channel);
3766 }
3767
3768 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003769 final long identity = Binder.clearCallingIdentity();
3770 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003771 if (channel < 0) {
3772 return false;
3773 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003774 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3775 null /* workSource */);
3776 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003777 return success;
3778 } finally {
3779 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003780 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003781 }
3782
3783 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003784 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003785 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3787 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003788 if (DBG) {
3789 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3790 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3791 + p3 + " data=" + data);
3792 }
3793 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3794 command, p1, p2, p3, data);
3795 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003796
Jordan Liu73b078d2019-02-28 12:03:40 -08003797 @Override
3798 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3799 int command, int p1, int p2, int p3, String data) {
3800 enforceModifyPermission();
3801 if (DBG) {
3802 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3803 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3804 + p3 + " data=" + data);
3805 }
3806 return iccTransmitApduLogicalChannelWithPermission(
3807 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3808 data);
3809 }
3810
3811 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3812 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003815 if (channel < 0) {
3816 return "";
3817 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003818
Malcolm Chend965c8b2018-02-28 15:00:40 -08003819 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003820 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3821 null /* workSource */);
3822 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003823
Malcolm Chend965c8b2018-02-28 15:00:40 -08003824 // Append the returned status code to the end of the response payload.
3825 String s = Integer.toHexString(
3826 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3827 if (response.payload != null) {
3828 s = IccUtils.bytesToHexString(response.payload) + s;
3829 }
3830 return s;
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003833 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003834 }
Jake Hambye994d462014-02-03 13:10:13 -08003835
Evan Charltonc66da362014-05-16 14:06:40 -07003836 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003837 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3838 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3840 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003841 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003842 if (DBG) {
3843 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3844 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3845 }
3846 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3847 cla, command, p1, p2, p3, data);
3848 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003849
Jordan Liu73b078d2019-02-28 12:03:40 -08003850 @Override
3851 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3852 int command, int p1, int p2, int p3, String data) {
3853 enforceModifyPermission();
3854 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3855 if (DBG) {
3856 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3857 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3858 + " data=" + data);
3859 }
3860
3861 return iccTransmitApduBasicChannelWithPermission(
3862 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3863 p2, p3, data);
3864 }
3865
3866 // open APDU basic channel assuming the caller has sufficient permissions
3867 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3868 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3872 && TextUtils.equals(ISDR_AID, data)) {
3873 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003874 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3875 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003876 if (bestComponent == null
3877 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3878 loge("The calling package is not allowed to select ISD-R.");
3879 throw new SecurityException(
3880 "The calling package is not allowed to select ISD-R.");
3881 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003882 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003883
Malcolm Chend965c8b2018-02-28 15:00:40 -08003884 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003885 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3886 null /* workSource */);
3887 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003888
Malcolm Chend965c8b2018-02-28 15:00:40 -08003889 // Append the returned status code to the end of the response payload.
3890 String s = Integer.toHexString(
3891 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3892 if (response.payload != null) {
3893 s = IccUtils.bytesToHexString(response.payload) + s;
3894 }
3895 return s;
3896 } finally {
3897 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003898 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003899 }
3900
3901 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003902 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003903 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3905 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003906
Malcolm Chend965c8b2018-02-28 15:00:40 -08003907 final long identity = Binder.clearCallingIdentity();
3908 try {
3909 if (DBG) {
3910 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3911 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3912 }
3913
3914 IccIoResult response =
3915 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3916 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3917 subId);
3918
3919 if (DBG) {
3920 log("Exchange SIM_IO [R]" + response);
3921 }
3922
3923 byte[] result = null;
3924 int length = 2;
3925 if (response.payload != null) {
3926 length = 2 + response.payload.length;
3927 result = new byte[length];
3928 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3929 } else {
3930 result = new byte[length];
3931 }
3932
3933 result[length - 1] = (byte) response.sw2;
3934 result[length - 2] = (byte) response.sw1;
3935 return result;
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003938 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003939 }
3940
Nathan Haroldb3014052017-01-25 15:57:32 -08003941 /**
3942 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3943 * on a particular subscription
3944 */
sqianb6e41952018-03-12 14:54:01 -07003945 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3947 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3948 return null;
3949 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003950
3951 final long identity = Binder.clearCallingIdentity();
3952 try {
3953 if (appType != TelephonyManager.APPTYPE_USIM
3954 && appType != TelephonyManager.APPTYPE_SIM) {
3955 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3956 return null;
3957 }
3958 Object response = sendRequest(
3959 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3960 if (response instanceof String[]) {
3961 return (String[]) response;
3962 }
3963 // Response is an Exception of some kind,
3964 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003965 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003966 } finally {
3967 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003968 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003969 }
3970
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003971 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003972 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3974 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003975
Malcolm Chend965c8b2018-02-28 15:00:40 -08003976 final long identity = Binder.clearCallingIdentity();
3977 try {
3978 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3979 if (response.payload == null) {
3980 return "";
3981 }
Evan Charltonc66da362014-05-16 14:06:40 -07003982
Malcolm Chend965c8b2018-02-28 15:00:40 -08003983 // Append the returned status code to the end of the response payload.
3984 String s = Integer.toHexString(
3985 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3986 s = IccUtils.bytesToHexString(response.payload) + s;
3987 return s;
3988 } finally {
3989 Binder.restoreCallingIdentity(identity);
3990 }
Evan Charltonc66da362014-05-16 14:06:40 -07003991 }
3992
Jake Hambye994d462014-02-03 13:10:13 -08003993 /**
3994 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3995 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3996 *
3997 * @param itemID the ID of the item to read
3998 * @return the NV item as a String, or null on error.
3999 */
4000 @Override
4001 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004002 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4004 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004005
4006 final long identity = Binder.clearCallingIdentity();
4007 try {
4008 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004009 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004010 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4011 return value;
4012 } finally {
4013 Binder.restoreCallingIdentity(identity);
4014 }
Jake Hambye994d462014-02-03 13:10:13 -08004015 }
4016
4017 /**
4018 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4019 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4020 *
4021 * @param itemID the ID of the item to read
4022 * @param itemValue the value to write, as a String
4023 * @return true on success; false on any failure
4024 */
4025 @Override
4026 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004027 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4029 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004030
4031 final long identity = Binder.clearCallingIdentity();
4032 try {
4033 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4034 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004035 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004036 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4037 return success;
4038 } finally {
4039 Binder.restoreCallingIdentity(identity);
4040 }
Jake Hambye994d462014-02-03 13:10:13 -08004041 }
4042
4043 /**
4044 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4045 * Used for device configuration by some CDMA operators.
4046 *
4047 * @param preferredRoamingList byte array containing the new PRL
4048 * @return true on success; false on any failure
4049 */
4050 @Override
4051 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4053 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004054
4055 final long identity = Binder.clearCallingIdentity();
4056 try {
4057 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4058 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4059 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4060 return success;
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
Jake Hambye994d462014-02-03 13:10:13 -08004064 }
4065
4066 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004067 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004068 * Used for device configuration by some CDMA operators.
4069 *
chen xu1cc0abe2018-10-26 17:39:23 -07004070 * @param slotIndex - device slot.
4071 *
Jake Hambye994d462014-02-03 13:10:13 -08004072 * @return true on success; false on any failure
4073 */
4074 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004075 public boolean resetModemConfig(int slotIndex) {
4076 Phone phone = PhoneFactory.getPhone(slotIndex);
4077 if (phone != null) {
4078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4079 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004080
chen xu1cc0abe2018-10-26 17:39:23 -07004081 final long identity = Binder.clearCallingIdentity();
4082 try {
4083 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4084 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4085 return success;
4086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004089 }
chen xu1cc0abe2018-10-26 17:39:23 -07004090 return false;
4091 }
4092
4093 /**
4094 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4095 *
4096 * @param slotIndex - device slot.
4097 *
4098 * @return true on success; false on any failure
4099 */
4100 @Override
4101 public boolean rebootModem(int slotIndex) {
4102 Phone phone = PhoneFactory.getPhone(slotIndex);
4103 if (phone != null) {
4104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4105 mApp, phone.getSubId(), "rebootModem");
4106
4107 final long identity = Binder.clearCallingIdentity();
4108 try {
4109 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4110 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4111 return success;
4112 } finally {
4113 Binder.restoreCallingIdentity(identity);
4114 }
4115 }
4116 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004117 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004118
Svet Ganovb320e182015-04-16 12:30:10 -07004119 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004120 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004122 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004123 return new String[0];
4124 }
4125
Malcolm Chend965c8b2018-02-28 15:00:40 -08004126 final long identity = Binder.clearCallingIdentity();
4127 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004128 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
Wink Saville36469e72014-06-11 15:17:00 -07004132 }
4133
Brad Ebinger51f743a2017-01-23 13:50:20 -08004134 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004135 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4136 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004137 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004138 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004139 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004140
4141 final long identity = Binder.clearCallingIdentity();
4142 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004143 ImsResolver resolver = PhoneFactory.getImsResolver();
4144 if (resolver == null) {
4145 // may happen if the device does not support IMS.
4146 return;
4147 }
4148 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004149 } finally {
4150 Binder.restoreCallingIdentity(identity);
4151 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004152 }
4153
4154 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004155 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4156 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004157 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004158 public void disableIms(int slotId) {
4159 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004160
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004163 ImsResolver resolver = PhoneFactory.getImsResolver();
4164 if (resolver == null) {
4165 // may happen if the device does not support IMS.
4166 return;
4167 }
4168 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004172 }
4173
4174 /**
4175 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4176 * feature or {@link null} if the service is not available. If the feature is available, the
4177 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4178 */
4179 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004180 IImsServiceFeatureCallback callback) {
4181 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004182
4183 final long identity = Binder.clearCallingIdentity();
4184 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004185 ImsResolver resolver = PhoneFactory.getImsResolver();
4186 if (resolver == null) {
4187 // may happen if the device does not support IMS.
4188 return null;
4189 }
4190 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004191 } finally {
4192 Binder.restoreCallingIdentity(identity);
4193 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004194 }
4195
4196 /**
4197 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4198 * feature during emergency calling or {@link null} if the service is not available. If the
4199 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4200 * listener for feature updates.
4201 */
4202 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4203 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004204
4205 final long identity = Binder.clearCallingIdentity();
4206 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004207 ImsResolver resolver = PhoneFactory.getImsResolver();
4208 if (resolver == null) {
4209 // may happen if the device does not support IMS.
4210 return null;
4211 }
4212 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004213 } finally {
4214 Binder.restoreCallingIdentity(identity);
4215 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004216 }
4217
Brad Ebinger5f64b052017-12-14 14:26:15 -08004218 /**
4219 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004220 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004221 */
4222 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4223 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004224
4225 final long identity = Binder.clearCallingIdentity();
4226 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004227 ImsResolver resolver = PhoneFactory.getImsResolver();
4228 if (resolver == null) {
4229 // may happen if the device does not support IMS.
4230 return null;
4231 }
4232 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004233 } finally {
4234 Binder.restoreCallingIdentity(identity);
4235 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004236 }
4237
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004238 /**
4239 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004240 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004241 */
4242 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4243 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004244
4245 final long identity = Binder.clearCallingIdentity();
4246 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004247 ImsResolver resolver = PhoneFactory.getImsResolver();
4248 if (resolver == null) {
4249 // may happen if the device does not support IMS.
4250 return null;
4251 }
4252 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004256 }
4257
Brad Ebinger884c07b2018-02-15 16:17:40 -08004258 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004259 * Sets the ImsService Package Name that Telephony will bind to.
4260 *
4261 * @param slotId the slot ID that the ImsService should bind for.
4262 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4263 * ImsService is the device default ImsService.
4264 * @param packageName The package name of the application that contains the ImsService to bind
4265 * to.
4266 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4267 * @hide
4268 */
4269 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004270 int[] subIds = SubscriptionManager.getSubId(slotId);
4271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4272 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4273 "setImsService");
4274
Malcolm Chend965c8b2018-02-28 15:00:40 -08004275 final long identity = Binder.clearCallingIdentity();
4276 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004277 ImsResolver resolver = PhoneFactory.getImsResolver();
4278 if (resolver == null) {
4279 // may happen if the device does not support IMS.
4280 return false;
4281 }
4282 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4283 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004287 }
4288
4289 /**
4290 * Return the ImsService configuration.
4291 *
4292 * @param slotId The slot that the ImsService is associated with.
4293 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4294 * the device default.
4295 * @return the package name of the ImsService configuration.
4296 */
4297 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004298 int[] subIds = SubscriptionManager.getSubId(slotId);
4299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4300 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4301 "getImsService");
4302
Malcolm Chend965c8b2018-02-28 15:00:40 -08004303 final long identity = Binder.clearCallingIdentity();
4304 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004305 ImsResolver resolver = PhoneFactory.getImsResolver();
4306 if (resolver == null) {
4307 // may happen if the device does not support IMS.
4308 return "";
4309 }
4310 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004314 }
4315
Wink Saville36469e72014-06-11 15:17:00 -07004316 public void setImsRegistrationState(boolean registered) {
4317 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004318
4319 final long identity = Binder.clearCallingIdentity();
4320 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004321 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004322 } finally {
4323 Binder.restoreCallingIdentity(identity);
4324 }
Wink Saville36469e72014-06-11 15:17:00 -07004325 }
4326
4327 /**
Stuart Scott54788802015-03-30 13:18:01 -07004328 * Set the network selection mode to automatic.
4329 *
4330 */
4331 @Override
4332 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4334 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004335
Pengquan Meng466e2482018-09-21 15:54:48 -07004336 if (!isActiveSubscription(subId)) {
4337 return;
4338 }
4339
Malcolm Chend965c8b2018-02-28 15:00:40 -08004340 final long identity = Binder.clearCallingIdentity();
4341 try {
4342 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4343 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4344 } finally {
4345 Binder.restoreCallingIdentity(identity);
4346 }
Stuart Scott54788802015-03-30 13:18:01 -07004347 }
4348
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004349 /**
4350 * Ask the radio to connect to the input network and change selection mode to manual.
4351 *
4352 * @param subId the id of the subscription.
4353 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4354 * the operator to attach to.
4355 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4356 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4357 * normal network selection next time.
4358 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004359 */
4360 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004361 public boolean setNetworkSelectionModeManual(
4362 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4364 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004365
4366 if (!isActiveSubscription(subId)) {
4367 return false;
4368 }
4369
Malcolm Chend965c8b2018-02-28 15:00:40 -08004370 final long identity = Binder.clearCallingIdentity();
4371 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004372 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004373 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004374 if (DBG) {
4375 log("setNetworkSelectionModeManual: subId: " + subId
4376 + " operator: " + operatorInfo);
4377 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004378 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004382 }
4383
4384 /**
4385 * Scans for available networks.
4386 */
4387 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004388 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4390 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004391 LocationAccessPolicy.LocationPermissionResult locationResult =
4392 LocationAccessPolicy.checkLocationPermission(mApp,
4393 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4394 .setCallingPackage(callingPackage)
4395 .setCallingPid(Binder.getCallingPid())
4396 .setCallingUid(Binder.getCallingUid())
4397 .setMethod("getCellNetworkScanResults")
4398 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4399 .build());
4400 switch (locationResult) {
4401 case DENIED_HARD:
4402 throw new SecurityException("Not allowed to access scan results -- location");
4403 case DENIED_SOFT:
4404 return null;
4405 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004406
Pengquan Meng0c05b502018-09-06 09:59:22 -07004407 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004408 try {
4409 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004410 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004411 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004415 }
4416
4417 /**
yinxub1bed742017-04-17 11:45:04 -07004418 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004419 *
yinxub1bed742017-04-17 11:45:04 -07004420 * @param subId id of the subscription
4421 * @param request contains the radio access networks with bands/channels to scan
4422 * @param messenger callback messenger for scan results or errors
4423 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004424 * @return the id of the requested scan which can be used to stop the scan.
4425 */
4426 @Override
4427 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004428 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4430 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004431 LocationAccessPolicy.LocationPermissionResult locationResult =
4432 LocationAccessPolicy.checkLocationPermission(mApp,
4433 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4434 .setCallingPackage(callingPackage)
4435 .setCallingPid(Binder.getCallingPid())
4436 .setCallingUid(Binder.getCallingUid())
4437 .setMethod("requestNetworkScan")
4438 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4439 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004440 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4441 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4442 if (e != null) {
4443 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4444 throw e;
4445 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004446 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004447 return TelephonyScanManager.INVALID_SCAN_ID;
4448 }
4449 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004450 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004451 return mNetworkScanRequestTracker.startNetworkScan(
4452 request, messenger, binder, getPhone(subId),
4453 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004454 }
4455
Hall Liub2ac8ef2019-02-28 15:56:23 -08004456 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4457 NetworkScanRequest request) {
4458 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4459 != PERMISSION_GRANTED) {
4460 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4461 + " without location access.");
4462 }
4463
4464 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4465 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004466 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4467 return new SecurityException("Specific channels must not be"
4468 + " scanned without location access.");
4469 }
4470 }
4471 }
4472
4473 List<String> allowedMccMncs =
4474 NetworkScanRequestTracker.getAllowedMccMncsForLocationRestrictedScan(mApp);
4475 for (String mccmnc : request.getPlmns()) {
4476 if (!allowedMccMncs.contains(mccmnc)) {
4477 return new SecurityException("Requested mccmnc " + mccmnc + " is not known to the"
4478 + " device and cannot be scanned for without location access.");
4479 }
4480 }
4481
4482 return null;
4483 }
4484
yinxu504e1392017-04-12 16:03:22 -07004485 /**
4486 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004487 *
4488 * @param subId id of the subscription
4489 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004490 */
4491 @Override
4492 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4494 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004495
4496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
yinxu504e1392017-04-12 16:03:22 -07004502 }
4503
4504 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004505 * Get the calculated preferred network type.
4506 * Used for debugging incorrect network type.
4507 *
4508 * @return the preferred network type, defined in RILConstants.java.
4509 */
4510 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004511 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004512 final Phone defaultPhone = getDefaultPhone();
4513 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4514 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004515 return RILConstants.PREFERRED_NETWORK_MODE;
4516 }
4517
Malcolm Chend965c8b2018-02-28 15:00:40 -08004518 final long identity = Binder.clearCallingIdentity();
4519 try {
4520 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004521 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
Junda Liu84d15a22014-07-02 11:21:04 -07004525 }
4526
4527 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004528 * Get the preferred network type.
4529 * Used for device configuration by some CDMA operators.
4530 *
4531 * @return the preferred network type, defined in RILConstants.java.
4532 */
4533 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004534 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004535 TelephonyPermissions
4536 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4537 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004538
4539 final long identity = Binder.clearCallingIdentity();
4540 try {
4541 if (DBG) log("getPreferredNetworkType");
4542 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4543 int networkType = (result != null ? result[0] : -1);
4544 if (DBG) log("getPreferredNetworkType: " + networkType);
4545 return networkType;
4546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004549 }
4550
4551 /**
4552 * Set the preferred network type.
4553 * Used for device configuration by some CDMA operators.
4554 *
4555 * @param networkType the preferred network type, defined in RILConstants.java.
4556 * @return true on success; false on any failure.
4557 */
4558 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004559 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4561 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004562
4563 final long identity = Binder.clearCallingIdentity();
4564 try {
4565 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4566 Boolean success = (Boolean) sendRequest(
4567 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4568 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4569 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004570 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004571 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4572 }
4573 return success;
4574 } finally {
4575 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004576 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004577 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004578
4579 /**
Miaoa84611c2019-03-15 09:21:10 +08004580 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004581 *
Miaoa84611c2019-03-15 09:21:10 +08004582 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004583 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004584 * @hide
4585 */
4586 @Override
Miaoa84611c2019-03-15 09:21:10 +08004587 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004588 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004589 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004590 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004591 try {
Miaoa84611c2019-03-15 09:21:10 +08004592 if (phone != null) {
4593 return phone.hasMatchedTetherApnSetting();
4594 } else {
4595 return false;
4596 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004597 } finally {
4598 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004599 }
Junda Liu475951f2014-11-07 16:45:03 -08004600 }
4601
4602 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004603 * Set mobile data enabled
4604 * Used by the user through settings etc to turn on/off mobile data
4605 *
4606 * @param enable {@code true} turn turn data on, else {@code false}
4607 */
4608 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004609 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4611 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004612
4613 final long identity = Binder.clearCallingIdentity();
4614 try {
4615 int phoneId = mSubscriptionController.getPhoneId(subId);
4616 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4617 Phone phone = PhoneFactory.getPhone(phoneId);
4618 if (phone != null) {
4619 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004620 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004621 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004622 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004623 }
4624 } finally {
4625 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004626 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004627 }
4628
4629 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004630 * Get the user enabled state of Mobile Data.
4631 *
4632 * TODO: remove and use isUserDataEnabled.
4633 * This can't be removed now because some vendor codes
4634 * calls through ITelephony directly while they should
4635 * use TelephonyManager.
4636 *
4637 * @return true on enabled
4638 */
4639 @Override
4640 public boolean getDataEnabled(int subId) {
4641 return isUserDataEnabled(subId);
4642 }
4643
4644 /**
4645 * Get whether mobile data is enabled per user setting.
4646 *
4647 * There are other factors deciding whether mobile data is actually enabled, but they are
4648 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004649 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004650 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004651 *
4652 * @return {@code true} if data is enabled else {@code false}
4653 */
4654 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004655 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004656 try {
4657 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4658 null);
4659 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4661 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004662 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004663
4664 final long identity = Binder.clearCallingIdentity();
4665 try {
4666 int phoneId = mSubscriptionController.getPhoneId(subId);
4667 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4668 Phone phone = PhoneFactory.getPhone(phoneId);
4669 if (phone != null) {
4670 boolean retVal = phone.isUserDataEnabled();
4671 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4672 return retVal;
4673 } else {
4674 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4675 return false;
4676 }
4677 } finally {
4678 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004679 }
4680 }
4681
4682 /**
4683 * Get whether mobile data is enabled.
4684 *
4685 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4686 * whether mobile data is actually enabled.
4687 *
4688 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4689 *
4690 * @return {@code true} if data is enabled else {@code false}
4691 */
4692 @Override
4693 public boolean isDataEnabled(int subId) {
4694 try {
4695 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4696 null);
4697 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4699 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004700 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004701
4702 final long identity = Binder.clearCallingIdentity();
4703 try {
4704 int phoneId = mSubscriptionController.getPhoneId(subId);
4705 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4706 Phone phone = PhoneFactory.getPhone(phoneId);
4707 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004708 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004709 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4710 return retVal;
4711 } else {
4712 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4713 return false;
4714 }
4715 } finally {
4716 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004717 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004718 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004719
4720 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004721 public int getCarrierPrivilegeStatus(int subId) {
4722 final Phone phone = getPhone(subId);
4723 if (phone == null) {
4724 loge("getCarrierPrivilegeStatus: Invalid subId");
4725 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4726 }
4727 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004728 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004729 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004730 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4731 }
4732 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004733 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004734 }
Junda Liu29340342014-07-10 15:23:27 -07004735
4736 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4738 final Phone phone = getPhone(subId);
4739 if (phone == null) {
4740 loge("getCarrierPrivilegeStatus: Invalid subId");
4741 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4742 }
4743 UiccProfile profile =
4744 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4745 if (profile == null) {
4746 loge("getCarrierPrivilegeStatus: No UICC");
4747 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4748 }
4749 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4750 }
4751
4752 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004753 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004754 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004755 if (TextUtils.isEmpty(pkgName))
4756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004757 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004758 if (card == null) {
4759 loge("checkCarrierPrivilegesForPackage: No UICC");
4760 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4761 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004762 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4763 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004764 }
4765
4766 @Override
4767 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004768 if (TextUtils.isEmpty(pkgName))
4769 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004770 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4771 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4772 UiccCard card = UiccController.getInstance().getUiccCard(i);
4773 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004774 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004775 continue;
4776 }
4777
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004778 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004779 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4780 break;
4781 }
4782 }
4783
4784 return result;
Junda Liu29340342014-07-10 15:23:27 -07004785 }
Derek Tan89e89d42014-07-08 17:00:10 -07004786
4787 @Override
Junda Liue64de782015-04-16 17:19:16 -07004788 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4789 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4790 loge("phoneId " + phoneId + " is not valid.");
4791 return null;
4792 }
4793 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004794 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004795 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004796 return null ;
4797 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004798 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004799 }
4800
Amith Yamasani6e118872016-02-19 12:53:51 -08004801 @Override
4802 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004803 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004804 List<String> privilegedPackages = new ArrayList<>();
4805 List<PackageInfo> packages = null;
4806 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4807 UiccCard card = UiccController.getInstance().getUiccCard(i);
4808 if (card == null) {
4809 // No UICC in that slot.
4810 continue;
4811 }
4812 if (card.hasCarrierPrivilegeRules()) {
4813 if (packages == null) {
4814 // Only check packages in user 0 for now
4815 packages = pm.getInstalledPackagesAsUser(
4816 PackageManager.MATCH_DISABLED_COMPONENTS
4817 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4818 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4819 }
4820 for (int p = packages.size() - 1; p >= 0; p--) {
4821 PackageInfo pkgInfo = packages.get(p);
4822 if (pkgInfo != null && pkgInfo.packageName != null
4823 && card.getCarrierPrivilegeStatus(pkgInfo)
4824 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4825 privilegedPackages.add(pkgInfo.packageName);
4826 }
4827 }
4828 }
4829 }
4830 return privilegedPackages;
4831 }
4832
Wink Savilleb564aae2014-10-23 10:18:09 -07004833 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004834 final Phone phone = getPhone(subId);
4835 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004836 if (card == null) {
4837 loge("getIccId: No UICC");
4838 return null;
4839 }
4840 String iccId = card.getIccId();
4841 if (TextUtils.isEmpty(iccId)) {
4842 loge("getIccId: ICC ID is null or empty.");
4843 return null;
4844 }
4845 return iccId;
4846 }
4847
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004848 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004849 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4850 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004851 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4852 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004853
Malcolm Chend965c8b2018-02-28 15:00:40 -08004854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 final String iccId = getIccId(subId);
4857 final Phone phone = getPhone(subId);
4858 if (phone == null) {
4859 return false;
4860 }
4861 final String subscriberId = phone.getSubscriberId();
4862
4863 if (DBG_MERGE) {
4864 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4865 + subscriberId + " to " + number);
4866 }
4867
4868 if (TextUtils.isEmpty(iccId)) {
4869 return false;
4870 }
4871
4872 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4873
4874 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4875 if (alphaTag == null) {
4876 editor.remove(alphaTagPrefKey);
4877 } else {
4878 editor.putString(alphaTagPrefKey, alphaTag);
4879 }
4880
4881 // Record both the line number and IMSI for this ICCID, since we need to
4882 // track all merged IMSIs based on line number
4883 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4884 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4885 if (number == null) {
4886 editor.remove(numberPrefKey);
4887 editor.remove(subscriberPrefKey);
4888 } else {
4889 editor.putString(numberPrefKey, number);
4890 editor.putString(subscriberPrefKey, subscriberId);
4891 }
4892
4893 editor.commit();
4894 return true;
4895 } finally {
4896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004897 }
Derek Tan7226c842014-07-02 17:42:23 -07004898 }
4899
4900 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004901 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004902 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004904 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004905 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004906 return null;
4907 }
Derek Tan97ebb422014-09-05 16:55:38 -07004908
Malcolm Chend965c8b2018-02-28 15:00:40 -08004909 final long identity = Binder.clearCallingIdentity();
4910 try {
4911 String iccId = getIccId(subId);
4912 if (iccId != null) {
4913 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4914 if (DBG_MERGE) {
4915 log("getLine1NumberForDisplay returning "
4916 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4917 }
4918 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004919 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004920 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4921 return null;
4922 } finally {
4923 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004924 }
Derek Tan7226c842014-07-02 17:42:23 -07004925 }
4926
4927 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004928 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004930 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004931 return null;
4932 }
Derek Tan97ebb422014-09-05 16:55:38 -07004933
Malcolm Chend965c8b2018-02-28 15:00:40 -08004934 final long identity = Binder.clearCallingIdentity();
4935 try {
4936 String iccId = getIccId(subId);
4937 if (iccId != null) {
4938 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4939 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4940 }
4941 return null;
4942 } finally {
4943 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004944 }
Derek Tan7226c842014-07-02 17:42:23 -07004945 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004946
4947 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004948 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004949 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4950 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004952 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4953 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004954 return null;
4955 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004956
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004957 final long identity = Binder.clearCallingIdentity();
4958 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004959 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004960 final TelephonyManager tele = TelephonyManager.from(context);
4961 final SubscriptionManager sub = SubscriptionManager.from(context);
4962
4963 // Figure out what subscribers are currently active
4964 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4965 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4966 // the process, where TelephonyManager was instantiated.
4967 // Otherwise AppOps check will fail.
4968
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004969 final int[] subIds = sub.getActiveSubscriptionIdList();
4970 for (int subId : subIds) {
4971 activeSubscriberIds.add(tele.getSubscriberId(subId));
4972 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004973
4974 // First pass, find a number override for an active subscriber
4975 String mergeNumber = null;
4976 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4977 for (String key : prefs.keySet()) {
4978 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4979 final String subscriberId = (String) prefs.get(key);
4980 if (activeSubscriberIds.contains(subscriberId)) {
4981 final String iccId = key.substring(
4982 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4983 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4984 mergeNumber = (String) prefs.get(numberKey);
4985 if (DBG_MERGE) {
4986 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4987 + " for active subscriber " + subscriberId);
4988 }
4989 if (!TextUtils.isEmpty(mergeNumber)) {
4990 break;
4991 }
4992 }
4993 }
4994 }
4995
4996 // Shortcut when no active merged subscribers
4997 if (TextUtils.isEmpty(mergeNumber)) {
4998 return null;
4999 }
5000
5001 // Second pass, find all subscribers under that line override
5002 final ArraySet<String> result = new ArraySet<>();
5003 for (String key : prefs.keySet()) {
5004 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5005 final String number = (String) prefs.get(key);
5006 if (mergeNumber.equals(number)) {
5007 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5008 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5009 final String subscriberId = (String) prefs.get(subscriberKey);
5010 if (!TextUtils.isEmpty(subscriberId)) {
5011 result.add(subscriberId);
5012 }
5013 }
5014 }
5015 }
5016
5017 final String[] resultArray = result.toArray(new String[result.size()]);
5018 Arrays.sort(resultArray);
5019 if (DBG_MERGE) {
5020 Slog.d(LOG_TAG,
5021 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5022 }
5023 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005026 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005027 }
5028
5029 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005030 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005031 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5032 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005033
5034 final long identity = Binder.clearCallingIdentity();
5035 try {
5036 final Phone phone = getPhone(subId);
5037 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
5040 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005041 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005042
5043 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005044 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005045 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5046 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005047 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005048
5049 final long identity = Binder.clearCallingIdentity();
5050 try {
5051 final Phone phone = getPhone(subId);
5052 if (phone == null) {
5053 return false;
5054 }
5055 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5056 cdmaNonRoamingList);
5057 } finally {
5058 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005059 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005060 }
5061
5062 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005063 @Deprecated
5064 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5065 enforceModifyPermission();
5066
5067 int returnValue = 0;
5068 try {
vagdevie435a3e2018-08-15 16:01:53 -07005069 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005070 if(result.exception == null) {
5071 if (result.result != null) {
5072 byte[] responseData = (byte[])(result.result);
5073 if(responseData.length > oemResp.length) {
5074 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5075 responseData.length + "bytes. Buffer Size is " +
5076 oemResp.length + "bytes.");
5077 }
5078 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5079 returnValue = responseData.length;
5080 }
5081 } else {
5082 CommandException ex = (CommandException) result.exception;
5083 returnValue = ex.getCommandError().ordinal();
5084 if(returnValue > 0) returnValue *= -1;
5085 }
5086 } catch (RuntimeException e) {
5087 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5088 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5089 if(returnValue > 0) returnValue *= -1;
5090 }
5091
5092 return returnValue;
5093 }
5094
5095 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005096 public void setRadioCapability(RadioAccessFamily[] rafs) {
5097 try {
5098 ProxyController.getInstance().setRadioCapability(rafs);
5099 } catch (RuntimeException e) {
5100 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5101 }
5102 }
5103
5104 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005105 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005106 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005107 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005108 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005109 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005110 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005111 final long identity = Binder.clearCallingIdentity();
5112 try {
chen xufeeed752018-10-26 14:17:57 -07005113 TelephonyPermissions
5114 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5115 mApp, phone.getSubId(), "getRadioAccessFamily");
5116 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005117 } finally {
5118 Binder.restoreCallingIdentity(identity);
5119 }
chen xufeeed752018-10-26 14:17:57 -07005120 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005121 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005122
5123 @Override
5124 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005125 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005126 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005127
5128 final long identity = Binder.clearCallingIdentity();
5129 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005130 ImsManager.getInstance(defaultPhone.getContext(),
5131 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005132 } finally {
5133 Binder.restoreCallingIdentity(identity);
5134 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005135 }
5136
5137 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005138 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005139 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005141 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005142 return false;
5143 }
Svet Ganovb320e182015-04-16 12:30:10 -07005144
Malcolm Chend965c8b2018-02-28 15:00:40 -08005145 final long identity = Binder.clearCallingIdentity();
5146 try {
5147 // Check the user preference and the system-level IMS setting. Even if the user has
5148 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5149 // In the long run, we may instead need to check if there exists a connection service
5150 // which can support video calling.
5151 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005152 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005153 return imsManager.isVtEnabledByPlatform()
5154 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5155 && imsManager.isVtEnabledByUser();
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
5158 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005159 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005160
Andrew Leea1239f22015-03-02 17:44:07 -08005161 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005162 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5163 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5164 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5165 return false;
5166 }
5167
5168 final long identity = Binder.clearCallingIdentity();
5169 try {
5170 CarrierConfigManager configManager =
5171 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005172 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005173 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Andrew Leea1239f22015-03-02 17:44:07 -08005177 }
5178
5179 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005180 public boolean isWorldPhone(int subId, String callingPackage) {
5181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5182 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5183 return false;
5184 }
5185
5186 final long identity = Binder.clearCallingIdentity();
5187 try {
5188 CarrierConfigManager configManager =
5189 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005190 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005191 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
Andrew Leea1239f22015-03-02 17:44:07 -08005195 }
5196
Andrew Lee9431b832015-03-09 18:46:45 -07005197 @Override
5198 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005199 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005200 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005201 }
5202
5203 @Override
5204 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005205 final long identity = Binder.clearCallingIdentity();
5206 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005207 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
Andrew Lee9431b832015-03-09 18:46:45 -07005211 }
5212
Hall Liuf6668912018-10-31 17:05:23 -07005213 /**
5214 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5215 * support for the feature and device firmware support.
5216 *
5217 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5218 */
5219 @Override
5220 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005222 final Phone phone = getPhone(subscriptionId);
5223 if (phone == null) {
5224 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5225 return false;
5226 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005227 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005228 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005229 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5230 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005231 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005232 return isCarrierSupported && isDeviceSupported;
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
Hall Liu98187582018-01-22 19:15:32 -08005236 }
5237
Hall Liuf6668912018-10-31 17:05:23 -07005238 /**
5239 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5240 * both also support RTT.
5241 */
5242 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005243 final long identity = Binder.clearCallingIdentity();
5244 try {
Hall Liuf6668912018-10-31 17:05:23 -07005245 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005246 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005250 }
5251
Sanket Padawe7310cc72015-01-14 09:53:20 -08005252 /**
5253 * Returns the unique device ID of phone, for example, the IMEI for
5254 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5255 *
5256 * <p>Requires Permission:
5257 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5258 */
5259 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005260 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005261 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005262 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005263 return null;
5264 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005265 int subId = phone.getSubId();
5266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5267 mApp, subId, callingPackage, "getDeviceId")) {
5268 return null;
5269 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005270
5271 final long identity = Binder.clearCallingIdentity();
5272 try {
5273 return phone.getDeviceId();
5274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005277 }
5278
Ping Sunc67b7c22016-03-02 19:16:45 +08005279 /**
5280 * {@hide}
5281 * Returns the IMS Registration Status on a particular subid
5282 *
5283 * @param subId
5284 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005285 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005286 Phone phone = getPhone(subId);
5287 if (phone != null) {
5288 return phone.isImsRegistered();
5289 } else {
5290 return false;
5291 }
5292 }
5293
Santos Cordon7a1885b2015-02-03 11:15:19 -08005294 @Override
5295 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005296 final long identity = Binder.clearCallingIdentity();
5297 try {
5298 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005302 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005303
Tyler Gunn327a9722019-04-03 15:28:53 -07005304 @Override
5305 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5306 final long identity = Binder.clearCallingIdentity();
5307 try {
5308 Phone phone = getPhone(subscriptionId);
5309 if (phone == null) {
5310 return null;
5311 }
5312 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
5316 }
5317
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005318 /**
5319 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005320 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005321 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005322 final long identity = Binder.clearCallingIdentity();
5323 try {
5324 Phone phone = getPhone(subId);
5325 if (phone != null) {
5326 return phone.isWifiCallingEnabled();
5327 } else {
5328 return false;
5329 }
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005332 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005333 }
5334
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005335 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005336 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005337 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005338 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005339 final long identity = Binder.clearCallingIdentity();
5340 try {
5341 Phone phone = getPhone(subId);
5342 if (phone != null) {
5343 return phone.isVideoEnabled();
5344 } else {
5345 return false;
5346 }
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005349 }
5350 }
5351
5352 /**
5353 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5354 * defined in {@link ImsRegistrationImplBase}.
5355 */
5356 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005357 final long identity = Binder.clearCallingIdentity();
5358 try {
5359 Phone phone = getPhone(subId);
5360 if (phone != null) {
5361 return phone.getImsRegistrationTech();
5362 } else {
5363 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5364 }
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005367 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005368 }
5369
Stuart Scott8eef64f2015-04-08 15:13:54 -07005370 @Override
5371 public void factoryReset(int subId) {
5372 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005373 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5374 return;
5375 }
5376
Svet Ganovcc087f82015-05-12 20:35:54 -07005377 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005378
Svet Ganovcc087f82015-05-12 20:35:54 -07005379 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005380 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5381 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005382 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005383 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005384 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005385 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5386 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005387 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005388 // There has been issues when Sms raw table somehow stores orphan
5389 // fragments. They lead to garbled message when new fragments come
5390 // in and combined with those stale ones. In case this happens again,
5391 // user can reset all network settings which will clean up this table.
5392 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005393 } finally {
5394 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005395 }
5396 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005397
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005398 private void cleanUpSmsRawTable(Context context) {
5399 ContentResolver resolver = context.getContentResolver();
5400 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5401 resolver.delete(uri, null, null);
5402 }
5403
Narayan Kamath1c496c22015-04-16 14:40:19 +01005404 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005405 public String getSimLocaleForSubscriber(int subId) {
5406 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5407 final Phone phone = getPhone(subId);
5408 if (phone == null) {
5409 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005410 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005411 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005412 final long identity = Binder.clearCallingIdentity();
5413 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005414 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5415 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005416 // Try and fetch the locale from the carrier properties or from the SIM language
5417 // preferences (EF-PL and EF-LI)...
5418 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005419 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005420 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5421 if (localeFromDefaultSim != null) {
5422 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5423 if (DBG) log("Using locale from subId: " + subId + " locale: "
5424 + localeFromDefaultSim);
5425 return localeFromDefaultSim.toLanguageTag();
5426 } else {
5427 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005428 }
5429 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005430
Malcolm Chend965c8b2018-02-28 15:00:40 -08005431 // The SIM language preferences only store a language (e.g. fr = French), not an
5432 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5433 // the SIM and carrier preferences does not include a country we add the country
5434 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005435 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005436 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005437 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005438 return mccLocale.toLanguageTag();
5439 }
5440
5441 if (DBG) log("No locale found - returning null");
5442 return null;
5443 } finally {
5444 Binder.restoreCallingIdentity(identity);
5445 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005446 }
5447
5448 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005449 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005450 }
5451
Malcolm Chend965c8b2018-02-28 15:00:40 -08005452 /**
5453 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5454 */
5455 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005456 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005457 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005458
Chenjie Yu1ba97252018-01-11 18:16:20 -08005459 private final ModemActivityInfo mLastModemActivityInfo =
5460 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5461
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005462 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005463 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5464 * representing the state of the modem.
5465 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005466 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5467 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005468 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005469 */
5470 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005471 public void requestModemActivityInfo(ResultReceiver result) {
5472 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005473 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005474
5475 final long identity = Binder.clearCallingIdentity();
5476 try {
5477 ModemActivityInfo ret = null;
5478 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005479 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5480 CMD_GET_MODEM_ACTIVITY_INFO,
5481 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005482 if (isModemActivityInfoValid(info)) {
5483 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5484 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5485 mergedTxTimeMs[i] =
5486 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5487 }
5488 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5489 mLastModemActivityInfo.setSleepTimeMillis(
5490 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5491 mLastModemActivityInfo.setIdleTimeMillis(
5492 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5493 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5494 mLastModemActivityInfo.setRxTimeMillis(
5495 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5496 mLastModemActivityInfo.setEnergyUsed(
5497 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005498 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005499 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5500 mLastModemActivityInfo.getSleepTimeMillis(),
5501 mLastModemActivityInfo.getIdleTimeMillis(),
5502 mLastModemActivityInfo.getTxTimeMillis(),
5503 mLastModemActivityInfo.getRxTimeMillis(),
5504 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005505 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005506 Bundle bundle = new Bundle();
5507 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5508 result.send(0, bundle);
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005511 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005512 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005513
Siddharth Rayf5d29552018-06-17 15:02:38 -07005514 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5515 // less than total activity duration.
5516 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5517 if (info == null) {
5518 return false;
5519 }
5520 int activityDurationMs =
5521 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5522 int totalTxTimeMs = 0;
5523 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5524 totalTxTimeMs += info.getTxTimeMillis()[i];
5525 }
5526 return (info.isValid()
5527 && (info.getSleepTimeMillis() <= activityDurationMs)
5528 && (info.getIdleTimeMillis() <= activityDurationMs)
5529 && (info.getRxTimeMillis() <= activityDurationMs)
5530 && (totalTxTimeMs <= activityDurationMs));
5531 }
5532
Jack Yu85bd38a2015-11-09 11:34:32 -08005533 /**
5534 * {@hide}
5535 * Returns the service state information on specified subscription.
5536 */
5537 @Override
5538 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005540 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005541 return null;
5542 }
5543
Hall Liuf19c44f2018-11-27 14:38:17 -08005544 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5545 LocationAccessPolicy.checkLocationPermission(mApp,
5546 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5547 .setCallingPackage(callingPackage)
5548 .setCallingPid(Binder.getCallingPid())
5549 .setCallingUid(Binder.getCallingUid())
5550 .setMethod("getServiceStateForSubscriber")
5551 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5552 .build());
5553
5554 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5555 LocationAccessPolicy.checkLocationPermission(mApp,
5556 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5557 .setCallingPackage(callingPackage)
5558 .setCallingPid(Binder.getCallingPid())
5559 .setCallingUid(Binder.getCallingUid())
5560 .setMethod("getServiceStateForSubscriber")
5561 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5562 .build());
5563 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5564 boolean hasFinePermission =
5565 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5566 boolean hasCoarsePermission =
5567 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5568
Malcolm Chend965c8b2018-02-28 15:00:40 -08005569 final long identity = Binder.clearCallingIdentity();
5570 try {
5571 final Phone phone = getPhone(subId);
5572 if (phone == null) {
5573 return null;
5574 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005575
Hall Liuf19c44f2018-11-27 14:38:17 -08005576 ServiceState ss = phone.getServiceState();
5577
5578 // Scrub out the location info in ServiceState depending on what level of access
5579 // the caller has.
5580 if (hasFinePermission) return ss;
5581 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5582 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005586 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005587
5588 /**
5589 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5590 *
5591 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5592 * voicemail ringtone.
5593 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5594 * PhoneAccount.
5595 */
5596 @Override
5597 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5601 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005602 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005603 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005604
Malcolm Chend965c8b2018-02-28 15:00:40 -08005605 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005609 }
5610
5611 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005612 * Sets the per-account voicemail ringtone.
5613 *
5614 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5615 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5616 *
5617 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5618 * voicemail ringtone.
5619 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5620 * PhoneAccount.
5621 */
5622 @Override
5623 public void setVoicemailRingtoneUri(String callingPackage,
5624 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005625 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005626 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5627 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005628 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5630 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5631 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005632 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005633
5634 final long identity = Binder.clearCallingIdentity();
5635 try {
5636 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5637 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005638 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005639 }
5640 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005643 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005644 }
5645
5646 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005647 * Returns whether vibration is set for voicemail notification in Phone settings.
5648 *
5649 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5650 * voicemail vibration setting.
5651 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5652 */
5653 @Override
5654 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005655 final long identity = Binder.clearCallingIdentity();
5656 try {
5657 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5658 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005659 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005660 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005661
Malcolm Chend965c8b2018-02-28 15:00:40 -08005662 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005666 }
5667
Youhan Wange64578a2016-05-02 15:32:42 -07005668 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005669 * Sets the per-account voicemail vibration.
5670 *
5671 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5672 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5673 *
5674 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5675 * voicemail vibration setting.
5676 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5677 * specific PhoneAccount.
5678 */
5679 @Override
5680 public void setVoicemailVibrationEnabled(String callingPackage,
5681 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005682 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5684 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005685 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5687 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5688 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005689 }
5690
Malcolm Chend965c8b2018-02-28 15:00:40 -08005691 final long identity = Binder.clearCallingIdentity();
5692 try {
5693 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5694 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005695 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005696 }
5697 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005700 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005701 }
5702
5703 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005704 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5705 *
5706 * @throws SecurityException if the caller does not have the required permission
5707 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005708 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005709 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005710 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005711 }
5712
5713 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005714 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5715 * permission.
5716 *
5717 * @throws SecurityException if the caller does not have the required permission
5718 */
5719 private void enforceSendSmsPermission() {
5720 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5721 }
5722
5723 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005724 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005725 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005726 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005727 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005728 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005729 final long identity = Binder.clearCallingIdentity();
5730 try {
5731 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005732 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005733 if (componentName == null) {
5734 throw new SecurityException(
5735 "Caller not current active visual voicemail package[null]");
5736 }
5737 String vvmPackage = componentName.getPackageName();
5738 if (!callingPackage.equals(vvmPackage)) {
5739 throw new SecurityException("Caller not current active visual voicemail package["
5740 + vvmPackage + "]");
5741 }
5742 } finally {
5743 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005744 }
5745 }
5746
5747 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005748 * Return the application ID for the app type.
5749 *
5750 * @param subId the subscription ID that this request applies to.
5751 * @param appType the uicc app type.
5752 * @return Application ID for specificied app type, or null if no uicc.
5753 */
5754 @Override
5755 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005756 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005757 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005758
5759 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005760 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005761 if (phone == null) {
5762 return null;
5763 }
5764 String aid = null;
5765 try {
5766 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5767 .getApplicationByType(appType).getAid();
5768 } catch (Exception e) {
5769 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5770 }
5771 return aid;
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005774 }
Youhan Wange64578a2016-05-02 15:32:42 -07005775 }
5776
Youhan Wang4001d252016-05-11 10:29:41 -07005777 /**
5778 * Return the Electronic Serial Number.
5779 *
5780 * @param subId the subscription ID that this request applies to.
5781 * @return ESN or null if error.
5782 */
5783 @Override
5784 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005785 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005786 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005787
5788 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005789 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005790 if (phone == null) {
5791 return null;
5792 }
5793 String esn = null;
5794 try {
5795 esn = phone.getEsn();
5796 } catch (Exception e) {
5797 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5798 }
5799 return esn;
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005802 }
Youhan Wang4001d252016-05-11 10:29:41 -07005803 }
5804
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005805 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005806 * Return the Preferred Roaming List Version.
5807 *
5808 * @param subId the subscription ID that this request applies to.
5809 * @return PRLVersion or null if error.
5810 */
5811 @Override
5812 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005813 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005814 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005815
5816 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005817 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005818 if (phone == null) {
5819 return null;
5820 }
5821 String cdmaPrlVersion = null;
5822 try {
5823 cdmaPrlVersion = phone.getCdmaPrlVersion();
5824 } catch (Exception e) {
5825 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5826 }
5827 return cdmaPrlVersion;
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005830 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005831 }
5832
5833 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005834 * Get snapshot of Telephony histograms
5835 * @return List of Telephony histograms
5836 * @hide
5837 */
5838 @Override
5839 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5841 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005842
5843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 return RIL.getTelephonyRILTimingHistograms();
5846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005849 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005850
5851 /**
5852 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005853 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5854 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005855 * Require system privileges. In the future we may add this to carrier APIs.
5856 *
Michele Berionne0963c862018-11-27 18:57:59 -08005857 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005858 */
5859 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005860 @TelephonyManager.SetCarrierRestrictionResult
5861 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005862 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005863 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005864
Michele Berionne0963c862018-11-27 18:57:59 -08005865 if (carrierRestrictionRules == null) {
5866 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005867 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005868
Malcolm Chend965c8b2018-02-28 15:00:40 -08005869 final long identity = Binder.clearCallingIdentity();
5870 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005871 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005872 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005873 } finally {
5874 Binder.restoreCallingIdentity(identity);
5875 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005876 }
5877
5878 /**
5879 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005880 * Get the allowed carrier list and the excluded carrier list, including the priority between
5881 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005882 * Require system privileges. In the future we may add this to carrier APIs.
5883 *
Michele Berionne0963c862018-11-27 18:57:59 -08005884 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005885 */
5886 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005887 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005888 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005890
5891 final long identity = Binder.clearCallingIdentity();
5892 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005893 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5894 if (response instanceof CarrierRestrictionRules) {
5895 return (CarrierRestrictionRules) response;
5896 }
5897 // Response is an Exception of some kind,
5898 // which is signalled to the user as a NULL retval
5899 return null;
5900 } catch (Exception e) {
5901 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5902 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005906 }
5907
fionaxu59545b42016-05-25 15:53:37 -07005908 /**
5909 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5910 * @param subId the subscription ID that this action applies to.
5911 * @param enabled control enable or disable metered apns.
5912 * {@hide}
5913 */
5914 @Override
5915 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5916 enforceModifyPermission();
5917 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005918
5919 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005920 if (phone == null) {
5921 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5922 return;
5923 }
5924 try {
5925 phone.carrierActionSetMeteredApnsEnabled(enabled);
5926 } catch (Exception e) {
5927 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005928 } finally {
5929 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005930 }
5931 }
5932
5933 /**
5934 * Action set from carrier signalling broadcast receivers to enable/disable radio
5935 * @param subId the subscription ID that this action applies to.
5936 * @param enabled control enable or disable radio.
5937 * {@hide}
5938 */
5939 @Override
5940 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5941 enforceModifyPermission();
5942 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005943
5944 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005945 if (phone == null) {
5946 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5947 return;
5948 }
5949 try {
5950 phone.carrierActionSetRadioEnabled(enabled);
5951 } catch (Exception e) {
5952 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005953 } finally {
5954 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005955 }
5956 }
5957
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005958 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005959 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5960 * network status based on which carrier apps could apply actions accordingly,
5961 * enable/disable default url handler for example.
5962 *
5963 * @param subId the subscription ID that this action applies to.
5964 * @param report control start/stop reporting the default network status.
5965 * {@hide}
5966 */
5967 @Override
5968 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5969 enforceModifyPermission();
5970 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005971
5972 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005973 if (phone == null) {
5974 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5975 return;
5976 }
5977 try {
5978 phone.carrierActionReportDefaultNetworkStatus(report);
5979 } catch (Exception e) {
5980 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005981 } finally {
5982 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005983 }
5984 }
5985
5986 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005987 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5988 * bug report is being generated.
5989 */
5990 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005991 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005992 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5993 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005994 writer.println("Permission Denial: can't dump Phone from pid="
5995 + Binder.getCallingPid()
5996 + ", uid=" + Binder.getCallingUid()
5997 + "without permission "
5998 + android.Manifest.permission.DUMP);
5999 return;
6000 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006001 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006002 }
Jack Yueb89b242016-06-22 13:27:47 -07006003
Brad Ebingerdac2f002018-04-03 15:17:52 -07006004 @Override
6005 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6006 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6007 throws RemoteException {
6008 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6009 }
6010
Jack Yueb89b242016-06-22 13:27:47 -07006011 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006012 * Get aggregated video call data usage since boot.
6013 *
6014 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6015 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006016 * {@hide}
6017 */
6018 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006019 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006020 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6021 null);
6022
Malcolm Chend965c8b2018-02-28 15:00:40 -08006023 final long identity = Binder.clearCallingIdentity();
6024 try {
6025 // NetworkStatsService keeps tracking the active network interface and identity. It
6026 // records the delta with the corresponding network identity.
6027 // We just return the total video call data usage snapshot since boot.
6028 Phone phone = getPhone(subId);
6029 if (phone != null) {
6030 return phone.getVtDataUsage(perUidStats);
6031 }
6032 return null;
6033 } finally {
6034 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006035 }
Jack Yueb89b242016-06-22 13:27:47 -07006036 }
Jack Yu75ab2952016-07-08 14:29:33 -07006037
6038 /**
6039 * Policy control of data connection. Usually used when data limit is passed.
6040 * @param enabled True if enabling the data, otherwise disabling.
6041 * @param subId Subscription index
6042 * {@hide}
6043 */
6044 @Override
6045 public void setPolicyDataEnabled(boolean enabled, int subId) {
6046 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006047
6048 final long identity = Binder.clearCallingIdentity();
6049 try {
6050 Phone phone = getPhone(subId);
6051 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006052 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006053 }
6054 } finally {
6055 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006056 }
6057 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006058
6059 /**
6060 * Get Client request stats
6061 * @return List of Client Request Stats
6062 * @hide
6063 */
6064 @Override
6065 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006067 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006068 return null;
6069 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006070 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006071
Malcolm Chend965c8b2018-02-28 15:00:40 -08006072 final long identity = Binder.clearCallingIdentity();
6073 try {
6074 if (phone != null) {
6075 return phone.getClientRequestStats();
6076 }
6077
6078 return null;
6079 } finally {
6080 Binder.restoreCallingIdentity(identity);
6081 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006082 }
6083
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006084 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006085 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006086 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006087 }
Jack Yueb4124c2017-02-16 15:32:43 -08006088
6089 /**
Grace Chen70990072017-03-24 17:21:30 -07006090 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006091 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006092 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006093 * @param state State of SIM (power down, power up, pass through)
6094 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6095 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6096 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006097 *
6098 **/
6099 @Override
Grace Chen70990072017-03-24 17:21:30 -07006100 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006101 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006102 Phone phone = PhoneFactory.getPhone(slotIndex);
6103
vagdevie435a3e2018-08-15 16:01:53 -07006104 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6105
Malcolm Chend965c8b2018-02-28 15:00:40 -08006106 final long identity = Binder.clearCallingIdentity();
6107 try {
6108 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006109 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006110 }
6111 } finally {
6112 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006113 }
6114 }
Shuo Qiandd210312017-04-12 22:11:33 +00006115
Tyler Gunn65d45c22017-06-05 11:22:26 -07006116 private boolean isUssdApiAllowed(int subId) {
6117 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006118 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006119 if (configManager == null) {
6120 return false;
6121 }
6122 PersistableBundle pb = configManager.getConfigForSubId(subId);
6123 if (pb == null) {
6124 return false;
6125 }
6126 return pb.getBoolean(
6127 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6128 }
6129
Shuo Qiandd210312017-04-12 22:11:33 +00006130 /**
6131 * Check if phone is in emergency callback mode
6132 * @return true if phone is in emergency callback mode
6133 * @param subId sub id
6134 */
goneil9c5f4872017-12-05 14:07:56 -08006135 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006136 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006137 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006138 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006139
6140 final long identity = Binder.clearCallingIdentity();
6141 try {
6142 if (phone != null) {
6143 return phone.isInEcm();
6144 } else {
6145 return false;
6146 }
6147 } finally {
6148 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006149 }
6150 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006151
6152 /**
6153 * Get the current signal strength information for the given subscription.
6154 * Because this information is not updated when the device is in a low power state
6155 * it should not be relied-upon to be current.
6156 * @param subId Subscription index
6157 * @return the most recent cached signal strength info from the modem
6158 */
6159 @Override
6160 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006161 final long identity = Binder.clearCallingIdentity();
6162 try {
6163 Phone p = getPhone(subId);
6164 if (p == null) {
6165 return null;
6166 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006167
Malcolm Chend965c8b2018-02-28 15:00:40 -08006168 return p.getSignalStrength();
6169 } finally {
6170 Binder.restoreCallingIdentity(identity);
6171 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006172 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006173
Pengquan Meng9140aec2018-08-22 14:49:57 -07006174 /**
chen xu907e5a22018-10-11 13:21:04 -07006175 * Get the current modem radio state for the given slot.
6176 * @param slotIndex slot index.
6177 * @param callingPackage the name of the package making the call.
6178 * @return the current radio power state from the modem
6179 */
6180 @Override
6181 public int getRadioPowerState(int slotIndex, String callingPackage) {
6182 Phone phone = PhoneFactory.getPhone(slotIndex);
6183 if (phone != null) {
6184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6185 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6186 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6187 }
6188
6189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 return phone.getRadioPowerState();
6192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
6195 }
6196 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6197 }
6198
6199 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006200 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6201 *
6202 * <p>Requires one of the following permissions:
6203 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6204 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6205 * privileges.
6206 *
6207 * @param subId subscription id
6208 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6209 * {@code false}.
6210 */
6211 @Override
6212 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006213 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6214 null /* message */);
6215
Pengquan Meng0c05b502018-09-06 09:59:22 -07006216 boolean isEnabled = false;
6217 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006218 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006219 Phone phone = getPhone(subId);
6220 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006221 } catch (Exception e) {
6222 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6223 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006224 } finally {
6225 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006226 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006227 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006228 }
6229
6230
6231 /**
6232 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6233 *
6234 * <p> Requires permission:
6235 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6236 * privileges.
6237 *
6238 * @param subId subscription id
6239 * @param isEnabled {@code true} means enable, {@code false} means disable.
6240 */
6241 @Override
6242 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6244 mApp, subId, "setDataRoamingEnabled");
6245
Pengquan Meng0c05b502018-09-06 09:59:22 -07006246 final long identity = Binder.clearCallingIdentity();
6247 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006248 Phone phone = getPhone(subId);
6249 if (phone != null) {
6250 phone.setDataRoamingEnabled(isEnabled);
6251 }
6252 } finally {
6253 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006254 }
6255 }
6256
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006257 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006258 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006259 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6260 mApp, subId, "isManualNetworkSelectionAllowed");
6261
Pengquan Meng312de0c2018-10-03 12:19:13 -07006262 boolean isAllowed = true;
6263 final long identity = Binder.clearCallingIdentity();
6264 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006265 Phone phone = getPhone(subId);
6266 if (phone != null) {
6267 isAllowed = phone.isCspPlmnEnabled();
6268 }
6269 } finally {
6270 Binder.restoreCallingIdentity(identity);
6271 }
6272 return isAllowed;
6273 }
6274
6275 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006276 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006277 try {
6278 enforceReadPrivilegedPermission("getUiccCardsInfo");
6279 } catch (SecurityException e) {
6280 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6281 // has carrier privileges on an active UICC
6282 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6283 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6284 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6285 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006286 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006287
6288 final long identity = Binder.clearCallingIdentity();
6289 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006290 UiccController uiccController = UiccController.getInstance();
6291 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6292
6293 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6294 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6295 // Remove private info if the caller doesn't have access
6296 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6297 for (UiccCardInfo cardInfo : cardInfos) {
6298 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6299 UiccProfile profile = card.getUiccProfile();
6300 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6301 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6302 filteredInfos.add(cardInfo.getUnprivileged());
6303 } else {
6304 filteredInfos.add(cardInfo);
6305 }
6306 }
6307 return filteredInfos;
6308 }
6309 return cardInfos;
6310 } catch (PackageManager.NameNotFoundException e) {
6311 // This should not happen since we pass the package info in from TelephonyManager
6312 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006313 } finally {
6314 Binder.restoreCallingIdentity(identity);
6315 }
6316 }
6317
6318 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006319 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006320 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006321
Malcolm Chend965c8b2018-02-28 15:00:40 -08006322 final long identity = Binder.clearCallingIdentity();
6323 try {
6324 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6325 if (slots == null) {
6326 Rlog.i(LOG_TAG, "slots is null.");
6327 return null;
6328 }
6329
6330 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6331 for (int i = 0; i < slots.length; i++) {
6332 UiccSlot slot = slots[i];
6333 if (slot == null) {
6334 continue;
6335 }
6336
6337 String cardId;
6338 UiccCard card = slot.getUiccCard();
6339 if (card != null) {
6340 cardId = card.getCardId();
6341 } else {
6342 cardId = slot.getIccId();
6343 }
6344
6345 int cardState = 0;
6346 switch (slot.getCardState()) {
6347 case CARDSTATE_ABSENT:
6348 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6349 break;
6350 case CARDSTATE_PRESENT:
6351 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6352 break;
6353 case CARDSTATE_ERROR:
6354 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6355 break;
6356 case CARDSTATE_RESTRICTED:
6357 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6358 break;
6359 default:
6360 break;
6361
6362 }
6363
6364 infos[i] = new UiccSlotInfo(
6365 slot.isActive(),
6366 slot.isEuicc(),
6367 cardId,
6368 cardState,
6369 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006370 slot.isExtendedApduSupported(),
6371 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006372 }
6373 return infos;
6374 } finally {
6375 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006376 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006377 }
6378
6379 @Override
6380 public boolean switchSlots(int[] physicalSlots) {
6381 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006382
6383 final long identity = Binder.clearCallingIdentity();
6384 try {
6385 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6386 } finally {
6387 Binder.restoreCallingIdentity(identity);
6388 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006389 }
Jack Yu4c988042018-02-27 15:30:01 -08006390
6391 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006392 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006393 final long identity = Binder.clearCallingIdentity();
6394 try {
6395 return UiccController.getInstance().getCardIdForDefaultEuicc();
6396 } finally {
6397 Binder.restoreCallingIdentity(identity);
6398 }
6399 }
6400
6401 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006402 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6403 enforceModifyPermission();
6404 final Phone phone = getPhone(subId);
6405 if (phone == null) {
6406 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6407 return;
6408 }
6409
Malcolm Chend965c8b2018-02-28 15:00:40 -08006410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 phone.setRadioIndicationUpdateMode(filters, mode);
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
Jack Yu4c988042018-02-27 15:30:01 -08006416 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006417
6418 /**
goneil47ffb6e2018-04-06 15:40:58 -07006419 * A test API to reload the UICC profile.
6420 *
6421 * <p>Requires that the calling app has permission
6422 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6423 * @hide
6424 */
6425 @Override
6426 public void refreshUiccProfile(int subId) {
6427 enforceModifyPermission();
6428
6429 final long identity = Binder.clearCallingIdentity();
6430 try {
6431 Phone phone = getPhone(subId);
6432 if (phone == null) {
6433 return;
6434 }
6435 UiccCard uiccCard = phone.getUiccCard();
6436 if (uiccCard == null) {
6437 return;
6438 }
6439 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6440 if (uiccProfile == null) {
6441 return;
6442 }
6443 uiccProfile.refresh();
6444 } finally {
6445 Binder.restoreCallingIdentity(identity);
6446 }
6447 }
6448
6449 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006450 * Returns false if the mobile data is disabled by default, otherwise return true.
6451 */
6452 private boolean getDefaultDataEnabled() {
6453 return "true".equalsIgnoreCase(
6454 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6455 }
6456
6457 /**
6458 * Returns true if the data roaming is enabled by default, i.e the system property
6459 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6460 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6461 */
6462 private boolean getDefaultDataRoamingEnabled(int subId) {
6463 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006464 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006465 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6466 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6467 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6468 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6469 return isDataRoamingEnabled;
6470 }
6471
6472 /**
6473 * Returns the default network type for the given {@code subId}, if the default network type is
6474 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6475 */
6476 private int getDefaultNetworkType(int subId) {
6477 return Integer.parseInt(
6478 TelephonyManager.getTelephonyProperty(
6479 mSubscriptionController.getPhoneId(subId),
6480 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6481 String.valueOf(Phone.PREFERRED_NT_MODE)));
6482 }
fionaxua13278b2018-03-21 00:08:13 -07006483
6484 @Override
6485 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6486 gid1, String gid2, String plmn, String spn) {
6487 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006488
6489 final long identity = Binder.clearCallingIdentity();
6490 try {
6491 final Phone phone = getPhone(subId);
6492 if (phone == null) {
6493 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6494 return;
6495 }
6496 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006499 }
fionaxua13278b2018-03-21 00:08:13 -07006500 }
6501
6502 @Override
6503 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006504 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006505
6506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 final Phone phone = getPhone(subId);
6509 if (phone == null) {
6510 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6511 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6512 }
6513 return phone.getCarrierIdListVersion();
6514 } finally {
6515 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006516 }
fionaxua13278b2018-03-21 00:08:13 -07006517 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006518
6519 @Override
6520 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6521 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6522 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6523 return -1;
6524 }
6525
6526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
6532 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006533
6534 @Override
6535 public int getCdmaRoamingMode(int subId) {
6536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6537 mApp, subId, "getCdmaRoamingMode");
6538
6539 final long identity = Binder.clearCallingIdentity();
6540 try {
6541 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6542 } finally {
6543 Binder.restoreCallingIdentity(identity);
6544 }
6545 }
6546
6547 @Override
6548 public boolean setCdmaRoamingMode(int subId, int mode) {
6549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6550 mApp, subId, "setCdmaRoamingMode");
6551
6552 final long identity = Binder.clearCallingIdentity();
6553 try {
6554 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6555 } finally {
6556 Binder.restoreCallingIdentity(identity);
6557 }
6558 }
6559
6560 @Override
6561 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6563 mApp, subId, "setCdmaSubscriptionMode");
6564
6565 final long identity = Binder.clearCallingIdentity();
6566 try {
6567 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
6571 }
chen xu7ee67862018-10-30 22:27:10 -07006572
sqian2fff4a32018-11-05 14:18:37 -08006573 private void ensureUserRunning(int userId) {
6574 if (!mUserManager.isUserRunning(userId)) {
6575 throw new IllegalStateException("User " + userId + " does not exist or not running");
6576 }
6577 }
6578
6579 /**
6580 * Returns a list of SMS apps on a given user.
6581 *
6582 * Only the shell user (UID 2000 or 0) can call it.
6583 * Target user must be running.
6584 */
6585 @Override
6586 public String[] getSmsApps(int userId) {
6587 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6588 ensureUserRunning(userId);
6589
6590 final Collection<SmsApplicationData> apps =
6591 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6592
6593 String[] ret = new String[apps.size()];
6594 int i = 0;
6595 for (SmsApplicationData app : apps) {
6596 ret[i++] = app.mPackageName;
6597 }
6598 return ret;
6599 }
6600
6601 /**
6602 * Returns the default SMS app package name on a given user.
6603 *
6604 * Only the shell user (UID 2000 or 0) can call it.
6605 * Target user must be running.
6606 */
6607 @Override
6608 public String getDefaultSmsApp(int userId) {
6609 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6610 ensureUserRunning(userId);
6611
6612 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6613 /* updateIfNeeded= */ true, userId);
6614 return cn == null ? null : cn.getPackageName();
6615 }
6616
6617 /**
6618 * Set a package as the default SMS app on a given user.
6619 *
6620 * Only the shell user (UID 2000 or 0) can call it.
6621 * Target user must be running.
6622 */
6623 @Override
6624 public void setDefaultSmsApp(int userId, String packageName) {
6625 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6626 ensureUserRunning(userId);
6627
6628 boolean found = false;
6629 for (String pkg : getSmsApps(userId)) {
6630 if (TextUtils.equals(packageName, pkg)) {
6631 found = true;
6632 break;
6633 }
6634 }
6635 if (!found) {
6636 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6637 }
6638
6639 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6640 }
6641
chen xu7ee67862018-10-30 22:27:10 -07006642 @Override
sqian65eefe12019-02-22 15:55:18 -08006643 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006644 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006646 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006647 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6648 }
6649 final long identity = Binder.clearCallingIdentity();
6650 try {
sqian991b35e2018-12-12 16:48:18 -08006651 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6652 for (Phone phone: PhoneFactory.getPhones()) {
6653 if (phone.getEmergencyNumberTracker() != null
6654 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6655 emergencyNumberListInternal.put(
6656 phone.getSubId(),
6657 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6658 }
sqian03bca152018-12-05 18:48:28 -08006659 }
sqian991b35e2018-12-12 16:48:18 -08006660 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006661 } finally {
6662 Binder.restoreCallingIdentity(identity);
6663 }
sqian04b86072018-11-07 14:02:21 -08006664 }
6665
6666 @Override
sqian65eefe12019-02-22 15:55:18 -08006667 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006668 final Phone defaultPhone = getDefaultPhone();
6669 if (!exactMatch) {
6670 TelephonyPermissions
6671 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006672 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006673 }
6674 final long identity = Binder.clearCallingIdentity();
6675 try {
sqian991b35e2018-12-12 16:48:18 -08006676 for (Phone phone: PhoneFactory.getPhones()) {
6677 if (phone.getEmergencyNumberTracker() != null
6678 && phone.getEmergencyNumberTracker() != null) {
6679 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6680 number, exactMatch)) {
6681 return true;
sqian03bca152018-12-05 18:48:28 -08006682 }
6683 }
sqian03bca152018-12-05 18:48:28 -08006684 }
6685 return false;
6686 } finally {
6687 Binder.restoreCallingIdentity(identity);
6688 }
6689 }
6690
sqian9d4df8b2019-01-15 18:32:07 -08006691 /**
6692 * Update emergency number list for test mode.
6693 */
6694 @Override
6695 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6696 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6697 "updateEmergencyNumberListTestMode");
6698
6699 final long identity = Binder.clearCallingIdentity();
6700 try {
6701 for (Phone phone: PhoneFactory.getPhones()) {
6702 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6703 if (tracker != null) {
6704 tracker.executeEmergencyNumberTestModeCommand(action, num);
6705 }
6706 }
6707 } finally {
6708 Binder.restoreCallingIdentity(identity);
6709 }
6710 }
6711
6712 /**
6713 * Get the full emergency number list for test mode.
6714 */
6715 @Override
6716 public List<String> getEmergencyNumberListTestMode() {
6717 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6718 "getEmergencyNumberListTestMode");
6719
6720 final long identity = Binder.clearCallingIdentity();
6721 try {
6722 Set<String> emergencyNumbers = new HashSet<>();
6723 for (Phone phone: PhoneFactory.getPhones()) {
6724 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6725 if (tracker != null) {
6726 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6727 emergencyNumbers.add(num.getNumber());
6728 }
6729 }
6730 }
6731 return new ArrayList<>(emergencyNumbers);
6732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734 }
6735 }
6736
sqian04b86072018-11-07 14:02:21 -08006737 @Override
chen xu7ee67862018-10-30 22:27:10 -07006738 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6739 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6740 Phone phone = getPhone(subId);
6741 if (phone == null) {
6742 return null;
6743 }
6744 final long identity = Binder.clearCallingIdentity();
6745 try {
6746 UiccProfile profile = UiccController.getInstance()
6747 .getUiccProfileForPhone(phone.getPhoneId());
6748 if (profile != null) {
6749 return profile.getCertsFromCarrierPrivilegeAccessRules();
6750 }
6751 } finally {
6752 Binder.restoreCallingIdentity(identity);
6753 }
6754 return null;
6755 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006756
6757 /**
6758 * Enable or disable a modem stack.
6759 */
6760 @Override
6761 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6762 enforceModifyPermission();
6763
6764 final long identity = Binder.clearCallingIdentity();
6765 try {
6766 Phone phone = PhoneFactory.getPhone(slotIndex);
6767 if (phone == null) {
6768 return false;
6769 } else {
6770 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6771 }
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
6774 }
6775 }
Micheled3107c52018-12-21 15:00:11 -08006776
Malcolm Chen33f55e12019-03-27 18:34:05 -07006777 /**
6778 * Whether a modem stack is enabled or not.
6779 */
6780 @Override
6781 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6782 Phone phone = PhoneFactory.getPhone(slotIndex);
6783 if (phone == null) return false;
6784
6785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6786 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6787 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6788 }
6789
6790 final long identity = Binder.clearCallingIdentity();
6791 try {
6792 return PhoneConfigurationManager.getInstance().getPhoneStatus(phone);
6793 } finally {
6794 Binder.restoreCallingIdentity(identity);
6795 }
6796 }
6797
Micheled3107c52018-12-21 15:00:11 -08006798 @Override
Michele2fb0f222019-03-19 14:58:42 -07006799 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006800 enforceModifyPermission();
6801
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
6804 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006805 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006806 .commit();
6807 } finally {
6808 Binder.restoreCallingIdentity(identity);
6809 }
6810 }
6811
6812 @Override
Michele2fb0f222019-03-19 14:58:42 -07006813 @TelephonyManager.IsMultiSimSupportedResult
6814 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006815 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006816 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6817 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006818 }
Micheled3107c52018-12-21 15:00:11 -08006819
6820 final long identity = Binder.clearCallingIdentity();
6821 try {
Michele2fb0f222019-03-19 14:58:42 -07006822 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006823 } finally {
6824 Binder.restoreCallingIdentity(identity);
6825 }
6826 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006827
Michele2fb0f222019-03-19 14:58:42 -07006828 @TelephonyManager.IsMultiSimSupportedResult
6829 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006830 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6831 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6832 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006833 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6834 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006835 }
6836 // Check if the hardware supports multisim functionality. If usage of multisim is not
6837 // supported by the modem, indicate that it is restricted.
6838 PhoneCapability staticCapability =
6839 mPhoneConfigurationManager.getStaticPhoneCapability();
6840 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006841 loge("isMultiSimSupportedInternal: no static configuration available");
6842 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006843 }
6844 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006845 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6846 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006847 }
6848 // Check if support of multiple SIMs is restricted by carrier
6849 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006850 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006851 }
6852
Michele2fb0f222019-03-19 14:58:42 -07006853 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006854 }
6855
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006856 /**
6857 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006858 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6859 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6860 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006861 * @param numOfSims number of active sims we want to switch to
6862 */
6863 @Override
6864 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006865 if (numOfSims == 1) {
6866 enforceModifyPermission();
6867 } else {
6868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6869 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6870 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006871 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006872
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006873 try {
Michele30b57b22019-03-01 12:01:14 -08006874 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006875 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006876 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6877 return;
6878 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006879 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6880 } finally {
6881 Binder.restoreCallingIdentity(identity);
6882 }
6883 }
6884
6885 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006886 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006887 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006888 */
6889 @Override
6890 public boolean isRebootRequiredForModemConfigChange() {
6891 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6892 final long identity = Binder.clearCallingIdentity();
6893 try {
6894 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6895 } finally {
6896 Binder.restoreCallingIdentity(identity);
6897 }
6898 }
6899
Pengquan Meng92d253b2019-02-06 11:12:53 -08006900 private void updateModemStateMetrics() {
6901 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6902 // TODO: check the state for each modem if the api is ready.
6903 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6904 }
6905
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006906 @Override
6907 public int[] getSlotsMapping() {
6908 enforceReadPrivilegedPermission("getSlotsMapping");
6909
6910 final long identity = Binder.clearCallingIdentity();
6911 try {
6912 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6913 // All logical slots should have a mapping to a physical slot.
6914 int[] logicalSlotsMapping = new int[phoneCount];
6915 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6916 for (int i = 0; i < slotInfos.length; i++) {
6917 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6918 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6919 }
6920 }
6921 return logicalSlotsMapping;
6922 } finally {
6923 Binder.restoreCallingIdentity(identity);
6924 }
6925 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006926
6927 /**
6928 * Get the IRadio HAL Version
6929 */
6930 @Override
6931 public int getRadioHalVersion() {
6932 Phone phone = getDefaultPhone();
6933 if (phone == null) return -1;
6934 HalVersion hv = phone.getHalVersion();
6935 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6936 return hv.major * 100 + hv.minor;
6937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006938}