blob: ca93961212c59717895c789e20e81af19acc07e3 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070027import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.content.Context;
29import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070030import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070031import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070032import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080033import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070034import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070035import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.net.Uri;
37import android.os.AsyncResult;
38import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080039import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.os.Bundle;
41import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070042import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Looper;
44import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070046import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080047import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070048import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070050import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070051import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070053import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070054import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070055import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080056import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070057import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080058import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080059import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070060import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070061import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080062import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070064import android.telephony.CellInfoGsm;
65import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070066import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070068import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070069import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080070import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070071import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080072import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070073import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080074import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080075import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070076import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080077import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070078import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080080import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070081import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080082import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070084import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070085import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080087import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000088import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070089import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070091import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080092import android.telephony.data.ApnSetting;
93import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070094import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080095import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070096import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080097import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070098import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080099import android.telephony.ims.aidl.IImsMmTelFeature;
100import android.telephony.ims.aidl.IImsRcsFeature;
101import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700102import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.feature.MmTelFeature;
104import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800105import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800107import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800109import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800110import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800111
Brad Ebinger35c841c2018-10-01 10:40:55 -0700112import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700113import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800114import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700115import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700116import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700117import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800118import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700119import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700120import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800122import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800123import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800125import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700126import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100127import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700128import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700131import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800132import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700133import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700134import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700135import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700136import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700137import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700138import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700139import com.android.internal.telephony.SmsApplication;
140import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800141import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800142import com.android.internal.telephony.TelephonyPermissions;
sqianf4ca7ed2019-01-15 18:32:07 -0800143import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700144import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800145import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800146import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.uicc.IccIoResult;
148import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800149import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700150import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800151import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800153import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000154import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700155import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800156import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700157import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800158import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700159import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700160import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800161
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700162import java.io.FileDescriptor;
163import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800164import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800166import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700167import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800168import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800169import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800170import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100171import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import java.util.Map;
sqianf4ca7ed2019-01-15 18:32:07 -0800173import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174
175/**
176 * Implementation of the ITelephony interface.
177 */
Santos Cordon117fee72014-05-16 17:56:12 -0700178public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179 private static final String LOG_TAG = "PhoneInterfaceManager";
180 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
181 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800182 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183
184 // Message codes used with mMainThreadHandler
185 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700186 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
187 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188 private static final int CMD_OPEN_CHANNEL = 9;
189 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
190 private static final int CMD_CLOSE_CHANNEL = 11;
191 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800192 private static final int CMD_NV_READ_ITEM = 13;
193 private static final int EVENT_NV_READ_ITEM_DONE = 14;
194 private static final int CMD_NV_WRITE_ITEM = 15;
195 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
196 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
197 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700198 private static final int CMD_RESET_MODEM_CONFIG = 19;
199 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800200 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
201 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
202 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
203 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800204 private static final int CMD_SEND_ENVELOPE = 25;
205 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000206 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
207 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700208 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
209 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
210 private static final int CMD_EXCHANGE_SIM_IO = 31;
211 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800212 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
213 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700214 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
215 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700216 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
217 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700218 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
219 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
220 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
221 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700222 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
223 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
224 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
225 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700226 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800227 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
228 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000229 private static final int CMD_SWITCH_SLOTS = 50;
230 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700231 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
232 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
233 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
234 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
235 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
236 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
237 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
238 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700239 private static final int CMD_GET_ALL_CELL_INFO = 60;
240 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
241 private static final int CMD_GET_CELL_LOCATION = 62;
242 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700243 private static final int CMD_MODEM_REBOOT = 64;
244 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700245 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
246 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800247 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
248 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800250 // Parameters of select command.
251 private static final int SELECT_COMMAND = 0xA4;
252 private static final int SELECT_P1 = 0x04;
253 private static final int SELECT_P2 = 0;
254 private static final int SELECT_P3 = 0x10;
255
Pengquan Meng85728fb2018-03-12 16:31:21 -0700256 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
257 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
258 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
259
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260 /** The singleton instance. */
261 private static PhoneInterfaceManager sInstance;
262
Wink Saville3ab207e2014-11-20 13:07:20 -0800263 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800264 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700265 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800266 private AppOpsManager mAppOps;
267 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800268 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800269 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700270 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271
Derek Tan97ebb422014-09-05 16:55:38 -0700272 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
273 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800274 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800275 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700276
Michelecea4cf22018-12-21 15:00:11 -0800277 // String to store multi SIM allowed
278 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
279
Derek Tan740e1672017-06-27 14:56:27 -0700280 // The AID of ISD-R.
281 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
282
yinxub1bed742017-04-17 11:45:04 -0700283 private NetworkScanRequestTracker mNetworkScanRequestTracker;
284
David Kelly5e06a7f2018-03-12 14:10:59 +0000285 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
286 private static final int MANUFACTURER_CODE_LENGTH = 8;
287
Derek Tan89e89d42014-07-08 17:00:10 -0700288 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700289 * A request object to use for transmitting data to an ICC.
290 */
291 private static final class IccAPDUArgument {
292 public int channel, cla, command, p1, p2, p3;
293 public String data;
294
295 public IccAPDUArgument(int channel, int cla, int command,
296 int p1, int p2, int p3, String data) {
297 this.channel = channel;
298 this.cla = cla;
299 this.command = command;
300 this.p1 = p1;
301 this.p2 = p2;
302 this.p3 = p3;
303 this.data = data;
304 }
305 }
306
307 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700308 * A request object to use for transmitting data to an ICC.
309 */
310 private static final class ManualNetworkSelectionArgument {
311 public OperatorInfo operatorInfo;
312 public boolean persistSelection;
313
314 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
315 this.operatorInfo = operatorInfo;
316 this.persistSelection = persistSelection;
317 }
318 }
319
320 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
322 * request after sending. The main thread will notify the request when it is complete.
323 */
324 private static final class MainThreadRequest {
325 /** The argument to use for the request */
326 public Object argument;
327 /** The result of the request that is run on the main thread */
328 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800329 // The subscriber id that this request applies to. Defaults to
330 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
331 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332
Nathan Harold92bed182018-10-12 18:16:49 -0700333 // In cases where subId is unavailable, the caller needs to specify the phone.
334 public Phone phone;
335
vagdeviaf9a5b92018-08-15 16:01:53 -0700336 public WorkSource workSource;
337
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 public MainThreadRequest(Object argument) {
339 this.argument = argument;
340 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800341
Nathan Harold92bed182018-10-12 18:16:49 -0700342 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
343 this.argument = argument;
344 if (phone != null) {
345 this.phone = phone;
346 }
347 this.workSource = workSource;
348 }
349
vagdeviaf9a5b92018-08-15 16:01:53 -0700350 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800351 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800352 if (subId != null) {
353 this.subId = subId;
354 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700355 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 }
358
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800359 private static final class IncomingThirdPartyCallArgs {
360 public final ComponentName component;
361 public final String callId;
362 public final String callerDisplayName;
363
364 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
365 String callerDisplayName) {
366 this.component = component;
367 this.callId = callId;
368 this.callerDisplayName = callerDisplayName;
369 }
370 }
371
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 /**
373 * A handler that processes messages on the main thread in the phone process. Since many
374 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
375 * inbound binder threads to the main thread in the phone process. The Binder thread
376 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
377 * on, which will be notified when the operation completes and will contain the result of the
378 * request.
379 *
380 * <p>If a MainThreadRequest object is provided in the msg.obj field,
381 * note that request.result must be set to something non-null for the calling thread to
382 * unblock.
383 */
384 private final class MainThreadHandler extends Handler {
385 @Override
386 public void handleMessage(Message msg) {
387 MainThreadRequest request;
388 Message onCompleted;
389 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800390 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700391 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800392 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393
394 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700395 case CMD_HANDLE_USSD_REQUEST: {
396 request = (MainThreadRequest) msg.obj;
397 final Phone phone = getPhoneFromRequest(request);
398 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
399 String ussdRequest = ussdObject.first;
400 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700401
Pengquan Menga1bb6272018-09-06 09:59:22 -0700402 if (!isUssdApiAllowed(request.subId)) {
403 // Carrier does not support use of this API, return failure.
404 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
405 UssdResponse response = new UssdResponse(ussdRequest, null);
406 Bundle returnData = new Bundle();
407 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
408 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700409
Pengquan Menga1bb6272018-09-06 09:59:22 -0700410 request.result = true;
411 notifyRequester(request);
412 return;
413 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700414
Pengquan Menga1bb6272018-09-06 09:59:22 -0700415 try {
416 request.result = phone != null
417 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
418 } catch (CallStateException cse) {
419 request.result = false;
420 }
421 // Wake up the requesting thread
422 notifyRequester(request);
423 break;
pkanwar32d516d2016-10-14 19:37:38 -0700424 }
425
Yorke Lee716f67e2015-06-17 15:39:16 -0700426 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700428 final Phone phone = getPhoneFromRequest(request);
429 request.result = phone != null ?
430 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
431 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700433 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700439 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800440 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700441 if (uiccCard == null) {
442 loge("iccTransmitApduLogicalChannel: No UICC");
443 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700444 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700445 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
447 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700448 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 iccArgument.channel, iccArgument.cla, iccArgument.command,
450 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700452 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 break;
454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 ar = (AsyncResult) msg.obj;
457 request = (MainThreadRequest) ar.userObj;
458 if (ar.exception == null && ar.result != null) {
459 request.result = ar.result;
460 } else {
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
462 if (ar.result == null) {
463 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800464 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800466 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 } else {
468 loge("iccTransmitApduLogicalChannel: Unknown exception");
469 }
470 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700471 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 break;
473
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
475 request = (MainThreadRequest) msg.obj;
476 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800477 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 if (uiccCard == null) {
479 loge("iccTransmitApduBasicChannel: No UICC");
480 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700481 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 } else {
483 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
484 request);
485 uiccCard.iccTransmitApduBasicChannel(
486 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
487 iccArgument.p3, iccArgument.data, onCompleted);
488 }
489 break;
490
491 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
492 ar = (AsyncResult) msg.obj;
493 request = (MainThreadRequest) ar.userObj;
494 if (ar.exception == null && ar.result != null) {
495 request.result = ar.result;
496 } else {
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
498 if (ar.result == null) {
499 loge("iccTransmitApduBasicChannel: Empty response");
500 } else if (ar.exception instanceof CommandException) {
501 loge("iccTransmitApduBasicChannel: CommandException: " +
502 ar.exception);
503 } else {
504 loge("iccTransmitApduBasicChannel: Unknown exception");
505 }
506 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 break;
509
510 case CMD_EXCHANGE_SIM_IO:
511 request = (MainThreadRequest) msg.obj;
512 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800513 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 if (uiccCard == null) {
515 loge("iccExchangeSimIO: No UICC");
516 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700517 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 } else {
519 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
520 request);
521 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
522 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
523 iccArgument.data, onCompleted);
524 }
525 break;
526
527 case EVENT_EXCHANGE_SIM_IO_DONE:
528 ar = (AsyncResult) msg.obj;
529 request = (MainThreadRequest) ar.userObj;
530 if (ar.exception == null && ar.result != null) {
531 request.result = ar.result;
532 } else {
533 request.result = new IccIoResult(0x6f, 0, (byte[])null);
534 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 break;
537
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 case CMD_SEND_ENVELOPE:
539 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800540 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 if (uiccCard == null) {
542 loge("sendEnvelopeWithStatus: No UICC");
543 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 } else {
546 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
547 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
548 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 break;
550
551 case EVENT_SEND_ENVELOPE_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700554 if (ar.exception == null && ar.result != null) {
555 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800556 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
558 if (ar.result == null) {
559 loge("sendEnvelopeWithStatus: Empty response");
560 } else if (ar.exception instanceof CommandException) {
561 loge("sendEnvelopeWithStatus: CommandException: " +
562 ar.exception);
563 } else {
564 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
565 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800566 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800568 break;
569
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 case CMD_OPEN_CHANNEL:
571 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800572 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800573 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 if (uiccCard == null) {
575 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800576 request.result = new IccOpenLogicalChannelResponse(-1,
577 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 } else {
580 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800581 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
582 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 break;
585
586 case EVENT_OPEN_CHANNEL_DONE:
587 ar = (AsyncResult) msg.obj;
588 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 int[] result = (int[]) ar.result;
592 int channelId = result[0];
593 byte[] selectResponse = null;
594 if (result.length > 1) {
595 selectResponse = new byte[result.length - 1];
596 for (int i = 1; i < result.length; ++i) {
597 selectResponse[i - 1] = (byte) result[i];
598 }
599 }
600 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700601 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 if (ar.result == null) {
604 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 if (ar.exception != null) {
607 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
608 }
609
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700611 if (ar.exception instanceof CommandException) {
612 CommandException.Error error =
613 ((CommandException) (ar.exception)).getCommandError();
614 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700616 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700617 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 }
619 }
620 openChannelResp = new IccOpenLogicalChannelResponse(
621 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700623 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
627 case CMD_CLOSE_CHANNEL:
628 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 if (uiccCard == null) {
631 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900632 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 } else {
635 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
636 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
637 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 break;
639
640 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800641 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
642 break;
643
644 case CMD_NV_READ_ITEM:
645 request = (MainThreadRequest) msg.obj;
646 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800647 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
648 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800649 break;
650
651 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 ar = (AsyncResult) msg.obj;
653 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800654 if (ar.exception == null && ar.result != null) {
655 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800657 request.result = "";
658 if (ar.result == null) {
659 loge("nvReadItem: Empty response");
660 } else if (ar.exception instanceof CommandException) {
661 loge("nvReadItem: CommandException: " +
662 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800664 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 }
666 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 break;
669
Jake Hambye994d462014-02-03 13:10:13 -0800670 case CMD_NV_WRITE_ITEM:
671 request = (MainThreadRequest) msg.obj;
672 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
673 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800674 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700675 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800676 break;
677
678 case EVENT_NV_WRITE_ITEM_DONE:
679 handleNullReturnEvent(msg, "nvWriteItem");
680 break;
681
682 case CMD_NV_WRITE_CDMA_PRL:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800685 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800686 break;
687
688 case EVENT_NV_WRITE_CDMA_PRL_DONE:
689 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
690 break;
691
chen xu6dac5ab2018-10-26 17:39:23 -0700692 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800693 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700694 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800695 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800696 break;
697
chen xu6dac5ab2018-10-26 17:39:23 -0700698 case EVENT_RESET_MODEM_CONFIG_DONE:
699 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
Jake Hamby7c27be32014-03-03 13:25:59 -0800702 case CMD_GET_PREFERRED_NETWORK_TYPE:
703 request = (MainThreadRequest) msg.obj;
704 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700705 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800706 break;
707
708 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
709 ar = (AsyncResult) msg.obj;
710 request = (MainThreadRequest) ar.userObj;
711 if (ar.exception == null && ar.result != null) {
712 request.result = ar.result; // Integer
713 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800714 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 if (ar.result == null) {
716 loge("getPreferredNetworkType: Empty response");
717 } else if (ar.exception instanceof CommandException) {
718 loge("getPreferredNetworkType: CommandException: " +
719 ar.exception);
720 } else {
721 loge("getPreferredNetworkType: Unknown exception");
722 }
723 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700724 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 break;
726
727 case CMD_SET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
730 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700731 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800732 break;
733
734 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
735 handleNullReturnEvent(msg, "setPreferredNetworkType");
736 break;
737
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000738 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
739 request = (MainThreadRequest)msg.obj;
740 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800741 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000742 break;
743
744 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
745 ar = (AsyncResult)msg.obj;
746 request = (MainThreadRequest)ar.userObj;
747 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700748 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000749 break;
750
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800751 case CMD_SET_VOICEMAIL_NUMBER:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
754 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800755 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
756 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800757 break;
758
759 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
760 handleNullReturnEvent(msg, "setVoicemailNumber");
761 break;
762
Stuart Scott54788802015-03-30 13:18:01 -0700763 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
766 request);
767 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
768 break;
769
770 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
771 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
772 break;
773
Shishir Agrawal302c8692015-06-19 13:49:39 -0700774 case CMD_PERFORM_NETWORK_SCAN:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
777 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
778 break;
779
780 case EVENT_PERFORM_NETWORK_SCAN_DONE:
781 ar = (AsyncResult) msg.obj;
782 request = (MainThreadRequest) ar.userObj;
783 CellNetworkScanResult cellScanResult;
784 if (ar.exception == null && ar.result != null) {
785 cellScanResult = new CellNetworkScanResult(
786 CellNetworkScanResult.STATUS_SUCCESS,
787 (List<OperatorInfo>) ar.result);
788 } else {
789 if (ar.result == null) {
790 loge("getCellNetworkScanResults: Empty response");
791 }
792 if (ar.exception != null) {
793 loge("getCellNetworkScanResults: Exception: " + ar.exception);
794 }
795 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
796 if (ar.exception instanceof CommandException) {
797 CommandException.Error error =
798 ((CommandException) (ar.exception)).getCommandError();
799 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
800 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
801 } else if (error == CommandException.Error.GENERIC_FAILURE) {
802 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
803 }
804 }
805 cellScanResult = new CellNetworkScanResult(errorCode, null);
806 }
807 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700808 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700809 break;
810
811 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
812 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700813 ManualNetworkSelectionArgument selArg =
814 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700815 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
816 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700817 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
818 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700819 break;
820
821 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 if (ar.exception == null) {
825 request.result = true;
826 } else {
827 request.result = false;
828 loge("setNetworkSelectionModeManual " + ar.exception);
829 }
830 notifyRequester(request);
831 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700832 break;
833
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700834 case CMD_GET_MODEM_ACTIVITY_INFO:
835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800837 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700838 break;
839
840 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
841 ar = (AsyncResult) msg.obj;
842 request = (MainThreadRequest) ar.userObj;
843 if (ar.exception == null && ar.result != null) {
844 request.result = ar.result;
845 } else {
846 if (ar.result == null) {
847 loge("queryModemActivityInfo: Empty response");
848 } else if (ar.exception instanceof CommandException) {
849 loge("queryModemActivityInfo: CommandException: " +
850 ar.exception);
851 } else {
852 loge("queryModemActivityInfo: Unknown exception");
853 }
854 }
Amit Mahajand4766222016-01-28 15:28:28 -0800855 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
856 if (request.result == null) {
857 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
858 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700859 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700860 break;
861
Meng Wang1a7c35a2016-05-05 20:56:15 -0700862 case CMD_SET_ALLOWED_CARRIERS:
863 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800864 CarrierRestrictionRules argument =
865 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800867 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700868 break;
869
870 case EVENT_SET_ALLOWED_CARRIERS_DONE:
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null && ar.result != null) {
874 request.result = ar.result;
875 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800876 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
877 if (ar.exception instanceof CommandException) {
878 loge("setAllowedCarriers: CommandException: " + ar.exception);
879 CommandException.Error error =
880 ((CommandException) (ar.exception)).getCommandError();
881 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
882 request.result =
883 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
884 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 } else {
886 loge("setAllowedCarriers: Unknown exception");
887 }
888 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700889 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 break;
891
892 case CMD_GET_ALLOWED_CARRIERS:
893 request = (MainThreadRequest) msg.obj;
894 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800895 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 break;
897
898 case EVENT_GET_ALLOWED_CARRIERS_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null && ar.result != null) {
902 request.result = ar.result;
903 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800904 request.result = new IllegalStateException(
905 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700906 if (ar.result == null) {
907 loge("getAllowedCarriers: Empty response");
908 } else if (ar.exception instanceof CommandException) {
909 loge("getAllowedCarriers: CommandException: " +
910 ar.exception);
911 } else {
912 loge("getAllowedCarriers: Unknown exception");
913 }
914 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700915 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 break;
917
Nathan Haroldb3014052017-01-25 15:57:32 -0800918 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
921 if (ar.exception == null && ar.result != null) {
922 request.result = ar.result;
923 } else {
924 request.result = new IllegalArgumentException(
925 "Failed to retrieve Forbidden Plmns");
926 if (ar.result == null) {
927 loge("getForbiddenPlmns: Empty response");
928 } else {
929 loge("getForbiddenPlmns: Unknown exception");
930 }
931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700932 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800933 break;
934
935 case CMD_GET_FORBIDDEN_PLMNS:
936 request = (MainThreadRequest) msg.obj;
937 uiccCard = getUiccCardFromRequest(request);
938 if (uiccCard == null) {
939 loge("getForbiddenPlmns() UiccCard is null");
940 request.result = new IllegalArgumentException(
941 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 break;
944 }
945 Integer appType = (Integer) request.argument;
946 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
947 if (uiccApp == null) {
948 loge("getForbiddenPlmns() no app with specified type -- "
949 + appType);
950 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700951 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800952 break;
953 } else {
954 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
955 + " specified type -- " + appType);
956 }
957 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
958 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
959 onCompleted);
960 break;
961
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000962 case CMD_SWITCH_SLOTS:
963 request = (MainThreadRequest) msg.obj;
964 int[] physicalSlots = (int[]) request.argument;
965 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
966 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
967 break;
968
969 case EVENT_SWITCH_SLOTS_DONE:
970 ar = (AsyncResult) msg.obj;
971 request = (MainThreadRequest) ar.userObj;
972 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700973 notifyRequester(request);
974 break;
975 case CMD_GET_NETWORK_SELECTION_MODE:
976 request = (MainThreadRequest) msg.obj;
977 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
978 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
979 break;
980
981 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception != null) {
985 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
986 } else {
987 int mode = ((int[]) ar.result)[0];
988 if (mode == 0) {
989 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
990 } else {
991 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
992 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000993 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700994 notifyRequester(request);
995 break;
996 case CMD_GET_CDMA_ROAMING_MODE:
997 request = (MainThreadRequest) msg.obj;
998 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
999 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1000 break;
1001 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 if (ar.exception != null) {
1005 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1006 } else {
1007 request.result = ((int[]) ar.result)[0];
1008 }
1009 notifyRequester(request);
1010 break;
1011 case CMD_SET_CDMA_ROAMING_MODE:
1012 request = (MainThreadRequest) msg.obj;
1013 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1014 int mode = (int) request.argument;
1015 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1016 break;
1017 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 request.result = ar.exception == null;
1021 notifyRequester(request);
1022 break;
1023 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1026 int subscriptionMode = (int) request.argument;
1027 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1028 break;
1029 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 request.result = ar.exception == null;
1033 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001034 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001035 case CMD_GET_ALL_CELL_INFO:
1036 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001037 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001038 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001039 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001040 case EVENT_GET_ALL_CELL_INFO_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001043 // If a timeout occurs, the response will be null
1044 request.result = (ar.exception == null && ar.result != null)
1045 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 synchronized (request) {
1047 request.notifyAll();
1048 }
1049 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001050 case CMD_REQUEST_CELL_INFO_UPDATE:
1051 request = (MainThreadRequest) msg.obj;
1052 request.phone.requestCellInfoUpdate(request.workSource,
1053 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1054 break;
1055 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1059 try {
1060 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001062 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1063 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001066 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001067 } else {
1068 // use the result as returned
1069 cb.onCellInfo((List<CellInfo>) ar.result);
1070 }
1071 } catch (RemoteException re) {
1072 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1073 }
1074 break;
1075 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001076 request = (MainThreadRequest) msg.obj;
1077 WorkSource ws = (WorkSource) request.argument;
1078 Phone phone = getPhoneFromRequest(request);
1079 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1080 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001081 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001082 ar = (AsyncResult) msg.obj;
1083 request = (MainThreadRequest) ar.userObj;
1084 if (ar.exception == null) {
1085 request.result = ar.result;
1086 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001088 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1089 ? new CdmaCellLocation() : new GsmCellLocation();
1090 }
1091
1092 synchronized (request) {
1093 request.notifyAll();
1094 }
1095 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001096 case CMD_MODEM_REBOOT:
1097 request = (MainThreadRequest) msg.obj;
1098 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001099 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001100 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001101 case EVENT_CMD_MODEM_REBOOT_DONE:
1102 handleNullReturnEvent(msg, "rebootModem");
1103 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001104 case CMD_REQUEST_ENABLE_MODEM:
1105 request = (MainThreadRequest) msg.obj;
1106 boolean enable = (boolean) request.argument;
1107 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001108 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001109 PhoneConfigurationManager.getInstance()
1110 .enablePhone(request.phone, enable, onCompleted);
1111 break;
1112 case EVENT_ENABLE_MODEM_DONE:
1113 ar = (AsyncResult) msg.obj;
1114 request = (MainThreadRequest) ar.userObj;
1115 request.result = (ar.exception == null);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001116 //update the cache as modem status has changed
1117 mPhoneConfigurationManager.addToPhoneStatusCache(
1118 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -08001119 updateModemStateMetrics();
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001120 notifyRequester(request);
1121 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001122 default:
1123 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1124 break;
1125 }
1126 }
Jake Hambye994d462014-02-03 13:10:13 -08001127
Pengquan Menga1bb6272018-09-06 09:59:22 -07001128 private void notifyRequester(MainThreadRequest request) {
1129 synchronized (request) {
1130 request.notifyAll();
1131 }
1132 }
1133
Jake Hambye994d462014-02-03 13:10:13 -08001134 private void handleNullReturnEvent(Message msg, String command) {
1135 AsyncResult ar = (AsyncResult) msg.obj;
1136 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1137 if (ar.exception == null) {
1138 request.result = true;
1139 } else {
1140 request.result = false;
1141 if (ar.exception instanceof CommandException) {
1142 loge(command + ": CommandException: " + ar.exception);
1143 } else {
1144 loge(command + ": Unknown exception");
1145 }
1146 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001147 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001149 }
1150
1151 /**
1152 * Posts the specified command to be executed on the main thread,
1153 * waits for the request to complete, and returns the result.
1154 * @see #sendRequestAsync
1155 */
1156 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001157 return sendRequest(
1158 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001159 }
1160
1161 /**
1162 * Posts the specified command to be executed on the main thread,
1163 * waits for the request to complete, and returns the result.
1164 * @see #sendRequestAsync
1165 */
1166 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1167 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001168 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001169 }
1170
1171 /**
1172 * Posts the specified command to be executed on the main thread,
1173 * waits for the request to complete, and returns the result.
1174 * @see #sendRequestAsync
1175 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001176 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001177 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001178 }
1179
1180 /**
1181 * Posts the specified command to be executed on the main thread,
1182 * waits for the request to complete, and returns the result.
1183 * @see #sendRequestAsync
1184 */
Nathan Harold92bed182018-10-12 18:16:49 -07001185 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1186 return sendRequest(command, argument, subId, null, workSource);
1187 }
1188
1189 /**
1190 * Posts the specified command to be executed on the main thread,
1191 * waits for the request to complete, and returns the result.
1192 * @see #sendRequestAsync
1193 */
1194 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1195 return sendRequest(
1196 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1197 }
1198
1199 /**
1200 * Posts the specified command to be executed on the main thread,
1201 * waits for the request to complete, and returns the result.
1202 * @see #sendRequestAsync
1203 */
1204 private Object sendRequest(
1205 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1207 throw new RuntimeException("This method will deadlock if called from the main thread.");
1208 }
1209
Nathan Harold92bed182018-10-12 18:16:49 -07001210 MainThreadRequest request = null;
1211 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1212 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1213 } else if (phone != null) {
1214 request = new MainThreadRequest(argument, phone, workSource);
1215 } else {
1216 request = new MainThreadRequest(argument, subId, workSource);
1217 }
1218
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 Message msg = mMainThreadHandler.obtainMessage(command, request);
1220 msg.sendToTarget();
1221
1222 // Wait for the request to complete
1223 synchronized (request) {
1224 while (request.result == null) {
1225 try {
1226 request.wait();
1227 } catch (InterruptedException e) {
1228 // Do nothing, go back and wait until the request is complete
1229 }
1230 }
1231 }
1232 return request.result;
1233 }
1234
1235 /**
1236 * Asynchronous ("fire and forget") version of sendRequest():
1237 * Posts the specified command to be executed on the main thread, and
1238 * returns immediately.
1239 * @see #sendRequest
1240 */
1241 private void sendRequestAsync(int command) {
1242 mMainThreadHandler.sendEmptyMessage(command);
1243 }
1244
1245 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001246 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001247 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001248 */
1249 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001250 sendRequestAsync(command, argument, null, null);
1251 }
1252
1253 /**
1254 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1255 * @see {@link #sendRequest(int,Object)}
1256 */
1257 private void sendRequestAsync(
1258 int command, Object argument, Phone phone, WorkSource workSource) {
1259 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001260 Message msg = mMainThreadHandler.obtainMessage(command, request);
1261 msg.sendToTarget();
1262 }
1263
1264 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 * Initialize the singleton PhoneInterfaceManager instance.
1266 * This is only done once, at startup, from PhoneApp.onCreate().
1267 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001268 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001269 synchronized (PhoneInterfaceManager.class) {
1270 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001271 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 } else {
1273 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1274 }
1275 return sInstance;
1276 }
1277 }
1278
1279 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001280 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001283 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1285 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001286 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001287 mTelephonySharedPreferences =
1288 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001289 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001290 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001292 publish();
1293 }
1294
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001295 private Phone getDefaultPhone() {
1296 Phone thePhone = getPhone(getDefaultSubscription());
1297 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1298 }
1299
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 private void publish() {
1301 if (DBG) log("publish: " + this);
1302
1303 ServiceManager.addService("phone", this);
1304 }
1305
Stuart Scott584921c2015-01-15 17:10:34 -08001306 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001307 if (request.phone != null) {
1308 return request.phone;
1309 } else {
1310 return getPhoneFromSubId(request.subId);
1311 }
1312 }
1313
1314 private Phone getPhoneFromSubId(int subId) {
1315 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1316 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001317 }
1318
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001319 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1320 Phone phone = getPhoneFromRequest(request);
1321 return phone == null ? null :
1322 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1323 }
1324
Wink Saville36469e72014-06-11 15:17:00 -07001325 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001326 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001327 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329
1330 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001331 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001332 }
1333
Wink Savilleb564aae2014-10-23 10:18:09 -07001334 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 if (DBG) log("dial: " + number);
1336 // No permission check needed here: This is just a wrapper around the
1337 // ACTION_DIAL intent, which is available to any app since it puts up
1338 // the UI before it does anything.
1339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001340 final long identity = Binder.clearCallingIdentity();
1341 try {
1342 String url = createTelUrl(number);
1343 if (url == null) {
1344 return;
1345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001347 // PENDING: should we just silently fail if phone is offhook or ringing?
1348 PhoneConstants.State state = mCM.getState(subId);
1349 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1350 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1351 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1352 mApp.startActivity(intent);
1353 }
1354 } finally {
1355 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001356 }
1357 }
1358
1359 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001360 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001361 }
1362
Wink Savilleb564aae2014-10-23 10:18:09 -07001363 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 if (DBG) log("call: " + number);
1365
1366 // This is just a wrapper around the ACTION_CALL intent, but we still
1367 // need to do a permission check since we're calling startActivity()
1368 // from the context of the phone app.
1369 enforceCallPermission();
1370
1371 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1372 != AppOpsManager.MODE_ALLOWED) {
1373 return;
1374 }
1375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001376 final long identity = Binder.clearCallingIdentity();
1377 try {
1378 String url = createTelUrl(number);
1379 if (url == null) {
1380 return;
1381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001383 boolean isValid = false;
1384 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1385 if (slist != null) {
1386 for (SubscriptionInfo subInfoRecord : slist) {
1387 if (subInfoRecord.getSubscriptionId() == subId) {
1388 isValid = true;
1389 break;
1390 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001391 }
Wink Saville08874612014-08-31 19:19:58 -07001392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001393 if (!isValid) {
1394 return;
1395 }
Wink Saville08874612014-08-31 19:19:58 -07001396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001397 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1398 intent.putExtra(SUBSCRIPTION_KEY, subId);
1399 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1400 mApp.startActivity(intent);
1401 } finally {
1402 Binder.restoreCallingIdentity(identity);
1403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 }
1405
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001407 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001408 }
1409
Wink Savilleb564aae2014-10-23 10:18:09 -07001410 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001411 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001412 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1413 }
1414
1415 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001416 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001417 }
1418
Wink Savilleb564aae2014-10-23 10:18:09 -07001419 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001420 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001421 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1422 }
1423
1424 /** {@hide} */
1425 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001426 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001427 }
1428
Wink Savilleb564aae2014-10-23 10:18:09 -07001429 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001431
1432 final long identity = Binder.clearCallingIdentity();
1433 try {
1434 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1435 checkSimPin.start();
1436 return checkSimPin.unlockSim(null, pin);
1437 } finally {
1438 Binder.restoreCallingIdentity(identity);
1439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 }
1441
Wink Saville9de0f752013-10-22 19:04:03 -07001442 /** {@hide} */
1443 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001444 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001445 }
1446
Wink Savilleb564aae2014-10-23 10:18:09 -07001447 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001449
1450 final long identity = Binder.clearCallingIdentity();
1451 try {
1452 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1453 checkSimPuk.start();
1454 return checkSimPuk.unlockSim(puk, pin);
1455 } finally {
1456 Binder.restoreCallingIdentity(identity);
1457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 }
1459
1460 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001461 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 * a synchronous one.
1463 */
1464 private static class UnlockSim extends Thread {
1465
1466 private final IccCard mSimCard;
1467
1468 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001469 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1470 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471
1472 // For replies from SimCard interface
1473 private Handler mHandler;
1474
1475 // For async handler to identify request type
1476 private static final int SUPPLY_PIN_COMPLETE = 100;
1477
1478 public UnlockSim(IccCard simCard) {
1479 mSimCard = simCard;
1480 }
1481
1482 @Override
1483 public void run() {
1484 Looper.prepare();
1485 synchronized (UnlockSim.this) {
1486 mHandler = new Handler() {
1487 @Override
1488 public void handleMessage(Message msg) {
1489 AsyncResult ar = (AsyncResult) msg.obj;
1490 switch (msg.what) {
1491 case SUPPLY_PIN_COMPLETE:
1492 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1493 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001494 mRetryCount = msg.arg1;
1495 if (ar.exception != null) {
1496 if (ar.exception instanceof CommandException &&
1497 ((CommandException)(ar.exception)).getCommandError()
1498 == CommandException.Error.PASSWORD_INCORRECT) {
1499 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1500 } else {
1501 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1502 }
1503 } else {
1504 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 mDone = true;
1507 UnlockSim.this.notifyAll();
1508 }
1509 break;
1510 }
1511 }
1512 };
1513 UnlockSim.this.notifyAll();
1514 }
1515 Looper.loop();
1516 }
1517
1518 /*
1519 * Use PIN or PUK to unlock SIM card
1520 *
1521 * If PUK is null, unlock SIM card with PIN
1522 *
1523 * If PUK is not null, unlock SIM card with PUK and set PIN code
1524 */
Wink Saville9de0f752013-10-22 19:04:03 -07001525 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526
1527 while (mHandler == null) {
1528 try {
1529 wait();
1530 } catch (InterruptedException e) {
1531 Thread.currentThread().interrupt();
1532 }
1533 }
1534 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1535
1536 if (puk == null) {
1537 mSimCard.supplyPin(pin, callback);
1538 } else {
1539 mSimCard.supplyPuk(puk, pin, callback);
1540 }
1541
1542 while (!mDone) {
1543 try {
1544 Log.d(LOG_TAG, "wait for done");
1545 wait();
1546 } catch (InterruptedException e) {
1547 // Restore the interrupted status
1548 Thread.currentThread().interrupt();
1549 }
1550 }
1551 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001552 int[] resultArray = new int[2];
1553 resultArray[0] = mResult;
1554 resultArray[1] = mRetryCount;
1555 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557 }
1558
1559 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001560 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001561
1562 }
1563
Wink Savilleb564aae2014-10-23 10:18:09 -07001564 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 // No permission check needed here: this call is harmless, and it's
1566 // needed for the ServiceState.requestStateUpdate() call (which is
1567 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001568 final long identity = Binder.clearCallingIdentity();
1569 try {
1570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
1572 phone.updateServiceLocation();
1573 }
1574 } finally {
1575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
1578
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001579 @Override
1580 public boolean isRadioOn(String callingPackage) {
1581 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001582 }
1583
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001584 @Override
1585 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001587 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001588 return false;
1589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001590
1591 final long identity = Binder.clearCallingIdentity();
1592 try {
1593 return isRadioOnForSubscriber(subId);
1594 } finally {
1595 Binder.restoreCallingIdentity(identity);
1596 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001597 }
1598
1599 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001600 final long identity = Binder.clearCallingIdentity();
1601 try {
1602 final Phone phone = getPhone(subId);
1603 if (phone != null) {
1604 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1605 } else {
1606 return false;
1607 }
1608 } finally {
1609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 }
1612
1613 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001614 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
Wink Saville36469e72014-06-11 15:17:00 -07001616
Wink Savilleb564aae2014-10-23 10:18:09 -07001617 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001619
1620 final long identity = Binder.clearCallingIdentity();
1621 try {
1622 final Phone phone = getPhone(subId);
1623 if (phone != null) {
1624 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1625 }
1626 } finally {
1627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001628 }
Wink Saville36469e72014-06-11 15:17:00 -07001629 }
1630
1631 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001632 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001633 }
1634
Wink Savilleb564aae2014-10-23 10:18:09 -07001635 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001636 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001637
1638 final long identity = Binder.clearCallingIdentity();
1639 try {
1640 final Phone phone = getPhone(subId);
1641 if (phone == null) {
1642 return false;
1643 }
1644 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1645 toggleRadioOnOffForSubscriber(subId);
1646 }
1647 return true;
1648 } finally {
1649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
Wink Saville36469e72014-06-11 15:17:00 -07001652
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001653 public boolean needMobileRadioShutdown() {
1654 /*
1655 * If any of the Radios are available, it will need to be
1656 * shutdown. So return true if any Radio is available.
1657 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001658 final long identity = Binder.clearCallingIdentity();
1659 try {
1660 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1661 Phone phone = PhoneFactory.getPhone(i);
1662 if (phone != null && phone.isRadioAvailable()) return true;
1663 }
1664 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1665 return false;
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001668 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001669 }
1670
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001671 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001672 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001673 enforceModifyPermission();
1674
1675 final long identity = Binder.clearCallingIdentity();
1676 try {
1677 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1678 logv("Shutting down Phone " + i);
1679 shutdownRadioUsingPhoneId(i);
1680 }
1681 } finally {
1682 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001683 }
1684 }
1685
1686 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001687 Phone phone = PhoneFactory.getPhone(phoneId);
1688 if (phone != null && phone.isRadioAvailable()) {
1689 phone.shutdownRadio();
1690 }
1691 }
1692
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001694 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001695
1696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1699 if (defaultPhone != null) {
1700 defaultPhone.setRadioPower(turnOn);
1701 return true;
1702 } else {
1703 loge("There's no default phone.");
1704 return false;
1705 }
1706 } finally {
1707 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001708 }
Wink Saville36469e72014-06-11 15:17:00 -07001709 }
1710
Wink Savilleb564aae2014-10-23 10:18:09 -07001711 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.setRadioPower(turnOn);
1719 return true;
1720 } else {
1721 return false;
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
Wink Saville36469e72014-06-11 15:17:00 -07001728 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001729 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 public boolean enableDataConnectivity() {
1731 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001732
1733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 int subId = mSubscriptionController.getDefaultDataSubId();
1736 final Phone phone = getPhone(subId);
1737 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001738 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001739 return true;
1740 } else {
1741 return false;
1742 }
1743 } finally {
1744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 }
1747
Wink Saville36469e72014-06-11 15:17:00 -07001748 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001749 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 public boolean disableDataConnectivity() {
1751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752
1753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 int subId = mSubscriptionController.getDefaultDataSubId();
1756 final Phone phone = getPhone(subId);
1757 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001758 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001759 return true;
1760 } else {
1761 return false;
1762 }
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 }
1767
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001769 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001770 final long identity = Binder.clearCallingIdentity();
1771 try {
1772 final Phone phone = getPhone(subId);
1773 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001774 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001775 } else {
1776 return false;
1777 }
1778 } finally {
1779 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 }
1782
1783 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001784 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001785 }
1786
pkanwarae03a6b2016-11-06 20:37:09 -08001787 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001788 enforceCallPermission();
1789
1790 final long identity = Binder.clearCallingIdentity();
1791 try {
1792 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1793 return;
1794 }
1795 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1796 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1797 } finally {
1798 Binder.restoreCallingIdentity(identity);
1799 }
pkanwar32d516d2016-10-14 19:37:38 -07001800 };
1801
Wink Savilleb564aae2014-10-23 10:18:09 -07001802 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001804
1805 final long identity = Binder.clearCallingIdentity();
1806 try {
1807 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1808 return false;
1809 }
1810 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1811 } finally {
1812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 }
1815
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001817 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001818 }
1819
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001820 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 Phone phone = PhoneFactory.getPhone(slotIndex);
1824 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1825 PhoneConstantConversions.convertCallState(phone.getState());
1826 } finally {
1827 Binder.restoreCallingIdentity(identity);
1828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 }
1830
Sanket Padawe356d7632015-06-22 14:03:32 -07001831 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833 final long identity = Binder.clearCallingIdentity();
1834 try {
1835 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1836 if (phone != null) {
1837 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1838 } else {
1839 return PhoneConstantConversions.convertDataState(
1840 PhoneConstants.DataState.DISCONNECTED);
1841 }
1842 } finally {
1843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 }
1846
Sanket Padawe356d7632015-06-22 14:03:32 -07001847 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1852 if (phone != null) {
1853 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1854 } else {
1855 return TelephonyManager.DATA_ACTIVITY_NONE;
1856 }
1857 } finally {
1858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 }
1861
1862 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001863 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001864 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001865 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001866
1867 LocationAccessPolicy.LocationPermissionResult locationResult =
1868 LocationAccessPolicy.checkLocationPermission(mApp,
1869 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1870 .setCallingPackage(callingPackage)
1871 .setCallingPid(Binder.getCallingPid())
1872 .setCallingUid(Binder.getCallingUid())
1873 .setMethod("getCellLocation")
1874 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1875 .build());
1876 switch (locationResult) {
1877 case DENIED_HARD:
1878 throw new SecurityException("Not allowed to access cell location");
1879 case DENIED_SOFT:
1880 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 }
1882
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001883 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001884 final long identity = Binder.clearCallingIdentity();
1885 try {
1886 if (DBG_LOC) log("getCellLocation: is active user");
1887 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001888 int subId = mSubscriptionController.getDefaultDataSubId();
1889 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1890 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001891 return data;
1892 } finally {
1893 Binder.restoreCallingIdentity(identity);
1894 }
Svetoslav64fad262015-04-14 14:35:21 -07001895 }
1896
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001898 public String getNetworkCountryIsoForPhone(int phoneId) {
1899 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1900 // registered cell info, so return a NULL country instead.
1901 final long identity = Binder.clearCallingIdentity();
1902 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001903 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1904 // Get default phone in this case.
1905 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1906 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001907 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001908 // Todo: fix this when we can get the actual cellular network info when the device
1909 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001910 if (TelephonyManager.NETWORK_TYPE_IWLAN
1911 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1912 return "";
1913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 Phone phone = PhoneFactory.getPhone(phoneId);
1915 if (phone != null) {
1916 ServiceStateTracker sst = phone.getServiceStateTracker();
1917 if (sst != null) {
1918 LocaleTracker lt = sst.getLocaleTracker();
1919 if (lt != null) {
1920 return lt.getCurrentCountry();
1921 }
1922 }
1923 }
1924 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001925 } finally {
1926 Binder.restoreCallingIdentity(identity);
1927 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001928 }
1929
1930 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001932 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001933 }
1934
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001936 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 mApp.enforceCallingOrSelfPermission(
1938 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001939
1940 final long identity = Binder.clearCallingIdentity();
1941 try {
1942 final Phone phone = getPhone(subId);
1943 if (phone != null) {
1944 phone.enableLocationUpdates();
1945 }
1946 } finally {
1947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 }
1950
1951 @Override
1952 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001953 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001954 }
1955
Sanket Padawe356d7632015-06-22 14:03:32 -07001956 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001957 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958 mApp.enforceCallingOrSelfPermission(
1959 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001960
1961 final long identity = Binder.clearCallingIdentity();
1962 try {
1963 final Phone phone = getPhone(subId);
1964 if (phone != null) {
1965 phone.disableLocationUpdates();
1966 }
1967 } finally {
1968 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971
Nathan Harold31d7ff32018-10-15 20:20:30 -07001972 /**
1973 * Returns the target SDK version number for a given package name.
1974 *
1975 * @return target SDK if the package is found or INT_MAX.
1976 */
1977 private int getTargetSdk(String packageName) {
1978 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001979 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1980 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001981 if (ai != null) return ai.targetSdkVersion;
1982 } catch (PackageManager.NameNotFoundException unexpected) {
1983 }
1984 return Integer.MAX_VALUE;
1985 }
1986
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 @Override
1988 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001989 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1990 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001991 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1992 throw new SecurityException(
1993 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1994 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001995
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1997 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1998 return null;
1999 }
Svetoslav64fad262015-04-14 14:35:21 -07002000
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002001 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002
Nathan Haroldf180aac2018-06-01 18:43:55 -07002003 List<CellInfo> info = getAllCellInfo(callingPackage);
2004 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005
Nathan Haroldf180aac2018-06-01 18:43:55 -07002006 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2007 for (CellInfo ci : info) {
2008 if (ci instanceof CellInfoGsm) {
2009 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2010 } else if (ci instanceof CellInfoWcdma) {
2011 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002014 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 }
2016
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002017 private List<CellInfo> getCachedCellInfo() {
2018 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2019 for (Phone phone : PhoneFactory.getPhones()) {
2020 List<CellInfo> info = phone.getAllCellInfo();
2021 if (info != null) cellInfos.addAll(info);
2022 }
2023 return cellInfos;
2024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002025
2026 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002027 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002028 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002029 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002030
2031 LocationAccessPolicy.LocationPermissionResult locationResult =
2032 LocationAccessPolicy.checkLocationPermission(mApp,
2033 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2034 .setCallingPackage(callingPackage)
2035 .setCallingPid(Binder.getCallingPid())
2036 .setCallingUid(Binder.getCallingUid())
2037 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002038 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002039 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2040 .build());
2041 switch (locationResult) {
2042 case DENIED_HARD:
2043 throw new SecurityException("Not allowed to access cell info");
2044 case DENIED_SOFT:
2045 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 }
2047
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002048 final int targetSdk = getTargetSdk(callingPackage);
2049 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2050 return getCachedCellInfo();
2051 }
2052
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002053 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002054 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002055 final long identity = Binder.clearCallingIdentity();
2056 try {
2057 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2058 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002059 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002060 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061 if (info != null) cellInfos.addAll(info);
2062 }
2063 return cellInfos;
2064 } finally {
2065 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 }
2067 }
2068
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002069 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002070 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2071 requestCellInfoUpdateInternal(
2072 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2073 }
2074
2075 @Override
2076 public void requestCellInfoUpdateWithWorkSource(
2077 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2078 enforceModifyPermission();
2079 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2080 }
2081
2082 private void requestCellInfoUpdateInternal(
2083 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002084 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002085 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002086
2087 LocationAccessPolicy.LocationPermissionResult locationResult =
2088 LocationAccessPolicy.checkLocationPermission(mApp,
2089 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2090 .setCallingPackage(callingPackage)
2091 .setCallingPid(Binder.getCallingPid())
2092 .setCallingUid(Binder.getCallingUid())
2093 .setMethod("requestCellInfoUpdate")
2094 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2095 .build());
2096 switch (locationResult) {
2097 case DENIED_HARD:
2098 throw new SecurityException("Not allowed to access cell info");
2099 case DENIED_SOFT:
2100 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002101 }
2102
2103 final Phone phone = getPhone(subId);
2104 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2105
2106 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2107 }
2108
2109 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002111 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002116 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 }
2121
Shishir Agrawala9f32182016-04-12 12:00:16 -07002122 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002123 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002124 Phone phone = PhoneFactory.getPhone(slotIndex);
2125 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002126 return null;
2127 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002128 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002129 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2130 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002131 return null;
2132 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 return phone.getImei();
2137 } finally {
2138 Binder.restoreCallingIdentity(identity);
2139 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002140 }
2141
2142 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002143 public String getTypeAllocationCodeForSlot(int slotIndex) {
2144 Phone phone = PhoneFactory.getPhone(slotIndex);
2145 String tac = null;
2146 if (phone != null) {
2147 String imei = phone.getImei();
2148 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2149 }
2150 return tac;
2151 }
2152
2153 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002154 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002155 Phone phone = PhoneFactory.getPhone(slotIndex);
2156 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002157 return null;
2158 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002159
Jeff Davidson913390f2018-02-23 17:11:49 -08002160 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002161 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2162 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002163 return null;
2164 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002165
2166 final long identity = Binder.clearCallingIdentity();
2167 try {
2168 return phone.getMeid();
2169 } finally {
2170 Binder.restoreCallingIdentity(identity);
2171 }
Jack Yu2af8d712017-03-15 17:14:14 -07002172 }
2173
2174 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002175 public String getManufacturerCodeForSlot(int slotIndex) {
2176 Phone phone = PhoneFactory.getPhone(slotIndex);
2177 String manufacturerCode = null;
2178 if (phone != null) {
2179 String meid = phone.getMeid();
2180 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2181 }
2182 return manufacturerCode;
2183 }
2184
2185 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002186 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002187 Phone phone = PhoneFactory.getPhone(slotIndex);
2188 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002189 return null;
2190 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002191 int subId = phone.getSubId();
2192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2193 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2194 return null;
2195 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002196
2197 final long identity = Binder.clearCallingIdentity();
2198 try {
2199 return phone.getDeviceSvn();
2200 } finally {
2201 Binder.restoreCallingIdentity(identity);
2202 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002203 }
2204
fionaxu43304da2017-11-27 22:51:16 -08002205 @Override
2206 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207 final long identity = Binder.clearCallingIdentity();
2208 try {
2209 final Phone phone = getPhone(subId);
2210 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
2213 }
fionaxu43304da2017-11-27 22:51:16 -08002214 }
2215
2216 @Override
2217 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002218 final long identity = Binder.clearCallingIdentity();
2219 try {
2220 final Phone phone = getPhone(subId);
2221 return phone == null ? null : phone.getCarrierName();
2222 } finally {
2223 Binder.restoreCallingIdentity(identity);
2224 }
fionaxu43304da2017-11-27 22:51:16 -08002225 }
2226
calvinpanffe225e2018-11-01 19:43:06 +08002227 @Override
chen xu0026ca62019-03-06 15:28:50 -08002228 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002229 final long identity = Binder.clearCallingIdentity();
2230 try {
2231 final Phone phone = getPhone(subId);
2232 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002233 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002234 } finally {
2235 Binder.restoreCallingIdentity(identity);
2236 }
2237 }
2238
2239 @Override
chen xu0026ca62019-03-06 15:28:50 -08002240 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002241 final long identity = Binder.clearCallingIdentity();
2242 try {
2243 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002244 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002245 } finally {
2246 Binder.restoreCallingIdentity(identity);
2247 }
2248 }
2249
chen xu651eec72018-11-11 19:03:44 -08002250 @Override
chen xu864e11c2018-12-06 22:10:03 -08002251 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2252 if (!isSubscriptionMccMnc) {
2253 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2254 }
chen xu651eec72018-11-11 19:03:44 -08002255 final Phone phone = PhoneFactory.getPhone(slotIndex);
2256 if (phone == null) {
2257 return TelephonyManager.UNKNOWN_CARRIER_ID;
2258 }
2259 final long identity = Binder.clearCallingIdentity();
2260 try {
2261 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
2264 }
2265 }
2266
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 //
2268 // Internal helper methods.
2269 //
2270
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002271 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2273 *
2274 * @throws SecurityException if the caller does not have the required permission
2275 */
2276 private void enforceModifyPermission() {
2277 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2278 }
2279
2280 /**
2281 * Make sure the caller has the CALL_PHONE permission.
2282 *
2283 * @throws SecurityException if the caller does not have the required permission
2284 */
2285 private void enforceCallPermission() {
2286 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2287 }
2288
Stuart Scott8eef64f2015-04-08 15:13:54 -07002289 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002290 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002291 "ConnectivityService");
2292 }
2293
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 private String createTelUrl(String number) {
2295 if (TextUtils.isEmpty(number)) {
2296 return null;
2297 }
2298
Jake Hambye994d462014-02-03 13:10:13 -08002299 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
Ihab Awadf9e92732013-12-05 18:02:52 -08002302 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2304 }
2305
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002306 private static void logv(String msg) {
2307 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2308 }
2309
Ihab Awadf9e92732013-12-05 18:02:52 -08002310 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2312 }
2313
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002316 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002317 }
2318
Sanket Padawe356d7632015-06-22 14:03:32 -07002319 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002320 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002321 final long identity = Binder.clearCallingIdentity();
2322 try {
2323 final Phone phone = PhoneFactory.getPhone(slotIndex);
2324 if (phone == null) {
2325 return PhoneConstants.PHONE_TYPE_NONE;
2326 } else {
2327 return phone.getPhoneType();
2328 }
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 }
2333
2334 /**
2335 * Returns the CDMA ERI icon index to display
2336 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002337 @Override
2338 public int getCdmaEriIconIndex(String callingPackage) {
2339 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002340 }
2341
Sanket Padawe356d7632015-06-22 14:03:32 -07002342 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002343 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002345 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002346 return -1;
2347 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348
2349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 final Phone phone = getPhone(subId);
2352 if (phone != null) {
2353 return phone.getCdmaEriIconIndex();
2354 } else {
2355 return -1;
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
2362 /**
2363 * Returns the CDMA ERI icon mode,
2364 * 0 - ON
2365 * 1 - FLASHING
2366 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002367 @Override
2368 public int getCdmaEriIconMode(String callingPackage) {
2369 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002370 }
2371
Sanket Padawe356d7632015-06-22 14:03:32 -07002372 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002373 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002375 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002376 return -1;
2377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378
2379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 final Phone phone = getPhone(subId);
2382 if (phone != null) {
2383 return phone.getCdmaEriIconMode();
2384 } else {
2385 return -1;
2386 }
2387 } finally {
2388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 }
2391
2392 /**
2393 * Returns the CDMA ERI text,
2394 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002395 @Override
2396 public String getCdmaEriText(String callingPackage) {
2397 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002398 }
2399
Sanket Padawe356d7632015-06-22 14:03:32 -07002400 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002401 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002402 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002403 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002404 return null;
2405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002406
2407 final long identity = Binder.clearCallingIdentity();
2408 try {
2409 final Phone phone = getPhone(subId);
2410 if (phone != null) {
2411 return phone.getCdmaEriText();
2412 } else {
2413 return null;
2414 }
2415 } finally {
2416 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 }
2419
2420 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002421 * Returns the CDMA MDN.
2422 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002423 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002424 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2426 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427
2428 final long identity = Binder.clearCallingIdentity();
2429 try {
2430 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002431 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432 return phone.getLine1Number();
2433 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002434 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435 return null;
2436 }
2437 } finally {
2438 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002439 }
2440 }
2441
2442 /**
2443 * Returns the CDMA MIN.
2444 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002445 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002446 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2448 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002449
2450 final long identity = Binder.clearCallingIdentity();
2451 try {
2452 final Phone phone = getPhone(subId);
2453 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2454 return phone.getCdmaMin();
2455 } else {
2456 return null;
2457 }
2458 } finally {
2459 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002460 }
2461 }
2462
Hall Liud892bec2018-11-30 14:51:45 -08002463 @Override
2464 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2465 INumberVerificationCallback callback, String callingPackage) {
2466 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2467 != PERMISSION_GRANTED) {
2468 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2469 }
2470 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2471
2472 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2473 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2474 throw new SecurityException("Calling package must be configured in the device config");
2475 }
2476
2477 if (range == null) {
2478 throw new NullPointerException("Range must be non-null");
2479 }
2480
2481 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002482 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002483
2484 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2485 }
2486
Junda Liuca05d5d2014-08-14 22:36:34 -07002487 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 * Returns true if CDMA provisioning needs to run.
2489 */
2490 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491 final long identity = Binder.clearCallingIdentity();
2492 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002493 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002494 } finally {
2495 Binder.restoreCallingIdentity(identity);
2496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
2499 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002500 * Sets the voice mail number of a given subId.
2501 */
2502 @Override
2503 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002504 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2509 new Pair<String, String>(alphaTag, number), new Integer(subId));
2510 return success;
2511 } finally {
2512 Binder.restoreCallingIdentity(identity);
2513 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002514 }
2515
Ta-wei Yen87c49842016-05-13 21:19:52 -07002516 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002517 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002519 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002520 if (!TextUtils.equals(callingPackage, systemDialer)) {
2521 throw new SecurityException("caller must be system dialer");
2522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523
2524 final long identity = Binder.clearCallingIdentity();
2525 try {
2526 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2527 if (phoneAccountHandle == null) {
2528 return null;
2529 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002530 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531 } finally {
2532 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002533 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002534 }
2535
2536 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002537 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002538 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002540 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002541 return null;
2542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002544 final long identity = Binder.clearCallingIdentity();
2545 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002546 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002547 } finally {
2548 Binder.restoreCallingIdentity(identity);
2549 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002550 }
2551
2552 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002553 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2554 VisualVoicemailSmsFilterSettings settings) {
2555 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002560 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561 } finally {
2562 Binder.restoreCallingIdentity(identity);
2563 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002564 }
2565
2566 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002567 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2568 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002573 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574 } finally {
2575 Binder.restoreCallingIdentity(identity);
2576 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002577 }
2578
2579 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002580 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2581 String callingPackage, int subId) {
2582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002587 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588 } finally {
2589 Binder.restoreCallingIdentity(identity);
2590 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002591 }
2592
2593 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002594 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002595 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002600 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 } finally {
2602 Binder.restoreCallingIdentity(identity);
2603 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002604 }
2605
2606 @Override
2607 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2608 String number, int port, String text, PendingIntent sentIntent) {
2609 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002610 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002611 enforceSendSmsPermission();
2612 // Make the calls as the phone process.
2613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2616 if (port == 0) {
2617 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2618 sentIntent, null, false);
2619 } else {
2620 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2621 smsManager.sendDataMessageWithSelfPermissions(number, null,
2622 (short) port, data, sentIntent, null);
2623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
2626 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002627 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002628 /**
fionaxu0152e512016-11-14 13:36:14 -08002629 * Sets the voice activation state of a given subId.
2630 */
2631 @Override
2632 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2634 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 final Phone phone = getPhone(subId);
2639 if (phone != null) {
2640 phone.setVoiceActivationState(activationState);
2641 } else {
2642 loge("setVoiceActivationState fails with invalid subId: " + subId);
2643 }
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002646 }
2647 }
2648
2649 /**
2650 * Sets the data activation state of a given subId.
2651 */
2652 @Override
2653 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2655 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656
2657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 final Phone phone = getPhone(subId);
2660 if (phone != null) {
2661 phone.setDataActivationState(activationState);
2662 } else {
2663 loge("setVoiceActivationState fails with invalid subId: " + subId);
2664 }
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002667 }
2668 }
2669
2670 /**
2671 * Returns the voice activation state of a given subId.
2672 */
2673 @Override
2674 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002675 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676
fionaxu0152e512016-11-14 13:36:14 -08002677 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678 final long identity = Binder.clearCallingIdentity();
2679 try {
2680 if (phone != null) {
2681 return phone.getVoiceActivationState();
2682 } else {
2683 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2684 }
2685 } finally {
2686 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002687 }
2688 }
2689
2690 /**
2691 * Returns the data activation state of a given subId.
2692 */
2693 @Override
2694 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002695 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696
fionaxu0152e512016-11-14 13:36:14 -08002697 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 if (phone != null) {
2701 return phone.getDataActivationState();
2702 } else {
2703 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002707 }
2708 }
2709
2710 /**
Wink Saville36469e72014-06-11 15:17:00 -07002711 * Returns the unread count of voicemails for a subId
2712 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002714 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2716 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2717 return 0;
2718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 final Phone phone = getPhone(subId);
2722 if (phone != null) {
2723 return phone.getVoiceMessageCount();
2724 } else {
2725 return 0;
2726 }
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 }
2731
2732 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002733 * returns true, if the device is in a state where both voice and data
2734 * are supported simultaneously. This can change based on location or network condition.
2735 */
2736 @Override
2737 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 final Phone phone = getPhone(subId);
2741 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002745 }
2746
2747 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002748 * Send the dialer code if called from the current default dialer or the caller has
2749 * carrier privilege.
2750 * @param inputCode The dialer code to send
2751 */
2752 @Override
2753 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002754 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002756 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2757 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002758 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002759 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2760 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002765 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766 } finally {
2767 Binder.restoreCallingIdentity(identity);
2768 }
fionaxu235cc5e2017-03-06 22:25:57 -08002769 }
2770
2771 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002772 * Returns the data network type.
2773 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 *
2775 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2776 */
2777 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002778 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 final Phone phone = getPhone(getDefaultSubscription());
2782 if (phone != null) {
2783 return phone.getServiceState().getDataNetworkType();
2784 } else {
2785 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002789 }
Wink Saville36469e72014-06-11 15:17:00 -07002790 }
2791
Pengquan Menga1bb6272018-09-06 09:59:22 -07002792 @Override
2793 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002794 if (!isActiveSubscription(subId)) {
2795 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2796 }
2797
Pengquan Menga1bb6272018-09-06 09:59:22 -07002798 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2799 }
2800
Brad Ebinger35c841c2018-10-01 10:40:55 -07002801 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002802 public boolean isInEmergencySmsMode() {
2803 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 for (Phone phone : PhoneFactory.getPhones()) {
2807 if (phone.isInEmergencySmsMode()) {
2808 return true;
2809 }
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
2813 }
2814 return false;
2815 }
2816
2817 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002818 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2819 throws RemoteException {
2820 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002821 final long token = Binder.clearCallingIdentity();
2822 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002824 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002825 .addRegistrationCallbackForSubscription(c, subId);
2826 } finally {
2827 Binder.restoreCallingIdentity(token);
2828 }
2829 }
2830
2831 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002832 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2833 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002834 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2835 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2836 }
2837 Binder.withCleanCallingIdentity(() -> {
2838 try {
2839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002840 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002841 .removeRegistrationCallbackForSubscription(c, subId);
2842 } catch (IllegalArgumentException e) {
2843 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2844 + "is inactive, ignoring unregister.");
2845 // If the subscription is no longer active, just return, since the callback
2846 // will already have been removed internally.
2847 }
2848 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002849 }
2850
2851 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002852 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2853 throws RemoteException {
2854 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2856 final long token = Binder.clearCallingIdentity();
2857 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002858 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002859 .addCapabilitiesCallbackForSubscription(c, subId);
2860 } finally {
2861 Binder.restoreCallingIdentity(token);
2862 }
2863 }
2864
2865 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002866 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2867 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002868
2869 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2870 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2871 }
2872 Binder.withCleanCallingIdentity(() -> {
2873 try {
2874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002875 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002876 .removeCapabilitiesCallbackForSubscription(c, subId);
2877 } catch (IllegalArgumentException e) {
2878 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2879 + "is inactive, ignoring unregister.");
2880 // If the subscription is no longer active, just return, since the callback
2881 // will already have been removed internally.
2882 }
2883 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002884 }
2885
2886 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002887 public boolean isCapable(int subId, int capability, int regTech) {
2888 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2890 final long token = Binder.clearCallingIdentity();
2891 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002892 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002893 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2894 } catch (ImsException e) {
2895 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2896 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002897 } catch (IllegalArgumentException e) {
2898 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2899 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002900 } finally {
2901 Binder.restoreCallingIdentity(token);
2902 }
2903 }
2904
2905 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002906 public boolean isAvailable(int subId, int capability, int regTech) {
2907 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002908 final long token = Binder.clearCallingIdentity();
2909 try {
2910 Phone phone = getPhone(subId);
2911 if (phone == null) return false;
2912 return phone.isImsCapabilityAvailable(capability, regTech);
2913 } finally {
2914 Binder.restoreCallingIdentity(token);
2915 }
2916 }
2917
2918 @Override
2919 public boolean isAdvancedCallingSettingEnabled(int subId) {
2920 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2922 final long token = Binder.clearCallingIdentity();
2923 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002924 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002925 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2926 } finally {
2927 Binder.restoreCallingIdentity(token);
2928 }
2929 }
2930
2931 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002932 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002934 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002938 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002939 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
2942 }
2943 }
2944
2945 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002946 public boolean isVtSettingEnabled(int subId) {
2947 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002951 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 getSlotIndexOrException(subId)).isVtEnabledByUser();
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
2955 }
2956 }
2957
2958 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002959 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002961 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002965 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 @Override
2972 public boolean isVoWiFiSettingEnabled(int subId) {
2973 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002977 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002978 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002985 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002987 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002991 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
2997 @Override
2998 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2999 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003003 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003004 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
3008 }
3009
3010 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003011 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003013 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003017 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003018 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
3025 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3027 "setVoWiFiNonPersistent");
3028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003031 boolean isRoaming = TelephonyManager.from(
3032 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003033 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003034 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
3038 }
3039
3040 @Override
3041 public int getVoWiFiModeSetting(int subId) {
3042 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003046 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003047 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
3050 }
3051 }
3052
3053 @Override
3054 public void setVoWiFiModeSetting(int subId, int mode) {
3055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3056 "setVoWiFiModeSetting");
3057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003060 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003061 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
3065 }
3066
3067 @Override
3068 public int getVoWiFiRoamingModeSetting(int subId) {
3069 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003073 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003074 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 @Override
3081 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3083 "setVoWiFiRoamingModeSetting");
3084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003087 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003088 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
3092 }
3093
3094 @Override
3095 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3097 "setRttCapabilityEnabled");
3098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003101 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
3106 }
3107
3108 @Override
3109 public boolean isTtyOverVolteEnabled(int subId) {
3110 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003114 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003115 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
3119 }
3120
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003121 @Override
3122 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3123 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003127 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003128 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
3132 }
3133
3134 @Override
3135 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3136 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3137 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003138 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3139 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3140 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003141 try {
3142 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003143 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003144 .removeProvisioningCallbackForSubscription(callback, subId);
3145 } catch (IllegalArgumentException e) {
3146 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3147 + "is inactive, ignoring unregister.");
3148 // If the subscription is no longer active, just return, since the callback will already
3149 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
3153 }
3154
3155 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003156 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3157 boolean isProvisioned) {
3158 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3159 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3160 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3161 }
3162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3163 "setProvisioningStatusForCapability");
3164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3167 Phone phone = getPhone(subId);
3168 if (phone == null) {
3169 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3170 + subId);
3171 return;
3172 }
3173 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3174 return;
3175 }
3176
3177 // this capability requires provisioning, route to the correct API.
3178 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3179 switch (capability) {
3180 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3181 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3182 ims.setVolteProvisioned(isProvisioned);
3183 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3184 ims.setWfcProvisioned(isProvisioned);
3185 }
3186 break;
3187 }
3188 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3189 // There is currently no difference in VT provisioning type.
3190 ims.setVtProvisioned(isProvisioned);
3191 break;
3192 }
3193 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3194 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3195 // change the capability of the feature instead if needed.
3196 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3197 == isProvisioned) {
3198 // No change in provisioning.
3199 return;
3200 }
3201 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3202 try {
3203 ims.changeMmTelCapability(capability, tech, isProvisioned);
3204 } catch (ImsException e) {
3205 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3206 + ", Exception" + e.getMessage());
3207 }
3208 break;
3209 }
3210 default: {
3211 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3212 + capability + "', which does not require provisioning.");
3213 }
3214 }
3215
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
3219 }
3220
3221 @Override
3222 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3223 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3224 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3225 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3226 }
3227 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3231 Phone phone = getPhone(subId);
3232 if (phone == null) {
3233 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3234 + subId);
3235 // We will fail with "true" as the provisioning status because this is the default
3236 // if we do not require provisioning.
3237 return true;
3238 }
3239
3240 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3241 return true;
3242 }
3243
3244 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3245 switch (capability) {
3246 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3247 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3248 return ims.isVolteProvisionedOnDevice();
3249 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3250 return ims.isWfcProvisionedOnDevice();
3251 }
3252 // This should never happen, since we are checking tech above to make sure it
3253 // is either LTE or IWLAN.
3254 throw new IllegalArgumentException("Invalid radio technology for voice "
3255 + "capability.");
3256 }
3257 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3258 // There is currently no difference in VT provisioning type.
3259 return ims.isVtProvisionedOnDevice();
3260 }
3261 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3262 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3263 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3264 }
3265 default: {
3266 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3267 + capability + "', which does not require provisioning.");
3268 }
3269 }
3270
3271 } finally {
3272 Binder.restoreCallingIdentity(identity);
3273 }
3274 }
3275
3276 @Override
3277 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3278 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3279 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3280 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3281 }
3282 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3283 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3284 return (provisionedBits & capability) > 0;
3285 }
3286
3287 @Override
3288 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3289 boolean isProvisioned) {
3290 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3291 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3292 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3293 }
3294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3295 "setProvisioningStatusForCapability");
3296 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3297 // If the current provisioning status for capability already matches isProvisioned,
3298 // do nothing.
3299 if (((provisionedBits & capability) > 0) == isProvisioned) {
3300 return;
3301 }
3302 if (isProvisioned) {
3303 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3304 } else {
3305 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3306 }
3307 }
3308
3309 /**
3310 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3311 * technology. The bitfield should mirror the bitfield defined by
3312 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3313 */
3314 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3315 String key = getMmTelProvisioningKey(subId, tech);
3316 // Default is no capabilities are provisioned.
3317 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3318 }
3319
3320 /**
3321 * Sets the MmTel capability provisioning bitfield (defined by
3322 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3323 * technology specified.
3324 *
3325 * Note: This is a synchronous command and should not be called on UI thread.
3326 */
3327 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3328 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3329 String key = getMmTelProvisioningKey(subId, tech);
3330 editor.putInt(key, newField);
3331 editor.commit();
3332 }
3333
3334 private static String getMmTelProvisioningKey(int subId, int tech) {
3335 // resulting key is provision_ims_mmtel_{subId}_{tech}
3336 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3337 }
3338
3339 /**
3340 * Query CarrierConfig to see if the specified capability requires provisioning for the
3341 * carrier associated with the subscription id.
3342 */
3343 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3344 int capability) {
3345 CarrierConfigManager configManager = new CarrierConfigManager(context);
3346 PersistableBundle c = configManager.getConfigForSubId(subId);
3347 boolean requireUtProvisioning = c.getBoolean(
3348 // By default, this config is true (even if there is no SIM). We also check to make
3349 // sure the subscription needs provisioning here, so we do not need to check for
3350 // the no-SIM case, where we would normally shortcut this to false.
3351 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3352 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3353 false);
3354 boolean requireVoiceVtProvisioning = c.getBoolean(
3355 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3356
3357 // First check to make sure that the capability requires provisioning.
3358 switch (capability) {
3359 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3360 // intentional fallthrough
3361 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3362 if (requireVoiceVtProvisioning) {
3363 // Voice and Video requires provisioning
3364 return true;
3365 }
3366 break;
3367 }
3368 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3369 if (requireUtProvisioning) {
3370 // UT requires provisioning
3371 return true;
3372 }
3373 break;
3374 }
3375 }
3376 return false;
3377 }
3378
3379 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003380 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003381 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3382 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3383 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003384 enforceReadPrivilegedPermission("getImsProvisioningInt");
3385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003388 int slotId = getSlotIndex(subId);
3389 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3390 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3391 + subId + "' for key:" + key);
3392 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3393 }
3394 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003395 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003396 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3397 + subId + "' for key:" + key);
3398 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
3402 }
3403
3404 @Override
3405 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003406 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3407 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3408 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003409 enforceReadPrivilegedPermission("getImsProvisioningString");
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003413 int slotId = getSlotIndex(subId);
3414 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3415 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3416 + subId + "' for key:" + key);
3417 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3418 }
3419 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003420 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3422 + subId + "' for key:" + key);
3423 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
3429 @Override
3430 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003431 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3432 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3433 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3435 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003439 int slotId = getSlotIndex(subId);
3440 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3441 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3442 + subId + "' for key:" + key);
3443 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3444 }
3445 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003446 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003447 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3448 + "' for key:" + key);
3449 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
3453 }
3454
3455 @Override
3456 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003457 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3458 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3459 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3461 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003462 final long identity = Binder.clearCallingIdentity();
3463 try {
3464 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003465 int slotId = getSlotIndex(subId);
3466 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3467 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3468 + subId + "' for key:" + key);
3469 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3470 }
3471 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003472 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003473 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3474 + "' for key:" + key);
3475 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003476 } finally {
3477 Binder.restoreCallingIdentity(identity);
3478 }
3479 }
3480
Brad Ebinger35c841c2018-10-01 10:40:55 -07003481 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3482 int slotId = SubscriptionManager.getSlotIndex(subId);
3483 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003484 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003485 }
3486 return slotId;
3487 }
3488
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003489 private int getSlotIndex(int subId) {
3490 int slotId = SubscriptionManager.getSlotIndex(subId);
3491 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3492 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3493 }
3494 return slotId;
3495 }
3496
Wink Saville36469e72014-06-11 15:17:00 -07003497 /**
3498 * Returns the network type for a subId
3499 */
3500 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003501 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003503 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003504 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3505 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 final Phone phone = getPhone(subId);
3510 if (phone != null) {
3511 return phone.getServiceState().getDataNetworkType();
3512 } else {
3513 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3514 }
3515 } finally {
3516 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003518 }
3519
3520 /**
3521 * Returns the data network type
3522 */
3523 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003524 public int getDataNetworkType(String callingPackage) {
3525 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003526 }
3527
3528 /**
3529 * Returns the data network type for a subId
3530 */
3531 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003532 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003533 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003534 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3536 }
3537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 final Phone phone = getPhone(subId);
3541 if (phone != null) {
3542 return phone.getServiceState().getDataNetworkType();
3543 } else {
3544 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3545 }
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003549 }
3550
3551 /**
Wink Saville36469e72014-06-11 15:17:00 -07003552 * Returns the Voice network type for a subId
3553 */
3554 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003555 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003557 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003558 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3559 }
3560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 final Phone phone = getPhone(subId);
3564 if (phone != null) {
3565 return phone.getServiceState().getVoiceNetworkType();
3566 } else {
3567 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3568 }
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003572 }
3573
3574 /**
3575 * @return true if a ICC card is present
3576 */
3577 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003578 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003579 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3580 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003581 }
3582
3583 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003584 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003585 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003586 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003587 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 final Phone phone = PhoneFactory.getPhone(slotIndex);
3591 if (phone != null) {
3592 return phone.getIccCard().hasIccCard();
3593 } else {
3594 return false;
3595 }
3596 } finally {
3597 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003599 }
3600
3601 /**
3602 * Return if the current radio is LTE on CDMA. This
3603 * is a tri-state return value as for a period of time
3604 * the mode may be unknown.
3605 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003606 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003607 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003608 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003609 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003610 @Override
3611 public int getLteOnCdmaMode(String callingPackage) {
3612 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003613 }
3614
Sanket Padawe356d7632015-06-22 14:03:32 -07003615 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003616 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003618 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003619 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3620 }
3621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 final Phone phone = getPhone(subId);
3625 if (phone == null) {
3626 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3627 } else {
3628 return phone.getLteOnCdmaMode();
3629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003632 }
Wink Saville36469e72014-06-11 15:17:00 -07003633 }
3634
Wink Saville36469e72014-06-11 15:17:00 -07003635 /**
3636 * {@hide}
3637 * Returns Default subId, 0 in the case of single standby.
3638 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003639 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003640 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003641 }
3642
Shishir Agrawala9f32182016-04-12 12:00:16 -07003643 private int getSlotForDefaultSubscription() {
3644 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3645 }
3646
Wink Savilleb564aae2014-10-23 10:18:09 -07003647 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003648 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003650
Pengquan Menge92a50d2018-09-21 15:54:48 -07003651 private boolean isActiveSubscription(int subId) {
3652 return mSubscriptionController.isActiveSubId(subId);
3653 }
3654
Ihab Awadf2177b72013-11-25 13:33:23 -08003655 /**
3656 * @see android.telephony.TelephonyManager.WifiCallingChoices
3657 */
3658 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003661 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3663 getWhenToMakeWifiCallsDefaultPreference());
3664 } finally {
3665 Binder.restoreCallingIdentity(identity);
3666 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003667 }
3668
3669 /**
3670 * @see android.telephony.TelephonyManager.WifiCallingChoices
3671 */
3672 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003676 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003681 }
3682
Sailesh Nepald1e68152013-12-12 19:08:02 -08003683 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003684 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003685 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003686 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003687
Jordan Liu4c733742019-02-28 12:03:40 -08003688 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3689 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3690 if (phoneId == -1) {
3691 throw new IllegalArgumentException("Given slot index: " + slotIndex
3692 + " does not correspond to an active phone");
3693 }
3694 return PhoneFactory.getPhone(phoneId);
3695 }
3696
Shishir Agrawal566b7612013-10-28 14:41:00 -07003697 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003698 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3699 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3701 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003703 if (DBG) {
3704 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3705 }
3706 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3707 p2);
3708 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003709
Jordan Liu4c733742019-02-28 12:03:40 -08003710
3711 @Override
3712 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3713 int slotIndex, String callingPackage, String aid, int p2) {
3714 enforceModifyPermission();
3715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3716 if (DBG) {
3717 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3718 }
3719 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3720 callingPackage, aid, p2);
3721 }
3722
3723 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3724 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 if (TextUtils.equals(ISDR_AID, aid)) {
3728 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003729 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3730 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731 if (bestComponent == null
3732 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3733 loge("The calling package is not allowed to access ISD-R.");
3734 throw new SecurityException(
3735 "The calling package is not allowed to access ISD-R.");
3736 }
Derek Tan740e1672017-06-27 14:56:27 -07003737 }
Derek Tan740e1672017-06-27 14:56:27 -07003738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003740 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3741 null /* workSource */);
3742 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743 return response;
3744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003747 }
3748
3749 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003750 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3752 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003753 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3754 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003756
Jordan Liu4c733742019-02-28 12:03:40 -08003757 @Override
3758 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3759 enforceModifyPermission();
3760 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3761 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3762 channel);
3763 }
3764
3765 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 final long identity = Binder.clearCallingIdentity();
3767 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 if (channel < 0) {
3769 return false;
3770 }
Jordan Liu4c733742019-02-28 12:03:40 -08003771 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3772 null /* workSource */);
3773 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774 return success;
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003777 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003778 }
3779
3780 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003781 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003782 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3784 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003785 if (DBG) {
3786 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3787 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3788 + p3 + " data=" + data);
3789 }
3790 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3791 command, p1, p2, p3, data);
3792 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003793
Jordan Liu4c733742019-02-28 12:03:40 -08003794 @Override
3795 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3796 int command, int p1, int p2, int p3, String data) {
3797 enforceModifyPermission();
3798 if (DBG) {
3799 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3800 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3801 + p3 + " data=" + data);
3802 }
3803 return iccTransmitApduLogicalChannelWithPermission(
3804 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3805 data);
3806 }
3807
3808 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3809 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 final long identity = Binder.clearCallingIdentity();
3811 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812 if (channel < 0) {
3813 return "";
3814 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003817 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3818 null /* workSource */);
3819 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821 // Append the returned status code to the end of the response payload.
3822 String s = Integer.toHexString(
3823 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3824 if (response.payload != null) {
3825 s = IccUtils.bytesToHexString(response.payload) + s;
3826 }
3827 return s;
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003830 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003831 }
Jake Hambye994d462014-02-03 13:10:13 -08003832
Evan Charltonc66da362014-05-16 14:06:40 -07003833 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003834 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3835 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3837 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003839 if (DBG) {
3840 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3841 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3842 }
3843 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3844 cla, command, p1, p2, p3, data);
3845 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003846
Jordan Liu4c733742019-02-28 12:03:40 -08003847 @Override
3848 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3849 int command, int p1, int p2, int p3, String data) {
3850 enforceModifyPermission();
3851 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3852 if (DBG) {
3853 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3854 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3855 + " data=" + data);
3856 }
3857
3858 return iccTransmitApduBasicChannelWithPermission(
3859 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3860 p2, p3, data);
3861 }
3862
3863 // open APDU basic channel assuming the caller has sufficient permissions
3864 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3865 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3869 && TextUtils.equals(ISDR_AID, data)) {
3870 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003871 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3872 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003873 if (bestComponent == null
3874 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3875 loge("The calling package is not allowed to select ISD-R.");
3876 throw new SecurityException(
3877 "The calling package is not allowed to select ISD-R.");
3878 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003879 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003881 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003882 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3883 null /* workSource */);
3884 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 // Append the returned status code to the end of the response payload.
3887 String s = Integer.toHexString(
3888 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3889 if (response.payload != null) {
3890 s = IccUtils.bytesToHexString(response.payload) + s;
3891 }
3892 return s;
3893 } finally {
3894 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003895 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003896 }
3897
3898 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003899 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003900 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3902 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 if (DBG) {
3907 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3908 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3909 }
3910
3911 IccIoResult response =
3912 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3913 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3914 subId);
3915
3916 if (DBG) {
3917 log("Exchange SIM_IO [R]" + response);
3918 }
3919
3920 byte[] result = null;
3921 int length = 2;
3922 if (response.payload != null) {
3923 length = 2 + response.payload.length;
3924 result = new byte[length];
3925 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3926 } else {
3927 result = new byte[length];
3928 }
3929
3930 result[length - 1] = (byte) response.sw2;
3931 result[length - 2] = (byte) response.sw1;
3932 return result;
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003935 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003936 }
3937
Nathan Haroldb3014052017-01-25 15:57:32 -08003938 /**
3939 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3940 * on a particular subscription
3941 */
sqianb6e41952018-03-12 14:54:01 -07003942 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3943 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3944 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3945 return null;
3946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947
3948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 if (appType != TelephonyManager.APPTYPE_USIM
3951 && appType != TelephonyManager.APPTYPE_SIM) {
3952 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3953 return null;
3954 }
3955 Object response = sendRequest(
3956 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3957 if (response instanceof String[]) {
3958 return (String[]) response;
3959 }
3960 // Response is an Exception of some kind,
3961 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003962 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003963 } finally {
3964 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003965 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003966 }
3967
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003968 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003969 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3971 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3976 if (response.payload == null) {
3977 return "";
3978 }
Evan Charltonc66da362014-05-16 14:06:40 -07003979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980 // Append the returned status code to the end of the response payload.
3981 String s = Integer.toHexString(
3982 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3983 s = IccUtils.bytesToHexString(response.payload) + s;
3984 return s;
3985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
Evan Charltonc66da362014-05-16 14:06:40 -07003988 }
3989
Jake Hambye994d462014-02-03 13:10:13 -08003990 /**
3991 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3992 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3993 *
3994 * @param itemID the ID of the item to read
3995 * @return the NV item as a String, or null on error.
3996 */
3997 @Override
3998 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003999 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4001 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002
4003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004006 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4008 return value;
4009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
Jake Hambye994d462014-02-03 13:10:13 -08004012 }
4013
4014 /**
4015 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4016 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4017 *
4018 * @param itemID the ID of the item to read
4019 * @param itemValue the value to write, as a String
4020 * @return true on success; false on any failure
4021 */
4022 @Override
4023 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004024 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4026 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4031 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004032 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004033 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4034 return success;
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
Jake Hambye994d462014-02-03 13:10:13 -08004038 }
4039
4040 /**
4041 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4042 * Used for device configuration by some CDMA operators.
4043 *
4044 * @param preferredRoamingList byte array containing the new PRL
4045 * @return true on success; false on any failure
4046 */
4047 @Override
4048 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4050 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4055 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4056 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4057 return success;
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
Jake Hambye994d462014-02-03 13:10:13 -08004061 }
4062
4063 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004064 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004065 * Used for device configuration by some CDMA operators.
4066 *
chen xu6dac5ab2018-10-26 17:39:23 -07004067 * @param slotIndex - device slot.
4068 *
Jake Hambye994d462014-02-03 13:10:13 -08004069 * @return true on success; false on any failure
4070 */
4071 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004072 public boolean resetModemConfig(int slotIndex) {
4073 Phone phone = PhoneFactory.getPhone(slotIndex);
4074 if (phone != null) {
4075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4076 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077
chen xu6dac5ab2018-10-26 17:39:23 -07004078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4081 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4082 return success;
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 }
chen xu6dac5ab2018-10-26 17:39:23 -07004087 return false;
4088 }
4089
4090 /**
4091 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4092 *
4093 * @param slotIndex - device slot.
4094 *
4095 * @return true on success; false on any failure
4096 */
4097 @Override
4098 public boolean rebootModem(int slotIndex) {
4099 Phone phone = PhoneFactory.getPhone(slotIndex);
4100 if (phone != null) {
4101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4102 mApp, phone.getSubId(), "rebootModem");
4103
4104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4107 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4108 return success;
4109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
4112 }
4113 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004114 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004115
Svet Ganovb320e182015-04-16 12:30:10 -07004116 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004117 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004119 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004120 return new String[0];
4121 }
4122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123 final long identity = Binder.clearCallingIdentity();
4124 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004125 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
Wink Saville36469e72014-06-11 15:17:00 -07004129 }
4130
Brad Ebinger51f743a2017-01-23 13:50:20 -08004131 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004132 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4133 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004134 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004135 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004136 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004140 ImsResolver resolver = PhoneFactory.getImsResolver();
4141 if (resolver == null) {
4142 // may happen if the device does not support IMS.
4143 return;
4144 }
4145 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004146 } finally {
4147 Binder.restoreCallingIdentity(identity);
4148 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004149 }
4150
4151 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004152 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4153 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004154 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004155 public void disableIms(int slotId) {
4156 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157
4158 final long identity = Binder.clearCallingIdentity();
4159 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004160 ImsResolver resolver = PhoneFactory.getImsResolver();
4161 if (resolver == null) {
4162 // may happen if the device does not support IMS.
4163 return;
4164 }
4165 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004169 }
4170
4171 /**
4172 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4173 * feature or {@link null} if the service is not available. If the feature is available, the
4174 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4175 */
4176 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004177 IImsServiceFeatureCallback callback) {
4178 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004179
4180 final long identity = Binder.clearCallingIdentity();
4181 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004182 ImsResolver resolver = PhoneFactory.getImsResolver();
4183 if (resolver == null) {
4184 // may happen if the device does not support IMS.
4185 return null;
4186 }
4187 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004191 }
4192
4193 /**
4194 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4195 * feature during emergency calling or {@link null} if the service is not available. If the
4196 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4197 * listener for feature updates.
4198 */
4199 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4200 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201
4202 final long identity = Binder.clearCallingIdentity();
4203 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004204 ImsResolver resolver = PhoneFactory.getImsResolver();
4205 if (resolver == null) {
4206 // may happen if the device does not support IMS.
4207 return null;
4208 }
4209 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004210 } finally {
4211 Binder.restoreCallingIdentity(identity);
4212 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004213 }
4214
Brad Ebinger5f64b052017-12-14 14:26:15 -08004215 /**
4216 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004217 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004218 */
4219 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4220 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004221
4222 final long identity = Binder.clearCallingIdentity();
4223 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004224 ImsResolver resolver = PhoneFactory.getImsResolver();
4225 if (resolver == null) {
4226 // may happen if the device does not support IMS.
4227 return null;
4228 }
4229 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230 } finally {
4231 Binder.restoreCallingIdentity(identity);
4232 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004233 }
4234
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004235 /**
4236 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004237 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004238 */
4239 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4240 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004241
4242 final long identity = Binder.clearCallingIdentity();
4243 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004244 ImsResolver resolver = PhoneFactory.getImsResolver();
4245 if (resolver == null) {
4246 // may happen if the device does not support IMS.
4247 return null;
4248 }
4249 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004253 }
4254
Brad Ebinger884c07b2018-02-15 16:17:40 -08004255 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004256 * Sets the ImsService Package Name that Telephony will bind to.
4257 *
4258 * @param slotId the slot ID that the ImsService should bind for.
4259 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4260 * ImsService is the device default ImsService.
4261 * @param packageName The package name of the application that contains the ImsService to bind
4262 * to.
4263 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4264 * @hide
4265 */
4266 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004267 int[] subIds = SubscriptionManager.getSubId(slotId);
4268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4269 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4270 "setImsService");
4271
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272 final long identity = Binder.clearCallingIdentity();
4273 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004274 ImsResolver resolver = PhoneFactory.getImsResolver();
4275 if (resolver == null) {
4276 // may happen if the device does not support IMS.
4277 return false;
4278 }
4279 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4280 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004284 }
4285
4286 /**
4287 * Return the ImsService configuration.
4288 *
4289 * @param slotId The slot that the ImsService is associated with.
4290 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4291 * the device default.
4292 * @return the package name of the ImsService configuration.
4293 */
4294 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004295 int[] subIds = SubscriptionManager.getSubId(slotId);
4296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4297 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4298 "getImsService");
4299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300 final long identity = Binder.clearCallingIdentity();
4301 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004302 ImsResolver resolver = PhoneFactory.getImsResolver();
4303 if (resolver == null) {
4304 // may happen if the device does not support IMS.
4305 return "";
4306 }
4307 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004311 }
4312
Wink Saville36469e72014-06-11 15:17:00 -07004313 public void setImsRegistrationState(boolean registered) {
4314 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004318 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
Wink Saville36469e72014-06-11 15:17:00 -07004322 }
4323
4324 /**
Stuart Scott54788802015-03-30 13:18:01 -07004325 * Set the network selection mode to automatic.
4326 *
4327 */
4328 @Override
4329 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4331 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332
Pengquan Menge92a50d2018-09-21 15:54:48 -07004333 if (!isActiveSubscription(subId)) {
4334 return;
4335 }
4336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4340 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
Stuart Scott54788802015-03-30 13:18:01 -07004344 }
4345
Pengquan Mengea84e042018-09-20 14:57:26 -07004346 /**
4347 * Ask the radio to connect to the input network and change selection mode to manual.
4348 *
4349 * @param subId the id of the subscription.
4350 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4351 * the operator to attach to.
4352 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4353 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4354 * normal network selection next time.
4355 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004356 */
4357 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004358 public boolean setNetworkSelectionModeManual(
4359 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4361 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004362
4363 if (!isActiveSubscription(subId)) {
4364 return false;
4365 }
4366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367 final long identity = Binder.clearCallingIdentity();
4368 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004369 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004371 if (DBG) {
4372 log("setNetworkSelectionModeManual: subId: " + subId
4373 + " operator: " + operatorInfo);
4374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004379 }
4380
4381 /**
4382 * Scans for available networks.
4383 */
4384 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004385 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4387 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004388 LocationAccessPolicy.LocationPermissionResult locationResult =
4389 LocationAccessPolicy.checkLocationPermission(mApp,
4390 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4391 .setCallingPackage(callingPackage)
4392 .setCallingPid(Binder.getCallingPid())
4393 .setCallingUid(Binder.getCallingUid())
4394 .setMethod("getCellNetworkScanResults")
4395 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4396 .build());
4397 switch (locationResult) {
4398 case DENIED_HARD:
4399 throw new SecurityException("Not allowed to access scan results -- location");
4400 case DENIED_SOFT:
4401 return null;
4402 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403
Pengquan Menga1bb6272018-09-06 09:59:22 -07004404 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 try {
4406 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004407 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 } finally {
4410 Binder.restoreCallingIdentity(identity);
4411 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004412 }
4413
4414 /**
yinxub1bed742017-04-17 11:45:04 -07004415 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004416 *
yinxub1bed742017-04-17 11:45:04 -07004417 * @param subId id of the subscription
4418 * @param request contains the radio access networks with bands/channels to scan
4419 * @param messenger callback messenger for scan results or errors
4420 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004421 * @return the id of the requested scan which can be used to stop the scan.
4422 */
4423 @Override
4424 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004425 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4427 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004428 LocationAccessPolicy.LocationPermissionResult locationResult =
4429 LocationAccessPolicy.checkLocationPermission(mApp,
4430 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4431 .setCallingPackage(callingPackage)
4432 .setCallingPid(Binder.getCallingPid())
4433 .setCallingUid(Binder.getCallingUid())
4434 .setMethod("requestNetworkScan")
4435 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4436 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004437 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4438 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4439 if (e != null) {
4440 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4441 throw e;
4442 } else {
4443 return TelephonyScanManager.INVALID_SCAN_ID;
4444 }
4445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004447 return mNetworkScanRequestTracker.startNetworkScan(
4448 request, messenger, binder, getPhone(subId),
4449 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004450 }
4451
Hall Liub2ac8ef2019-02-28 15:56:23 -08004452 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4453 NetworkScanRequest request) {
4454 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4455 != PERMISSION_GRANTED) {
4456 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4457 + " without location access.");
4458 }
4459
4460 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4461 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
4462 if (ras.getBands() != null && ras.getBands().length > 0) {
4463 return new SecurityException("Specific bands must not be"
4464 + " scanned without location access.");
4465 }
4466 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4467 return new SecurityException("Specific channels must not be"
4468 + " scanned without location access.");
4469 }
4470 }
4471 }
4472
4473 List<String> allowedMccMncs =
4474 NetworkScanRequestTracker.getAllowedMccMncsForLocationRestrictedScan(mApp);
4475 for (String mccmnc : request.getPlmns()) {
4476 if (!allowedMccMncs.contains(mccmnc)) {
4477 return new SecurityException("Requested mccmnc " + mccmnc + " is not known to the"
4478 + " device and cannot be scanned for without location access.");
4479 }
4480 }
4481
4482 return null;
4483 }
4484
yinxu504e1392017-04-12 16:03:22 -07004485 /**
4486 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004487 *
4488 * @param subId id of the subscription
4489 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004490 */
4491 @Override
4492 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4494 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495
4496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
yinxu504e1392017-04-12 16:03:22 -07004502 }
4503
4504 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004505 * Get the calculated preferred network type.
4506 * Used for debugging incorrect network type.
4507 *
4508 * @return the preferred network type, defined in RILConstants.java.
4509 */
4510 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004511 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004512 final Phone defaultPhone = getDefaultPhone();
4513 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4514 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004515 return RILConstants.PREFERRED_NETWORK_MODE;
4516 }
4517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 final long identity = Binder.clearCallingIdentity();
4519 try {
4520 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004521 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
Junda Liu84d15a22014-07-02 11:21:04 -07004525 }
4526
4527 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004528 * Get the preferred network type.
4529 * Used for device configuration by some CDMA operators.
4530 *
4531 * @return the preferred network type, defined in RILConstants.java.
4532 */
4533 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004534 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004535 TelephonyPermissions
4536 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4537 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538
4539 final long identity = Binder.clearCallingIdentity();
4540 try {
4541 if (DBG) log("getPreferredNetworkType");
4542 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4543 int networkType = (result != null ? result[0] : -1);
4544 if (DBG) log("getPreferredNetworkType: " + networkType);
4545 return networkType;
4546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004549 }
4550
4551 /**
4552 * Set the preferred network type.
4553 * Used for device configuration by some CDMA operators.
4554 *
4555 * @param networkType the preferred network type, defined in RILConstants.java.
4556 * @return true on success; false on any failure.
4557 */
4558 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004559 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4561 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004562
4563 final long identity = Binder.clearCallingIdentity();
4564 try {
4565 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4566 Boolean success = (Boolean) sendRequest(
4567 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4568 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4569 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004570 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4572 }
4573 return success;
4574 } finally {
4575 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004576 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004577 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004578
4579 /**
Miaoa84611c2019-03-15 09:21:10 +08004580 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004581 *
Miaoa84611c2019-03-15 09:21:10 +08004582 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004583 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004584 * @hide
4585 */
4586 @Override
Miaoa84611c2019-03-15 09:21:10 +08004587 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004588 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004590 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 try {
Miaoa84611c2019-03-15 09:21:10 +08004592 if (phone != null) {
4593 return phone.hasMatchedTetherApnSetting();
4594 } else {
4595 return false;
4596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 } finally {
4598 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004599 }
Junda Liu475951f2014-11-07 16:45:03 -08004600 }
4601
4602 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004603 * Set mobile data enabled
4604 * Used by the user through settings etc to turn on/off mobile data
4605 *
4606 * @param enable {@code true} turn turn data on, else {@code false}
4607 */
4608 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004609 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4611 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004612
4613 final long identity = Binder.clearCallingIdentity();
4614 try {
4615 int phoneId = mSubscriptionController.getPhoneId(subId);
4616 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4617 Phone phone = PhoneFactory.getPhone(phoneId);
4618 if (phone != null) {
4619 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004620 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004622 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623 }
4624 } finally {
4625 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004626 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004627 }
4628
4629 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004630 * Get the user enabled state of Mobile Data.
4631 *
4632 * TODO: remove and use isUserDataEnabled.
4633 * This can't be removed now because some vendor codes
4634 * calls through ITelephony directly while they should
4635 * use TelephonyManager.
4636 *
4637 * @return true on enabled
4638 */
4639 @Override
4640 public boolean getDataEnabled(int subId) {
4641 return isUserDataEnabled(subId);
4642 }
4643
4644 /**
4645 * Get whether mobile data is enabled per user setting.
4646 *
4647 * There are other factors deciding whether mobile data is actually enabled, but they are
4648 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004649 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004650 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004651 *
4652 * @return {@code true} if data is enabled else {@code false}
4653 */
4654 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004655 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004656 try {
4657 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4658 null);
4659 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4661 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663
4664 final long identity = Binder.clearCallingIdentity();
4665 try {
4666 int phoneId = mSubscriptionController.getPhoneId(subId);
4667 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4668 Phone phone = PhoneFactory.getPhone(phoneId);
4669 if (phone != null) {
4670 boolean retVal = phone.isUserDataEnabled();
4671 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4672 return retVal;
4673 } else {
4674 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4675 return false;
4676 }
4677 } finally {
4678 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004679 }
4680 }
4681
4682 /**
4683 * Get whether mobile data is enabled.
4684 *
4685 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4686 * whether mobile data is actually enabled.
4687 *
4688 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4689 *
4690 * @return {@code true} if data is enabled else {@code false}
4691 */
4692 @Override
4693 public boolean isDataEnabled(int subId) {
4694 try {
4695 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4696 null);
4697 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4699 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004701
4702 final long identity = Binder.clearCallingIdentity();
4703 try {
4704 int phoneId = mSubscriptionController.getPhoneId(subId);
4705 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4706 Phone phone = PhoneFactory.getPhone(phoneId);
4707 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004708 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004709 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4710 return retVal;
4711 } else {
4712 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4713 return false;
4714 }
4715 } finally {
4716 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004717 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004718 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004719
4720 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004721 public int getCarrierPrivilegeStatus(int subId) {
4722 final Phone phone = getPhone(subId);
4723 if (phone == null) {
4724 loge("getCarrierPrivilegeStatus: Invalid subId");
4725 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4726 }
4727 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004728 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004729 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004730 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4731 }
4732 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004733 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004734 }
Junda Liu29340342014-07-10 15:23:27 -07004735
4736 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4738 final Phone phone = getPhone(subId);
4739 if (phone == null) {
4740 loge("getCarrierPrivilegeStatus: Invalid subId");
4741 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4742 }
4743 UiccProfile profile =
4744 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4745 if (profile == null) {
4746 loge("getCarrierPrivilegeStatus: No UICC");
4747 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4748 }
4749 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4750 }
4751
4752 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004753 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004754 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004755 if (TextUtils.isEmpty(pkgName))
4756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004757 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004758 if (card == null) {
4759 loge("checkCarrierPrivilegesForPackage: No UICC");
4760 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4761 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004762 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4763 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004764 }
4765
4766 @Override
4767 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004768 if (TextUtils.isEmpty(pkgName))
4769 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004770 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4771 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4772 UiccCard card = UiccController.getInstance().getUiccCard(i);
4773 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004774 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004775 continue;
4776 }
4777
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004778 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004779 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4780 break;
4781 }
4782 }
4783
4784 return result;
Junda Liu29340342014-07-10 15:23:27 -07004785 }
Derek Tan89e89d42014-07-08 17:00:10 -07004786
4787 @Override
Junda Liue64de782015-04-16 17:19:16 -07004788 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4789 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4790 loge("phoneId " + phoneId + " is not valid.");
4791 return null;
4792 }
4793 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004794 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004795 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004796 return null ;
4797 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004798 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004799 }
4800
Amith Yamasani6e118872016-02-19 12:53:51 -08004801 @Override
4802 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004803 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004804 List<String> privilegedPackages = new ArrayList<>();
4805 List<PackageInfo> packages = null;
4806 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4807 UiccCard card = UiccController.getInstance().getUiccCard(i);
4808 if (card == null) {
4809 // No UICC in that slot.
4810 continue;
4811 }
4812 if (card.hasCarrierPrivilegeRules()) {
4813 if (packages == null) {
4814 // Only check packages in user 0 for now
4815 packages = pm.getInstalledPackagesAsUser(
4816 PackageManager.MATCH_DISABLED_COMPONENTS
4817 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4818 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4819 }
4820 for (int p = packages.size() - 1; p >= 0; p--) {
4821 PackageInfo pkgInfo = packages.get(p);
4822 if (pkgInfo != null && pkgInfo.packageName != null
4823 && card.getCarrierPrivilegeStatus(pkgInfo)
4824 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4825 privilegedPackages.add(pkgInfo.packageName);
4826 }
4827 }
4828 }
4829 }
4830 return privilegedPackages;
4831 }
4832
Wink Savilleb564aae2014-10-23 10:18:09 -07004833 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004834 final Phone phone = getPhone(subId);
4835 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004836 if (card == null) {
4837 loge("getIccId: No UICC");
4838 return null;
4839 }
4840 String iccId = card.getIccId();
4841 if (TextUtils.isEmpty(iccId)) {
4842 loge("getIccId: ICC ID is null or empty.");
4843 return null;
4844 }
4845 return iccId;
4846 }
4847
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004848 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004849 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4850 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004851 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4852 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 final String iccId = getIccId(subId);
4857 final Phone phone = getPhone(subId);
4858 if (phone == null) {
4859 return false;
4860 }
4861 final String subscriberId = phone.getSubscriberId();
4862
4863 if (DBG_MERGE) {
4864 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4865 + subscriberId + " to " + number);
4866 }
4867
4868 if (TextUtils.isEmpty(iccId)) {
4869 return false;
4870 }
4871
4872 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4873
4874 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4875 if (alphaTag == null) {
4876 editor.remove(alphaTagPrefKey);
4877 } else {
4878 editor.putString(alphaTagPrefKey, alphaTag);
4879 }
4880
4881 // Record both the line number and IMSI for this ICCID, since we need to
4882 // track all merged IMSIs based on line number
4883 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4884 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4885 if (number == null) {
4886 editor.remove(numberPrefKey);
4887 editor.remove(subscriberPrefKey);
4888 } else {
4889 editor.putString(numberPrefKey, number);
4890 editor.putString(subscriberPrefKey, subscriberId);
4891 }
4892
4893 editor.commit();
4894 return true;
4895 } finally {
4896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004897 }
Derek Tan7226c842014-07-02 17:42:23 -07004898 }
4899
4900 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004901 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004902 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004904 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004905 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004906 return null;
4907 }
Derek Tan97ebb422014-09-05 16:55:38 -07004908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 final long identity = Binder.clearCallingIdentity();
4910 try {
4911 String iccId = getIccId(subId);
4912 if (iccId != null) {
4913 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4914 if (DBG_MERGE) {
4915 log("getLine1NumberForDisplay returning "
4916 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4917 }
4918 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004920 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4921 return null;
4922 } finally {
4923 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004924 }
Derek Tan7226c842014-07-02 17:42:23 -07004925 }
4926
4927 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004928 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004930 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004931 return null;
4932 }
Derek Tan97ebb422014-09-05 16:55:38 -07004933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 final long identity = Binder.clearCallingIdentity();
4935 try {
4936 String iccId = getIccId(subId);
4937 if (iccId != null) {
4938 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4939 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4940 }
4941 return null;
4942 } finally {
4943 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004944 }
Derek Tan7226c842014-07-02 17:42:23 -07004945 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004946
4947 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004948 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004949 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4950 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004952 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4953 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004954 return null;
4955 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004956
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004957 final long identity = Binder.clearCallingIdentity();
4958 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004959 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 final TelephonyManager tele = TelephonyManager.from(context);
4961 final SubscriptionManager sub = SubscriptionManager.from(context);
4962
4963 // Figure out what subscribers are currently active
4964 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4965 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4966 // the process, where TelephonyManager was instantiated.
4967 // Otherwise AppOps check will fail.
4968
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004969 final int[] subIds = sub.getActiveSubscriptionIdList();
4970 for (int subId : subIds) {
4971 activeSubscriberIds.add(tele.getSubscriberId(subId));
4972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973
4974 // First pass, find a number override for an active subscriber
4975 String mergeNumber = null;
4976 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4977 for (String key : prefs.keySet()) {
4978 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4979 final String subscriberId = (String) prefs.get(key);
4980 if (activeSubscriberIds.contains(subscriberId)) {
4981 final String iccId = key.substring(
4982 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4983 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4984 mergeNumber = (String) prefs.get(numberKey);
4985 if (DBG_MERGE) {
4986 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4987 + " for active subscriber " + subscriberId);
4988 }
4989 if (!TextUtils.isEmpty(mergeNumber)) {
4990 break;
4991 }
4992 }
4993 }
4994 }
4995
4996 // Shortcut when no active merged subscribers
4997 if (TextUtils.isEmpty(mergeNumber)) {
4998 return null;
4999 }
5000
5001 // Second pass, find all subscribers under that line override
5002 final ArraySet<String> result = new ArraySet<>();
5003 for (String key : prefs.keySet()) {
5004 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5005 final String number = (String) prefs.get(key);
5006 if (mergeNumber.equals(number)) {
5007 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5008 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5009 final String subscriberId = (String) prefs.get(subscriberKey);
5010 if (!TextUtils.isEmpty(subscriberId)) {
5011 result.add(subscriberId);
5012 }
5013 }
5014 }
5015 }
5016
5017 final String[] resultArray = result.toArray(new String[result.size()]);
5018 Arrays.sort(resultArray);
5019 if (DBG_MERGE) {
5020 Slog.d(LOG_TAG,
5021 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5022 }
5023 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005026 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005027 }
5028
5029 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005030 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005031 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5032 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033
5034 final long identity = Binder.clearCallingIdentity();
5035 try {
5036 final Phone phone = getPhone(subId);
5037 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
5040 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005041 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005042
5043 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005044 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005045 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5046 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005047 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048
5049 final long identity = Binder.clearCallingIdentity();
5050 try {
5051 final Phone phone = getPhone(subId);
5052 if (phone == null) {
5053 return false;
5054 }
5055 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5056 cdmaNonRoamingList);
5057 } finally {
5058 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005059 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005060 }
5061
5062 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005063 @Deprecated
5064 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5065 enforceModifyPermission();
5066
5067 int returnValue = 0;
5068 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005069 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005070 if(result.exception == null) {
5071 if (result.result != null) {
5072 byte[] responseData = (byte[])(result.result);
5073 if(responseData.length > oemResp.length) {
5074 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5075 responseData.length + "bytes. Buffer Size is " +
5076 oemResp.length + "bytes.");
5077 }
5078 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5079 returnValue = responseData.length;
5080 }
5081 } else {
5082 CommandException ex = (CommandException) result.exception;
5083 returnValue = ex.getCommandError().ordinal();
5084 if(returnValue > 0) returnValue *= -1;
5085 }
5086 } catch (RuntimeException e) {
5087 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5088 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5089 if(returnValue > 0) returnValue *= -1;
5090 }
5091
5092 return returnValue;
5093 }
5094
5095 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005096 public void setRadioCapability(RadioAccessFamily[] rafs) {
5097 try {
5098 ProxyController.getInstance().setRadioCapability(rafs);
5099 } catch (RuntimeException e) {
5100 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5101 }
5102 }
5103
5104 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005105 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005106 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005107 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005108 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005109 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 final long identity = Binder.clearCallingIdentity();
5112 try {
chen xub97461a2018-10-26 14:17:57 -07005113 TelephonyPermissions
5114 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5115 mApp, phone.getSubId(), "getRadioAccessFamily");
5116 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 } finally {
5118 Binder.restoreCallingIdentity(identity);
5119 }
chen xub97461a2018-10-26 14:17:57 -07005120 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005121 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005122
5123 @Override
5124 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005125 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005126 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005127
5128 final long identity = Binder.clearCallingIdentity();
5129 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005130 ImsManager.getInstance(defaultPhone.getContext(),
5131 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 } finally {
5133 Binder.restoreCallingIdentity(identity);
5134 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005135 }
5136
5137 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005138 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005139 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005141 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005142 return false;
5143 }
Svet Ganovb320e182015-04-16 12:30:10 -07005144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 final long identity = Binder.clearCallingIdentity();
5146 try {
5147 // Check the user preference and the system-level IMS setting. Even if the user has
5148 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5149 // In the long run, we may instead need to check if there exists a connection service
5150 // which can support video calling.
5151 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005152 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 return imsManager.isVtEnabledByPlatform()
5154 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5155 && imsManager.isVtEnabledByUser();
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
5158 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005159 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005160
Andrew Leea1239f22015-03-02 17:44:07 -08005161 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5163 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5164 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5165 return false;
5166 }
5167
5168 final long identity = Binder.clearCallingIdentity();
5169 try {
5170 CarrierConfigManager configManager =
5171 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005172 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Andrew Leea1239f22015-03-02 17:44:07 -08005177 }
5178
5179 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 public boolean isWorldPhone(int subId, String callingPackage) {
5181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5182 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5183 return false;
5184 }
5185
5186 final long identity = Binder.clearCallingIdentity();
5187 try {
5188 CarrierConfigManager configManager =
5189 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005190 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
Andrew Leea1239f22015-03-02 17:44:07 -08005195 }
5196
Andrew Lee9431b832015-03-09 18:46:45 -07005197 @Override
5198 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005199 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005200 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005201 }
5202
5203 @Override
5204 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 final long identity = Binder.clearCallingIdentity();
5206 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005207 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
Andrew Lee9431b832015-03-09 18:46:45 -07005211 }
5212
Hall Liuf6668912018-10-31 17:05:23 -07005213 /**
5214 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5215 * support for the feature and device firmware support.
5216 *
5217 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5218 */
5219 @Override
5220 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005222 final Phone phone = getPhone(subscriptionId);
5223 if (phone == null) {
5224 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5225 return false;
5226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005228 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5230 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005231 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 return isCarrierSupported && isDeviceSupported;
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
Hall Liu98187582018-01-22 19:15:32 -08005236 }
5237
Hall Liuf6668912018-10-31 17:05:23 -07005238 /**
5239 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5240 * both also support RTT.
5241 */
5242 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 final long identity = Binder.clearCallingIdentity();
5244 try {
Hall Liuf6668912018-10-31 17:05:23 -07005245 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005246 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005250 }
5251
Sanket Padawe7310cc72015-01-14 09:53:20 -08005252 /**
5253 * Returns the unique device ID of phone, for example, the IMEI for
5254 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5255 *
5256 * <p>Requires Permission:
5257 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5258 */
5259 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005260 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005261 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005262 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005263 return null;
5264 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005265 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005266 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5267 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005268 return null;
5269 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270
5271 final long identity = Binder.clearCallingIdentity();
5272 try {
5273 return phone.getDeviceId();
5274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005277 }
5278
Ping Sunc67b7c22016-03-02 19:16:45 +08005279 /**
5280 * {@hide}
5281 * Returns the IMS Registration Status on a particular subid
5282 *
5283 * @param subId
5284 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005285 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005286 Phone phone = getPhone(subId);
5287 if (phone != null) {
5288 return phone.isImsRegistered();
5289 } else {
5290 return false;
5291 }
5292 }
5293
Santos Cordon7a1885b2015-02-03 11:15:19 -08005294 @Override
5295 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 final long identity = Binder.clearCallingIdentity();
5297 try {
5298 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005302 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005303
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005304 /**
5305 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005306 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005307 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308 final long identity = Binder.clearCallingIdentity();
5309 try {
5310 Phone phone = getPhone(subId);
5311 if (phone != null) {
5312 return phone.isWifiCallingEnabled();
5313 } else {
5314 return false;
5315 }
5316 } finally {
5317 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005318 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005319 }
5320
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005321 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005322 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005323 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005324 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 final long identity = Binder.clearCallingIdentity();
5326 try {
5327 Phone phone = getPhone(subId);
5328 if (phone != null) {
5329 return phone.isVideoEnabled();
5330 } else {
5331 return false;
5332 }
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005335 }
5336 }
5337
5338 /**
5339 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5340 * defined in {@link ImsRegistrationImplBase}.
5341 */
5342 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 final long identity = Binder.clearCallingIdentity();
5344 try {
5345 Phone phone = getPhone(subId);
5346 if (phone != null) {
5347 return phone.getImsRegistrationTech();
5348 } else {
5349 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5350 }
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005353 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005354 }
5355
Stuart Scott8eef64f2015-04-08 15:13:54 -07005356 @Override
5357 public void factoryReset(int subId) {
5358 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005359 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5360 return;
5361 }
5362
Svet Ganovcc087f82015-05-12 20:35:54 -07005363 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005364
Svet Ganovcc087f82015-05-12 20:35:54 -07005365 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005366 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5367 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005368 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005369 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005370 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005371 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5372 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005373 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005374 // There has been issues when Sms raw table somehow stores orphan
5375 // fragments. They lead to garbled message when new fragments come
5376 // in and combined with those stale ones. In case this happens again,
5377 // user can reset all network settings which will clean up this table.
5378 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005379 } finally {
5380 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005381 }
5382 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005383
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005384 private void cleanUpSmsRawTable(Context context) {
5385 ContentResolver resolver = context.getContentResolver();
5386 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5387 resolver.delete(uri, null, null);
5388 }
5389
Narayan Kamath1c496c22015-04-16 14:40:19 +01005390 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005391 public String getSimLocaleForSubscriber(int subId) {
5392 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5393 final Phone phone = getPhone(subId);
5394 if (phone == null) {
5395 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005396 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005397 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 final long identity = Binder.clearCallingIdentity();
5399 try {
chen xu5d3637b2019-01-21 23:31:38 -08005400 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5401 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005402 if (info == null) {
5403 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5404 return null;
5405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 // Try and fetch the locale from the carrier properties or from the SIM language
5407 // preferences (EF-PL and EF-LI)...
5408 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005410 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5411 if (localeFromDefaultSim != null) {
5412 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5413 if (DBG) log("Using locale from subId: " + subId + " locale: "
5414 + localeFromDefaultSim);
5415 return localeFromDefaultSim.toLanguageTag();
5416 } else {
5417 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 }
5419 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 // The SIM language preferences only store a language (e.g. fr = French), not an
5422 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5423 // the SIM and carrier preferences does not include a country we add the country
5424 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005425 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005427 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 return mccLocale.toLanguageTag();
5429 }
5430
5431 if (DBG) log("No locale found - returning null");
5432 return null;
5433 } finally {
5434 Binder.restoreCallingIdentity(identity);
5435 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005436 }
5437
5438 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005439 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005440 }
5441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 /**
5443 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5444 */
5445 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005446 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005447 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005448
Chenjie Yu1ba97252018-01-11 18:16:20 -08005449 private final ModemActivityInfo mLastModemActivityInfo =
5450 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5451
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005452 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005453 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5454 * representing the state of the modem.
5455 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005456 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5457 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005458 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005459 */
5460 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005461 public void requestModemActivityInfo(ResultReceiver result) {
5462 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005463 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 ModemActivityInfo ret = null;
5468 synchronized (mLastModemActivityInfo) {
5469 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5470 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005471 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005472 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5474 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005475 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5476 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 }
5478 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005479 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5480 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 mLastModemActivityInfo.setIdleTimeMillis(
5482 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5483 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5484 mLastModemActivityInfo.setRxTimeMillis(
5485 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5486 mLastModemActivityInfo.setEnergyUsed(
5487 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5490 mLastModemActivityInfo.getSleepTimeMillis(),
5491 mLastModemActivityInfo.getIdleTimeMillis(),
5492 mLastModemActivityInfo.getTxTimeMillis(),
5493 mLastModemActivityInfo.getRxTimeMillis(),
5494 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496 Bundle bundle = new Bundle();
5497 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5498 result.send(0, bundle);
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005501 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005502 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005503
Siddharth Rayb8114062018-06-17 15:02:38 -07005504 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5505 // less than total activity duration.
5506 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5507 if (info == null) {
5508 return false;
5509 }
5510 int activityDurationMs =
5511 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5512 int totalTxTimeMs = 0;
5513 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5514 totalTxTimeMs += info.getTxTimeMillis()[i];
5515 }
5516 return (info.isValid()
5517 && (info.getSleepTimeMillis() <= activityDurationMs)
5518 && (info.getIdleTimeMillis() <= activityDurationMs)
5519 && (info.getRxTimeMillis() <= activityDurationMs)
5520 && (totalTxTimeMs <= activityDurationMs));
5521 }
5522
Jack Yu85bd38a2015-11-09 11:34:32 -08005523 /**
5524 * {@hide}
5525 * Returns the service state information on specified subscription.
5526 */
5527 @Override
5528 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005530 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005531 return null;
5532 }
5533
Hall Liuf19c44f2018-11-27 14:38:17 -08005534 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5535 LocationAccessPolicy.checkLocationPermission(mApp,
5536 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5537 .setCallingPackage(callingPackage)
5538 .setCallingPid(Binder.getCallingPid())
5539 .setCallingUid(Binder.getCallingUid())
5540 .setMethod("getServiceStateForSubscriber")
5541 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5542 .build());
5543
5544 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5545 LocationAccessPolicy.checkLocationPermission(mApp,
5546 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5547 .setCallingPackage(callingPackage)
5548 .setCallingPid(Binder.getCallingPid())
5549 .setCallingUid(Binder.getCallingUid())
5550 .setMethod("getServiceStateForSubscriber")
5551 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5552 .build());
5553 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5554 boolean hasFinePermission =
5555 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5556 boolean hasCoarsePermission =
5557 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 final long identity = Binder.clearCallingIdentity();
5560 try {
5561 final Phone phone = getPhone(subId);
5562 if (phone == null) {
5563 return null;
5564 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005565
Hall Liuf19c44f2018-11-27 14:38:17 -08005566 ServiceState ss = phone.getServiceState();
5567
5568 // Scrub out the location info in ServiceState depending on what level of access
5569 // the caller has.
5570 if (hasFinePermission) return ss;
5571 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5572 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005576 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005577
5578 /**
5579 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5580 *
5581 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5582 * voicemail ringtone.
5583 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5584 * PhoneAccount.
5585 */
5586 @Override
5587 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 final long identity = Binder.clearCallingIdentity();
5589 try {
5590 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5591 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005592 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005599 }
5600
5601 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005602 * Sets the per-account voicemail ringtone.
5603 *
5604 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5605 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5606 *
5607 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5608 * voicemail ringtone.
5609 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5610 * PhoneAccount.
5611 */
5612 @Override
5613 public void setVoicemailRingtoneUri(String callingPackage,
5614 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005615 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005616 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5617 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005618 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5620 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5621 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623
5624 final long identity = Binder.clearCallingIdentity();
5625 try {
5626 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5627 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005628 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 }
5630 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005633 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005634 }
5635
5636 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005637 * Returns whether vibration is set for voicemail notification in Phone settings.
5638 *
5639 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5640 * voicemail vibration setting.
5641 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5642 */
5643 @Override
5644 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 final long identity = Binder.clearCallingIdentity();
5646 try {
5647 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5648 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005649 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
5655 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005656 }
5657
Youhan Wange64578a2016-05-02 15:32:42 -07005658 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005659 * Sets the per-account voicemail vibration.
5660 *
5661 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5662 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5663 *
5664 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5665 * voicemail vibration setting.
5666 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5667 * specific PhoneAccount.
5668 */
5669 @Override
5670 public void setVoicemailVibrationEnabled(String callingPackage,
5671 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005672 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5674 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005675 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5677 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5678 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005679 }
5680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 final long identity = Binder.clearCallingIdentity();
5682 try {
5683 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5684 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005685 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 }
5687 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5688 } finally {
5689 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005690 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005691 }
5692
5693 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005694 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5695 *
5696 * @throws SecurityException if the caller does not have the required permission
5697 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005698 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005699 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005700 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005701 }
5702
5703 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005704 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5705 * permission.
5706 *
5707 * @throws SecurityException if the caller does not have the required permission
5708 */
5709 private void enforceSendSmsPermission() {
5710 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5711 }
5712
5713 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005714 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005715 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005716 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005717 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005718 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 final long identity = Binder.clearCallingIdentity();
5720 try {
5721 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005722 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 if (componentName == null) {
5724 throw new SecurityException(
5725 "Caller not current active visual voicemail package[null]");
5726 }
5727 String vvmPackage = componentName.getPackageName();
5728 if (!callingPackage.equals(vvmPackage)) {
5729 throw new SecurityException("Caller not current active visual voicemail package["
5730 + vvmPackage + "]");
5731 }
5732 } finally {
5733 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005734 }
5735 }
5736
5737 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005738 * Return the application ID for the app type.
5739 *
5740 * @param subId the subscription ID that this request applies to.
5741 * @param appType the uicc app type.
5742 * @return Application ID for specificied app type, or null if no uicc.
5743 */
5744 @Override
5745 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005746 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005747 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748
5749 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005750 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 if (phone == null) {
5752 return null;
5753 }
5754 String aid = null;
5755 try {
5756 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5757 .getApplicationByType(appType).getAid();
5758 } catch (Exception e) {
5759 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5760 }
5761 return aid;
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005764 }
Youhan Wange64578a2016-05-02 15:32:42 -07005765 }
5766
Youhan Wang4001d252016-05-11 10:29:41 -07005767 /**
5768 * Return the Electronic Serial Number.
5769 *
5770 * @param subId the subscription ID that this request applies to.
5771 * @return ESN or null if error.
5772 */
5773 @Override
5774 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005775 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005776 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777
5778 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005779 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 if (phone == null) {
5781 return null;
5782 }
5783 String esn = null;
5784 try {
5785 esn = phone.getEsn();
5786 } catch (Exception e) {
5787 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5788 }
5789 return esn;
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005792 }
Youhan Wang4001d252016-05-11 10:29:41 -07005793 }
5794
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005795 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005796 * Return the Preferred Roaming List Version.
5797 *
5798 * @param subId the subscription ID that this request applies to.
5799 * @return PRLVersion or null if error.
5800 */
5801 @Override
5802 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005803 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005804 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805
5806 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005807 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 if (phone == null) {
5809 return null;
5810 }
5811 String cdmaPrlVersion = null;
5812 try {
5813 cdmaPrlVersion = phone.getCdmaPrlVersion();
5814 } catch (Exception e) {
5815 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5816 }
5817 return cdmaPrlVersion;
5818 } finally {
5819 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005820 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005821 }
5822
5823 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005824 * Get snapshot of Telephony histograms
5825 * @return List of Telephony histograms
5826 * @hide
5827 */
5828 @Override
5829 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5831 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832
5833 final long identity = Binder.clearCallingIdentity();
5834 try {
5835 return RIL.getTelephonyRILTimingHistograms();
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005839 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005840
5841 /**
5842 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005843 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5844 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005845 * Require system privileges. In the future we may add this to carrier APIs.
5846 *
Michele Berionne482f8202018-11-27 18:57:59 -08005847 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005848 */
5849 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005850 @TelephonyManager.SetCarrierRestrictionResult
5851 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005852 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005853 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005854
Michele Berionne482f8202018-11-27 18:57:59 -08005855 if (carrierRestrictionRules == null) {
5856 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005857 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 final long identity = Binder.clearCallingIdentity();
5860 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005861 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005862 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 } finally {
5864 Binder.restoreCallingIdentity(identity);
5865 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005866 }
5867
5868 /**
5869 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005870 * Get the allowed carrier list and the excluded carrier list, including the priority between
5871 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005872 * Require system privileges. In the future we may add this to carrier APIs.
5873 *
Michele Berionne482f8202018-11-27 18:57:59 -08005874 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005875 */
5876 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005877 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005878 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005879 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880
5881 final long identity = Binder.clearCallingIdentity();
5882 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005883 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5884 if (response instanceof CarrierRestrictionRules) {
5885 return (CarrierRestrictionRules) response;
5886 }
5887 // Response is an Exception of some kind,
5888 // which is signalled to the user as a NULL retval
5889 return null;
5890 } catch (Exception e) {
5891 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5892 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005896 }
5897
fionaxu59545b42016-05-25 15:53:37 -07005898 /**
5899 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5900 * @param subId the subscription ID that this action applies to.
5901 * @param enabled control enable or disable metered apns.
5902 * {@hide}
5903 */
5904 @Override
5905 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5906 enforceModifyPermission();
5907 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908
5909 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005910 if (phone == null) {
5911 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5912 return;
5913 }
5914 try {
5915 phone.carrierActionSetMeteredApnsEnabled(enabled);
5916 } catch (Exception e) {
5917 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 } finally {
5919 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005920 }
5921 }
5922
5923 /**
5924 * Action set from carrier signalling broadcast receivers to enable/disable radio
5925 * @param subId the subscription ID that this action applies to.
5926 * @param enabled control enable or disable radio.
5927 * {@hide}
5928 */
5929 @Override
5930 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5931 enforceModifyPermission();
5932 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933
5934 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005935 if (phone == null) {
5936 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5937 return;
5938 }
5939 try {
5940 phone.carrierActionSetRadioEnabled(enabled);
5941 } catch (Exception e) {
5942 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 } finally {
5944 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005945 }
5946 }
5947
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005948 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005949 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5950 * network status based on which carrier apps could apply actions accordingly,
5951 * enable/disable default url handler for example.
5952 *
5953 * @param subId the subscription ID that this action applies to.
5954 * @param report control start/stop reporting the default network status.
5955 * {@hide}
5956 */
5957 @Override
5958 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5959 enforceModifyPermission();
5960 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961
5962 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005963 if (phone == null) {
5964 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5965 return;
5966 }
5967 try {
5968 phone.carrierActionReportDefaultNetworkStatus(report);
5969 } catch (Exception e) {
5970 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 } finally {
5972 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005973 }
5974 }
5975
5976 /**
fionaxud9622282017-07-17 17:51:30 -07005977 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5978 * @param subId the subscription ID that this action applies to.
5979 * {@hide}
5980 */
5981 @Override
5982 public void carrierActionResetAll(int subId) {
5983 enforceModifyPermission();
5984 final Phone phone = getPhone(subId);
5985 if (phone == null) {
5986 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
5987 return;
5988 }
5989 try {
5990 phone.carrierActionResetAll();
5991 } catch (Exception e) {
5992 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
5993 }
5994 }
5995
5996 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005997 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5998 * bug report is being generated.
5999 */
6000 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006001 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006002 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6003 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006004 writer.println("Permission Denial: can't dump Phone from pid="
6005 + Binder.getCallingPid()
6006 + ", uid=" + Binder.getCallingUid()
6007 + "without permission "
6008 + android.Manifest.permission.DUMP);
6009 return;
6010 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006011 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006012 }
Jack Yueb89b242016-06-22 13:27:47 -07006013
Brad Ebingerdac2f002018-04-03 15:17:52 -07006014 @Override
6015 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6016 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6017 throws RemoteException {
6018 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6019 }
6020
Jack Yueb89b242016-06-22 13:27:47 -07006021 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006022 * Get aggregated video call data usage since boot.
6023 *
6024 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6025 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006026 * {@hide}
6027 */
6028 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006029 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006030 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6031 null);
6032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 final long identity = Binder.clearCallingIdentity();
6034 try {
6035 // NetworkStatsService keeps tracking the active network interface and identity. It
6036 // records the delta with the corresponding network identity.
6037 // We just return the total video call data usage snapshot since boot.
6038 Phone phone = getPhone(subId);
6039 if (phone != null) {
6040 return phone.getVtDataUsage(perUidStats);
6041 }
6042 return null;
6043 } finally {
6044 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006045 }
Jack Yueb89b242016-06-22 13:27:47 -07006046 }
Jack Yu75ab2952016-07-08 14:29:33 -07006047
6048 /**
6049 * Policy control of data connection. Usually used when data limit is passed.
6050 * @param enabled True if enabling the data, otherwise disabling.
6051 * @param subId Subscription index
6052 * {@hide}
6053 */
6054 @Override
6055 public void setPolicyDataEnabled(boolean enabled, int subId) {
6056 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057
6058 final long identity = Binder.clearCallingIdentity();
6059 try {
6060 Phone phone = getPhone(subId);
6061 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006062 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063 }
6064 } finally {
6065 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006066 }
6067 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006068
6069 /**
6070 * Get Client request stats
6071 * @return List of Client Request Stats
6072 * @hide
6073 */
6074 @Override
6075 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006077 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006078 return null;
6079 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006080 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 final long identity = Binder.clearCallingIdentity();
6083 try {
6084 if (phone != null) {
6085 return phone.getClientRequestStats();
6086 }
6087
6088 return null;
6089 } finally {
6090 Binder.restoreCallingIdentity(identity);
6091 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006092 }
6093
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006094 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006095 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006096 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006097 }
Jack Yueb4124c2017-02-16 15:32:43 -08006098
6099 /**
Grace Chen70990072017-03-24 17:21:30 -07006100 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006101 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006102 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006103 * @param state State of SIM (power down, power up, pass through)
6104 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6105 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6106 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006107 *
6108 **/
6109 @Override
Grace Chen70990072017-03-24 17:21:30 -07006110 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006111 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006112 Phone phone = PhoneFactory.getPhone(slotIndex);
6113
vagdeviaf9a5b92018-08-15 16:01:53 -07006114 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 final long identity = Binder.clearCallingIdentity();
6117 try {
6118 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006119 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 }
6121 } finally {
6122 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006123 }
6124 }
Shuo Qiandd210312017-04-12 22:11:33 +00006125
Tyler Gunn65d45c22017-06-05 11:22:26 -07006126 private boolean isUssdApiAllowed(int subId) {
6127 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006128 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006129 if (configManager == null) {
6130 return false;
6131 }
6132 PersistableBundle pb = configManager.getConfigForSubId(subId);
6133 if (pb == null) {
6134 return false;
6135 }
6136 return pb.getBoolean(
6137 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6138 }
6139
Shuo Qiandd210312017-04-12 22:11:33 +00006140 /**
6141 * Check if phone is in emergency callback mode
6142 * @return true if phone is in emergency callback mode
6143 * @param subId sub id
6144 */
goneil9c5f4872017-12-05 14:07:56 -08006145 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006146 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006147 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006148 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149
6150 final long identity = Binder.clearCallingIdentity();
6151 try {
6152 if (phone != null) {
6153 return phone.isInEcm();
6154 } else {
6155 return false;
6156 }
6157 } finally {
6158 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006159 }
6160 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006161
6162 /**
6163 * Get the current signal strength information for the given subscription.
6164 * Because this information is not updated when the device is in a low power state
6165 * it should not be relied-upon to be current.
6166 * @param subId Subscription index
6167 * @return the most recent cached signal strength info from the modem
6168 */
6169 @Override
6170 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 final long identity = Binder.clearCallingIdentity();
6172 try {
6173 Phone p = getPhone(subId);
6174 if (p == null) {
6175 return null;
6176 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006178 return p.getSignalStrength();
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
6181 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006182 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006183
Pengquan Meng77b7f132018-08-22 14:49:57 -07006184 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006185 * Get the current modem radio state for the given slot.
6186 * @param slotIndex slot index.
6187 * @param callingPackage the name of the package making the call.
6188 * @return the current radio power state from the modem
6189 */
6190 @Override
6191 public int getRadioPowerState(int slotIndex, String callingPackage) {
6192 Phone phone = PhoneFactory.getPhone(slotIndex);
6193 if (phone != null) {
6194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6195 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6196 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6197 }
6198
6199 final long identity = Binder.clearCallingIdentity();
6200 try {
6201 return phone.getRadioPowerState();
6202 } finally {
6203 Binder.restoreCallingIdentity(identity);
6204 }
6205 }
6206 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6207 }
6208
6209 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006210 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6211 *
6212 * <p>Requires one of the following permissions:
6213 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6214 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6215 * privileges.
6216 *
6217 * @param subId subscription id
6218 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6219 * {@code false}.
6220 */
6221 @Override
6222 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006223 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6224 null /* message */);
6225
Pengquan Menga1bb6272018-09-06 09:59:22 -07006226 boolean isEnabled = false;
6227 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006228 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006229 Phone phone = getPhone(subId);
6230 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006231 } catch (Exception e) {
6232 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6233 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006234 } finally {
6235 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006236 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006237 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006238 }
6239
6240
6241 /**
6242 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6243 *
6244 * <p> Requires permission:
6245 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6246 * privileges.
6247 *
6248 * @param subId subscription id
6249 * @param isEnabled {@code true} means enable, {@code false} means disable.
6250 */
6251 @Override
6252 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6254 mApp, subId, "setDataRoamingEnabled");
6255
Pengquan Menga1bb6272018-09-06 09:59:22 -07006256 final long identity = Binder.clearCallingIdentity();
6257 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006258 Phone phone = getPhone(subId);
6259 if (phone != null) {
6260 phone.setDataRoamingEnabled(isEnabled);
6261 }
6262 } finally {
6263 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006264 }
6265 }
6266
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006267 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006268 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006269 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6270 mApp, subId, "isManualNetworkSelectionAllowed");
6271
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006272 boolean isAllowed = true;
6273 final long identity = Binder.clearCallingIdentity();
6274 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006275 Phone phone = getPhone(subId);
6276 if (phone != null) {
6277 isAllowed = phone.isCspPlmnEnabled();
6278 }
6279 } finally {
6280 Binder.restoreCallingIdentity(identity);
6281 }
6282 return isAllowed;
6283 }
6284
6285 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006286 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liuc65bc952019-02-12 17:54:02 -08006287 try {
6288 enforceReadPrivilegedPermission("getUiccCardsInfo");
6289 } catch (SecurityException e) {
6290 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6291 // has carrier privileges on an active UICC
6292 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6293 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6294 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6295 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006296 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006297
6298 final long identity = Binder.clearCallingIdentity();
6299 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006300 UiccController uiccController = UiccController.getInstance();
6301 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6302
6303 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6304 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6305 // Remove private info if the caller doesn't have access
6306 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6307 for (UiccCardInfo cardInfo : cardInfos) {
6308 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6309 UiccProfile profile = card.getUiccProfile();
6310 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6311 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6312 filteredInfos.add(cardInfo.getUnprivileged());
6313 } else {
6314 filteredInfos.add(cardInfo);
6315 }
6316 }
6317 return filteredInfos;
6318 }
6319 return cardInfos;
6320 } catch (PackageManager.NameNotFoundException e) {
6321 // This should not happen since we pass the package info in from TelephonyManager
6322 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
6326 }
6327
6328 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006329 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006330 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 final long identity = Binder.clearCallingIdentity();
6333 try {
6334 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6335 if (slots == null) {
6336 Rlog.i(LOG_TAG, "slots is null.");
6337 return null;
6338 }
6339
6340 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6341 for (int i = 0; i < slots.length; i++) {
6342 UiccSlot slot = slots[i];
6343 if (slot == null) {
6344 continue;
6345 }
6346
6347 String cardId;
6348 UiccCard card = slot.getUiccCard();
6349 if (card != null) {
6350 cardId = card.getCardId();
6351 } else {
6352 cardId = slot.getIccId();
6353 }
6354
6355 int cardState = 0;
6356 switch (slot.getCardState()) {
6357 case CARDSTATE_ABSENT:
6358 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6359 break;
6360 case CARDSTATE_PRESENT:
6361 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6362 break;
6363 case CARDSTATE_ERROR:
6364 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6365 break;
6366 case CARDSTATE_RESTRICTED:
6367 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6368 break;
6369 default:
6370 break;
6371
6372 }
6373
6374 infos[i] = new UiccSlotInfo(
6375 slot.isActive(),
6376 slot.isEuicc(),
6377 cardId,
6378 cardState,
6379 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006380 slot.isExtendedApduSupported(),
6381 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 }
6383 return infos;
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006386 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006387 }
6388
6389 @Override
6390 public boolean switchSlots(int[] physicalSlots) {
6391 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006392
6393 final long identity = Binder.clearCallingIdentity();
6394 try {
6395 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6396 } finally {
6397 Binder.restoreCallingIdentity(identity);
6398 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006399 }
Jack Yu4c988042018-02-27 15:30:01 -08006400
6401 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006402 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006403 final long identity = Binder.clearCallingIdentity();
6404 try {
6405 return UiccController.getInstance().getCardIdForDefaultEuicc();
6406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
6409 }
6410
6411 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006412 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6413 enforceModifyPermission();
6414 final Phone phone = getPhone(subId);
6415 if (phone == null) {
6416 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6417 return;
6418 }
6419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 final long identity = Binder.clearCallingIdentity();
6421 try {
6422 phone.setRadioIndicationUpdateMode(filters, mode);
6423 } finally {
6424 Binder.restoreCallingIdentity(identity);
6425 }
Jack Yu4c988042018-02-27 15:30:01 -08006426 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006427
6428 /**
goneil47ffb6e2018-04-06 15:40:58 -07006429 * A test API to reload the UICC profile.
6430 *
6431 * <p>Requires that the calling app has permission
6432 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6433 * @hide
6434 */
6435 @Override
6436 public void refreshUiccProfile(int subId) {
6437 enforceModifyPermission();
6438
6439 final long identity = Binder.clearCallingIdentity();
6440 try {
6441 Phone phone = getPhone(subId);
6442 if (phone == null) {
6443 return;
6444 }
6445 UiccCard uiccCard = phone.getUiccCard();
6446 if (uiccCard == null) {
6447 return;
6448 }
6449 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6450 if (uiccProfile == null) {
6451 return;
6452 }
6453 uiccProfile.refresh();
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
6456 }
6457 }
6458
6459 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006460 * Returns false if the mobile data is disabled by default, otherwise return true.
6461 */
6462 private boolean getDefaultDataEnabled() {
6463 return "true".equalsIgnoreCase(
6464 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6465 }
6466
6467 /**
6468 * Returns true if the data roaming is enabled by default, i.e the system property
6469 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6470 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6471 */
6472 private boolean getDefaultDataRoamingEnabled(int subId) {
6473 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006474 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006475 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6476 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6477 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6478 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6479 return isDataRoamingEnabled;
6480 }
6481
6482 /**
6483 * Returns the default network type for the given {@code subId}, if the default network type is
6484 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6485 */
6486 private int getDefaultNetworkType(int subId) {
6487 return Integer.parseInt(
6488 TelephonyManager.getTelephonyProperty(
6489 mSubscriptionController.getPhoneId(subId),
6490 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6491 String.valueOf(Phone.PREFERRED_NT_MODE)));
6492 }
fionaxua13278b2018-03-21 00:08:13 -07006493
6494 @Override
6495 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006496 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006497 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006498
6499 final long identity = Binder.clearCallingIdentity();
6500 try {
6501 final Phone phone = getPhone(subId);
6502 if (phone == null) {
6503 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6504 return;
6505 }
chen xueaba88a2019-03-15 13:15:10 -07006506 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6507 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508 } finally {
6509 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006510 }
fionaxua13278b2018-03-21 00:08:13 -07006511 }
6512
6513 @Override
6514 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006515 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516
6517 final long identity = Binder.clearCallingIdentity();
6518 try {
6519 final Phone phone = getPhone(subId);
6520 if (phone == null) {
6521 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6522 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6523 }
6524 return phone.getCarrierIdListVersion();
6525 } finally {
6526 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006527 }
fionaxua13278b2018-03-21 00:08:13 -07006528 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006529
6530 @Override
6531 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6533 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6534 return -1;
6535 }
6536
6537 final long identity = Binder.clearCallingIdentity();
6538 try {
6539 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6540 } finally {
6541 Binder.restoreCallingIdentity(identity);
6542 }
6543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006544
6545 @Override
6546 public int getCdmaRoamingMode(int subId) {
6547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6548 mApp, subId, "getCdmaRoamingMode");
6549
6550 final long identity = Binder.clearCallingIdentity();
6551 try {
6552 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6553 } finally {
6554 Binder.restoreCallingIdentity(identity);
6555 }
6556 }
6557
6558 @Override
6559 public boolean setCdmaRoamingMode(int subId, int mode) {
6560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6561 mApp, subId, "setCdmaRoamingMode");
6562
6563 final long identity = Binder.clearCallingIdentity();
6564 try {
6565 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6566 } finally {
6567 Binder.restoreCallingIdentity(identity);
6568 }
6569 }
6570
6571 @Override
6572 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6574 mApp, subId, "setCdmaSubscriptionMode");
6575
6576 final long identity = Binder.clearCallingIdentity();
6577 try {
6578 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6579 } finally {
6580 Binder.restoreCallingIdentity(identity);
6581 }
6582 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006583
6584 private void ensureUserRunning(int userId) {
6585 if (!mUserManager.isUserRunning(userId)) {
6586 throw new IllegalStateException("User " + userId + " does not exist or not running");
6587 }
6588 }
6589
6590 /**
6591 * Returns a list of SMS apps on a given user.
6592 *
6593 * Only the shell user (UID 2000 or 0) can call it.
6594 * Target user must be running.
6595 */
6596 @Override
6597 public String[] getSmsApps(int userId) {
6598 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6599 ensureUserRunning(userId);
6600
6601 final Collection<SmsApplicationData> apps =
6602 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6603
6604 String[] ret = new String[apps.size()];
6605 int i = 0;
6606 for (SmsApplicationData app : apps) {
6607 ret[i++] = app.mPackageName;
6608 }
6609 return ret;
6610 }
6611
6612 /**
6613 * Returns the default SMS app package name on a given user.
6614 *
6615 * Only the shell user (UID 2000 or 0) can call it.
6616 * Target user must be running.
6617 */
6618 @Override
6619 public String getDefaultSmsApp(int userId) {
6620 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6621 ensureUserRunning(userId);
6622
6623 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6624 /* updateIfNeeded= */ true, userId);
6625 return cn == null ? null : cn.getPackageName();
6626 }
6627
6628 /**
6629 * Set a package as the default SMS app on a given user.
6630 *
6631 * Only the shell user (UID 2000 or 0) can call it.
6632 * Target user must be running.
6633 */
6634 @Override
6635 public void setDefaultSmsApp(int userId, String packageName) {
6636 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6637 ensureUserRunning(userId);
6638
6639 boolean found = false;
6640 for (String pkg : getSmsApps(userId)) {
6641 if (TextUtils.equals(packageName, pkg)) {
6642 found = true;
6643 break;
6644 }
6645 }
6646 if (!found) {
6647 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6648 }
6649
6650 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6651 }
sqianc5eccab2018-10-19 18:46:41 -07006652
6653 @Override
sqian8c685422019-02-22 15:55:18 -08006654 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006655 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006657 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006658 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6659 }
6660 final long identity = Binder.clearCallingIdentity();
6661 try {
sqian854d44b2018-12-12 16:48:18 -08006662 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6663 for (Phone phone: PhoneFactory.getPhones()) {
6664 if (phone.getEmergencyNumberTracker() != null
6665 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6666 emergencyNumberListInternal.put(
6667 phone.getSubId(),
6668 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6669 }
sqian11b7a0e2018-12-05 18:48:28 -08006670 }
sqian854d44b2018-12-12 16:48:18 -08006671 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006672 } finally {
6673 Binder.restoreCallingIdentity(identity);
6674 }
sqianc5eccab2018-10-19 18:46:41 -07006675 }
6676
6677 @Override
sqian8c685422019-02-22 15:55:18 -08006678 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006679 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006680 if (!exactMatch) {
6681 TelephonyPermissions
6682 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006683 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006684 }
6685 final long identity = Binder.clearCallingIdentity();
6686 try {
sqian854d44b2018-12-12 16:48:18 -08006687 for (Phone phone: PhoneFactory.getPhones()) {
6688 if (phone.getEmergencyNumberTracker() != null
6689 && phone.getEmergencyNumberTracker() != null) {
6690 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6691 number, exactMatch)) {
6692 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006693 }
6694 }
sqian11b7a0e2018-12-05 18:48:28 -08006695 }
6696 return false;
6697 } finally {
6698 Binder.restoreCallingIdentity(identity);
6699 }
6700 }
6701
sqianf4ca7ed2019-01-15 18:32:07 -08006702 /**
6703 * Update emergency number list for test mode.
6704 */
6705 @Override
6706 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6707 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6708 "updateEmergencyNumberListTestMode");
6709
6710 final long identity = Binder.clearCallingIdentity();
6711 try {
6712 for (Phone phone: PhoneFactory.getPhones()) {
6713 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6714 if (tracker != null) {
6715 tracker.executeEmergencyNumberTestModeCommand(action, num);
6716 }
6717 }
6718 } finally {
6719 Binder.restoreCallingIdentity(identity);
6720 }
6721 }
6722
6723 /**
6724 * Get the full emergency number list for test mode.
6725 */
6726 @Override
6727 public List<String> getEmergencyNumberListTestMode() {
6728 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6729 "getEmergencyNumberListTestMode");
6730
6731 final long identity = Binder.clearCallingIdentity();
6732 try {
6733 Set<String> emergencyNumbers = new HashSet<>();
6734 for (Phone phone: PhoneFactory.getPhones()) {
6735 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6736 if (tracker != null) {
6737 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6738 emergencyNumbers.add(num.getNumber());
6739 }
6740 }
6741 }
6742 return new ArrayList<>(emergencyNumbers);
6743 } finally {
6744 Binder.restoreCallingIdentity(identity);
6745 }
6746 }
6747
chen xud6b45bd2018-10-30 22:27:10 -07006748 @Override
6749 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6750 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6751 Phone phone = getPhone(subId);
6752 if (phone == null) {
6753 return null;
6754 }
6755 final long identity = Binder.clearCallingIdentity();
6756 try {
6757 UiccProfile profile = UiccController.getInstance()
6758 .getUiccProfileForPhone(phone.getPhoneId());
6759 if (profile != null) {
6760 return profile.getCertsFromCarrierPrivilegeAccessRules();
6761 }
6762 } finally {
6763 Binder.restoreCallingIdentity(identity);
6764 }
6765 return null;
6766 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006767
6768 /**
6769 * Enable or disable a modem stack.
6770 */
6771 @Override
6772 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6773 enforceModifyPermission();
6774
6775 final long identity = Binder.clearCallingIdentity();
6776 try {
6777 Phone phone = PhoneFactory.getPhone(slotIndex);
6778 if (phone == null) {
6779 return false;
6780 } else {
6781 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6782 }
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
6786 }
Michelecea4cf22018-12-21 15:00:11 -08006787
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006788 /**
6789 * Whether a modem stack is enabled or not.
6790 */
6791 @Override
6792 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6793 Phone phone = PhoneFactory.getPhone(slotIndex);
6794 if (phone == null) return false;
6795
6796 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6797 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6798 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6799 }
6800
6801 final long identity = Binder.clearCallingIdentity();
6802 try {
6803 return PhoneConfigurationManager.getInstance().getPhoneStatus(phone);
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
6806 }
6807 }
6808
Michelecea4cf22018-12-21 15:00:11 -08006809 @Override
Michele0ea7d782019-03-19 14:58:42 -07006810 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006811 enforceModifyPermission();
6812
6813 final long identity = Binder.clearCallingIdentity();
6814 try {
6815 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006816 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006817 .commit();
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
6820 }
6821 }
6822
6823 @Override
Michele0ea7d782019-03-19 14:58:42 -07006824 @TelephonyManager.IsMultiSimSupportedResult
6825 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006827 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6828 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006829 }
Michelecea4cf22018-12-21 15:00:11 -08006830
6831 final long identity = Binder.clearCallingIdentity();
6832 try {
Michele0ea7d782019-03-19 14:58:42 -07006833 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006834 } finally {
6835 Binder.restoreCallingIdentity(identity);
6836 }
6837 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006838
Michele0ea7d782019-03-19 14:58:42 -07006839 @TelephonyManager.IsMultiSimSupportedResult
6840 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006841 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6842 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6843 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006844 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6845 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006846 }
6847 // Check if the hardware supports multisim functionality. If usage of multisim is not
6848 // supported by the modem, indicate that it is restricted.
6849 PhoneCapability staticCapability =
6850 mPhoneConfigurationManager.getStaticPhoneCapability();
6851 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006852 loge("isMultiSimSupportedInternal: no static configuration available");
6853 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006854 }
6855 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006856 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6857 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006858 }
6859 // Check if support of multiple SIMs is restricted by carrier
6860 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006861 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006862 }
6863
Michele0ea7d782019-03-19 14:58:42 -07006864 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006865 }
6866
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006867 /**
6868 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006869 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6870 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6871 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006872 * @param numOfSims number of active sims we want to switch to
6873 */
6874 @Override
6875 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006876 if (numOfSims == 1) {
6877 enforceModifyPermission();
6878 } else {
6879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6880 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6881 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006882 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006883
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006884 try {
Michele30b57b22019-03-01 12:01:14 -08006885 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006886 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006887 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6888 return;
6889 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006890 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6891 } finally {
6892 Binder.restoreCallingIdentity(identity);
6893 }
6894 }
6895
6896 /**
chen xub4baa772019-04-03 10:23:41 -07006897 * Get whether making changes to modem configurations will trigger reboot.
6898 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006899 */
6900 @Override
chen xub4baa772019-04-03 10:23:41 -07006901 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6902 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6903 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6904 return false;
6905 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006906 final long identity = Binder.clearCallingIdentity();
6907 try {
6908 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6909 } finally {
6910 Binder.restoreCallingIdentity(identity);
6911 }
6912 }
6913
Nathan Harold29f5f052019-02-15 13:41:57 -08006914 private void updateModemStateMetrics() {
6915 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6916 // TODO: check the state for each modem if the api is ready.
6917 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6918 }
6919
Pengquan Meng3889a572019-01-23 11:16:29 -08006920 @Override
6921 public int[] getSlotsMapping() {
6922 enforceReadPrivilegedPermission("getSlotsMapping");
6923
6924 final long identity = Binder.clearCallingIdentity();
6925 try {
6926 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6927 // All logical slots should have a mapping to a physical slot.
6928 int[] logicalSlotsMapping = new int[phoneCount];
6929 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6930 for (int i = 0; i < slotInfos.length; i++) {
6931 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6932 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6933 }
6934 }
6935 return logicalSlotsMapping;
6936 } finally {
6937 Binder.restoreCallingIdentity(identity);
6938 }
6939 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006940
6941 /**
6942 * Get the IRadio HAL Version
6943 */
6944 @Override
6945 public int getRadioHalVersion() {
6946 Phone phone = getDefaultPhone();
6947 if (phone == null) return -1;
6948 HalVersion hv = phone.getHalVersion();
6949 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6950 return hv.major * 100 + hv.minor;
6951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006952}