blob: cbda21b8d0de2ed9c221c09edff1c0132bb9171a [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);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800838 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 break;
840
841 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
842 ar = (AsyncResult) msg.obj;
843 request = (MainThreadRequest) ar.userObj;
844 if (ar.exception == null && ar.result != null) {
845 request.result = ar.result;
846 } else {
847 if (ar.result == null) {
848 loge("queryModemActivityInfo: Empty response");
849 } else if (ar.exception instanceof CommandException) {
850 loge("queryModemActivityInfo: CommandException: " +
851 ar.exception);
852 } else {
853 loge("queryModemActivityInfo: Unknown exception");
854 }
855 }
Amit Mahajand4766222016-01-28 15:28:28 -0800856 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
857 if (request.result == null) {
858 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
859 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700860 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700861 break;
862
Meng Wang1a7c35a2016-05-05 20:56:15 -0700863 case CMD_SET_ALLOWED_CARRIERS:
864 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800865 CarrierRestrictionRules argument =
866 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700867 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800868 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 break;
870
871 case EVENT_SET_ALLOWED_CARRIERS_DONE:
872 ar = (AsyncResult) msg.obj;
873 request = (MainThreadRequest) ar.userObj;
874 if (ar.exception == null && ar.result != null) {
875 request.result = ar.result;
876 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800877 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
878 if (ar.exception instanceof CommandException) {
879 loge("setAllowedCarriers: CommandException: " + ar.exception);
880 CommandException.Error error =
881 ((CommandException) (ar.exception)).getCommandError();
882 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
883 request.result =
884 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
885 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 } else {
887 loge("setAllowedCarriers: Unknown exception");
888 }
889 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700890 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 break;
892
893 case CMD_GET_ALLOWED_CARRIERS:
894 request = (MainThreadRequest) msg.obj;
895 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800896 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 break;
898
899 case EVENT_GET_ALLOWED_CARRIERS_DONE:
900 ar = (AsyncResult) msg.obj;
901 request = (MainThreadRequest) ar.userObj;
902 if (ar.exception == null && ar.result != null) {
903 request.result = ar.result;
904 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800905 request.result = new IllegalStateException(
906 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 if (ar.result == null) {
908 loge("getAllowedCarriers: Empty response");
909 } else if (ar.exception instanceof CommandException) {
910 loge("getAllowedCarriers: CommandException: " +
911 ar.exception);
912 } else {
913 loge("getAllowedCarriers: Unknown exception");
914 }
915 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700916 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 break;
918
Nathan Haroldb3014052017-01-25 15:57:32 -0800919 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
920 ar = (AsyncResult) msg.obj;
921 request = (MainThreadRequest) ar.userObj;
922 if (ar.exception == null && ar.result != null) {
923 request.result = ar.result;
924 } else {
925 request.result = new IllegalArgumentException(
926 "Failed to retrieve Forbidden Plmns");
927 if (ar.result == null) {
928 loge("getForbiddenPlmns: Empty response");
929 } else {
930 loge("getForbiddenPlmns: Unknown exception");
931 }
932 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700933 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800934 break;
935
936 case CMD_GET_FORBIDDEN_PLMNS:
937 request = (MainThreadRequest) msg.obj;
938 uiccCard = getUiccCardFromRequest(request);
939 if (uiccCard == null) {
940 loge("getForbiddenPlmns() UiccCard is null");
941 request.result = new IllegalArgumentException(
942 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700943 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 break;
945 }
946 Integer appType = (Integer) request.argument;
947 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
948 if (uiccApp == null) {
949 loge("getForbiddenPlmns() no app with specified type -- "
950 + appType);
951 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700952 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800953 break;
954 } else {
955 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
956 + " specified type -- " + appType);
957 }
958 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
959 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
960 onCompleted);
961 break;
962
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000963 case CMD_SWITCH_SLOTS:
964 request = (MainThreadRequest) msg.obj;
965 int[] physicalSlots = (int[]) request.argument;
966 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
967 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
968 break;
969
970 case EVENT_SWITCH_SLOTS_DONE:
971 ar = (AsyncResult) msg.obj;
972 request = (MainThreadRequest) ar.userObj;
973 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700974 notifyRequester(request);
975 break;
976 case CMD_GET_NETWORK_SELECTION_MODE:
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
979 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
980 break;
981
982 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 if (ar.exception != null) {
986 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
987 } else {
988 int mode = ((int[]) ar.result)[0];
989 if (mode == 0) {
990 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
991 } else {
992 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
993 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000994 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700995 notifyRequester(request);
996 break;
997 case CMD_GET_CDMA_ROAMING_MODE:
998 request = (MainThreadRequest) msg.obj;
999 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1000 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1001 break;
1002 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
1005 if (ar.exception != null) {
1006 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1007 } else {
1008 request.result = ((int[]) ar.result)[0];
1009 }
1010 notifyRequester(request);
1011 break;
1012 case CMD_SET_CDMA_ROAMING_MODE:
1013 request = (MainThreadRequest) msg.obj;
1014 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1015 int mode = (int) request.argument;
1016 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1017 break;
1018 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1019 ar = (AsyncResult) msg.obj;
1020 request = (MainThreadRequest) ar.userObj;
1021 request.result = ar.exception == null;
1022 notifyRequester(request);
1023 break;
1024 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1025 request = (MainThreadRequest) msg.obj;
1026 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1027 int subscriptionMode = (int) request.argument;
1028 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1029 break;
1030 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1031 ar = (AsyncResult) msg.obj;
1032 request = (MainThreadRequest) ar.userObj;
1033 request.result = ar.exception == null;
1034 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001035 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001036 case CMD_GET_ALL_CELL_INFO:
1037 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001038 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001039 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001040 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001041 case EVENT_GET_ALL_CELL_INFO_DONE:
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001044 // If a timeout occurs, the response will be null
1045 request.result = (ar.exception == null && ar.result != null)
1046 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001047 synchronized (request) {
1048 request.notifyAll();
1049 }
1050 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001051 case CMD_REQUEST_CELL_INFO_UPDATE:
1052 request = (MainThreadRequest) msg.obj;
1053 request.phone.requestCellInfoUpdate(request.workSource,
1054 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1055 break;
1056 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
1059 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1060 try {
1061 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001063 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1064 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001066 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001067 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 } else {
1069 // use the result as returned
1070 cb.onCellInfo((List<CellInfo>) ar.result);
1071 }
1072 } catch (RemoteException re) {
1073 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1074 }
1075 break;
1076 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001077 request = (MainThreadRequest) msg.obj;
1078 WorkSource ws = (WorkSource) request.argument;
1079 Phone phone = getPhoneFromRequest(request);
1080 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1081 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001082 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001083 ar = (AsyncResult) msg.obj;
1084 request = (MainThreadRequest) ar.userObj;
1085 if (ar.exception == null) {
1086 request.result = ar.result;
1087 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001088 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001089 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1090 ? new CdmaCellLocation() : new GsmCellLocation();
1091 }
1092
1093 synchronized (request) {
1094 request.notifyAll();
1095 }
1096 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001097 case CMD_MODEM_REBOOT:
1098 request = (MainThreadRequest) msg.obj;
1099 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001100 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001101 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001102 case EVENT_CMD_MODEM_REBOOT_DONE:
1103 handleNullReturnEvent(msg, "rebootModem");
1104 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001105 case CMD_REQUEST_ENABLE_MODEM:
1106 request = (MainThreadRequest) msg.obj;
1107 boolean enable = (boolean) request.argument;
1108 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001109 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001110 PhoneConfigurationManager.getInstance()
1111 .enablePhone(request.phone, enable, onCompleted);
1112 break;
1113 case EVENT_ENABLE_MODEM_DONE:
1114 ar = (AsyncResult) msg.obj;
1115 request = (MainThreadRequest) ar.userObj;
1116 request.result = (ar.exception == null);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001117 //update the cache as modem status has changed
1118 mPhoneConfigurationManager.addToPhoneStatusCache(
1119 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001120 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001121 notifyRequester(request);
1122 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001123 default:
1124 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1125 break;
1126 }
1127 }
Jake Hambye994d462014-02-03 13:10:13 -08001128
Pengquan Meng0c05b502018-09-06 09:59:22 -07001129 private void notifyRequester(MainThreadRequest request) {
1130 synchronized (request) {
1131 request.notifyAll();
1132 }
1133 }
1134
Jake Hambye994d462014-02-03 13:10:13 -08001135 private void handleNullReturnEvent(Message msg, String command) {
1136 AsyncResult ar = (AsyncResult) msg.obj;
1137 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1138 if (ar.exception == null) {
1139 request.result = true;
1140 } else {
1141 request.result = false;
1142 if (ar.exception instanceof CommandException) {
1143 loge(command + ": CommandException: " + ar.exception);
1144 } else {
1145 loge(command + ": Unknown exception");
1146 }
1147 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001148 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150 }
1151
1152 /**
1153 * Posts the specified command to be executed on the main thread,
1154 * waits for the request to complete, and returns the result.
1155 * @see #sendRequestAsync
1156 */
1157 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001158 return sendRequest(
1159 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001160 }
1161
1162 /**
1163 * Posts the specified command to be executed on the main thread,
1164 * waits for the request to complete, and returns the result.
1165 * @see #sendRequestAsync
1166 */
1167 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1168 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001169 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001170 }
1171
1172 /**
1173 * Posts the specified command to be executed on the main thread,
1174 * waits for the request to complete, and returns the result.
1175 * @see #sendRequestAsync
1176 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001177 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001178 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001179 }
1180
1181 /**
1182 * Posts the specified command to be executed on the main thread,
1183 * waits for the request to complete, and returns the result.
1184 * @see #sendRequestAsync
1185 */
Nathan Harold92bed182018-10-12 18:16:49 -07001186 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1187 return sendRequest(command, argument, subId, null, workSource);
1188 }
1189
1190 /**
1191 * Posts the specified command to be executed on the main thread,
1192 * waits for the request to complete, and returns the result.
1193 * @see #sendRequestAsync
1194 */
1195 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1196 return sendRequest(
1197 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1198 }
1199
1200 /**
1201 * Posts the specified command to be executed on the main thread,
1202 * waits for the request to complete, and returns the result.
1203 * @see #sendRequestAsync
1204 */
1205 private Object sendRequest(
1206 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001207 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1208 throw new RuntimeException("This method will deadlock if called from the main thread.");
1209 }
1210
Nathan Harold92bed182018-10-12 18:16:49 -07001211 MainThreadRequest request = null;
1212 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1213 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1214 } else if (phone != null) {
1215 request = new MainThreadRequest(argument, phone, workSource);
1216 } else {
1217 request = new MainThreadRequest(argument, subId, workSource);
1218 }
1219
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001220 Message msg = mMainThreadHandler.obtainMessage(command, request);
1221 msg.sendToTarget();
1222
1223 // Wait for the request to complete
1224 synchronized (request) {
1225 while (request.result == null) {
1226 try {
1227 request.wait();
1228 } catch (InterruptedException e) {
1229 // Do nothing, go back and wait until the request is complete
1230 }
1231 }
1232 }
1233 return request.result;
1234 }
1235
1236 /**
1237 * Asynchronous ("fire and forget") version of sendRequest():
1238 * Posts the specified command to be executed on the main thread, and
1239 * returns immediately.
1240 * @see #sendRequest
1241 */
1242 private void sendRequestAsync(int command) {
1243 mMainThreadHandler.sendEmptyMessage(command);
1244 }
1245
1246 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001247 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001248 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001249 */
1250 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001251 sendRequestAsync(command, argument, null, null);
1252 }
1253
1254 /**
1255 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1256 * @see {@link #sendRequest(int,Object)}
1257 */
1258 private void sendRequestAsync(
1259 int command, Object argument, Phone phone, WorkSource workSource) {
1260 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001261 Message msg = mMainThreadHandler.obtainMessage(command, request);
1262 msg.sendToTarget();
1263 }
1264
1265 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 * Initialize the singleton PhoneInterfaceManager instance.
1267 * This is only done once, at startup, from PhoneApp.onCreate().
1268 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001269 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 synchronized (PhoneInterfaceManager.class) {
1271 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001272 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 } else {
1274 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1275 }
1276 return sInstance;
1277 }
1278 }
1279
1280 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001281 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001284 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1286 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001287 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001288 mTelephonySharedPreferences =
1289 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001290 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001291 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001292
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001293 publish();
1294 }
1295
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001296 private Phone getDefaultPhone() {
1297 Phone thePhone = getPhone(getDefaultSubscription());
1298 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1299 }
1300
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 private void publish() {
1302 if (DBG) log("publish: " + this);
1303
1304 ServiceManager.addService("phone", this);
1305 }
1306
Stuart Scott584921c2015-01-15 17:10:34 -08001307 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001308 if (request.phone != null) {
1309 return request.phone;
1310 } else {
1311 return getPhoneFromSubId(request.subId);
1312 }
1313 }
1314
1315 private Phone getPhoneFromSubId(int subId) {
1316 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1317 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001318 }
1319
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001320 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1321 Phone phone = getPhoneFromRequest(request);
1322 return phone == null ? null :
1323 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1324 }
1325
Wink Saville36469e72014-06-11 15:17:00 -07001326 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001327 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001328 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330
1331 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001332 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001333 }
1334
Wink Savilleb564aae2014-10-23 10:18:09 -07001335 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 if (DBG) log("dial: " + number);
1337 // No permission check needed here: This is just a wrapper around the
1338 // ACTION_DIAL intent, which is available to any app since it puts up
1339 // the UI before it does anything.
1340
Malcolm Chend965c8b2018-02-28 15:00:40 -08001341 final long identity = Binder.clearCallingIdentity();
1342 try {
1343 String url = createTelUrl(number);
1344 if (url == null) {
1345 return;
1346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001347
Malcolm Chend965c8b2018-02-28 15:00:40 -08001348 // PENDING: should we just silently fail if phone is offhook or ringing?
1349 PhoneConstants.State state = mCM.getState(subId);
1350 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1351 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1352 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1353 mApp.startActivity(intent);
1354 }
1355 } finally {
1356 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 }
1358 }
1359
1360 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001361 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001362 }
1363
Wink Savilleb564aae2014-10-23 10:18:09 -07001364 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 if (DBG) log("call: " + number);
1366
1367 // This is just a wrapper around the ACTION_CALL intent, but we still
1368 // need to do a permission check since we're calling startActivity()
1369 // from the context of the phone app.
1370 enforceCallPermission();
1371
1372 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1373 != AppOpsManager.MODE_ALLOWED) {
1374 return;
1375 }
1376
Malcolm Chend965c8b2018-02-28 15:00:40 -08001377 final long identity = Binder.clearCallingIdentity();
1378 try {
1379 String url = createTelUrl(number);
1380 if (url == null) {
1381 return;
1382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383
Malcolm Chend965c8b2018-02-28 15:00:40 -08001384 boolean isValid = false;
1385 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1386 if (slist != null) {
1387 for (SubscriptionInfo subInfoRecord : slist) {
1388 if (subInfoRecord.getSubscriptionId() == subId) {
1389 isValid = true;
1390 break;
1391 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001392 }
Wink Saville08874612014-08-31 19:19:58 -07001393 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001394 if (!isValid) {
1395 return;
1396 }
Wink Saville08874612014-08-31 19:19:58 -07001397
Malcolm Chend965c8b2018-02-28 15:00:40 -08001398 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1399 intent.putExtra(SUBSCRIPTION_KEY, subId);
1400 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1401 mApp.startActivity(intent);
1402 } finally {
1403 Binder.restoreCallingIdentity(identity);
1404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 }
1406
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001408 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001409 }
1410
Wink Savilleb564aae2014-10-23 10:18:09 -07001411 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001412 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001413 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1414 }
1415
1416 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001417 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001418 }
1419
Wink Savilleb564aae2014-10-23 10:18:09 -07001420 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001421 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001422 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1423 }
1424
1425 /** {@hide} */
1426 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001427 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001428 }
1429
Wink Savilleb564aae2014-10-23 10:18:09 -07001430 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001432
1433 final long identity = Binder.clearCallingIdentity();
1434 try {
1435 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1436 checkSimPin.start();
1437 return checkSimPin.unlockSim(null, pin);
1438 } finally {
1439 Binder.restoreCallingIdentity(identity);
1440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441 }
1442
Wink Saville9de0f752013-10-22 19:04:03 -07001443 /** {@hide} */
1444 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001445 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001446 }
1447
Wink Savilleb564aae2014-10-23 10:18:09 -07001448 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001450
1451 final long identity = Binder.clearCallingIdentity();
1452 try {
1453 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1454 checkSimPuk.start();
1455 return checkSimPuk.unlockSim(puk, pin);
1456 } finally {
1457 Binder.restoreCallingIdentity(identity);
1458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 }
1460
1461 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001462 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001463 * a synchronous one.
1464 */
1465 private static class UnlockSim extends Thread {
1466
1467 private final IccCard mSimCard;
1468
1469 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001470 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1471 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472
1473 // For replies from SimCard interface
1474 private Handler mHandler;
1475
1476 // For async handler to identify request type
1477 private static final int SUPPLY_PIN_COMPLETE = 100;
1478
1479 public UnlockSim(IccCard simCard) {
1480 mSimCard = simCard;
1481 }
1482
1483 @Override
1484 public void run() {
1485 Looper.prepare();
1486 synchronized (UnlockSim.this) {
1487 mHandler = new Handler() {
1488 @Override
1489 public void handleMessage(Message msg) {
1490 AsyncResult ar = (AsyncResult) msg.obj;
1491 switch (msg.what) {
1492 case SUPPLY_PIN_COMPLETE:
1493 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1494 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001495 mRetryCount = msg.arg1;
1496 if (ar.exception != null) {
1497 if (ar.exception instanceof CommandException &&
1498 ((CommandException)(ar.exception)).getCommandError()
1499 == CommandException.Error.PASSWORD_INCORRECT) {
1500 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1501 } else {
1502 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1503 }
1504 } else {
1505 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507 mDone = true;
1508 UnlockSim.this.notifyAll();
1509 }
1510 break;
1511 }
1512 }
1513 };
1514 UnlockSim.this.notifyAll();
1515 }
1516 Looper.loop();
1517 }
1518
1519 /*
1520 * Use PIN or PUK to unlock SIM card
1521 *
1522 * If PUK is null, unlock SIM card with PIN
1523 *
1524 * If PUK is not null, unlock SIM card with PUK and set PIN code
1525 */
Wink Saville9de0f752013-10-22 19:04:03 -07001526 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527
1528 while (mHandler == null) {
1529 try {
1530 wait();
1531 } catch (InterruptedException e) {
1532 Thread.currentThread().interrupt();
1533 }
1534 }
1535 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1536
1537 if (puk == null) {
1538 mSimCard.supplyPin(pin, callback);
1539 } else {
1540 mSimCard.supplyPuk(puk, pin, callback);
1541 }
1542
1543 while (!mDone) {
1544 try {
1545 Log.d(LOG_TAG, "wait for done");
1546 wait();
1547 } catch (InterruptedException e) {
1548 // Restore the interrupted status
1549 Thread.currentThread().interrupt();
1550 }
1551 }
1552 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001553 int[] resultArray = new int[2];
1554 resultArray[0] = mResult;
1555 resultArray[1] = mRetryCount;
1556 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 }
1558 }
1559
1560 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001561 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001562
1563 }
1564
Wink Savilleb564aae2014-10-23 10:18:09 -07001565 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 // No permission check needed here: this call is harmless, and it's
1567 // needed for the ServiceState.requestStateUpdate() call (which is
1568 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 final Phone phone = getPhone(subId);
1572 if (phone != null) {
1573 phone.updateServiceLocation();
1574 }
1575 } finally {
1576 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 }
1579
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001580 @Override
1581 public boolean isRadioOn(String callingPackage) {
1582 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001583 }
1584
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001585 @Override
1586 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001588 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001589 return false;
1590 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001591
1592 final long identity = Binder.clearCallingIdentity();
1593 try {
1594 return isRadioOnForSubscriber(subId);
1595 } finally {
1596 Binder.restoreCallingIdentity(identity);
1597 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001598 }
1599
1600 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001601 final long identity = Binder.clearCallingIdentity();
1602 try {
1603 final Phone phone = getPhone(subId);
1604 if (phone != null) {
1605 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1606 } else {
1607 return false;
1608 }
1609 } finally {
1610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 }
1613
1614 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001615 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 }
Wink Saville36469e72014-06-11 15:17:00 -07001617
Wink Savilleb564aae2014-10-23 10:18:09 -07001618 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001620
1621 final long identity = Binder.clearCallingIdentity();
1622 try {
1623 final Phone phone = getPhone(subId);
1624 if (phone != null) {
1625 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1626 }
1627 } finally {
1628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 }
Wink Saville36469e72014-06-11 15:17:00 -07001630 }
1631
1632 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001633 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001634 }
1635
Wink Savilleb564aae2014-10-23 10:18:09 -07001636 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001637 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001638
1639 final long identity = Binder.clearCallingIdentity();
1640 try {
1641 final Phone phone = getPhone(subId);
1642 if (phone == null) {
1643 return false;
1644 }
1645 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1646 toggleRadioOnOffForSubscriber(subId);
1647 }
1648 return true;
1649 } finally {
1650 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
Wink Saville36469e72014-06-11 15:17:00 -07001653
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001654 public boolean needMobileRadioShutdown() {
1655 /*
1656 * If any of the Radios are available, it will need to be
1657 * shutdown. So return true if any Radio is available.
1658 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001659 final long identity = Binder.clearCallingIdentity();
1660 try {
1661 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1662 Phone phone = PhoneFactory.getPhone(i);
1663 if (phone != null && phone.isRadioAvailable()) return true;
1664 }
1665 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1666 return false;
1667 } finally {
1668 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001669 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001670 }
1671
Malcolm Chend965c8b2018-02-28 15:00:40 -08001672 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001673 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001674 enforceModifyPermission();
1675
1676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1679 logv("Shutting down Phone " + i);
1680 shutdownRadioUsingPhoneId(i);
1681 }
1682 } finally {
1683 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001684 }
1685 }
1686
1687 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001688 Phone phone = PhoneFactory.getPhone(phoneId);
1689 if (phone != null && phone.isRadioAvailable()) {
1690 phone.shutdownRadio();
1691 }
1692 }
1693
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001695 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001696
1697 final long identity = Binder.clearCallingIdentity();
1698 try {
1699 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1700 if (defaultPhone != null) {
1701 defaultPhone.setRadioPower(turnOn);
1702 return true;
1703 } else {
1704 loge("There's no default phone.");
1705 return false;
1706 }
1707 } finally {
1708 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001709 }
Wink Saville36469e72014-06-11 15:17:00 -07001710 }
1711
Wink Savilleb564aae2014-10-23 10:18:09 -07001712 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001714
1715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 final Phone phone = getPhone(subId);
1718 if (phone != null) {
1719 phone.setRadioPower(turnOn);
1720 return true;
1721 } else {
1722 return false;
1723 }
1724 } finally {
1725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727 }
1728
Wink Saville36469e72014-06-11 15:17:00 -07001729 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001730 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001731 public boolean enableDataConnectivity() {
1732 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001733
1734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 int subId = mSubscriptionController.getDefaultDataSubId();
1737 final Phone phone = getPhone(subId);
1738 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001739 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001740 return true;
1741 } else {
1742 return false;
1743 }
1744 } finally {
1745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 }
1748
Wink Saville36469e72014-06-11 15:17:00 -07001749 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001750 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 public boolean disableDataConnectivity() {
1752 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001753
1754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 int subId = mSubscriptionController.getDefaultDataSubId();
1757 final Phone phone = getPhone(subId);
1758 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001759 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001760 return true;
1761 } else {
1762 return false;
1763 }
1764 } finally {
1765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 }
1768
Sanket Padawe356d7632015-06-22 14:03:32 -07001769 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001770 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001771 final long identity = Binder.clearCallingIdentity();
1772 try {
1773 final Phone phone = getPhone(subId);
1774 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001775 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001776 } else {
1777 return false;
1778 }
1779 } finally {
1780 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 }
1783
1784 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001785 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001786 }
1787
pkanwarae03a6b2016-11-06 20:37:09 -08001788 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001789 enforceCallPermission();
1790
1791 final long identity = Binder.clearCallingIdentity();
1792 try {
1793 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1794 return;
1795 }
1796 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1797 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1798 } finally {
1799 Binder.restoreCallingIdentity(identity);
1800 }
pkanwar32d516d2016-10-14 19:37:38 -07001801 };
1802
Wink Savilleb564aae2014-10-23 10:18:09 -07001803 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001805
1806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1809 return false;
1810 }
1811 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1812 } finally {
1813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
1816
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001818 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001819 }
1820
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001821 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001822 final long identity = Binder.clearCallingIdentity();
1823 try {
1824 Phone phone = PhoneFactory.getPhone(slotIndex);
1825 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1826 PhoneConstantConversions.convertCallState(phone.getState());
1827 } finally {
1828 Binder.restoreCallingIdentity(identity);
1829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 }
1831
Sanket Padawe356d7632015-06-22 14:03:32 -07001832 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1837 if (phone != null) {
1838 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1839 } else {
1840 return PhoneConstantConversions.convertDataState(
1841 PhoneConstants.DataState.DISCONNECTED);
1842 }
1843 } finally {
1844 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 }
1847
Sanket Padawe356d7632015-06-22 14:03:32 -07001848 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001850 final long identity = Binder.clearCallingIdentity();
1851 try {
1852 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1853 if (phone != null) {
1854 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1855 } else {
1856 return TelephonyManager.DATA_ACTIVITY_NONE;
1857 }
1858 } finally {
1859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 }
1862
1863 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001864 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001865 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001866 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001867
1868 LocationAccessPolicy.LocationPermissionResult locationResult =
1869 LocationAccessPolicy.checkLocationPermission(mApp,
1870 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1871 .setCallingPackage(callingPackage)
1872 .setCallingPid(Binder.getCallingPid())
1873 .setCallingUid(Binder.getCallingUid())
1874 .setMethod("getCellLocation")
1875 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1876 .build());
1877 switch (locationResult) {
1878 case DENIED_HARD:
1879 throw new SecurityException("Not allowed to access cell location");
1880 case DENIED_SOFT:
1881 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 }
1883
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001884 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001885 final long identity = Binder.clearCallingIdentity();
1886 try {
1887 if (DBG_LOC) log("getCellLocation: is active user");
1888 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001889 int subId = mSubscriptionController.getDefaultDataSubId();
1890 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1891 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001892 return data;
1893 } finally {
1894 Binder.restoreCallingIdentity(identity);
1895 }
Svetoslav64fad262015-04-14 14:35:21 -07001896 }
1897
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001899 public String getNetworkCountryIsoForPhone(int phoneId) {
1900 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1901 // registered cell info, so return a NULL country instead.
1902 final long identity = Binder.clearCallingIdentity();
1903 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001904 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1905 // Get default phone in this case.
1906 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1907 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001908 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001909 // Todo: fix this when we can get the actual cellular network info when the device
1910 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001911 if (TelephonyManager.NETWORK_TYPE_IWLAN
1912 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1913 return "";
1914 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001915 Phone phone = PhoneFactory.getPhone(phoneId);
1916 if (phone != null) {
1917 ServiceStateTracker sst = phone.getServiceStateTracker();
1918 if (sst != null) {
1919 LocaleTracker lt = sst.getLocaleTracker();
1920 if (lt != null) {
1921 return lt.getCurrentCountry();
1922 }
1923 }
1924 }
1925 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001926 } finally {
1927 Binder.restoreCallingIdentity(identity);
1928 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001929 }
1930
1931 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001932 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001933 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001934 }
1935
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001937 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 mApp.enforceCallingOrSelfPermission(
1939 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001940
1941 final long identity = Binder.clearCallingIdentity();
1942 try {
1943 final Phone phone = getPhone(subId);
1944 if (phone != null) {
1945 phone.enableLocationUpdates();
1946 }
1947 } finally {
1948 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 }
1951
1952 @Override
1953 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001954 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001955 }
1956
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001958 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 mApp.enforceCallingOrSelfPermission(
1960 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001961
1962 final long identity = Binder.clearCallingIdentity();
1963 try {
1964 final Phone phone = getPhone(subId);
1965 if (phone != null) {
1966 phone.disableLocationUpdates();
1967 }
1968 } finally {
1969 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 }
1972
Nathan Harold31d7ff32018-10-15 20:20:30 -07001973 /**
1974 * Returns the target SDK version number for a given package name.
1975 *
1976 * @return target SDK if the package is found or INT_MAX.
1977 */
1978 private int getTargetSdk(String packageName) {
1979 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001980 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1981 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001982 if (ai != null) return ai.targetSdkVersion;
1983 } catch (PackageManager.NameNotFoundException unexpected) {
1984 }
1985 return Integer.MAX_VALUE;
1986 }
1987
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 @Override
1989 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001990 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1991 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001992 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1993 throw new SecurityException(
1994 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1995 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001996
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1998 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1999 return null;
2000 }
Svetoslav64fad262015-04-14 14:35:21 -07002001
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002002 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003
Nathan Haroldf180aac2018-06-01 18:43:55 -07002004 List<CellInfo> info = getAllCellInfo(callingPackage);
2005 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006
Nathan Haroldf180aac2018-06-01 18:43:55 -07002007 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2008 for (CellInfo ci : info) {
2009 if (ci instanceof CellInfoGsm) {
2010 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2011 } else if (ci instanceof CellInfoWcdma) {
2012 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002014 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002015 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 }
2017
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002018 private List<CellInfo> getCachedCellInfo() {
2019 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2020 for (Phone phone : PhoneFactory.getPhones()) {
2021 List<CellInfo> info = phone.getAllCellInfo();
2022 if (info != null) cellInfos.addAll(info);
2023 }
2024 return cellInfos;
2025 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026
2027 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002028 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002029 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002030 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002031
2032 LocationAccessPolicy.LocationPermissionResult locationResult =
2033 LocationAccessPolicy.checkLocationPermission(mApp,
2034 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2035 .setCallingPackage(callingPackage)
2036 .setCallingPid(Binder.getCallingPid())
2037 .setCallingUid(Binder.getCallingUid())
2038 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002039 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002040 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2041 .build());
2042 switch (locationResult) {
2043 case DENIED_HARD:
2044 throw new SecurityException("Not allowed to access cell info");
2045 case DENIED_SOFT:
2046 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 }
2048
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002049 final int targetSdk = getTargetSdk(callingPackage);
2050 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2051 return getCachedCellInfo();
2052 }
2053
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002054 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002055 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002056 final long identity = Binder.clearCallingIdentity();
2057 try {
2058 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2059 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002060 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002061 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002062 if (info != null) cellInfos.addAll(info);
2063 }
2064 return cellInfos;
2065 } finally {
2066 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 }
2068 }
2069
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002070 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002071 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2072 requestCellInfoUpdateInternal(
2073 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2074 }
2075
2076 @Override
2077 public void requestCellInfoUpdateWithWorkSource(
2078 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2079 enforceModifyPermission();
2080 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2081 }
2082
2083 private void requestCellInfoUpdateInternal(
2084 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002085 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002086 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002087
2088 LocationAccessPolicy.LocationPermissionResult locationResult =
2089 LocationAccessPolicy.checkLocationPermission(mApp,
2090 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2091 .setCallingPackage(callingPackage)
2092 .setCallingPid(Binder.getCallingPid())
2093 .setCallingUid(Binder.getCallingUid())
2094 .setMethod("requestCellInfoUpdate")
2095 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2096 .build());
2097 switch (locationResult) {
2098 case DENIED_HARD:
2099 throw new SecurityException("Not allowed to access cell info");
2100 case DENIED_SOFT:
2101 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002102 }
2103
2104 final Phone phone = getPhone(subId);
2105 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2106
2107 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2108 }
2109
2110 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002112 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002113 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002114
2115 final long identity = Binder.clearCallingIdentity();
2116 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002117 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 }
2122
Shishir Agrawala9f32182016-04-12 12:00:16 -07002123 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002124 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002125 Phone phone = PhoneFactory.getPhone(slotIndex);
2126 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002127 return null;
2128 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002129 int subId = phone.getSubId();
2130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2131 mApp, subId, callingPackage, "getImeiForSlot")) {
2132 return null;
2133 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002134
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 return phone.getImei();
2138 } finally {
2139 Binder.restoreCallingIdentity(identity);
2140 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002141 }
2142
2143 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002144 public String getTypeAllocationCodeForSlot(int slotIndex) {
2145 Phone phone = PhoneFactory.getPhone(slotIndex);
2146 String tac = null;
2147 if (phone != null) {
2148 String imei = phone.getImei();
2149 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2150 }
2151 return tac;
2152 }
2153
2154 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002155 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002156 Phone phone = PhoneFactory.getPhone(slotIndex);
2157 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002158 return null;
2159 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002160
Jeff Davidson913390f2018-02-23 17:11:49 -08002161 int subId = phone.getSubId();
2162 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2163 mApp, subId, callingPackage, "getMeidForSlot")) {
2164 return null;
2165 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002166
2167 final long identity = Binder.clearCallingIdentity();
2168 try {
2169 return phone.getMeid();
2170 } finally {
2171 Binder.restoreCallingIdentity(identity);
2172 }
Jack Yu2af8d712017-03-15 17:14:14 -07002173 }
2174
2175 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002176 public String getManufacturerCodeForSlot(int slotIndex) {
2177 Phone phone = PhoneFactory.getPhone(slotIndex);
2178 String manufacturerCode = null;
2179 if (phone != null) {
2180 String meid = phone.getMeid();
2181 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2182 }
2183 return manufacturerCode;
2184 }
2185
2186 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002187 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002188 Phone phone = PhoneFactory.getPhone(slotIndex);
2189 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002190 return null;
2191 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002192 int subId = phone.getSubId();
2193 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2194 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2195 return null;
2196 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002197
2198 final long identity = Binder.clearCallingIdentity();
2199 try {
2200 return phone.getDeviceSvn();
2201 } finally {
2202 Binder.restoreCallingIdentity(identity);
2203 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002204 }
2205
fionaxu43304da2017-11-27 22:51:16 -08002206 @Override
2207 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002208 final long identity = Binder.clearCallingIdentity();
2209 try {
2210 final Phone phone = getPhone(subId);
2211 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2212 } finally {
2213 Binder.restoreCallingIdentity(identity);
2214 }
fionaxu43304da2017-11-27 22:51:16 -08002215 }
2216
2217 @Override
2218 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002219 final long identity = Binder.clearCallingIdentity();
2220 try {
2221 final Phone phone = getPhone(subId);
2222 return phone == null ? null : phone.getCarrierName();
2223 } finally {
2224 Binder.restoreCallingIdentity(identity);
2225 }
fionaxu43304da2017-11-27 22:51:16 -08002226 }
2227
calvinpaneed9ae82018-11-01 19:43:06 +08002228 @Override
chen xua31f22b2019-03-06 15:28:50 -08002229 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002230 final long identity = Binder.clearCallingIdentity();
2231 try {
2232 final Phone phone = getPhone(subId);
2233 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002234 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002235 } finally {
2236 Binder.restoreCallingIdentity(identity);
2237 }
2238 }
2239
2240 @Override
chen xua31f22b2019-03-06 15:28:50 -08002241 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002245 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002246 } finally {
2247 Binder.restoreCallingIdentity(identity);
2248 }
2249 }
2250
chen xu02581692018-11-11 19:03:44 -08002251 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002252 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2253 if (!isSubscriptionMccMnc) {
2254 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2255 }
chen xu02581692018-11-11 19:03:44 -08002256 final Phone phone = PhoneFactory.getPhone(slotIndex);
2257 if (phone == null) {
2258 return TelephonyManager.UNKNOWN_CARRIER_ID;
2259 }
2260 final long identity = Binder.clearCallingIdentity();
2261 try {
2262 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
2265 }
2266 }
2267
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 //
2269 // Internal helper methods.
2270 //
2271
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002272 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2274 *
2275 * @throws SecurityException if the caller does not have the required permission
2276 */
2277 private void enforceModifyPermission() {
2278 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2279 }
2280
2281 /**
2282 * Make sure the caller has the CALL_PHONE permission.
2283 *
2284 * @throws SecurityException if the caller does not have the required permission
2285 */
2286 private void enforceCallPermission() {
2287 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2288 }
2289
Stuart Scott8eef64f2015-04-08 15:13:54 -07002290 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002291 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002292 "ConnectivityService");
2293 }
2294
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 private String createTelUrl(String number) {
2296 if (TextUtils.isEmpty(number)) {
2297 return null;
2298 }
2299
Jake Hambye994d462014-02-03 13:10:13 -08002300 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
Ihab Awadf9e92732013-12-05 18:02:52 -08002303 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2305 }
2306
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002307 private static void logv(String msg) {
2308 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2309 }
2310
Ihab Awadf9e92732013-12-05 18:02:52 -08002311 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2313 }
2314
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002315 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002317 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002318 }
2319
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002321 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 final Phone phone = PhoneFactory.getPhone(slotIndex);
2325 if (phone == null) {
2326 return PhoneConstants.PHONE_TYPE_NONE;
2327 } else {
2328 return phone.getPhoneType();
2329 }
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334
2335 /**
2336 * Returns the CDMA ERI icon index to display
2337 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002338 @Override
2339 public int getCdmaEriIconIndex(String callingPackage) {
2340 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002341 }
2342
Sanket Padawe356d7632015-06-22 14:03:32 -07002343 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002344 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002346 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002347 return -1;
2348 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002349
2350 final long identity = Binder.clearCallingIdentity();
2351 try {
2352 final Phone phone = getPhone(subId);
2353 if (phone != null) {
2354 return phone.getCdmaEriIconIndex();
2355 } else {
2356 return -1;
2357 }
2358 } finally {
2359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 }
2362
2363 /**
2364 * Returns the CDMA ERI icon mode,
2365 * 0 - ON
2366 * 1 - FLASHING
2367 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002368 @Override
2369 public int getCdmaEriIconMode(String callingPackage) {
2370 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002371 }
2372
Sanket Padawe356d7632015-06-22 14:03:32 -07002373 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002374 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002376 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002377 return -1;
2378 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002379
2380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 final Phone phone = getPhone(subId);
2383 if (phone != null) {
2384 return phone.getCdmaEriIconMode();
2385 } else {
2386 return -1;
2387 }
2388 } finally {
2389 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 }
2392
2393 /**
2394 * Returns the CDMA ERI text,
2395 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002396 @Override
2397 public String getCdmaEriText(String callingPackage) {
2398 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002399 }
2400
Sanket Padawe356d7632015-06-22 14:03:32 -07002401 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002402 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002404 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002405 return null;
2406 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002407
2408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 final Phone phone = getPhone(subId);
2411 if (phone != null) {
2412 return phone.getCdmaEriText();
2413 } else {
2414 return null;
2415 }
2416 } finally {
2417 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
2420
2421 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002422 * Returns the CDMA MDN.
2423 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002424 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002425 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2427 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002428
2429 final long identity = Binder.clearCallingIdentity();
2430 try {
2431 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002432 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002433 return phone.getLine1Number();
2434 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002435 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002436 return null;
2437 }
2438 } finally {
2439 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002440 }
2441 }
2442
2443 /**
2444 * Returns the CDMA MIN.
2445 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002446 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002447 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2449 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002450
2451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 final Phone phone = getPhone(subId);
2454 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2455 return phone.getCdmaMin();
2456 } else {
2457 return null;
2458 }
2459 } finally {
2460 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002461 }
2462 }
2463
Hall Liud892bec2018-11-30 14:51:45 -08002464 @Override
2465 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2466 INumberVerificationCallback callback, String callingPackage) {
2467 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2468 != PERMISSION_GRANTED) {
2469 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2470 }
2471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2472
2473 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2474 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2475 throw new SecurityException("Calling package must be configured in the device config");
2476 }
2477
2478 if (range == null) {
2479 throw new NullPointerException("Range must be non-null");
2480 }
2481
2482 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002483 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002484
2485 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2486 }
2487
Junda Liuca05d5d2014-08-14 22:36:34 -07002488 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 * Returns true if CDMA provisioning needs to run.
2490 */
2491 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002492 final long identity = Binder.clearCallingIdentity();
2493 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002494 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002495 } finally {
2496 Binder.restoreCallingIdentity(identity);
2497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 }
2499
2500 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002501 * Sets the voice mail number of a given subId.
2502 */
2503 @Override
2504 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002505 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002506
2507 final long identity = Binder.clearCallingIdentity();
2508 try {
2509 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2510 new Pair<String, String>(alphaTag, number), new Integer(subId));
2511 return success;
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002515 }
2516
Ta-wei Yen87c49842016-05-13 21:19:52 -07002517 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002518 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2519 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002520 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002521 if (!TextUtils.equals(callingPackage, systemDialer)) {
2522 throw new SecurityException("caller must be system dialer");
2523 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002524
2525 final long identity = Binder.clearCallingIdentity();
2526 try {
2527 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2528 if (phoneAccountHandle == null) {
2529 return null;
2530 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002531 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002532 } finally {
2533 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002534 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002535 }
2536
2537 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002538 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002539 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002541 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002542 return null;
2543 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002544
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002545 final long identity = Binder.clearCallingIdentity();
2546 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002547 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002548 } finally {
2549 Binder.restoreCallingIdentity(identity);
2550 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002551 }
2552
2553 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002554 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2555 VisualVoicemailSmsFilterSettings settings) {
2556 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002557
2558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002561 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002562 } finally {
2563 Binder.restoreCallingIdentity(identity);
2564 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002565 }
2566
2567 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002568 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2569 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002574 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002578 }
2579
2580 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002581 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2582 String callingPackage, int subId) {
2583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002584
2585 final long identity = Binder.clearCallingIdentity();
2586 try {
2587 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002588 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002592 }
2593
2594 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002595 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002596 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002597
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002601 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002602 } finally {
2603 Binder.restoreCallingIdentity(identity);
2604 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002605 }
2606
2607 @Override
2608 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2609 String number, int port, String text, PendingIntent sentIntent) {
2610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002611 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002612 enforceSendSmsPermission();
2613 // Make the calls as the phone process.
2614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2617 if (port == 0) {
2618 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2619 sentIntent, null, false);
2620 } else {
2621 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2622 smsManager.sendDataMessageWithSelfPermissions(number, null,
2623 (short) port, data, sentIntent, null);
2624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002628 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002629 /**
fionaxu0152e512016-11-14 13:36:14 -08002630 * Sets the voice activation state of a given subId.
2631 */
2632 @Override
2633 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2635 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 if (phone != null) {
2641 phone.setVoiceActivationState(activationState);
2642 } else {
2643 loge("setVoiceActivationState fails with invalid subId: " + subId);
2644 }
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002647 }
2648 }
2649
2650 /**
2651 * Sets the data activation state of a given subId.
2652 */
2653 @Override
2654 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2656 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002657
2658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 final Phone phone = getPhone(subId);
2661 if (phone != null) {
2662 phone.setDataActivationState(activationState);
2663 } else {
2664 loge("setVoiceActivationState fails with invalid subId: " + subId);
2665 }
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002668 }
2669 }
2670
2671 /**
2672 * Returns the voice activation state of a given subId.
2673 */
2674 @Override
2675 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002676 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002677
fionaxu0152e512016-11-14 13:36:14 -08002678 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 if (phone != null) {
2682 return phone.getVoiceActivationState();
2683 } else {
2684 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2685 }
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002688 }
2689 }
2690
2691 /**
2692 * Returns the data activation state of a given subId.
2693 */
2694 @Override
2695 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002696 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002697
fionaxu0152e512016-11-14 13:36:14 -08002698 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002699 final long identity = Binder.clearCallingIdentity();
2700 try {
2701 if (phone != null) {
2702 return phone.getDataActivationState();
2703 } else {
2704 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2705 }
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002708 }
2709 }
2710
2711 /**
Wink Saville36469e72014-06-11 15:17:00 -07002712 * Returns the unread count of voicemails for a subId
2713 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002714 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002715 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2717 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2718 return 0;
2719 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 final Phone phone = getPhone(subId);
2723 if (phone != null) {
2724 return phone.getVoiceMessageCount();
2725 } else {
2726 return 0;
2727 }
2728 } finally {
2729 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002730 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 }
2732
2733 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002734 * returns true, if the device is in a state where both voice and data
2735 * are supported simultaneously. This can change based on location or network condition.
2736 */
2737 @Override
2738 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 final Phone phone = getPhone(subId);
2742 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
2745 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002746 }
2747
2748 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002749 * Send the dialer code if called from the current default dialer or the caller has
2750 * carrier privilege.
2751 * @param inputCode The dialer code to send
2752 */
2753 @Override
2754 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002755 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002756 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002757 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2758 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002759 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002760 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2761 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002762 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002763
2764 final long identity = Binder.clearCallingIdentity();
2765 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002766 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002767 } finally {
2768 Binder.restoreCallingIdentity(identity);
2769 }
fionaxu235cc5e2017-03-06 22:25:57 -08002770 }
2771
2772 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002773 * Returns the data network type.
2774 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 *
2776 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2777 */
2778 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002779 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 final Phone phone = getPhone(getDefaultSubscription());
2783 if (phone != null) {
2784 return phone.getServiceState().getDataNetworkType();
2785 } else {
2786 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2787 }
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002790 }
Wink Saville36469e72014-06-11 15:17:00 -07002791 }
2792
Pengquan Meng0c05b502018-09-06 09:59:22 -07002793 @Override
2794 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002795 if (!isActiveSubscription(subId)) {
2796 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2797 }
2798
Pengquan Meng0c05b502018-09-06 09:59:22 -07002799 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2800 }
2801
Brad Ebinger4c460712018-10-01 10:40:55 -07002802 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002803 public boolean isInEmergencySmsMode() {
2804 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 for (Phone phone : PhoneFactory.getPhones()) {
2808 if (phone.isInEmergencySmsMode()) {
2809 return true;
2810 }
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
2814 }
2815 return false;
2816 }
2817
2818 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002819 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2820 throws RemoteException {
2821 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002822 final long token = Binder.clearCallingIdentity();
2823 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002825 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002826 .addRegistrationCallbackForSubscription(c, subId);
2827 } finally {
2828 Binder.restoreCallingIdentity(token);
2829 }
2830 }
2831
2832 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002833 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2834 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2836 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2837 }
2838 Binder.withCleanCallingIdentity(() -> {
2839 try {
2840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002841 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002842 .removeRegistrationCallbackForSubscription(c, subId);
2843 } catch (IllegalArgumentException e) {
2844 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2845 + "is inactive, ignoring unregister.");
2846 // If the subscription is no longer active, just return, since the callback
2847 // will already have been removed internally.
2848 }
2849 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002850 }
2851
2852 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002853 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2854 throws RemoteException {
2855 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002856 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2857 final long token = Binder.clearCallingIdentity();
2858 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002859 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002860 .addCapabilitiesCallbackForSubscription(c, subId);
2861 } finally {
2862 Binder.restoreCallingIdentity(token);
2863 }
2864 }
2865
2866 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002867 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2868 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002869
2870 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2871 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2872 }
2873 Binder.withCleanCallingIdentity(() -> {
2874 try {
2875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002876 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002877 .removeCapabilitiesCallbackForSubscription(c, subId);
2878 } catch (IllegalArgumentException e) {
2879 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2880 + "is inactive, ignoring unregister.");
2881 // If the subscription is no longer active, just return, since the callback
2882 // will already have been removed internally.
2883 }
2884 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002885 }
2886
2887 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002888 public boolean isCapable(int subId, int capability, int regTech) {
2889 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2891 final long token = Binder.clearCallingIdentity();
2892 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002893 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002894 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2895 } catch (ImsException e) {
2896 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2897 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002898 } catch (IllegalArgumentException e) {
2899 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2900 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002901 } finally {
2902 Binder.restoreCallingIdentity(token);
2903 }
2904 }
2905
2906 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002907 public boolean isAvailable(int subId, int capability, int regTech) {
2908 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002909 final long token = Binder.clearCallingIdentity();
2910 try {
2911 Phone phone = getPhone(subId);
2912 if (phone == null) return false;
2913 return phone.isImsCapabilityAvailable(capability, regTech);
2914 } finally {
2915 Binder.restoreCallingIdentity(token);
2916 }
2917 }
2918
2919 @Override
2920 public boolean isAdvancedCallingSettingEnabled(int subId) {
2921 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2923 final long token = Binder.clearCallingIdentity();
2924 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002925 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002926 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2927 } finally {
2928 Binder.restoreCallingIdentity(token);
2929 }
2930 }
2931
2932 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002933 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002935 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002939 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002940 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
2943 }
2944 }
2945
2946 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002947 public boolean isVtSettingEnabled(int subId) {
2948 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002952 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002953 getSlotIndexOrException(subId)).isVtEnabledByUser();
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
2957 }
2958
2959 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002960 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002962 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002963 final long identity = Binder.clearCallingIdentity();
2964 try {
2965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002966 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 @Override
2973 public boolean isVoWiFiSettingEnabled(int subId) {
2974 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002978 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002979 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
2982 }
2983 }
2984
2985 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002986 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002988 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002989 final long identity = Binder.clearCallingIdentity();
2990 try {
2991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002992 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
2996 }
2997
2998 @Override
2999 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3000 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003004 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003005 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 }
3010
3011 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003012 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003014 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003018 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003019 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3020 } finally {
3021 Binder.restoreCallingIdentity(identity);
3022 }
3023 }
3024
3025 @Override
3026 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3028 "setVoWiFiNonPersistent");
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003032 boolean isRoaming = TelephonyManager.from(
3033 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003034 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003035 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
3039 }
3040
3041 @Override
3042 public int getVoWiFiModeSetting(int subId) {
3043 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003047 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003048 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
3052 }
3053
3054 @Override
3055 public void setVoWiFiModeSetting(int subId, int mode) {
3056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3057 "setVoWiFiModeSetting");
3058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003061 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003062 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3063 } finally {
3064 Binder.restoreCallingIdentity(identity);
3065 }
3066 }
3067
3068 @Override
3069 public int getVoWiFiRoamingModeSetting(int subId) {
3070 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003074 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003075 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
3079 }
3080
3081 @Override
3082 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3084 "setVoWiFiRoamingModeSetting");
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003088 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003089 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
3092 }
3093 }
3094
3095 @Override
3096 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3098 "setRttCapabilityEnabled");
3099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003102 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003103 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3104 } finally {
3105 Binder.restoreCallingIdentity(identity);
3106 }
3107 }
3108
3109 @Override
3110 public boolean isTtyOverVolteEnabled(int subId) {
3111 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003115 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003116 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
3120 }
3121
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003122 @Override
3123 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3124 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003128 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003129 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003130 } finally {
3131 Binder.restoreCallingIdentity(identity);
3132 }
3133 }
3134
3135 @Override
3136 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3137 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3138 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003139 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3140 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3141 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003142 try {
3143 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003144 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003145 .removeProvisioningCallbackForSubscription(callback, subId);
3146 } catch (IllegalArgumentException e) {
3147 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3148 + "is inactive, ignoring unregister.");
3149 // If the subscription is no longer active, just return, since the callback will already
3150 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
3154 }
3155
3156 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003157 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3158 boolean isProvisioned) {
3159 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3160 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3161 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3162 }
3163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3164 "setProvisioningStatusForCapability");
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3168 Phone phone = getPhone(subId);
3169 if (phone == null) {
3170 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3171 + subId);
3172 return;
3173 }
3174 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3175 return;
3176 }
3177
3178 // this capability requires provisioning, route to the correct API.
3179 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3180 switch (capability) {
3181 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3182 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3183 ims.setVolteProvisioned(isProvisioned);
3184 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3185 ims.setWfcProvisioned(isProvisioned);
3186 }
3187 break;
3188 }
3189 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3190 // There is currently no difference in VT provisioning type.
3191 ims.setVtProvisioned(isProvisioned);
3192 break;
3193 }
3194 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3195 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3196 // change the capability of the feature instead if needed.
3197 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3198 == isProvisioned) {
3199 // No change in provisioning.
3200 return;
3201 }
3202 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3203 try {
3204 ims.changeMmTelCapability(capability, tech, isProvisioned);
3205 } catch (ImsException e) {
3206 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3207 + ", Exception" + e.getMessage());
3208 }
3209 break;
3210 }
3211 default: {
3212 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3213 + capability + "', which does not require provisioning.");
3214 }
3215 }
3216
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
3220 }
3221
3222 @Override
3223 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3224 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3225 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3226 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3227 }
3228 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3232 Phone phone = getPhone(subId);
3233 if (phone == null) {
3234 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3235 + subId);
3236 // We will fail with "true" as the provisioning status because this is the default
3237 // if we do not require provisioning.
3238 return true;
3239 }
3240
3241 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3242 return true;
3243 }
3244
3245 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3246 switch (capability) {
3247 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3248 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3249 return ims.isVolteProvisionedOnDevice();
3250 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3251 return ims.isWfcProvisionedOnDevice();
3252 }
3253 // This should never happen, since we are checking tech above to make sure it
3254 // is either LTE or IWLAN.
3255 throw new IllegalArgumentException("Invalid radio technology for voice "
3256 + "capability.");
3257 }
3258 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3259 // There is currently no difference in VT provisioning type.
3260 return ims.isVtProvisionedOnDevice();
3261 }
3262 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3263 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3264 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3265 }
3266 default: {
3267 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3268 + capability + "', which does not require provisioning.");
3269 }
3270 }
3271
3272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
3275 }
3276
3277 @Override
3278 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3279 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3280 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3281 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3282 }
3283 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3284 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3285 return (provisionedBits & capability) > 0;
3286 }
3287
3288 @Override
3289 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3290 boolean isProvisioned) {
3291 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3292 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3293 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3294 }
3295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3296 "setProvisioningStatusForCapability");
3297 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3298 // If the current provisioning status for capability already matches isProvisioned,
3299 // do nothing.
3300 if (((provisionedBits & capability) > 0) == isProvisioned) {
3301 return;
3302 }
3303 if (isProvisioned) {
3304 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3305 } else {
3306 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3307 }
3308 }
3309
3310 /**
3311 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3312 * technology. The bitfield should mirror the bitfield defined by
3313 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3314 */
3315 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3316 String key = getMmTelProvisioningKey(subId, tech);
3317 // Default is no capabilities are provisioned.
3318 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3319 }
3320
3321 /**
3322 * Sets the MmTel capability provisioning bitfield (defined by
3323 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3324 * technology specified.
3325 *
3326 * Note: This is a synchronous command and should not be called on UI thread.
3327 */
3328 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3329 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3330 String key = getMmTelProvisioningKey(subId, tech);
3331 editor.putInt(key, newField);
3332 editor.commit();
3333 }
3334
3335 private static String getMmTelProvisioningKey(int subId, int tech) {
3336 // resulting key is provision_ims_mmtel_{subId}_{tech}
3337 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3338 }
3339
3340 /**
3341 * Query CarrierConfig to see if the specified capability requires provisioning for the
3342 * carrier associated with the subscription id.
3343 */
3344 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3345 int capability) {
3346 CarrierConfigManager configManager = new CarrierConfigManager(context);
3347 PersistableBundle c = configManager.getConfigForSubId(subId);
3348 boolean requireUtProvisioning = c.getBoolean(
3349 // By default, this config is true (even if there is no SIM). We also check to make
3350 // sure the subscription needs provisioning here, so we do not need to check for
3351 // the no-SIM case, where we would normally shortcut this to false.
3352 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3353 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3354 false);
3355 boolean requireVoiceVtProvisioning = c.getBoolean(
3356 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3357
3358 // First check to make sure that the capability requires provisioning.
3359 switch (capability) {
3360 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3361 // intentional fallthrough
3362 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3363 if (requireVoiceVtProvisioning) {
3364 // Voice and Video requires provisioning
3365 return true;
3366 }
3367 break;
3368 }
3369 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3370 if (requireUtProvisioning) {
3371 // UT requires provisioning
3372 return true;
3373 }
3374 break;
3375 }
3376 }
3377 return false;
3378 }
3379
3380 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003381 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003382 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3383 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3384 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003385 enforceReadPrivilegedPermission("getImsProvisioningInt");
3386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003389 int slotId = getSlotIndex(subId);
3390 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3391 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3392 + subId + "' for key:" + key);
3393 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3394 }
3395 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003396 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003397 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3398 + subId + "' for key:" + key);
3399 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
3403 }
3404
3405 @Override
3406 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003407 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3408 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3409 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003410 enforceReadPrivilegedPermission("getImsProvisioningString");
3411 final long identity = Binder.clearCallingIdentity();
3412 try {
3413 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003414 int slotId = getSlotIndex(subId);
3415 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3416 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3417 + subId + "' for key:" + key);
3418 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3419 }
3420 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003421 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003422 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3423 + subId + "' for key:" + key);
3424 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
3428 }
3429
3430 @Override
3431 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003432 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3433 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3434 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3436 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003440 int slotId = getSlotIndex(subId);
3441 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3442 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3443 + subId + "' for key:" + key);
3444 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3445 }
3446 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003447 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003448 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3449 + "' for key:" + key);
3450 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003451 } finally {
3452 Binder.restoreCallingIdentity(identity);
3453 }
3454 }
3455
3456 @Override
3457 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003458 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3459 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3460 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3462 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003466 int slotId = getSlotIndex(subId);
3467 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3468 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3469 + subId + "' for key:" + key);
3470 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3471 }
3472 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003473 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003474 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3475 + "' for key:" + key);
3476 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003477 } finally {
3478 Binder.restoreCallingIdentity(identity);
3479 }
3480 }
3481
Brad Ebinger4c460712018-10-01 10:40:55 -07003482 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3483 int slotId = SubscriptionManager.getSlotIndex(subId);
3484 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003485 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003486 }
3487 return slotId;
3488 }
3489
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003490 private int getSlotIndex(int subId) {
3491 int slotId = SubscriptionManager.getSlotIndex(subId);
3492 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3493 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3494 }
3495 return slotId;
3496 }
3497
Wink Saville36469e72014-06-11 15:17:00 -07003498 /**
3499 * Returns the network type for a subId
3500 */
3501 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003502 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003504 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003505 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3506 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003507
Malcolm Chend965c8b2018-02-28 15:00:40 -08003508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 final Phone phone = getPhone(subId);
3511 if (phone != null) {
3512 return phone.getServiceState().getDataNetworkType();
3513 } else {
3514 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3515 }
3516 } finally {
3517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519 }
3520
3521 /**
3522 * Returns the data network type
3523 */
3524 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003525 public int getDataNetworkType(String callingPackage) {
3526 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003527 }
3528
3529 /**
3530 * Returns the data network type for a subId
3531 */
3532 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003533 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003535 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003536 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3537 }
3538
Malcolm Chend965c8b2018-02-28 15:00:40 -08003539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 final Phone phone = getPhone(subId);
3542 if (phone != null) {
3543 return phone.getServiceState().getDataNetworkType();
3544 } else {
3545 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3546 }
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003550 }
3551
3552 /**
Wink Saville36469e72014-06-11 15:17:00 -07003553 * Returns the Voice network type for a subId
3554 */
3555 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003556 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003558 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003559 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3560 }
3561
Malcolm Chend965c8b2018-02-28 15:00:40 -08003562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 final Phone phone = getPhone(subId);
3565 if (phone != null) {
3566 return phone.getServiceState().getVoiceNetworkType();
3567 } else {
3568 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3569 }
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003573 }
3574
3575 /**
3576 * @return true if a ICC card is present
3577 */
3578 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003579 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003580 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3581 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003582 }
3583
3584 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003585 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003586 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003587 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003588 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003589 final long identity = Binder.clearCallingIdentity();
3590 try {
3591 final Phone phone = PhoneFactory.getPhone(slotIndex);
3592 if (phone != null) {
3593 return phone.getIccCard().hasIccCard();
3594 } else {
3595 return false;
3596 }
3597 } finally {
3598 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003600 }
3601
3602 /**
3603 * Return if the current radio is LTE on CDMA. This
3604 * is a tri-state return value as for a period of time
3605 * the mode may be unknown.
3606 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003607 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003608 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003609 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003611 @Override
3612 public int getLteOnCdmaMode(String callingPackage) {
3613 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003614 }
3615
Sanket Padawe356d7632015-06-22 14:03:32 -07003616 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003617 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003619 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003620 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3621 }
3622
Malcolm Chend965c8b2018-02-28 15:00:40 -08003623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 final Phone phone = getPhone(subId);
3626 if (phone == null) {
3627 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3628 } else {
3629 return phone.getLteOnCdmaMode();
3630 }
3631 } finally {
3632 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003633 }
Wink Saville36469e72014-06-11 15:17:00 -07003634 }
3635
Wink Saville36469e72014-06-11 15:17:00 -07003636 /**
3637 * {@hide}
3638 * Returns Default subId, 0 in the case of single standby.
3639 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003640 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003641 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003642 }
3643
Shishir Agrawala9f32182016-04-12 12:00:16 -07003644 private int getSlotForDefaultSubscription() {
3645 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3646 }
3647
Wink Savilleb564aae2014-10-23 10:18:09 -07003648 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003649 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003650 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003651
Pengquan Meng466e2482018-09-21 15:54:48 -07003652 private boolean isActiveSubscription(int subId) {
3653 return mSubscriptionController.isActiveSubId(subId);
3654 }
3655
Ihab Awadf2177b72013-11-25 13:33:23 -08003656 /**
3657 * @see android.telephony.TelephonyManager.WifiCallingChoices
3658 */
3659 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003662 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003663 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3664 getWhenToMakeWifiCallsDefaultPreference());
3665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003668 }
3669
3670 /**
3671 * @see android.telephony.TelephonyManager.WifiCallingChoices
3672 */
3673 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003677 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003678 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003682 }
3683
Sailesh Nepald1e68152013-12-12 19:08:02 -08003684 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003685 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003686 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003687 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003688
Jordan Liu73b078d2019-02-28 12:03:40 -08003689 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3690 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3691 if (phoneId == -1) {
3692 throw new IllegalArgumentException("Given slot index: " + slotIndex
3693 + " does not correspond to an active phone");
3694 }
3695 return PhoneFactory.getPhone(phoneId);
3696 }
3697
Shishir Agrawal566b7612013-10-28 14:41:00 -07003698 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003699 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3700 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3702 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003703 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003704 if (DBG) {
3705 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3706 }
3707 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3708 p2);
3709 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003710
Jordan Liu73b078d2019-02-28 12:03:40 -08003711
3712 @Override
3713 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3714 int slotIndex, String callingPackage, String aid, int p2) {
3715 enforceModifyPermission();
3716 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3717 if (DBG) {
3718 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3719 }
3720 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3721 callingPackage, aid, p2);
3722 }
3723
3724 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3725 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003726 final long identity = Binder.clearCallingIdentity();
3727 try {
3728 if (TextUtils.equals(ISDR_AID, aid)) {
3729 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003730 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3731 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003732 if (bestComponent == null
3733 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3734 loge("The calling package is not allowed to access ISD-R.");
3735 throw new SecurityException(
3736 "The calling package is not allowed to access ISD-R.");
3737 }
Derek Tan740e1672017-06-27 14:56:27 -07003738 }
Derek Tan740e1672017-06-27 14:56:27 -07003739
Malcolm Chend965c8b2018-02-28 15:00:40 -08003740 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003741 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3742 null /* workSource */);
3743 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003744 return response;
3745 } finally {
3746 Binder.restoreCallingIdentity(identity);
3747 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003748 }
3749
3750 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003751 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3753 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003754 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3755 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3756 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003757
Jordan Liu73b078d2019-02-28 12:03:40 -08003758 @Override
3759 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3760 enforceModifyPermission();
3761 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3762 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3763 channel);
3764 }
3765
3766 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003767 final long identity = Binder.clearCallingIdentity();
3768 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003769 if (channel < 0) {
3770 return false;
3771 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003772 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3773 null /* workSource */);
3774 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003775 return success;
3776 } finally {
3777 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003778 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003779 }
3780
3781 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003782 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003783 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3785 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003786 if (DBG) {
3787 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3788 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3789 + p3 + " data=" + data);
3790 }
3791 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3792 command, p1, p2, p3, data);
3793 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003794
Jordan Liu73b078d2019-02-28 12:03:40 -08003795 @Override
3796 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3797 int command, int p1, int p2, int p3, String data) {
3798 enforceModifyPermission();
3799 if (DBG) {
3800 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3801 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3802 + p3 + " data=" + data);
3803 }
3804 return iccTransmitApduLogicalChannelWithPermission(
3805 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3806 data);
3807 }
3808
3809 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3810 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003811 final long identity = Binder.clearCallingIdentity();
3812 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003813 if (channel < 0) {
3814 return "";
3815 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003816
Malcolm Chend965c8b2018-02-28 15:00:40 -08003817 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003818 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3819 null /* workSource */);
3820 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003821
Malcolm Chend965c8b2018-02-28 15:00:40 -08003822 // Append the returned status code to the end of the response payload.
3823 String s = Integer.toHexString(
3824 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3825 if (response.payload != null) {
3826 s = IccUtils.bytesToHexString(response.payload) + s;
3827 }
3828 return s;
3829 } finally {
3830 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003832 }
Jake Hambye994d462014-02-03 13:10:13 -08003833
Evan Charltonc66da362014-05-16 14:06:40 -07003834 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003835 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3836 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3838 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003840 if (DBG) {
3841 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3842 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3843 }
3844 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3845 cla, command, p1, p2, p3, data);
3846 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003847
Jordan Liu73b078d2019-02-28 12:03:40 -08003848 @Override
3849 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3850 int command, int p1, int p2, int p3, String data) {
3851 enforceModifyPermission();
3852 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3853 if (DBG) {
3854 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3855 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3856 + " data=" + data);
3857 }
3858
3859 return iccTransmitApduBasicChannelWithPermission(
3860 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3861 p2, p3, data);
3862 }
3863
3864 // open APDU basic channel assuming the caller has sufficient permissions
3865 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3866 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003867 final long identity = Binder.clearCallingIdentity();
3868 try {
3869 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3870 && TextUtils.equals(ISDR_AID, data)) {
3871 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003872 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3873 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003874 if (bestComponent == null
3875 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3876 loge("The calling package is not allowed to select ISD-R.");
3877 throw new SecurityException(
3878 "The calling package is not allowed to select ISD-R.");
3879 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003880 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003881
Malcolm Chend965c8b2018-02-28 15:00:40 -08003882 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003883 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3884 null /* workSource */);
3885 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003886
Malcolm Chend965c8b2018-02-28 15:00:40 -08003887 // Append the returned status code to the end of the response payload.
3888 String s = Integer.toHexString(
3889 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3890 if (response.payload != null) {
3891 s = IccUtils.bytesToHexString(response.payload) + s;
3892 }
3893 return s;
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003896 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003897 }
3898
3899 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003900 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003901 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3903 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003904
Malcolm Chend965c8b2018-02-28 15:00:40 -08003905 final long identity = Binder.clearCallingIdentity();
3906 try {
3907 if (DBG) {
3908 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3909 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3910 }
3911
3912 IccIoResult response =
3913 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3914 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3915 subId);
3916
3917 if (DBG) {
3918 log("Exchange SIM_IO [R]" + response);
3919 }
3920
3921 byte[] result = null;
3922 int length = 2;
3923 if (response.payload != null) {
3924 length = 2 + response.payload.length;
3925 result = new byte[length];
3926 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3927 } else {
3928 result = new byte[length];
3929 }
3930
3931 result[length - 1] = (byte) response.sw2;
3932 result[length - 2] = (byte) response.sw1;
3933 return result;
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003936 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003937 }
3938
Nathan Haroldb3014052017-01-25 15:57:32 -08003939 /**
3940 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3941 * on a particular subscription
3942 */
sqianb6e41952018-03-12 14:54:01 -07003943 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3945 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3946 return null;
3947 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003948
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 if (appType != TelephonyManager.APPTYPE_USIM
3952 && appType != TelephonyManager.APPTYPE_SIM) {
3953 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3954 return null;
3955 }
3956 Object response = sendRequest(
3957 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3958 if (response instanceof String[]) {
3959 return (String[]) response;
3960 }
3961 // Response is an Exception of some kind,
3962 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003963 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003964 } finally {
3965 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003966 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003967 }
3968
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003969 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003970 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3972 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003973
Malcolm Chend965c8b2018-02-28 15:00:40 -08003974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3977 if (response.payload == null) {
3978 return "";
3979 }
Evan Charltonc66da362014-05-16 14:06:40 -07003980
Malcolm Chend965c8b2018-02-28 15:00:40 -08003981 // Append the returned status code to the end of the response payload.
3982 String s = Integer.toHexString(
3983 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3984 s = IccUtils.bytesToHexString(response.payload) + s;
3985 return s;
3986 } finally {
3987 Binder.restoreCallingIdentity(identity);
3988 }
Evan Charltonc66da362014-05-16 14:06:40 -07003989 }
3990
Jake Hambye994d462014-02-03 13:10:13 -08003991 /**
3992 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3993 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3994 *
3995 * @param itemID the ID of the item to read
3996 * @return the NV item as a String, or null on error.
3997 */
3998 @Override
3999 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07004000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4002 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004003
4004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004007 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004008 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4009 return value;
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
Jake Hambye994d462014-02-03 13:10:13 -08004013 }
4014
4015 /**
4016 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4017 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4018 *
4019 * @param itemID the ID of the item to read
4020 * @param itemValue the value to write, as a String
4021 * @return true on success; false on any failure
4022 */
4023 @Override
4024 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004025 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4027 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004028
4029 final long identity = Binder.clearCallingIdentity();
4030 try {
4031 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4032 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004033 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004034 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4035 return success;
4036 } finally {
4037 Binder.restoreCallingIdentity(identity);
4038 }
Jake Hambye994d462014-02-03 13:10:13 -08004039 }
4040
4041 /**
4042 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4043 * Used for device configuration by some CDMA operators.
4044 *
4045 * @param preferredRoamingList byte array containing the new PRL
4046 * @return true on success; false on any failure
4047 */
4048 @Override
4049 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4051 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004052
4053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4056 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4057 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4058 return success;
4059 } finally {
4060 Binder.restoreCallingIdentity(identity);
4061 }
Jake Hambye994d462014-02-03 13:10:13 -08004062 }
4063
4064 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004065 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004066 * Used for device configuration by some CDMA operators.
4067 *
chen xu1cc0abe2018-10-26 17:39:23 -07004068 * @param slotIndex - device slot.
4069 *
Jake Hambye994d462014-02-03 13:10:13 -08004070 * @return true on success; false on any failure
4071 */
4072 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004073 public boolean resetModemConfig(int slotIndex) {
4074 Phone phone = PhoneFactory.getPhone(slotIndex);
4075 if (phone != null) {
4076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4077 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004078
chen xu1cc0abe2018-10-26 17:39:23 -07004079 final long identity = Binder.clearCallingIdentity();
4080 try {
4081 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4082 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4083 return success;
4084 } finally {
4085 Binder.restoreCallingIdentity(identity);
4086 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004087 }
chen xu1cc0abe2018-10-26 17:39:23 -07004088 return false;
4089 }
4090
4091 /**
4092 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4093 *
4094 * @param slotIndex - device slot.
4095 *
4096 * @return true on success; false on any failure
4097 */
4098 @Override
4099 public boolean rebootModem(int slotIndex) {
4100 Phone phone = PhoneFactory.getPhone(slotIndex);
4101 if (phone != null) {
4102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4103 mApp, phone.getSubId(), "rebootModem");
4104
4105 final long identity = Binder.clearCallingIdentity();
4106 try {
4107 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4108 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4109 return success;
4110 } finally {
4111 Binder.restoreCallingIdentity(identity);
4112 }
4113 }
4114 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004115 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004116
Svet Ganovb320e182015-04-16 12:30:10 -07004117 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004118 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004120 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004121 return new String[0];
4122 }
4123
Malcolm Chend965c8b2018-02-28 15:00:40 -08004124 final long identity = Binder.clearCallingIdentity();
4125 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004126 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
Wink Saville36469e72014-06-11 15:17:00 -07004130 }
4131
Brad Ebinger51f743a2017-01-23 13:50:20 -08004132 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004133 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4134 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004135 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004136 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004137 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004138
4139 final long identity = Binder.clearCallingIdentity();
4140 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004141 ImsResolver resolver = PhoneFactory.getImsResolver();
4142 if (resolver == null) {
4143 // may happen if the device does not support IMS.
4144 return;
4145 }
4146 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004147 } finally {
4148 Binder.restoreCallingIdentity(identity);
4149 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004150 }
4151
4152 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004153 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4154 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004155 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004156 public void disableIms(int slotId) {
4157 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004158
4159 final long identity = Binder.clearCallingIdentity();
4160 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004161 ImsResolver resolver = PhoneFactory.getImsResolver();
4162 if (resolver == null) {
4163 // may happen if the device does not support IMS.
4164 return;
4165 }
4166 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004167 } finally {
4168 Binder.restoreCallingIdentity(identity);
4169 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004170 }
4171
4172 /**
4173 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4174 * feature or {@link null} if the service is not available. If the feature is available, the
4175 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4176 */
4177 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004178 IImsServiceFeatureCallback callback) {
4179 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004180
4181 final long identity = Binder.clearCallingIdentity();
4182 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004183 ImsResolver resolver = PhoneFactory.getImsResolver();
4184 if (resolver == null) {
4185 // may happen if the device does not support IMS.
4186 return null;
4187 }
4188 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004192 }
4193
4194 /**
4195 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4196 * feature during emergency calling or {@link null} if the service is not available. If the
4197 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4198 * listener for feature updates.
4199 */
4200 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4201 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004202
4203 final long identity = Binder.clearCallingIdentity();
4204 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004205 ImsResolver resolver = PhoneFactory.getImsResolver();
4206 if (resolver == null) {
4207 // may happen if the device does not support IMS.
4208 return null;
4209 }
4210 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004211 } finally {
4212 Binder.restoreCallingIdentity(identity);
4213 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004214 }
4215
Brad Ebinger5f64b052017-12-14 14:26:15 -08004216 /**
4217 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004218 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004219 */
4220 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4221 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004222
4223 final long identity = Binder.clearCallingIdentity();
4224 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004225 ImsResolver resolver = PhoneFactory.getImsResolver();
4226 if (resolver == null) {
4227 // may happen if the device does not support IMS.
4228 return null;
4229 }
4230 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004231 } finally {
4232 Binder.restoreCallingIdentity(identity);
4233 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004234 }
4235
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004236 /**
4237 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004238 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004239 */
4240 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4241 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004242
4243 final long identity = Binder.clearCallingIdentity();
4244 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004245 ImsResolver resolver = PhoneFactory.getImsResolver();
4246 if (resolver == null) {
4247 // may happen if the device does not support IMS.
4248 return null;
4249 }
4250 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004254 }
4255
Brad Ebinger884c07b2018-02-15 16:17:40 -08004256 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004257 * Sets the ImsService Package Name that Telephony will bind to.
4258 *
4259 * @param slotId the slot ID that the ImsService should bind for.
4260 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4261 * ImsService is the device default ImsService.
4262 * @param packageName The package name of the application that contains the ImsService to bind
4263 * to.
4264 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4265 * @hide
4266 */
4267 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004268 int[] subIds = SubscriptionManager.getSubId(slotId);
4269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4270 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4271 "setImsService");
4272
Malcolm Chend965c8b2018-02-28 15:00:40 -08004273 final long identity = Binder.clearCallingIdentity();
4274 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004275 ImsResolver resolver = PhoneFactory.getImsResolver();
4276 if (resolver == null) {
4277 // may happen if the device does not support IMS.
4278 return false;
4279 }
4280 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4281 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004285 }
4286
4287 /**
4288 * Return the ImsService configuration.
4289 *
4290 * @param slotId The slot that the ImsService is associated with.
4291 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4292 * the device default.
4293 * @return the package name of the ImsService configuration.
4294 */
4295 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004296 int[] subIds = SubscriptionManager.getSubId(slotId);
4297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4298 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4299 "getImsService");
4300
Malcolm Chend965c8b2018-02-28 15:00:40 -08004301 final long identity = Binder.clearCallingIdentity();
4302 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004303 ImsResolver resolver = PhoneFactory.getImsResolver();
4304 if (resolver == null) {
4305 // may happen if the device does not support IMS.
4306 return "";
4307 }
4308 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004309 } finally {
4310 Binder.restoreCallingIdentity(identity);
4311 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004312 }
4313
Wink Saville36469e72014-06-11 15:17:00 -07004314 public void setImsRegistrationState(boolean registered) {
4315 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004316
4317 final long identity = Binder.clearCallingIdentity();
4318 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004319 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
Wink Saville36469e72014-06-11 15:17:00 -07004323 }
4324
4325 /**
Stuart Scott54788802015-03-30 13:18:01 -07004326 * Set the network selection mode to automatic.
4327 *
4328 */
4329 @Override
4330 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4332 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004333
Pengquan Meng466e2482018-09-21 15:54:48 -07004334 if (!isActiveSubscription(subId)) {
4335 return;
4336 }
4337
Malcolm Chend965c8b2018-02-28 15:00:40 -08004338 final long identity = Binder.clearCallingIdentity();
4339 try {
4340 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4341 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
Stuart Scott54788802015-03-30 13:18:01 -07004345 }
4346
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004347 /**
4348 * Ask the radio to connect to the input network and change selection mode to manual.
4349 *
4350 * @param subId the id of the subscription.
4351 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4352 * the operator to attach to.
4353 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4354 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4355 * normal network selection next time.
4356 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004357 */
4358 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004359 public boolean setNetworkSelectionModeManual(
4360 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4362 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004363
4364 if (!isActiveSubscription(subId)) {
4365 return false;
4366 }
4367
Malcolm Chend965c8b2018-02-28 15:00:40 -08004368 final long identity = Binder.clearCallingIdentity();
4369 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004370 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004371 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004372 if (DBG) {
4373 log("setNetworkSelectionModeManual: subId: " + subId
4374 + " operator: " + operatorInfo);
4375 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004376 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004380 }
4381
4382 /**
4383 * Scans for available networks.
4384 */
4385 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004386 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4388 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004389 LocationAccessPolicy.LocationPermissionResult locationResult =
4390 LocationAccessPolicy.checkLocationPermission(mApp,
4391 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4392 .setCallingPackage(callingPackage)
4393 .setCallingPid(Binder.getCallingPid())
4394 .setCallingUid(Binder.getCallingUid())
4395 .setMethod("getCellNetworkScanResults")
4396 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4397 .build());
4398 switch (locationResult) {
4399 case DENIED_HARD:
4400 throw new SecurityException("Not allowed to access scan results -- location");
4401 case DENIED_SOFT:
4402 return null;
4403 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004404
Pengquan Meng0c05b502018-09-06 09:59:22 -07004405 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004406 try {
4407 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004408 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004409 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004413 }
4414
4415 /**
yinxub1bed742017-04-17 11:45:04 -07004416 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004417 *
yinxub1bed742017-04-17 11:45:04 -07004418 * @param subId id of the subscription
4419 * @param request contains the radio access networks with bands/channels to scan
4420 * @param messenger callback messenger for scan results or errors
4421 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004422 * @return the id of the requested scan which can be used to stop the scan.
4423 */
4424 @Override
4425 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004426 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4428 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004429 LocationAccessPolicy.LocationPermissionResult locationResult =
4430 LocationAccessPolicy.checkLocationPermission(mApp,
4431 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4432 .setCallingPackage(callingPackage)
4433 .setCallingPid(Binder.getCallingPid())
4434 .setCallingUid(Binder.getCallingUid())
4435 .setMethod("requestNetworkScan")
4436 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4437 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004438 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4439 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4440 if (e != null) {
4441 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4442 throw e;
4443 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004444 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004445 return TelephonyScanManager.INVALID_SCAN_ID;
4446 }
4447 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004448 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004449 return mNetworkScanRequestTracker.startNetworkScan(
4450 request, messenger, binder, getPhone(subId),
4451 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004452 }
4453
Hall Liub2ac8ef2019-02-28 15:56:23 -08004454 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4455 NetworkScanRequest request) {
4456 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4457 != PERMISSION_GRANTED) {
4458 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4459 + " without location access.");
4460 }
4461
4462 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4463 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004464 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4465 return new SecurityException("Specific channels must not be"
4466 + " scanned without location access.");
4467 }
4468 }
4469 }
4470
4471 List<String> allowedMccMncs =
4472 NetworkScanRequestTracker.getAllowedMccMncsForLocationRestrictedScan(mApp);
4473 for (String mccmnc : request.getPlmns()) {
4474 if (!allowedMccMncs.contains(mccmnc)) {
4475 return new SecurityException("Requested mccmnc " + mccmnc + " is not known to the"
4476 + " device and cannot be scanned for without location access.");
4477 }
4478 }
4479
4480 return null;
4481 }
4482
yinxu504e1392017-04-12 16:03:22 -07004483 /**
4484 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004485 *
4486 * @param subId id of the subscription
4487 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004488 */
4489 @Override
4490 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4492 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004493
4494 final long identity = Binder.clearCallingIdentity();
4495 try {
4496 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
yinxu504e1392017-04-12 16:03:22 -07004500 }
4501
4502 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004503 * Get the calculated preferred network type.
4504 * Used for debugging incorrect network type.
4505 *
4506 * @return the preferred network type, defined in RILConstants.java.
4507 */
4508 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004509 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004510 final Phone defaultPhone = getDefaultPhone();
4511 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4512 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004513 return RILConstants.PREFERRED_NETWORK_MODE;
4514 }
4515
Malcolm Chend965c8b2018-02-28 15:00:40 -08004516 final long identity = Binder.clearCallingIdentity();
4517 try {
4518 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004519 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
Junda Liu84d15a22014-07-02 11:21:04 -07004523 }
4524
4525 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004526 * Get the preferred network type.
4527 * Used for device configuration by some CDMA operators.
4528 *
4529 * @return the preferred network type, defined in RILConstants.java.
4530 */
4531 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004532 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004533 TelephonyPermissions
4534 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4535 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004536
4537 final long identity = Binder.clearCallingIdentity();
4538 try {
4539 if (DBG) log("getPreferredNetworkType");
4540 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4541 int networkType = (result != null ? result[0] : -1);
4542 if (DBG) log("getPreferredNetworkType: " + networkType);
4543 return networkType;
4544 } finally {
4545 Binder.restoreCallingIdentity(identity);
4546 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004547 }
4548
4549 /**
4550 * Set the preferred network type.
4551 * Used for device configuration by some CDMA operators.
4552 *
4553 * @param networkType the preferred network type, defined in RILConstants.java.
4554 * @return true on success; false on any failure.
4555 */
4556 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004557 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4559 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004560
4561 final long identity = Binder.clearCallingIdentity();
4562 try {
4563 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4564 Boolean success = (Boolean) sendRequest(
4565 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4566 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4567 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004568 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004569 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4570 }
4571 return success;
4572 } finally {
4573 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004574 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004575 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004576
4577 /**
Miaoa84611c2019-03-15 09:21:10 +08004578 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004579 *
Miaoa84611c2019-03-15 09:21:10 +08004580 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004581 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004582 * @hide
4583 */
4584 @Override
Miaoa84611c2019-03-15 09:21:10 +08004585 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004586 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004587 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004588 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004589 try {
Miaoa84611c2019-03-15 09:21:10 +08004590 if (phone != null) {
4591 return phone.hasMatchedTetherApnSetting();
4592 } else {
4593 return false;
4594 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004595 } finally {
4596 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004597 }
Junda Liu475951f2014-11-07 16:45:03 -08004598 }
4599
4600 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004601 * Set mobile data enabled
4602 * Used by the user through settings etc to turn on/off mobile data
4603 *
4604 * @param enable {@code true} turn turn data on, else {@code false}
4605 */
4606 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004607 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4609 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004610
4611 final long identity = Binder.clearCallingIdentity();
4612 try {
4613 int phoneId = mSubscriptionController.getPhoneId(subId);
4614 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4615 Phone phone = PhoneFactory.getPhone(phoneId);
4616 if (phone != null) {
4617 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004618 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004619 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004620 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004621 }
4622 } finally {
4623 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004624 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004625 }
4626
4627 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004628 * Get the user enabled state of Mobile Data.
4629 *
4630 * TODO: remove and use isUserDataEnabled.
4631 * This can't be removed now because some vendor codes
4632 * calls through ITelephony directly while they should
4633 * use TelephonyManager.
4634 *
4635 * @return true on enabled
4636 */
4637 @Override
4638 public boolean getDataEnabled(int subId) {
4639 return isUserDataEnabled(subId);
4640 }
4641
4642 /**
4643 * Get whether mobile data is enabled per user setting.
4644 *
4645 * There are other factors deciding whether mobile data is actually enabled, but they are
4646 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004647 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004648 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004649 *
4650 * @return {@code true} if data is enabled else {@code false}
4651 */
4652 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004653 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004654 try {
4655 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4656 null);
4657 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4659 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004660 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004661
4662 final long identity = Binder.clearCallingIdentity();
4663 try {
4664 int phoneId = mSubscriptionController.getPhoneId(subId);
4665 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4666 Phone phone = PhoneFactory.getPhone(phoneId);
4667 if (phone != null) {
4668 boolean retVal = phone.isUserDataEnabled();
4669 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4670 return retVal;
4671 } else {
4672 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4673 return false;
4674 }
4675 } finally {
4676 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004677 }
4678 }
4679
4680 /**
4681 * Get whether mobile data is enabled.
4682 *
4683 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4684 * whether mobile data is actually enabled.
4685 *
4686 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4687 *
4688 * @return {@code true} if data is enabled else {@code false}
4689 */
4690 @Override
4691 public boolean isDataEnabled(int subId) {
4692 try {
4693 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4694 null);
4695 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4697 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004698 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004699
4700 final long identity = Binder.clearCallingIdentity();
4701 try {
4702 int phoneId = mSubscriptionController.getPhoneId(subId);
4703 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4704 Phone phone = PhoneFactory.getPhone(phoneId);
4705 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004706 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004707 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4708 return retVal;
4709 } else {
4710 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4711 return false;
4712 }
4713 } finally {
4714 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004715 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004716 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004717
4718 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004719 public int getCarrierPrivilegeStatus(int subId) {
4720 final Phone phone = getPhone(subId);
4721 if (phone == null) {
4722 loge("getCarrierPrivilegeStatus: Invalid subId");
4723 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4724 }
4725 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004726 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004727 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004728 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4729 }
4730 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004731 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004732 }
Junda Liu29340342014-07-10 15:23:27 -07004733
4734 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004735 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4736 final Phone phone = getPhone(subId);
4737 if (phone == null) {
4738 loge("getCarrierPrivilegeStatus: Invalid subId");
4739 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4740 }
4741 UiccProfile profile =
4742 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4743 if (profile == null) {
4744 loge("getCarrierPrivilegeStatus: No UICC");
4745 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4746 }
4747 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4748 }
4749
4750 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004751 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004752 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004753 if (TextUtils.isEmpty(pkgName))
4754 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004755 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004756 if (card == null) {
4757 loge("checkCarrierPrivilegesForPackage: No UICC");
4758 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4759 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004760 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4761 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004762 }
4763
4764 @Override
4765 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004766 if (TextUtils.isEmpty(pkgName))
4767 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004768 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4769 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4770 UiccCard card = UiccController.getInstance().getUiccCard(i);
4771 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004772 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004773 continue;
4774 }
4775
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004776 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004777 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4778 break;
4779 }
4780 }
4781
4782 return result;
Junda Liu29340342014-07-10 15:23:27 -07004783 }
Derek Tan89e89d42014-07-08 17:00:10 -07004784
4785 @Override
Junda Liue64de782015-04-16 17:19:16 -07004786 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4787 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4788 loge("phoneId " + phoneId + " is not valid.");
4789 return null;
4790 }
4791 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004792 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004793 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004794 return null ;
4795 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004796 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004797 }
4798
Amith Yamasani6e118872016-02-19 12:53:51 -08004799 @Override
4800 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004801 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004802 List<String> privilegedPackages = new ArrayList<>();
4803 List<PackageInfo> packages = null;
4804 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4805 UiccCard card = UiccController.getInstance().getUiccCard(i);
4806 if (card == null) {
4807 // No UICC in that slot.
4808 continue;
4809 }
4810 if (card.hasCarrierPrivilegeRules()) {
4811 if (packages == null) {
4812 // Only check packages in user 0 for now
4813 packages = pm.getInstalledPackagesAsUser(
4814 PackageManager.MATCH_DISABLED_COMPONENTS
4815 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4816 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4817 }
4818 for (int p = packages.size() - 1; p >= 0; p--) {
4819 PackageInfo pkgInfo = packages.get(p);
4820 if (pkgInfo != null && pkgInfo.packageName != null
4821 && card.getCarrierPrivilegeStatus(pkgInfo)
4822 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4823 privilegedPackages.add(pkgInfo.packageName);
4824 }
4825 }
4826 }
4827 }
4828 return privilegedPackages;
4829 }
4830
Wink Savilleb564aae2014-10-23 10:18:09 -07004831 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004832 final Phone phone = getPhone(subId);
4833 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004834 if (card == null) {
4835 loge("getIccId: No UICC");
4836 return null;
4837 }
4838 String iccId = card.getIccId();
4839 if (TextUtils.isEmpty(iccId)) {
4840 loge("getIccId: ICC ID is null or empty.");
4841 return null;
4842 }
4843 return iccId;
4844 }
4845
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004846 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004847 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4848 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004849 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4850 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004851
Malcolm Chend965c8b2018-02-28 15:00:40 -08004852 final long identity = Binder.clearCallingIdentity();
4853 try {
4854 final String iccId = getIccId(subId);
4855 final Phone phone = getPhone(subId);
4856 if (phone == null) {
4857 return false;
4858 }
4859 final String subscriberId = phone.getSubscriberId();
4860
4861 if (DBG_MERGE) {
4862 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4863 + subscriberId + " to " + number);
4864 }
4865
4866 if (TextUtils.isEmpty(iccId)) {
4867 return false;
4868 }
4869
4870 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4871
4872 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4873 if (alphaTag == null) {
4874 editor.remove(alphaTagPrefKey);
4875 } else {
4876 editor.putString(alphaTagPrefKey, alphaTag);
4877 }
4878
4879 // Record both the line number and IMSI for this ICCID, since we need to
4880 // track all merged IMSIs based on line number
4881 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4882 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4883 if (number == null) {
4884 editor.remove(numberPrefKey);
4885 editor.remove(subscriberPrefKey);
4886 } else {
4887 editor.putString(numberPrefKey, number);
4888 editor.putString(subscriberPrefKey, subscriberId);
4889 }
4890
4891 editor.commit();
4892 return true;
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004895 }
Derek Tan7226c842014-07-02 17:42:23 -07004896 }
4897
4898 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004899 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004900 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004901 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004902 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004903 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004904 return null;
4905 }
Derek Tan97ebb422014-09-05 16:55:38 -07004906
Malcolm Chend965c8b2018-02-28 15:00:40 -08004907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 String iccId = getIccId(subId);
4910 if (iccId != null) {
4911 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4912 if (DBG_MERGE) {
4913 log("getLine1NumberForDisplay returning "
4914 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4915 }
4916 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004917 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004918 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4919 return null;
4920 } finally {
4921 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004922 }
Derek Tan7226c842014-07-02 17:42:23 -07004923 }
4924
4925 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004926 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004927 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004928 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004929 return null;
4930 }
Derek Tan97ebb422014-09-05 16:55:38 -07004931
Malcolm Chend965c8b2018-02-28 15:00:40 -08004932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 String iccId = getIccId(subId);
4935 if (iccId != null) {
4936 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4937 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4938 }
4939 return null;
4940 } finally {
4941 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004942 }
Derek Tan7226c842014-07-02 17:42:23 -07004943 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004944
4945 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004946 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004947 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4948 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004949 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004950 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4951 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004952 return null;
4953 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004954
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004955 final long identity = Binder.clearCallingIdentity();
4956 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004957 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004958 final TelephonyManager tele = TelephonyManager.from(context);
4959 final SubscriptionManager sub = SubscriptionManager.from(context);
4960
4961 // Figure out what subscribers are currently active
4962 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4963 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4964 // the process, where TelephonyManager was instantiated.
4965 // Otherwise AppOps check will fail.
4966
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004967 final int[] subIds = sub.getActiveSubscriptionIdList();
4968 for (int subId : subIds) {
4969 activeSubscriberIds.add(tele.getSubscriberId(subId));
4970 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004971
4972 // First pass, find a number override for an active subscriber
4973 String mergeNumber = null;
4974 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4975 for (String key : prefs.keySet()) {
4976 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4977 final String subscriberId = (String) prefs.get(key);
4978 if (activeSubscriberIds.contains(subscriberId)) {
4979 final String iccId = key.substring(
4980 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4981 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4982 mergeNumber = (String) prefs.get(numberKey);
4983 if (DBG_MERGE) {
4984 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4985 + " for active subscriber " + subscriberId);
4986 }
4987 if (!TextUtils.isEmpty(mergeNumber)) {
4988 break;
4989 }
4990 }
4991 }
4992 }
4993
4994 // Shortcut when no active merged subscribers
4995 if (TextUtils.isEmpty(mergeNumber)) {
4996 return null;
4997 }
4998
4999 // Second pass, find all subscribers under that line override
5000 final ArraySet<String> result = new ArraySet<>();
5001 for (String key : prefs.keySet()) {
5002 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5003 final String number = (String) prefs.get(key);
5004 if (mergeNumber.equals(number)) {
5005 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5006 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5007 final String subscriberId = (String) prefs.get(subscriberKey);
5008 if (!TextUtils.isEmpty(subscriberId)) {
5009 result.add(subscriberId);
5010 }
5011 }
5012 }
5013 }
5014
5015 final String[] resultArray = result.toArray(new String[result.size()]);
5016 Arrays.sort(resultArray);
5017 if (DBG_MERGE) {
5018 Slog.d(LOG_TAG,
5019 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5020 }
5021 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005022 } finally {
5023 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005024 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005025 }
5026
5027 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005028 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005029 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5030 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005031
5032 final long identity = Binder.clearCallingIdentity();
5033 try {
5034 final Phone phone = getPhone(subId);
5035 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005039 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005040
5041 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005042 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005043 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5044 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005045 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005046
5047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 final Phone phone = getPhone(subId);
5050 if (phone == null) {
5051 return false;
5052 }
5053 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5054 cdmaNonRoamingList);
5055 } finally {
5056 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005057 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005058 }
5059
5060 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005061 @Deprecated
5062 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5063 enforceModifyPermission();
5064
5065 int returnValue = 0;
5066 try {
vagdevie435a3e2018-08-15 16:01:53 -07005067 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005068 if(result.exception == null) {
5069 if (result.result != null) {
5070 byte[] responseData = (byte[])(result.result);
5071 if(responseData.length > oemResp.length) {
5072 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5073 responseData.length + "bytes. Buffer Size is " +
5074 oemResp.length + "bytes.");
5075 }
5076 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5077 returnValue = responseData.length;
5078 }
5079 } else {
5080 CommandException ex = (CommandException) result.exception;
5081 returnValue = ex.getCommandError().ordinal();
5082 if(returnValue > 0) returnValue *= -1;
5083 }
5084 } catch (RuntimeException e) {
5085 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5086 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5087 if(returnValue > 0) returnValue *= -1;
5088 }
5089
5090 return returnValue;
5091 }
5092
5093 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005094 public void setRadioCapability(RadioAccessFamily[] rafs) {
5095 try {
5096 ProxyController.getInstance().setRadioCapability(rafs);
5097 } catch (RuntimeException e) {
5098 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5099 }
5100 }
5101
5102 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005103 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005104 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005105 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005106 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005107 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005108 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005109 final long identity = Binder.clearCallingIdentity();
5110 try {
chen xufeeed752018-10-26 14:17:57 -07005111 TelephonyPermissions
5112 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5113 mApp, phone.getSubId(), "getRadioAccessFamily");
5114 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005115 } finally {
5116 Binder.restoreCallingIdentity(identity);
5117 }
chen xufeeed752018-10-26 14:17:57 -07005118 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005119 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005120
5121 @Override
5122 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005123 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005124 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005125
5126 final long identity = Binder.clearCallingIdentity();
5127 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005128 ImsManager.getInstance(defaultPhone.getContext(),
5129 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005130 } finally {
5131 Binder.restoreCallingIdentity(identity);
5132 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005133 }
5134
5135 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005136 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005137 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005138 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005139 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005140 return false;
5141 }
Svet Ganovb320e182015-04-16 12:30:10 -07005142
Malcolm Chend965c8b2018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 // Check the user preference and the system-level IMS setting. Even if the user has
5146 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5147 // In the long run, we may instead need to check if there exists a connection service
5148 // which can support video calling.
5149 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005150 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005151 return imsManager.isVtEnabledByPlatform()
5152 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5153 && imsManager.isVtEnabledByUser();
5154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005157 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005158
Andrew Leea1239f22015-03-02 17:44:07 -08005159 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005160 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5162 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5163 return false;
5164 }
5165
5166 final long identity = Binder.clearCallingIdentity();
5167 try {
5168 CarrierConfigManager configManager =
5169 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005170 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005171 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
Andrew Leea1239f22015-03-02 17:44:07 -08005175 }
5176
5177 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005178 public boolean isWorldPhone(int subId, String callingPackage) {
5179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5180 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5181 return false;
5182 }
5183
5184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 CarrierConfigManager configManager =
5187 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005188 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005189 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5190 } finally {
5191 Binder.restoreCallingIdentity(identity);
5192 }
Andrew Leea1239f22015-03-02 17:44:07 -08005193 }
5194
Andrew Lee9431b832015-03-09 18:46:45 -07005195 @Override
5196 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005197 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005198 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005199 }
5200
5201 @Override
5202 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005203 final long identity = Binder.clearCallingIdentity();
5204 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005205 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005206 } finally {
5207 Binder.restoreCallingIdentity(identity);
5208 }
Andrew Lee9431b832015-03-09 18:46:45 -07005209 }
5210
Hall Liuf6668912018-10-31 17:05:23 -07005211 /**
5212 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5213 * support for the feature and device firmware support.
5214 *
5215 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5216 */
5217 @Override
5218 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005219 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005220 final Phone phone = getPhone(subscriptionId);
5221 if (phone == null) {
5222 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5223 return false;
5224 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005225 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005226 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005227 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5228 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005229 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005230 return isCarrierSupported && isDeviceSupported;
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
Hall Liu98187582018-01-22 19:15:32 -08005234 }
5235
Hall Liuf6668912018-10-31 17:05:23 -07005236 /**
5237 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5238 * both also support RTT.
5239 */
5240 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005241 final long identity = Binder.clearCallingIdentity();
5242 try {
Hall Liuf6668912018-10-31 17:05:23 -07005243 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005244 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005248 }
5249
Sanket Padawe7310cc72015-01-14 09:53:20 -08005250 /**
5251 * Returns the unique device ID of phone, for example, the IMEI for
5252 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5253 *
5254 * <p>Requires Permission:
5255 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5256 */
5257 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005258 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005259 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005260 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005261 return null;
5262 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005263 int subId = phone.getSubId();
5264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5265 mApp, subId, callingPackage, "getDeviceId")) {
5266 return null;
5267 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005268
5269 final long identity = Binder.clearCallingIdentity();
5270 try {
5271 return phone.getDeviceId();
5272 } finally {
5273 Binder.restoreCallingIdentity(identity);
5274 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005275 }
5276
Ping Sunc67b7c22016-03-02 19:16:45 +08005277 /**
5278 * {@hide}
5279 * Returns the IMS Registration Status on a particular subid
5280 *
5281 * @param subId
5282 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005283 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005284 Phone phone = getPhone(subId);
5285 if (phone != null) {
5286 return phone.isImsRegistered();
5287 } else {
5288 return false;
5289 }
5290 }
5291
Santos Cordon7a1885b2015-02-03 11:15:19 -08005292 @Override
5293 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005294 final long identity = Binder.clearCallingIdentity();
5295 try {
5296 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5297 } finally {
5298 Binder.restoreCallingIdentity(identity);
5299 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005300 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005301
Tyler Gunn327a9722019-04-03 15:28:53 -07005302 @Override
5303 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5304 final long identity = Binder.clearCallingIdentity();
5305 try {
5306 Phone phone = getPhone(subscriptionId);
5307 if (phone == null) {
5308 return null;
5309 }
5310 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
5314 }
5315
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005316 /**
5317 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005318 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005319 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005320 final long identity = Binder.clearCallingIdentity();
5321 try {
5322 Phone phone = getPhone(subId);
5323 if (phone != null) {
5324 return phone.isWifiCallingEnabled();
5325 } else {
5326 return false;
5327 }
5328 } finally {
5329 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005330 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005331 }
5332
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005333 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005334 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005335 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005336 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 Phone phone = getPhone(subId);
5340 if (phone != null) {
5341 return phone.isVideoEnabled();
5342 } else {
5343 return false;
5344 }
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005347 }
5348 }
5349
5350 /**
5351 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5352 * defined in {@link ImsRegistrationImplBase}.
5353 */
5354 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005355 final long identity = Binder.clearCallingIdentity();
5356 try {
5357 Phone phone = getPhone(subId);
5358 if (phone != null) {
5359 return phone.getImsRegistrationTech();
5360 } else {
5361 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5362 }
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005365 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005366 }
5367
Stuart Scott8eef64f2015-04-08 15:13:54 -07005368 @Override
5369 public void factoryReset(int subId) {
5370 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005371 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5372 return;
5373 }
5374
Svet Ganovcc087f82015-05-12 20:35:54 -07005375 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005376
Svet Ganovcc087f82015-05-12 20:35:54 -07005377 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005378 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5379 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005380 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005381 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005382 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005383 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5384 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005385 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005386 // There has been issues when Sms raw table somehow stores orphan
5387 // fragments. They lead to garbled message when new fragments come
5388 // in and combined with those stale ones. In case this happens again,
5389 // user can reset all network settings which will clean up this table.
5390 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005391 } finally {
5392 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005393 }
5394 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005395
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005396 private void cleanUpSmsRawTable(Context context) {
5397 ContentResolver resolver = context.getContentResolver();
5398 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5399 resolver.delete(uri, null, null);
5400 }
5401
Narayan Kamath1c496c22015-04-16 14:40:19 +01005402 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005403 public String getSimLocaleForSubscriber(int subId) {
5404 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5405 final Phone phone = getPhone(subId);
5406 if (phone == null) {
5407 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005408 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005409 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005412 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5413 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005414 // Try and fetch the locale from the carrier properties or from the SIM language
5415 // preferences (EF-PL and EF-LI)...
5416 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005417 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005418 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5419 if (localeFromDefaultSim != null) {
5420 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5421 if (DBG) log("Using locale from subId: " + subId + " locale: "
5422 + localeFromDefaultSim);
5423 return localeFromDefaultSim.toLanguageTag();
5424 } else {
5425 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005426 }
5427 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005428
Malcolm Chend965c8b2018-02-28 15:00:40 -08005429 // The SIM language preferences only store a language (e.g. fr = French), not an
5430 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5431 // the SIM and carrier preferences does not include a country we add the country
5432 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005433 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005434 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005435 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005436 return mccLocale.toLanguageTag();
5437 }
5438
5439 if (DBG) log("No locale found - returning null");
5440 return null;
5441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005444 }
5445
5446 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005447 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005448 }
5449
Malcolm Chend965c8b2018-02-28 15:00:40 -08005450 /**
5451 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5452 */
5453 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005454 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005455 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005456
Chenjie Yu1ba97252018-01-11 18:16:20 -08005457 private final ModemActivityInfo mLastModemActivityInfo =
5458 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5459
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005460 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005461 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5462 * representing the state of the modem.
5463 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005464 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5465 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005466 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005467 */
5468 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005469 public void requestModemActivityInfo(ResultReceiver result) {
5470 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005471 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005472
5473 final long identity = Binder.clearCallingIdentity();
5474 try {
5475 ModemActivityInfo ret = null;
5476 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005477 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5478 CMD_GET_MODEM_ACTIVITY_INFO,
5479 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005480 if (isModemActivityInfoValid(info)) {
5481 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5482 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5483 mergedTxTimeMs[i] =
5484 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5485 }
5486 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5487 mLastModemActivityInfo.setSleepTimeMillis(
5488 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5489 mLastModemActivityInfo.setIdleTimeMillis(
5490 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5491 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5492 mLastModemActivityInfo.setRxTimeMillis(
5493 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5494 mLastModemActivityInfo.setEnergyUsed(
5495 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005496 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005497 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5498 mLastModemActivityInfo.getSleepTimeMillis(),
5499 mLastModemActivityInfo.getIdleTimeMillis(),
5500 mLastModemActivityInfo.getTxTimeMillis(),
5501 mLastModemActivityInfo.getRxTimeMillis(),
5502 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005503 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005504 Bundle bundle = new Bundle();
5505 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5506 result.send(0, bundle);
5507 } finally {
5508 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005509 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005510 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005511
Siddharth Rayf5d29552018-06-17 15:02:38 -07005512 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5513 // less than total activity duration.
5514 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5515 if (info == null) {
5516 return false;
5517 }
5518 int activityDurationMs =
5519 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5520 int totalTxTimeMs = 0;
5521 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5522 totalTxTimeMs += info.getTxTimeMillis()[i];
5523 }
5524 return (info.isValid()
5525 && (info.getSleepTimeMillis() <= activityDurationMs)
5526 && (info.getIdleTimeMillis() <= activityDurationMs)
5527 && (info.getRxTimeMillis() <= activityDurationMs)
5528 && (totalTxTimeMs <= activityDurationMs));
5529 }
5530
Jack Yu85bd38a2015-11-09 11:34:32 -08005531 /**
5532 * {@hide}
5533 * Returns the service state information on specified subscription.
5534 */
5535 @Override
5536 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005538 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005539 return null;
5540 }
5541
Hall Liuf19c44f2018-11-27 14:38:17 -08005542 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5543 LocationAccessPolicy.checkLocationPermission(mApp,
5544 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5545 .setCallingPackage(callingPackage)
5546 .setCallingPid(Binder.getCallingPid())
5547 .setCallingUid(Binder.getCallingUid())
5548 .setMethod("getServiceStateForSubscriber")
5549 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5550 .build());
5551
5552 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5553 LocationAccessPolicy.checkLocationPermission(mApp,
5554 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5555 .setCallingPackage(callingPackage)
5556 .setCallingPid(Binder.getCallingPid())
5557 .setCallingUid(Binder.getCallingUid())
5558 .setMethod("getServiceStateForSubscriber")
5559 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5560 .build());
5561 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5562 boolean hasFinePermission =
5563 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5564 boolean hasCoarsePermission =
5565 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5566
Malcolm Chend965c8b2018-02-28 15:00:40 -08005567 final long identity = Binder.clearCallingIdentity();
5568 try {
5569 final Phone phone = getPhone(subId);
5570 if (phone == null) {
5571 return null;
5572 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005573
Hall Liuf19c44f2018-11-27 14:38:17 -08005574 ServiceState ss = phone.getServiceState();
5575
5576 // Scrub out the location info in ServiceState depending on what level of access
5577 // the caller has.
5578 if (hasFinePermission) return ss;
5579 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5580 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005581 } finally {
5582 Binder.restoreCallingIdentity(identity);
5583 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005584 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005585
5586 /**
5587 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5588 *
5589 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5590 * voicemail ringtone.
5591 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5592 * PhoneAccount.
5593 */
5594 @Override
5595 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005596 final long identity = Binder.clearCallingIdentity();
5597 try {
5598 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5599 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005600 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005601 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005602
Malcolm Chend965c8b2018-02-28 15:00:40 -08005603 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5604 } finally {
5605 Binder.restoreCallingIdentity(identity);
5606 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005607 }
5608
5609 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005610 * Sets the per-account voicemail ringtone.
5611 *
5612 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5613 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5614 *
5615 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5616 * voicemail ringtone.
5617 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5618 * PhoneAccount.
5619 */
5620 @Override
5621 public void setVoicemailRingtoneUri(String callingPackage,
5622 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005623 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5625 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005626 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5628 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5629 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005630 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005631
5632 final long identity = Binder.clearCallingIdentity();
5633 try {
5634 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5635 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005636 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005637 }
5638 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5639 } finally {
5640 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005641 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005642 }
5643
5644 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005645 * Returns whether vibration is set for voicemail notification in Phone settings.
5646 *
5647 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5648 * voicemail vibration setting.
5649 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5650 */
5651 @Override
5652 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005653 final long identity = Binder.clearCallingIdentity();
5654 try {
5655 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5656 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005657 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005658 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005659
Malcolm Chend965c8b2018-02-28 15:00:40 -08005660 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5661 } finally {
5662 Binder.restoreCallingIdentity(identity);
5663 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005664 }
5665
Youhan Wange64578a2016-05-02 15:32:42 -07005666 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005667 * Sets the per-account voicemail vibration.
5668 *
5669 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5670 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5671 *
5672 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5673 * voicemail vibration setting.
5674 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5675 * specific PhoneAccount.
5676 */
5677 @Override
5678 public void setVoicemailVibrationEnabled(String callingPackage,
5679 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005680 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5682 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005683 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5685 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5686 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005687 }
5688
Malcolm Chend965c8b2018-02-28 15:00:40 -08005689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5692 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005693 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005694 }
5695 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5696 } finally {
5697 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005698 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005699 }
5700
5701 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005702 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5703 *
5704 * @throws SecurityException if the caller does not have the required permission
5705 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005706 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005707 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005708 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005709 }
5710
5711 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005712 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5713 * permission.
5714 *
5715 * @throws SecurityException if the caller does not have the required permission
5716 */
5717 private void enforceSendSmsPermission() {
5718 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5719 }
5720
5721 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005722 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005723 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005724 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005725 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005726 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005727 final long identity = Binder.clearCallingIdentity();
5728 try {
5729 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005730 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005731 if (componentName == null) {
5732 throw new SecurityException(
5733 "Caller not current active visual voicemail package[null]");
5734 }
5735 String vvmPackage = componentName.getPackageName();
5736 if (!callingPackage.equals(vvmPackage)) {
5737 throw new SecurityException("Caller not current active visual voicemail package["
5738 + vvmPackage + "]");
5739 }
5740 } finally {
5741 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005742 }
5743 }
5744
5745 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005746 * Return the application ID for the app type.
5747 *
5748 * @param subId the subscription ID that this request applies to.
5749 * @param appType the uicc app type.
5750 * @return Application ID for specificied app type, or null if no uicc.
5751 */
5752 @Override
5753 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005754 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005755 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005756
5757 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005758 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005759 if (phone == null) {
5760 return null;
5761 }
5762 String aid = null;
5763 try {
5764 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5765 .getApplicationByType(appType).getAid();
5766 } catch (Exception e) {
5767 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5768 }
5769 return aid;
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005772 }
Youhan Wange64578a2016-05-02 15:32:42 -07005773 }
5774
Youhan Wang4001d252016-05-11 10:29:41 -07005775 /**
5776 * Return the Electronic Serial Number.
5777 *
5778 * @param subId the subscription ID that this request applies to.
5779 * @return ESN or null if error.
5780 */
5781 @Override
5782 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005783 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005784 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005785
5786 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005787 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005788 if (phone == null) {
5789 return null;
5790 }
5791 String esn = null;
5792 try {
5793 esn = phone.getEsn();
5794 } catch (Exception e) {
5795 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5796 }
5797 return esn;
5798 } finally {
5799 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005800 }
Youhan Wang4001d252016-05-11 10:29:41 -07005801 }
5802
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005803 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005804 * Return the Preferred Roaming List Version.
5805 *
5806 * @param subId the subscription ID that this request applies to.
5807 * @return PRLVersion or null if error.
5808 */
5809 @Override
5810 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005811 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005812 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005813
5814 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005815 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005816 if (phone == null) {
5817 return null;
5818 }
5819 String cdmaPrlVersion = null;
5820 try {
5821 cdmaPrlVersion = phone.getCdmaPrlVersion();
5822 } catch (Exception e) {
5823 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5824 }
5825 return cdmaPrlVersion;
5826 } finally {
5827 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005828 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005829 }
5830
5831 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005832 * Get snapshot of Telephony histograms
5833 * @return List of Telephony histograms
5834 * @hide
5835 */
5836 @Override
5837 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5839 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005840
5841 final long identity = Binder.clearCallingIdentity();
5842 try {
5843 return RIL.getTelephonyRILTimingHistograms();
5844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005847 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005848
5849 /**
5850 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005851 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5852 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005853 * Require system privileges. In the future we may add this to carrier APIs.
5854 *
Michele Berionne0963c862018-11-27 18:57:59 -08005855 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005856 */
5857 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005858 @TelephonyManager.SetCarrierRestrictionResult
5859 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005860 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005861 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005862
Michele Berionne0963c862018-11-27 18:57:59 -08005863 if (carrierRestrictionRules == null) {
5864 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005865 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005866
Malcolm Chend965c8b2018-02-28 15:00:40 -08005867 final long identity = Binder.clearCallingIdentity();
5868 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005869 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005870 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005871 } finally {
5872 Binder.restoreCallingIdentity(identity);
5873 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005874 }
5875
5876 /**
5877 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005878 * Get the allowed carrier list and the excluded carrier list, including the priority between
5879 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005880 * Require system privileges. In the future we may add this to carrier APIs.
5881 *
Michele Berionne0963c862018-11-27 18:57:59 -08005882 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005883 */
5884 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005885 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005886 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005887 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005888
5889 final long identity = Binder.clearCallingIdentity();
5890 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005891 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5892 if (response instanceof CarrierRestrictionRules) {
5893 return (CarrierRestrictionRules) response;
5894 }
5895 // Response is an Exception of some kind,
5896 // which is signalled to the user as a NULL retval
5897 return null;
5898 } catch (Exception e) {
5899 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5900 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005904 }
5905
fionaxu59545b42016-05-25 15:53:37 -07005906 /**
5907 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5908 * @param subId the subscription ID that this action applies to.
5909 * @param enabled control enable or disable metered apns.
5910 * {@hide}
5911 */
5912 @Override
5913 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5914 enforceModifyPermission();
5915 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005916
5917 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005918 if (phone == null) {
5919 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5920 return;
5921 }
5922 try {
5923 phone.carrierActionSetMeteredApnsEnabled(enabled);
5924 } catch (Exception e) {
5925 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005926 } finally {
5927 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005928 }
5929 }
5930
5931 /**
5932 * Action set from carrier signalling broadcast receivers to enable/disable radio
5933 * @param subId the subscription ID that this action applies to.
5934 * @param enabled control enable or disable radio.
5935 * {@hide}
5936 */
5937 @Override
5938 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5939 enforceModifyPermission();
5940 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005941
5942 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005943 if (phone == null) {
5944 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5945 return;
5946 }
5947 try {
5948 phone.carrierActionSetRadioEnabled(enabled);
5949 } catch (Exception e) {
5950 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005951 } finally {
5952 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005953 }
5954 }
5955
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005956 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005957 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5958 * network status based on which carrier apps could apply actions accordingly,
5959 * enable/disable default url handler for example.
5960 *
5961 * @param subId the subscription ID that this action applies to.
5962 * @param report control start/stop reporting the default network status.
5963 * {@hide}
5964 */
5965 @Override
5966 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5967 enforceModifyPermission();
5968 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005969
5970 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005971 if (phone == null) {
5972 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5973 return;
5974 }
5975 try {
5976 phone.carrierActionReportDefaultNetworkStatus(report);
5977 } catch (Exception e) {
5978 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005979 } finally {
5980 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005981 }
5982 }
5983
5984 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005985 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5986 * bug report is being generated.
5987 */
5988 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005989 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005990 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5991 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005992 writer.println("Permission Denial: can't dump Phone from pid="
5993 + Binder.getCallingPid()
5994 + ", uid=" + Binder.getCallingUid()
5995 + "without permission "
5996 + android.Manifest.permission.DUMP);
5997 return;
5998 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005999 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006000 }
Jack Yueb89b242016-06-22 13:27:47 -07006001
Brad Ebingerdac2f002018-04-03 15:17:52 -07006002 @Override
6003 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6004 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6005 throws RemoteException {
6006 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6007 }
6008
Jack Yueb89b242016-06-22 13:27:47 -07006009 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006010 * Get aggregated video call data usage since boot.
6011 *
6012 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6013 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006014 * {@hide}
6015 */
6016 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006017 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006018 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6019 null);
6020
Malcolm Chend965c8b2018-02-28 15:00:40 -08006021 final long identity = Binder.clearCallingIdentity();
6022 try {
6023 // NetworkStatsService keeps tracking the active network interface and identity. It
6024 // records the delta with the corresponding network identity.
6025 // We just return the total video call data usage snapshot since boot.
6026 Phone phone = getPhone(subId);
6027 if (phone != null) {
6028 return phone.getVtDataUsage(perUidStats);
6029 }
6030 return null;
6031 } finally {
6032 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006033 }
Jack Yueb89b242016-06-22 13:27:47 -07006034 }
Jack Yu75ab2952016-07-08 14:29:33 -07006035
6036 /**
6037 * Policy control of data connection. Usually used when data limit is passed.
6038 * @param enabled True if enabling the data, otherwise disabling.
6039 * @param subId Subscription index
6040 * {@hide}
6041 */
6042 @Override
6043 public void setPolicyDataEnabled(boolean enabled, int subId) {
6044 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006045
6046 final long identity = Binder.clearCallingIdentity();
6047 try {
6048 Phone phone = getPhone(subId);
6049 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006050 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006051 }
6052 } finally {
6053 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006054 }
6055 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006056
6057 /**
6058 * Get Client request stats
6059 * @return List of Client Request Stats
6060 * @hide
6061 */
6062 @Override
6063 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006065 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006066 return null;
6067 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006068 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006069
Malcolm Chend965c8b2018-02-28 15:00:40 -08006070 final long identity = Binder.clearCallingIdentity();
6071 try {
6072 if (phone != null) {
6073 return phone.getClientRequestStats();
6074 }
6075
6076 return null;
6077 } finally {
6078 Binder.restoreCallingIdentity(identity);
6079 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006080 }
6081
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006082 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006083 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006084 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006085 }
Jack Yueb4124c2017-02-16 15:32:43 -08006086
6087 /**
Grace Chen70990072017-03-24 17:21:30 -07006088 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006089 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006090 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006091 * @param state State of SIM (power down, power up, pass through)
6092 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6093 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6094 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006095 *
6096 **/
6097 @Override
Grace Chen70990072017-03-24 17:21:30 -07006098 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006099 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006100 Phone phone = PhoneFactory.getPhone(slotIndex);
6101
vagdevie435a3e2018-08-15 16:01:53 -07006102 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6103
Malcolm Chend965c8b2018-02-28 15:00:40 -08006104 final long identity = Binder.clearCallingIdentity();
6105 try {
6106 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006107 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006108 }
6109 } finally {
6110 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006111 }
6112 }
Shuo Qiandd210312017-04-12 22:11:33 +00006113
Tyler Gunn65d45c22017-06-05 11:22:26 -07006114 private boolean isUssdApiAllowed(int subId) {
6115 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006116 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006117 if (configManager == null) {
6118 return false;
6119 }
6120 PersistableBundle pb = configManager.getConfigForSubId(subId);
6121 if (pb == null) {
6122 return false;
6123 }
6124 return pb.getBoolean(
6125 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6126 }
6127
Shuo Qiandd210312017-04-12 22:11:33 +00006128 /**
6129 * Check if phone is in emergency callback mode
6130 * @return true if phone is in emergency callback mode
6131 * @param subId sub id
6132 */
goneil9c5f4872017-12-05 14:07:56 -08006133 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006134 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006135 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006136 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006137
6138 final long identity = Binder.clearCallingIdentity();
6139 try {
6140 if (phone != null) {
6141 return phone.isInEcm();
6142 } else {
6143 return false;
6144 }
6145 } finally {
6146 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006147 }
6148 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006149
6150 /**
6151 * Get the current signal strength information for the given subscription.
6152 * Because this information is not updated when the device is in a low power state
6153 * it should not be relied-upon to be current.
6154 * @param subId Subscription index
6155 * @return the most recent cached signal strength info from the modem
6156 */
6157 @Override
6158 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006159 final long identity = Binder.clearCallingIdentity();
6160 try {
6161 Phone p = getPhone(subId);
6162 if (p == null) {
6163 return null;
6164 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006165
Malcolm Chend965c8b2018-02-28 15:00:40 -08006166 return p.getSignalStrength();
6167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006170 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006171
Pengquan Meng9140aec2018-08-22 14:49:57 -07006172 /**
chen xu907e5a22018-10-11 13:21:04 -07006173 * Get the current modem radio state for the given slot.
6174 * @param slotIndex slot index.
6175 * @param callingPackage the name of the package making the call.
6176 * @return the current radio power state from the modem
6177 */
6178 @Override
6179 public int getRadioPowerState(int slotIndex, String callingPackage) {
6180 Phone phone = PhoneFactory.getPhone(slotIndex);
6181 if (phone != null) {
6182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6183 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6184 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6185 }
6186
6187 final long identity = Binder.clearCallingIdentity();
6188 try {
6189 return phone.getRadioPowerState();
6190 } finally {
6191 Binder.restoreCallingIdentity(identity);
6192 }
6193 }
6194 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6195 }
6196
6197 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006198 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6199 *
6200 * <p>Requires one of the following permissions:
6201 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6202 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6203 * privileges.
6204 *
6205 * @param subId subscription id
6206 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6207 * {@code false}.
6208 */
6209 @Override
6210 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006211 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6212 null /* message */);
6213
Pengquan Meng0c05b502018-09-06 09:59:22 -07006214 boolean isEnabled = false;
6215 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006216 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006217 Phone phone = getPhone(subId);
6218 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006219 } catch (Exception e) {
6220 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6221 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006222 } finally {
6223 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006224 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006225 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006226 }
6227
6228
6229 /**
6230 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6231 *
6232 * <p> Requires permission:
6233 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6234 * privileges.
6235 *
6236 * @param subId subscription id
6237 * @param isEnabled {@code true} means enable, {@code false} means disable.
6238 */
6239 @Override
6240 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6242 mApp, subId, "setDataRoamingEnabled");
6243
Pengquan Meng0c05b502018-09-06 09:59:22 -07006244 final long identity = Binder.clearCallingIdentity();
6245 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006246 Phone phone = getPhone(subId);
6247 if (phone != null) {
6248 phone.setDataRoamingEnabled(isEnabled);
6249 }
6250 } finally {
6251 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006252 }
6253 }
6254
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006255 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006256 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006257 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6258 mApp, subId, "isManualNetworkSelectionAllowed");
6259
Pengquan Meng312de0c2018-10-03 12:19:13 -07006260 boolean isAllowed = true;
6261 final long identity = Binder.clearCallingIdentity();
6262 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006263 Phone phone = getPhone(subId);
6264 if (phone != null) {
6265 isAllowed = phone.isCspPlmnEnabled();
6266 }
6267 } finally {
6268 Binder.restoreCallingIdentity(identity);
6269 }
6270 return isAllowed;
6271 }
6272
6273 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006274 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006275 try {
6276 enforceReadPrivilegedPermission("getUiccCardsInfo");
6277 } catch (SecurityException e) {
6278 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6279 // has carrier privileges on an active UICC
6280 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6281 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6282 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6283 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006284 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006285
6286 final long identity = Binder.clearCallingIdentity();
6287 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006288 UiccController uiccController = UiccController.getInstance();
6289 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6290
6291 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6292 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6293 // Remove private info if the caller doesn't have access
6294 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6295 for (UiccCardInfo cardInfo : cardInfos) {
6296 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6297 UiccProfile profile = card.getUiccProfile();
6298 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6299 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6300 filteredInfos.add(cardInfo.getUnprivileged());
6301 } else {
6302 filteredInfos.add(cardInfo);
6303 }
6304 }
6305 return filteredInfos;
6306 }
6307 return cardInfos;
6308 } catch (PackageManager.NameNotFoundException e) {
6309 // This should not happen since we pass the package info in from TelephonyManager
6310 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006311 } finally {
6312 Binder.restoreCallingIdentity(identity);
6313 }
6314 }
6315
6316 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006317 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006318 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006319
Malcolm Chend965c8b2018-02-28 15:00:40 -08006320 final long identity = Binder.clearCallingIdentity();
6321 try {
6322 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6323 if (slots == null) {
6324 Rlog.i(LOG_TAG, "slots is null.");
6325 return null;
6326 }
6327
6328 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6329 for (int i = 0; i < slots.length; i++) {
6330 UiccSlot slot = slots[i];
6331 if (slot == null) {
6332 continue;
6333 }
6334
6335 String cardId;
6336 UiccCard card = slot.getUiccCard();
6337 if (card != null) {
6338 cardId = card.getCardId();
6339 } else {
6340 cardId = slot.getIccId();
6341 }
6342
6343 int cardState = 0;
6344 switch (slot.getCardState()) {
6345 case CARDSTATE_ABSENT:
6346 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6347 break;
6348 case CARDSTATE_PRESENT:
6349 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6350 break;
6351 case CARDSTATE_ERROR:
6352 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6353 break;
6354 case CARDSTATE_RESTRICTED:
6355 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6356 break;
6357 default:
6358 break;
6359
6360 }
6361
6362 infos[i] = new UiccSlotInfo(
6363 slot.isActive(),
6364 slot.isEuicc(),
6365 cardId,
6366 cardState,
6367 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006368 slot.isExtendedApduSupported(),
6369 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006370 }
6371 return infos;
6372 } finally {
6373 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006374 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006375 }
6376
6377 @Override
6378 public boolean switchSlots(int[] physicalSlots) {
6379 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006380
6381 final long identity = Binder.clearCallingIdentity();
6382 try {
6383 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006387 }
Jack Yu4c988042018-02-27 15:30:01 -08006388
6389 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006390 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006391 final long identity = Binder.clearCallingIdentity();
6392 try {
6393 return UiccController.getInstance().getCardIdForDefaultEuicc();
6394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
6397 }
6398
6399 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006400 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6401 enforceModifyPermission();
6402 final Phone phone = getPhone(subId);
6403 if (phone == null) {
6404 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6405 return;
6406 }
6407
Malcolm Chend965c8b2018-02-28 15:00:40 -08006408 final long identity = Binder.clearCallingIdentity();
6409 try {
6410 phone.setRadioIndicationUpdateMode(filters, mode);
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
Jack Yu4c988042018-02-27 15:30:01 -08006414 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006415
6416 /**
goneil47ffb6e2018-04-06 15:40:58 -07006417 * A test API to reload the UICC profile.
6418 *
6419 * <p>Requires that the calling app has permission
6420 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6421 * @hide
6422 */
6423 @Override
6424 public void refreshUiccProfile(int subId) {
6425 enforceModifyPermission();
6426
6427 final long identity = Binder.clearCallingIdentity();
6428 try {
6429 Phone phone = getPhone(subId);
6430 if (phone == null) {
6431 return;
6432 }
6433 UiccCard uiccCard = phone.getUiccCard();
6434 if (uiccCard == null) {
6435 return;
6436 }
6437 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6438 if (uiccProfile == null) {
6439 return;
6440 }
6441 uiccProfile.refresh();
6442 } finally {
6443 Binder.restoreCallingIdentity(identity);
6444 }
6445 }
6446
6447 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006448 * Returns false if the mobile data is disabled by default, otherwise return true.
6449 */
6450 private boolean getDefaultDataEnabled() {
6451 return "true".equalsIgnoreCase(
6452 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6453 }
6454
6455 /**
6456 * Returns true if the data roaming is enabled by default, i.e the system property
6457 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6458 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6459 */
6460 private boolean getDefaultDataRoamingEnabled(int subId) {
6461 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006462 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006463 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6464 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6465 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6466 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6467 return isDataRoamingEnabled;
6468 }
6469
6470 /**
6471 * Returns the default network type for the given {@code subId}, if the default network type is
6472 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6473 */
6474 private int getDefaultNetworkType(int subId) {
6475 return Integer.parseInt(
6476 TelephonyManager.getTelephonyProperty(
6477 mSubscriptionController.getPhoneId(subId),
6478 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6479 String.valueOf(Phone.PREFERRED_NT_MODE)));
6480 }
fionaxua13278b2018-03-21 00:08:13 -07006481
6482 @Override
6483 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6484 gid1, String gid2, String plmn, String spn) {
6485 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006486
6487 final long identity = Binder.clearCallingIdentity();
6488 try {
6489 final Phone phone = getPhone(subId);
6490 if (phone == null) {
6491 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6492 return;
6493 }
6494 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6495 } finally {
6496 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006497 }
fionaxua13278b2018-03-21 00:08:13 -07006498 }
6499
6500 @Override
6501 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006502 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006503
6504 final long identity = Binder.clearCallingIdentity();
6505 try {
6506 final Phone phone = getPhone(subId);
6507 if (phone == null) {
6508 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6509 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6510 }
6511 return phone.getCarrierIdListVersion();
6512 } finally {
6513 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006514 }
fionaxua13278b2018-03-21 00:08:13 -07006515 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006516
6517 @Override
6518 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6519 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6520 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6521 return -1;
6522 }
6523
6524 final long identity = Binder.clearCallingIdentity();
6525 try {
6526 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6527 } finally {
6528 Binder.restoreCallingIdentity(identity);
6529 }
6530 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006531
6532 @Override
6533 public int getCdmaRoamingMode(int subId) {
6534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6535 mApp, subId, "getCdmaRoamingMode");
6536
6537 final long identity = Binder.clearCallingIdentity();
6538 try {
6539 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6540 } finally {
6541 Binder.restoreCallingIdentity(identity);
6542 }
6543 }
6544
6545 @Override
6546 public boolean setCdmaRoamingMode(int subId, int mode) {
6547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6548 mApp, subId, "setCdmaRoamingMode");
6549
6550 final long identity = Binder.clearCallingIdentity();
6551 try {
6552 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6553 } finally {
6554 Binder.restoreCallingIdentity(identity);
6555 }
6556 }
6557
6558 @Override
6559 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6561 mApp, subId, "setCdmaSubscriptionMode");
6562
6563 final long identity = Binder.clearCallingIdentity();
6564 try {
6565 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6566 } finally {
6567 Binder.restoreCallingIdentity(identity);
6568 }
6569 }
chen xu7ee67862018-10-30 22:27:10 -07006570
sqian2fff4a32018-11-05 14:18:37 -08006571 private void ensureUserRunning(int userId) {
6572 if (!mUserManager.isUserRunning(userId)) {
6573 throw new IllegalStateException("User " + userId + " does not exist or not running");
6574 }
6575 }
6576
6577 /**
6578 * Returns a list of SMS apps on a given user.
6579 *
6580 * Only the shell user (UID 2000 or 0) can call it.
6581 * Target user must be running.
6582 */
6583 @Override
6584 public String[] getSmsApps(int userId) {
6585 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6586 ensureUserRunning(userId);
6587
6588 final Collection<SmsApplicationData> apps =
6589 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6590
6591 String[] ret = new String[apps.size()];
6592 int i = 0;
6593 for (SmsApplicationData app : apps) {
6594 ret[i++] = app.mPackageName;
6595 }
6596 return ret;
6597 }
6598
6599 /**
6600 * Returns the default SMS app package name on a given user.
6601 *
6602 * Only the shell user (UID 2000 or 0) can call it.
6603 * Target user must be running.
6604 */
6605 @Override
6606 public String getDefaultSmsApp(int userId) {
6607 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6608 ensureUserRunning(userId);
6609
6610 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6611 /* updateIfNeeded= */ true, userId);
6612 return cn == null ? null : cn.getPackageName();
6613 }
6614
6615 /**
6616 * Set a package as the default SMS app on a given user.
6617 *
6618 * Only the shell user (UID 2000 or 0) can call it.
6619 * Target user must be running.
6620 */
6621 @Override
6622 public void setDefaultSmsApp(int userId, String packageName) {
6623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6624 ensureUserRunning(userId);
6625
6626 boolean found = false;
6627 for (String pkg : getSmsApps(userId)) {
6628 if (TextUtils.equals(packageName, pkg)) {
6629 found = true;
6630 break;
6631 }
6632 }
6633 if (!found) {
6634 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6635 }
6636
6637 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6638 }
6639
chen xu7ee67862018-10-30 22:27:10 -07006640 @Override
sqian65eefe12019-02-22 15:55:18 -08006641 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006642 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006643 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006644 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006645 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6646 }
6647 final long identity = Binder.clearCallingIdentity();
6648 try {
sqian991b35e2018-12-12 16:48:18 -08006649 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6650 for (Phone phone: PhoneFactory.getPhones()) {
6651 if (phone.getEmergencyNumberTracker() != null
6652 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6653 emergencyNumberListInternal.put(
6654 phone.getSubId(),
6655 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6656 }
sqian03bca152018-12-05 18:48:28 -08006657 }
sqian991b35e2018-12-12 16:48:18 -08006658 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006659 } finally {
6660 Binder.restoreCallingIdentity(identity);
6661 }
sqian04b86072018-11-07 14:02:21 -08006662 }
6663
6664 @Override
sqian65eefe12019-02-22 15:55:18 -08006665 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006666 final Phone defaultPhone = getDefaultPhone();
6667 if (!exactMatch) {
6668 TelephonyPermissions
6669 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006670 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006671 }
6672 final long identity = Binder.clearCallingIdentity();
6673 try {
sqian991b35e2018-12-12 16:48:18 -08006674 for (Phone phone: PhoneFactory.getPhones()) {
6675 if (phone.getEmergencyNumberTracker() != null
6676 && phone.getEmergencyNumberTracker() != null) {
6677 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6678 number, exactMatch)) {
6679 return true;
sqian03bca152018-12-05 18:48:28 -08006680 }
6681 }
sqian03bca152018-12-05 18:48:28 -08006682 }
6683 return false;
6684 } finally {
6685 Binder.restoreCallingIdentity(identity);
6686 }
6687 }
6688
sqian9d4df8b2019-01-15 18:32:07 -08006689 /**
6690 * Update emergency number list for test mode.
6691 */
6692 @Override
6693 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6694 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6695 "updateEmergencyNumberListTestMode");
6696
6697 final long identity = Binder.clearCallingIdentity();
6698 try {
6699 for (Phone phone: PhoneFactory.getPhones()) {
6700 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6701 if (tracker != null) {
6702 tracker.executeEmergencyNumberTestModeCommand(action, num);
6703 }
6704 }
6705 } finally {
6706 Binder.restoreCallingIdentity(identity);
6707 }
6708 }
6709
6710 /**
6711 * Get the full emergency number list for test mode.
6712 */
6713 @Override
6714 public List<String> getEmergencyNumberListTestMode() {
6715 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6716 "getEmergencyNumberListTestMode");
6717
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
6720 Set<String> emergencyNumbers = new HashSet<>();
6721 for (Phone phone: PhoneFactory.getPhones()) {
6722 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6723 if (tracker != null) {
6724 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6725 emergencyNumbers.add(num.getNumber());
6726 }
6727 }
6728 }
6729 return new ArrayList<>(emergencyNumbers);
6730 } finally {
6731 Binder.restoreCallingIdentity(identity);
6732 }
6733 }
6734
sqian04b86072018-11-07 14:02:21 -08006735 @Override
chen xu7ee67862018-10-30 22:27:10 -07006736 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6737 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6738 Phone phone = getPhone(subId);
6739 if (phone == null) {
6740 return null;
6741 }
6742 final long identity = Binder.clearCallingIdentity();
6743 try {
6744 UiccProfile profile = UiccController.getInstance()
6745 .getUiccProfileForPhone(phone.getPhoneId());
6746 if (profile != null) {
6747 return profile.getCertsFromCarrierPrivilegeAccessRules();
6748 }
6749 } finally {
6750 Binder.restoreCallingIdentity(identity);
6751 }
6752 return null;
6753 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006754
6755 /**
6756 * Enable or disable a modem stack.
6757 */
6758 @Override
6759 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6760 enforceModifyPermission();
6761
6762 final long identity = Binder.clearCallingIdentity();
6763 try {
6764 Phone phone = PhoneFactory.getPhone(slotIndex);
6765 if (phone == null) {
6766 return false;
6767 } else {
6768 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6769 }
6770 } finally {
6771 Binder.restoreCallingIdentity(identity);
6772 }
6773 }
Micheled3107c52018-12-21 15:00:11 -08006774
6775 @Override
Michele2fb0f222019-03-19 14:58:42 -07006776 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006777 enforceModifyPermission();
6778
6779 final long identity = Binder.clearCallingIdentity();
6780 try {
6781 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006782 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006783 .commit();
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
6787 }
6788
6789 @Override
Michele2fb0f222019-03-19 14:58:42 -07006790 @TelephonyManager.IsMultiSimSupportedResult
6791 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006793 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6794 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006795 }
Micheled3107c52018-12-21 15:00:11 -08006796
6797 final long identity = Binder.clearCallingIdentity();
6798 try {
Michele2fb0f222019-03-19 14:58:42 -07006799 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006800 } finally {
6801 Binder.restoreCallingIdentity(identity);
6802 }
6803 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006804
Michele2fb0f222019-03-19 14:58:42 -07006805 @TelephonyManager.IsMultiSimSupportedResult
6806 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006807 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6808 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6809 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006810 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6811 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006812 }
6813 // Check if the hardware supports multisim functionality. If usage of multisim is not
6814 // supported by the modem, indicate that it is restricted.
6815 PhoneCapability staticCapability =
6816 mPhoneConfigurationManager.getStaticPhoneCapability();
6817 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006818 loge("isMultiSimSupportedInternal: no static configuration available");
6819 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006820 }
6821 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006822 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6823 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006824 }
6825 // Check if support of multiple SIMs is restricted by carrier
6826 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006827 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006828 }
6829
Michele2fb0f222019-03-19 14:58:42 -07006830 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006831 }
6832
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006833 /**
6834 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006835 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6836 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6837 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006838 * @param numOfSims number of active sims we want to switch to
6839 */
6840 @Override
6841 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006842 if (numOfSims == 1) {
6843 enforceModifyPermission();
6844 } else {
6845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6846 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6847 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006848 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006849
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006850 try {
Michele30b57b22019-03-01 12:01:14 -08006851 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006852 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006853 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6854 return;
6855 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006856 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6857 } finally {
6858 Binder.restoreCallingIdentity(identity);
6859 }
6860 }
6861
6862 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006863 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006864 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006865 */
6866 @Override
6867 public boolean isRebootRequiredForModemConfigChange() {
6868 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6869 final long identity = Binder.clearCallingIdentity();
6870 try {
6871 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6872 } finally {
6873 Binder.restoreCallingIdentity(identity);
6874 }
6875 }
6876
Pengquan Meng92d253b2019-02-06 11:12:53 -08006877 private void updateModemStateMetrics() {
6878 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6879 // TODO: check the state for each modem if the api is ready.
6880 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6881 }
6882
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006883 @Override
6884 public int[] getSlotsMapping() {
6885 enforceReadPrivilegedPermission("getSlotsMapping");
6886
6887 final long identity = Binder.clearCallingIdentity();
6888 try {
6889 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6890 // All logical slots should have a mapping to a physical slot.
6891 int[] logicalSlotsMapping = new int[phoneCount];
6892 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6893 for (int i = 0; i < slotInfos.length; i++) {
6894 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6895 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6896 }
6897 }
6898 return logicalSlotsMapping;
6899 } finally {
6900 Binder.restoreCallingIdentity(identity);
6901 }
6902 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006903
6904 /**
6905 * Get the IRadio HAL Version
6906 */
6907 @Override
6908 public int getRadioHalVersion() {
6909 Phone phone = getDefaultPhone();
6910 if (phone == null) return -1;
6911 HalVersion hv = phone.getHalVersion();
6912 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6913 return hv.major * 100 + hv.minor;
6914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006915}