blob: b96779a907eed38f47931bcb6800a0ecb1994877 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070047import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080048import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070049import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070051import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070052import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070054import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070055import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070056import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080057import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070058import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080059import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080060import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070061import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070062import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080063import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070065import android.telephony.CellInfoGsm;
66import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070067import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070068import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070069import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070070import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080071import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070072import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080073import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070074import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080075import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080076import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070077import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080078import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080081import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070082import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080083import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080088import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000089import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070090import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070094import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080095import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080097import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070098import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080099import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700100import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800101import android.telephony.ims.aidl.IImsMmTelFeature;
102import android.telephony.ims.aidl.IImsRcsFeature;
103import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800105import android.telephony.ims.feature.MmTelFeature;
106import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800107import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800109import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800111import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800112import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800113
Brad Ebinger35c841c2018-10-01 10:40:55 -0700114import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700115import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800116import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700117import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700118import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700119import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800120import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700121import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800124import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700125import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800126import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800128import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700129import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100130import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700131import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700132import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700134import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800135import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700136import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700137import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700138import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700139import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700140import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700141import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700142import com.android.internal.telephony.SmsApplication;
143import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700144import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800145import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800146import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700147import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800148import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700149import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800150import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800151import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152import com.android.internal.telephony.uicc.IccIoResult;
153import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800154import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700155import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800156import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800158import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000159import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700160import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800161import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700162import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700163import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800164import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700165import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700166import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800167
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700168import java.io.FileDescriptor;
169import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800170import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700173import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800174import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800175import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800176import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100177import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700179import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800180import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
182/**
183 * Implementation of the ITelephony interface.
184 */
Santos Cordon117fee72014-05-16 17:56:12 -0700185public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 private static final String LOG_TAG = "PhoneInterfaceManager";
187 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
188 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800189 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
191 // Message codes used with mMainThreadHandler
192 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700193 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
194 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195 private static final int CMD_OPEN_CHANNEL = 9;
196 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
197 private static final int CMD_CLOSE_CHANNEL = 11;
198 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800199 private static final int CMD_NV_READ_ITEM = 13;
200 private static final int EVENT_NV_READ_ITEM_DONE = 14;
201 private static final int CMD_NV_WRITE_ITEM = 15;
202 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
203 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
204 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700205 private static final int CMD_RESET_MODEM_CONFIG = 19;
206 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800207 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
208 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
209 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
210 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800211 private static final int CMD_SEND_ENVELOPE = 25;
212 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000213 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
214 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700215 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
216 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
217 private static final int CMD_EXCHANGE_SIM_IO = 31;
218 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800219 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
220 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700221 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
222 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700223 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
224 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700225 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
226 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
227 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700229 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
230 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
231 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
232 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700233 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800234 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
235 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000236 private static final int CMD_SWITCH_SLOTS = 50;
237 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700238 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
239 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
240 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
241 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
242 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
243 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
244 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
245 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700246 private static final int CMD_GET_ALL_CELL_INFO = 60;
247 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
248 private static final int CMD_GET_CELL_LOCATION = 62;
249 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700250 private static final int CMD_MODEM_REBOOT = 64;
251 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700252 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
253 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800254 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
255 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700256 private static final int CMD_GET_MODEM_STATUS = 70;
257 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800259 // Parameters of select command.
260 private static final int SELECT_COMMAND = 0xA4;
261 private static final int SELECT_P1 = 0x04;
262 private static final int SELECT_P2 = 0;
263 private static final int SELECT_P3 = 0x10;
264
Pengquan Meng85728fb2018-03-12 16:31:21 -0700265 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
266 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
267 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
268
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 /** The singleton instance. */
270 private static PhoneInterfaceManager sInstance;
271
Wink Saville3ab207e2014-11-20 13:07:20 -0800272 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800273 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700274 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private AppOpsManager mAppOps;
276 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800277 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700279 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280
Derek Tan97ebb422014-09-05 16:55:38 -0700281 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
282 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800283 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800284 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700285
Michelecea4cf22018-12-21 15:00:11 -0800286 // String to store multi SIM allowed
287 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
288
Derek Tan740e1672017-06-27 14:56:27 -0700289 // The AID of ISD-R.
290 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
291
yinxub1bed742017-04-17 11:45:04 -0700292 private NetworkScanRequestTracker mNetworkScanRequestTracker;
293
David Kelly5e06a7f2018-03-12 14:10:59 +0000294 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
295 private static final int MANUFACTURER_CODE_LENGTH = 8;
296
Derek Tan89e89d42014-07-08 17:00:10 -0700297 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700298 * A request object to use for transmitting data to an ICC.
299 */
300 private static final class IccAPDUArgument {
301 public int channel, cla, command, p1, p2, p3;
302 public String data;
303
304 public IccAPDUArgument(int channel, int cla, int command,
305 int p1, int p2, int p3, String data) {
306 this.channel = channel;
307 this.cla = cla;
308 this.command = command;
309 this.p1 = p1;
310 this.p2 = p2;
311 this.p3 = p3;
312 this.data = data;
313 }
314 }
315
316 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700317 * A request object to use for transmitting data to an ICC.
318 */
319 private static final class ManualNetworkSelectionArgument {
320 public OperatorInfo operatorInfo;
321 public boolean persistSelection;
322
323 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
324 this.operatorInfo = operatorInfo;
325 this.persistSelection = persistSelection;
326 }
327 }
328
329 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
331 * request after sending. The main thread will notify the request when it is complete.
332 */
333 private static final class MainThreadRequest {
334 /** The argument to use for the request */
335 public Object argument;
336 /** The result of the request that is run on the main thread */
337 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800338 // The subscriber id that this request applies to. Defaults to
339 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
340 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
Nathan Harold92bed182018-10-12 18:16:49 -0700342 // In cases where subId is unavailable, the caller needs to specify the phone.
343 public Phone phone;
344
vagdeviaf9a5b92018-08-15 16:01:53 -0700345 public WorkSource workSource;
346
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 public MainThreadRequest(Object argument) {
348 this.argument = argument;
349 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800350
Nathan Harold92bed182018-10-12 18:16:49 -0700351 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
352 this.argument = argument;
353 if (phone != null) {
354 this.phone = phone;
355 }
356 this.workSource = workSource;
357 }
358
vagdeviaf9a5b92018-08-15 16:01:53 -0700359 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800360 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800361 if (subId != null) {
362 this.subId = subId;
363 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700364 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 }
367
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800368 private static final class IncomingThirdPartyCallArgs {
369 public final ComponentName component;
370 public final String callId;
371 public final String callerDisplayName;
372
373 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
374 String callerDisplayName) {
375 this.component = component;
376 this.callId = callId;
377 this.callerDisplayName = callerDisplayName;
378 }
379 }
380
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 /**
382 * A handler that processes messages on the main thread in the phone process. Since many
383 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
384 * inbound binder threads to the main thread in the phone process. The Binder thread
385 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
386 * on, which will be notified when the operation completes and will contain the result of the
387 * request.
388 *
389 * <p>If a MainThreadRequest object is provided in the msg.obj field,
390 * note that request.result must be set to something non-null for the calling thread to
391 * unblock.
392 */
393 private final class MainThreadHandler extends Handler {
394 @Override
395 public void handleMessage(Message msg) {
396 MainThreadRequest request;
397 Message onCompleted;
398 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800399 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800401 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
403 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700404 case CMD_HANDLE_USSD_REQUEST: {
405 request = (MainThreadRequest) msg.obj;
406 final Phone phone = getPhoneFromRequest(request);
407 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
408 String ussdRequest = ussdObject.first;
409 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700410
Pengquan Menga1bb6272018-09-06 09:59:22 -0700411 if (!isUssdApiAllowed(request.subId)) {
412 // Carrier does not support use of this API, return failure.
413 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
414 UssdResponse response = new UssdResponse(ussdRequest, null);
415 Bundle returnData = new Bundle();
416 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
417 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700418
Pengquan Menga1bb6272018-09-06 09:59:22 -0700419 request.result = true;
420 notifyRequester(request);
421 return;
422 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 try {
425 request.result = phone != null
426 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
427 } catch (CallStateException cse) {
428 request.result = false;
429 }
430 // Wake up the requesting thread
431 notifyRequester(request);
432 break;
pkanwar32d516d2016-10-14 19:37:38 -0700433 }
434
Yorke Lee716f67e2015-06-17 15:39:16 -0700435 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700437 final Phone phone = getPhoneFromRequest(request);
438 request.result = phone != null ?
439 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
440 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700442 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 if (uiccCard == null) {
451 loge("iccTransmitApduLogicalChannel: No UICC");
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700454 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
456 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 iccArgument.channel, iccArgument.cla, iccArgument.command,
459 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700461 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 break;
463
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 ar = (AsyncResult) msg.obj;
466 request = (MainThreadRequest) ar.userObj;
467 if (ar.exception == null && ar.result != null) {
468 request.result = ar.result;
469 } else {
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
471 if (ar.result == null) {
472 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800473 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800475 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 } else {
477 loge("iccTransmitApduLogicalChannel: Unknown exception");
478 }
479 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 break;
482
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
484 request = (MainThreadRequest) msg.obj;
485 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800486 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 if (uiccCard == null) {
488 loge("iccTransmitApduBasicChannel: No UICC");
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700490 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 } else {
492 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
493 request);
494 uiccCard.iccTransmitApduBasicChannel(
495 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
496 iccArgument.p3, iccArgument.data, onCompleted);
497 }
498 break;
499
500 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
507 if (ar.result == null) {
508 loge("iccTransmitApduBasicChannel: Empty response");
509 } else if (ar.exception instanceof CommandException) {
510 loge("iccTransmitApduBasicChannel: CommandException: " +
511 ar.exception);
512 } else {
513 loge("iccTransmitApduBasicChannel: Unknown exception");
514 }
515 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 break;
518
519 case CMD_EXCHANGE_SIM_IO:
520 request = (MainThreadRequest) msg.obj;
521 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800522 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 if (uiccCard == null) {
524 loge("iccExchangeSimIO: No UICC");
525 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 } else {
528 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
529 request);
530 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
531 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
532 iccArgument.data, onCompleted);
533 }
534 break;
535
536 case EVENT_EXCHANGE_SIM_IO_DONE:
537 ar = (AsyncResult) msg.obj;
538 request = (MainThreadRequest) ar.userObj;
539 if (ar.exception == null && ar.result != null) {
540 request.result = ar.result;
541 } else {
542 request.result = new IccIoResult(0x6f, 0, (byte[])null);
543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 break;
546
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 case CMD_SEND_ENVELOPE:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("sendEnvelopeWithStatus: No UICC");
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 } else {
555 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
556 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
557 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800558 break;
559
560 case EVENT_SEND_ENVELOPE_DONE:
561 ar = (AsyncResult) msg.obj;
562 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700563 if (ar.exception == null && ar.result != null) {
564 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
567 if (ar.result == null) {
568 loge("sendEnvelopeWithStatus: Empty response");
569 } else if (ar.exception instanceof CommandException) {
570 loge("sendEnvelopeWithStatus: CommandException: " +
571 ar.exception);
572 } else {
573 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
574 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800575 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 break;
578
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 case CMD_OPEN_CHANNEL:
580 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800582 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 if (uiccCard == null) {
584 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800585 request.result = new IccOpenLogicalChannelResponse(-1,
586 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 } else {
589 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800590 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
591 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 break;
594
595 case EVENT_OPEN_CHANNEL_DONE:
596 ar = (AsyncResult) msg.obj;
597 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 int[] result = (int[]) ar.result;
601 int channelId = result[0];
602 byte[] selectResponse = null;
603 if (result.length > 1) {
604 selectResponse = new byte[result.length - 1];
605 for (int i = 1; i < result.length; ++i) {
606 selectResponse[i - 1] = (byte) result[i];
607 }
608 }
609 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.result == null) {
613 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 if (ar.exception != null) {
616 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
617 }
618
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700619 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700620 if (ar.exception instanceof CommandException) {
621 CommandException.Error error =
622 ((CommandException) (ar.exception)).getCommandError();
623 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700625 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 }
628 }
629 openChannelResp = new IccOpenLogicalChannelResponse(
630 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700632 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case CMD_CLOSE_CHANNEL:
637 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800638 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 if (uiccCard == null) {
640 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900641 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 } else {
644 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
645 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
646 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800650 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
651 break;
652
653 case CMD_NV_READ_ITEM:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800656 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
657 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800658 break;
659
660 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 ar = (AsyncResult) msg.obj;
662 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800663 if (ar.exception == null && ar.result != null) {
664 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800666 request.result = "";
667 if (ar.result == null) {
668 loge("nvReadItem: Empty response");
669 } else if (ar.exception instanceof CommandException) {
670 loge("nvReadItem: CommandException: " +
671 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800673 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
675 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
Jake Hambye994d462014-02-03 13:10:13 -0800679 case CMD_NV_WRITE_ITEM:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
682 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800683 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700684 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800685 break;
686
687 case EVENT_NV_WRITE_ITEM_DONE:
688 handleNullReturnEvent(msg, "nvWriteItem");
689 break;
690
691 case CMD_NV_WRITE_CDMA_PRL:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800694 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800695 break;
696
697 case EVENT_NV_WRITE_CDMA_PRL_DONE:
698 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
699 break;
700
chen xu6dac5ab2018-10-26 17:39:23 -0700701 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800702 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700703 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800704 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
chen xu6dac5ab2018-10-26 17:39:23 -0700707 case EVENT_RESET_MODEM_CONFIG_DONE:
708 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 case CMD_GET_PREFERRED_NETWORK_TYPE:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700714 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 break;
716
717 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
718 ar = (AsyncResult) msg.obj;
719 request = (MainThreadRequest) ar.userObj;
720 if (ar.exception == null && ar.result != null) {
721 request.result = ar.result; // Integer
722 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800723 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 if (ar.result == null) {
725 loge("getPreferredNetworkType: Empty response");
726 } else if (ar.exception instanceof CommandException) {
727 loge("getPreferredNetworkType: CommandException: " +
728 ar.exception);
729 } else {
730 loge("getPreferredNetworkType: Unknown exception");
731 }
732 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 break;
735
736 case CMD_SET_PREFERRED_NETWORK_TYPE:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
739 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700740 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
744 handleNullReturnEvent(msg, "setPreferredNetworkType");
745 break;
746
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000747 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
748 request = (MainThreadRequest)msg.obj;
749 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800750 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000751 break;
752
753 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
754 ar = (AsyncResult)msg.obj;
755 request = (MainThreadRequest)ar.userObj;
756 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700757 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000758 break;
759
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800760 case CMD_SET_VOICEMAIL_NUMBER:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
763 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800764 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
765 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800766 break;
767
768 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
769 handleNullReturnEvent(msg, "setVoicemailNumber");
770 break;
771
Stuart Scott54788802015-03-30 13:18:01 -0700772 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
775 request);
776 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
777 break;
778
779 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
780 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
781 break;
782
Shishir Agrawal302c8692015-06-19 13:49:39 -0700783 case CMD_PERFORM_NETWORK_SCAN:
784 request = (MainThreadRequest) msg.obj;
785 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
786 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
787 break;
788
789 case EVENT_PERFORM_NETWORK_SCAN_DONE:
790 ar = (AsyncResult) msg.obj;
791 request = (MainThreadRequest) ar.userObj;
792 CellNetworkScanResult cellScanResult;
793 if (ar.exception == null && ar.result != null) {
794 cellScanResult = new CellNetworkScanResult(
795 CellNetworkScanResult.STATUS_SUCCESS,
796 (List<OperatorInfo>) ar.result);
797 } else {
798 if (ar.result == null) {
799 loge("getCellNetworkScanResults: Empty response");
800 }
801 if (ar.exception != null) {
802 loge("getCellNetworkScanResults: Exception: " + ar.exception);
803 }
804 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
805 if (ar.exception instanceof CommandException) {
806 CommandException.Error error =
807 ((CommandException) (ar.exception)).getCommandError();
808 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
809 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
810 } else if (error == CommandException.Error.GENERIC_FAILURE) {
811 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
812 }
813 }
814 cellScanResult = new CellNetworkScanResult(errorCode, null);
815 }
816 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700817 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700818 break;
819
820 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
821 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700822 ManualNetworkSelectionArgument selArg =
823 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
825 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700826 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
827 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700828 break;
829
830 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700831 ar = (AsyncResult) msg.obj;
832 request = (MainThreadRequest) ar.userObj;
833 if (ar.exception == null) {
834 request.result = true;
835 } else {
836 request.result = false;
837 loge("setNetworkSelectionModeManual " + ar.exception);
838 }
839 notifyRequester(request);
840 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 case CMD_GET_MODEM_ACTIVITY_INFO:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700846 if (defaultPhone != null) {
847 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
848 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700849 break;
850
851 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
857 if (ar.result == null) {
858 loge("queryModemActivityInfo: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("queryModemActivityInfo: CommandException: " +
861 ar.exception);
862 } else {
863 loge("queryModemActivityInfo: Unknown exception");
864 }
865 }
Amit Mahajand4766222016-01-28 15:28:28 -0800866 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
867 if (request.result == null) {
868 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
869 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700870 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700871 break;
872
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 case CMD_SET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800875 CarrierRestrictionRules argument =
876 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800878 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 break;
880
881 case EVENT_SET_ALLOWED_CARRIERS_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result;
886 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800887 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
888 if (ar.exception instanceof CommandException) {
889 loge("setAllowedCarriers: CommandException: " + ar.exception);
890 CommandException.Error error =
891 ((CommandException) (ar.exception)).getCommandError();
892 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
893 request.result =
894 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
895 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 } else {
897 loge("setAllowedCarriers: Unknown exception");
898 }
899 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700900 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 break;
902
903 case CMD_GET_ALLOWED_CARRIERS:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800906 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 break;
908
909 case EVENT_GET_ALLOWED_CARRIERS_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800915 request.result = new IllegalStateException(
916 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 if (ar.result == null) {
918 loge("getAllowedCarriers: Empty response");
919 } else if (ar.exception instanceof CommandException) {
920 loge("getAllowedCarriers: CommandException: " +
921 ar.exception);
922 } else {
923 loge("getAllowedCarriers: Unknown exception");
924 }
925 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700926 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700927 break;
928
Nathan Haroldb3014052017-01-25 15:57:32 -0800929 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
932 if (ar.exception == null && ar.result != null) {
933 request.result = ar.result;
934 } else {
935 request.result = new IllegalArgumentException(
936 "Failed to retrieve Forbidden Plmns");
937 if (ar.result == null) {
938 loge("getForbiddenPlmns: Empty response");
939 } else {
940 loge("getForbiddenPlmns: Unknown exception");
941 }
942 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700943 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 break;
945
946 case CMD_GET_FORBIDDEN_PLMNS:
947 request = (MainThreadRequest) msg.obj;
948 uiccCard = getUiccCardFromRequest(request);
949 if (uiccCard == null) {
950 loge("getForbiddenPlmns() UiccCard is null");
951 request.result = new IllegalArgumentException(
952 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700953 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800954 break;
955 }
956 Integer appType = (Integer) request.argument;
957 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
958 if (uiccApp == null) {
959 loge("getForbiddenPlmns() no app with specified type -- "
960 + appType);
961 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700962 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800963 break;
964 } else {
965 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
966 + " specified type -- " + appType);
967 }
968 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
969 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
970 onCompleted);
971 break;
972
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000973 case CMD_SWITCH_SLOTS:
974 request = (MainThreadRequest) msg.obj;
975 int[] physicalSlots = (int[]) request.argument;
976 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
977 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
978 break;
979
980 case EVENT_SWITCH_SLOTS_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700984 notifyRequester(request);
985 break;
986 case CMD_GET_NETWORK_SELECTION_MODE:
987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
989 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
990 break;
991
992 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 if (ar.exception != null) {
996 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
997 } else {
998 int mode = ((int[]) ar.result)[0];
999 if (mode == 0) {
1000 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1001 } else {
1002 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1003 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001004 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001005 notifyRequester(request);
1006 break;
1007 case CMD_GET_CDMA_ROAMING_MODE:
1008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1010 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1011 break;
1012 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception != null) {
1016 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1017 } else {
1018 request.result = ((int[]) ar.result)[0];
1019 }
1020 notifyRequester(request);
1021 break;
1022 case CMD_SET_CDMA_ROAMING_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1025 int mode = (int) request.argument;
1026 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1027 break;
1028 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 request.result = ar.exception == null;
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1037 int subscriptionMode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001045 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 case CMD_GET_ALL_CELL_INFO:
1047 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001048 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001049 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 case EVENT_GET_ALL_CELL_INFO_DONE:
1052 ar = (AsyncResult) msg.obj;
1053 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001054 // If a timeout occurs, the response will be null
1055 request.result = (ar.exception == null && ar.result != null)
1056 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 synchronized (request) {
1058 request.notifyAll();
1059 }
1060 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 case CMD_REQUEST_CELL_INFO_UPDATE:
1062 request = (MainThreadRequest) msg.obj;
1063 request.phone.requestCellInfoUpdate(request.workSource,
1064 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1065 break;
1066 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1070 try {
1071 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001073 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1074 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001077 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 } else {
1079 // use the result as returned
1080 cb.onCellInfo((List<CellInfo>) ar.result);
1081 }
1082 } catch (RemoteException re) {
1083 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1084 }
1085 break;
1086 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001087 request = (MainThreadRequest) msg.obj;
1088 WorkSource ws = (WorkSource) request.argument;
1089 Phone phone = getPhoneFromRequest(request);
1090 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1091 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 if (ar.exception == null) {
1096 request.result = ar.result;
1097 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001098 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001099 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1100 ? new CdmaCellLocation() : new GsmCellLocation();
1101 }
1102
1103 synchronized (request) {
1104 request.notifyAll();
1105 }
1106 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001107 case CMD_MODEM_REBOOT:
1108 request = (MainThreadRequest) msg.obj;
1109 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001110 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001111 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001112 case EVENT_CMD_MODEM_REBOOT_DONE:
1113 handleNullReturnEvent(msg, "rebootModem");
1114 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001115 case CMD_REQUEST_ENABLE_MODEM:
1116 request = (MainThreadRequest) msg.obj;
1117 boolean enable = (boolean) request.argument;
1118 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001119 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001120 PhoneConfigurationManager.getInstance()
1121 .enablePhone(request.phone, enable, onCompleted);
1122 break;
1123 case EVENT_ENABLE_MODEM_DONE:
1124 ar = (AsyncResult) msg.obj;
1125 request = (MainThreadRequest) ar.userObj;
1126 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001127 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001128 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001129 if ((boolean) request.result) {
1130 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1131 updateModemStateMetrics();
1132 } else {
1133 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1134 + ar.exception);
1135 }
1136 notifyRequester(request);
1137 break;
1138 case CMD_GET_MODEM_STATUS:
1139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1141 PhoneConfigurationManager.getInstance()
1142 .getPhoneStatusFromModem(request.phone, onCompleted);
1143 break;
1144 case EVENT_GET_MODEM_STATUS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 int id = request.phone.getPhoneId();
1148 if (ar.exception == null && ar.result != null) {
1149 request.result = ar.result;
1150 //update the cache as modem status has changed
1151 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1152 (boolean) request.result);
1153 } else {
1154 // Return true if modem status cannot be retrieved. For most cases,
1155 // modem status is on. And for older version modems, GET_MODEM_STATUS
1156 // and disable modem are not supported. Modem is always on.
1157 // TODO: this should be fixed in R to support a third
1158 // status UNKNOWN b/131631629
1159 request.result = true;
1160 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1161 + ar.exception);
1162 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001163 notifyRequester(request);
1164 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 default:
1166 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1167 break;
1168 }
1169 }
Jake Hambye994d462014-02-03 13:10:13 -08001170
Pengquan Menga1bb6272018-09-06 09:59:22 -07001171 private void notifyRequester(MainThreadRequest request) {
1172 synchronized (request) {
1173 request.notifyAll();
1174 }
1175 }
1176
Jake Hambye994d462014-02-03 13:10:13 -08001177 private void handleNullReturnEvent(Message msg, String command) {
1178 AsyncResult ar = (AsyncResult) msg.obj;
1179 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1180 if (ar.exception == null) {
1181 request.result = true;
1182 } else {
1183 request.result = false;
1184 if (ar.exception instanceof CommandException) {
1185 loge(command + ": CommandException: " + ar.exception);
1186 } else {
1187 loge(command + ": Unknown exception");
1188 }
1189 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001190 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 }
1193
1194 /**
1195 * Posts the specified command to be executed on the main thread,
1196 * waits for the request to complete, and returns the result.
1197 * @see #sendRequestAsync
1198 */
1199 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001200 return sendRequest(
1201 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001202 }
1203
1204 /**
1205 * Posts the specified command to be executed on the main thread,
1206 * waits for the request to complete, and returns the result.
1207 * @see #sendRequestAsync
1208 */
1209 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1210 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001211 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001212 }
1213
1214 /**
1215 * Posts the specified command to be executed on the main thread,
1216 * waits for the request to complete, and returns the result.
1217 * @see #sendRequestAsync
1218 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001219 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001220 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001221 }
1222
1223 /**
1224 * Posts the specified command to be executed on the main thread,
1225 * waits for the request to complete, and returns the result.
1226 * @see #sendRequestAsync
1227 */
Nathan Harold92bed182018-10-12 18:16:49 -07001228 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1229 return sendRequest(command, argument, subId, null, workSource);
1230 }
1231
1232 /**
1233 * Posts the specified command to be executed on the main thread,
1234 * waits for the request to complete, and returns the result.
1235 * @see #sendRequestAsync
1236 */
1237 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1238 return sendRequest(
1239 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1240 }
1241
1242 /**
1243 * Posts the specified command to be executed on the main thread,
1244 * waits for the request to complete, and returns the result.
1245 * @see #sendRequestAsync
1246 */
1247 private Object sendRequest(
1248 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1250 throw new RuntimeException("This method will deadlock if called from the main thread.");
1251 }
1252
Nathan Harold92bed182018-10-12 18:16:49 -07001253 MainThreadRequest request = null;
1254 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1255 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1256 } else if (phone != null) {
1257 request = new MainThreadRequest(argument, phone, workSource);
1258 } else {
1259 request = new MainThreadRequest(argument, subId, workSource);
1260 }
1261
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 Message msg = mMainThreadHandler.obtainMessage(command, request);
1263 msg.sendToTarget();
1264
1265 // Wait for the request to complete
1266 synchronized (request) {
1267 while (request.result == null) {
1268 try {
1269 request.wait();
1270 } catch (InterruptedException e) {
1271 // Do nothing, go back and wait until the request is complete
1272 }
1273 }
1274 }
1275 return request.result;
1276 }
1277
1278 /**
1279 * Asynchronous ("fire and forget") version of sendRequest():
1280 * Posts the specified command to be executed on the main thread, and
1281 * returns immediately.
1282 * @see #sendRequest
1283 */
1284 private void sendRequestAsync(int command) {
1285 mMainThreadHandler.sendEmptyMessage(command);
1286 }
1287
1288 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001289 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001290 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001291 */
1292 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 sendRequestAsync(command, argument, null, null);
1294 }
1295
1296 /**
1297 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1298 * @see {@link #sendRequest(int,Object)}
1299 */
1300 private void sendRequestAsync(
1301 int command, Object argument, Phone phone, WorkSource workSource) {
1302 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001303 Message msg = mMainThreadHandler.obtainMessage(command, request);
1304 msg.sendToTarget();
1305 }
1306
1307 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 * Initialize the singleton PhoneInterfaceManager instance.
1309 * This is only done once, at startup, from PhoneApp.onCreate().
1310 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001311 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 synchronized (PhoneInterfaceManager.class) {
1313 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001314 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 } else {
1316 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1317 }
1318 return sInstance;
1319 }
1320 }
1321
1322 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001323 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001326 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1328 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001329 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001330 mTelephonySharedPreferences =
1331 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001332 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001333 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001334
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 publish();
1336 }
1337
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001338 private Phone getDefaultPhone() {
1339 Phone thePhone = getPhone(getDefaultSubscription());
1340 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1341 }
1342
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 private void publish() {
1344 if (DBG) log("publish: " + this);
1345
1346 ServiceManager.addService("phone", this);
1347 }
1348
Stuart Scott584921c2015-01-15 17:10:34 -08001349 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001350 if (request.phone != null) {
1351 return request.phone;
1352 } else {
1353 return getPhoneFromSubId(request.subId);
1354 }
1355 }
1356
1357 private Phone getPhoneFromSubId(int subId) {
1358 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1359 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001360 }
1361
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001362 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1363 Phone phone = getPhoneFromRequest(request);
1364 return phone == null ? null :
1365 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1366 }
1367
Wink Saville36469e72014-06-11 15:17:00 -07001368 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001369 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001370 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372
1373 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
1376
Wink Savilleb564aae2014-10-23 10:18:09 -07001377 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 if (DBG) log("dial: " + number);
1379 // No permission check needed here: This is just a wrapper around the
1380 // ACTION_DIAL intent, which is available to any app since it puts up
1381 // the UI before it does anything.
1382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001383 final long identity = Binder.clearCallingIdentity();
1384 try {
1385 String url = createTelUrl(number);
1386 if (url == null) {
1387 return;
1388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001390 // PENDING: should we just silently fail if phone is offhook or ringing?
1391 PhoneConstants.State state = mCM.getState(subId);
1392 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1393 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1394 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1395 mApp.startActivity(intent);
1396 }
1397 } finally {
1398 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 }
1400 }
1401
1402 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001403 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001404 }
1405
Wink Savilleb564aae2014-10-23 10:18:09 -07001406 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 if (DBG) log("call: " + number);
1408
1409 // This is just a wrapper around the ACTION_CALL intent, but we still
1410 // need to do a permission check since we're calling startActivity()
1411 // from the context of the phone app.
1412 enforceCallPermission();
1413
1414 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1415 != AppOpsManager.MODE_ALLOWED) {
1416 return;
1417 }
1418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001419 final long identity = Binder.clearCallingIdentity();
1420 try {
1421 String url = createTelUrl(number);
1422 if (url == null) {
1423 return;
1424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001426 boolean isValid = false;
1427 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1428 if (slist != null) {
1429 for (SubscriptionInfo subInfoRecord : slist) {
1430 if (subInfoRecord.getSubscriptionId() == subId) {
1431 isValid = true;
1432 break;
1433 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001434 }
Wink Saville08874612014-08-31 19:19:58 -07001435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001436 if (!isValid) {
1437 return;
1438 }
Wink Saville08874612014-08-31 19:19:58 -07001439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001440 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1441 intent.putExtra(SUBSCRIPTION_KEY, subId);
1442 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1443 mApp.startActivity(intent);
1444 } finally {
1445 Binder.restoreCallingIdentity(identity);
1446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 }
1448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001450 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001451 }
1452
Wink Savilleb564aae2014-10-23 10:18:09 -07001453 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001455 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1456 }
1457
1458 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001459 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001460 }
1461
Wink Savilleb564aae2014-10-23 10:18:09 -07001462 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001463 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001464 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1465 }
1466
1467 /** {@hide} */
1468 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001469 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001470 }
1471
Wink Savilleb564aae2014-10-23 10:18:09 -07001472 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001474
1475 final long identity = Binder.clearCallingIdentity();
1476 try {
1477 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1478 checkSimPin.start();
1479 return checkSimPin.unlockSim(null, pin);
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
1482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484
Wink Saville9de0f752013-10-22 19:04:03 -07001485 /** {@hide} */
1486 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001492
1493 final long identity = Binder.clearCallingIdentity();
1494 try {
1495 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1496 checkSimPuk.start();
1497 return checkSimPuk.unlockSim(puk, pin);
1498 } finally {
1499 Binder.restoreCallingIdentity(identity);
1500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
1502
1503 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001504 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 * a synchronous one.
1506 */
1507 private static class UnlockSim extends Thread {
1508
1509 private final IccCard mSimCard;
1510
1511 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001512 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1513 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514
1515 // For replies from SimCard interface
1516 private Handler mHandler;
1517
1518 // For async handler to identify request type
1519 private static final int SUPPLY_PIN_COMPLETE = 100;
1520
1521 public UnlockSim(IccCard simCard) {
1522 mSimCard = simCard;
1523 }
1524
1525 @Override
1526 public void run() {
1527 Looper.prepare();
1528 synchronized (UnlockSim.this) {
1529 mHandler = new Handler() {
1530 @Override
1531 public void handleMessage(Message msg) {
1532 AsyncResult ar = (AsyncResult) msg.obj;
1533 switch (msg.what) {
1534 case SUPPLY_PIN_COMPLETE:
1535 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1536 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001537 mRetryCount = msg.arg1;
1538 if (ar.exception != null) {
1539 if (ar.exception instanceof CommandException &&
1540 ((CommandException)(ar.exception)).getCommandError()
1541 == CommandException.Error.PASSWORD_INCORRECT) {
1542 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1543 } else {
1544 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1545 }
1546 } else {
1547 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 mDone = true;
1550 UnlockSim.this.notifyAll();
1551 }
1552 break;
1553 }
1554 }
1555 };
1556 UnlockSim.this.notifyAll();
1557 }
1558 Looper.loop();
1559 }
1560
1561 /*
1562 * Use PIN or PUK to unlock SIM card
1563 *
1564 * If PUK is null, unlock SIM card with PIN
1565 *
1566 * If PUK is not null, unlock SIM card with PUK and set PIN code
1567 */
Wink Saville9de0f752013-10-22 19:04:03 -07001568 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569
1570 while (mHandler == null) {
1571 try {
1572 wait();
1573 } catch (InterruptedException e) {
1574 Thread.currentThread().interrupt();
1575 }
1576 }
1577 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1578
1579 if (puk == null) {
1580 mSimCard.supplyPin(pin, callback);
1581 } else {
1582 mSimCard.supplyPuk(puk, pin, callback);
1583 }
1584
1585 while (!mDone) {
1586 try {
1587 Log.d(LOG_TAG, "wait for done");
1588 wait();
1589 } catch (InterruptedException e) {
1590 // Restore the interrupted status
1591 Thread.currentThread().interrupt();
1592 }
1593 }
1594 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001595 int[] resultArray = new int[2];
1596 resultArray[0] = mResult;
1597 resultArray[1] = mRetryCount;
1598 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 }
1600 }
1601
1602 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001603 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001604
1605 }
1606
Wink Savilleb564aae2014-10-23 10:18:09 -07001607 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 // No permission check needed here: this call is harmless, and it's
1609 // needed for the ServiceState.requestStateUpdate() call (which is
1610 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001611 final long identity = Binder.clearCallingIdentity();
1612 try {
1613 final Phone phone = getPhone(subId);
1614 if (phone != null) {
1615 phone.updateServiceLocation();
1616 }
1617 } finally {
1618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001622 @Override
1623 public boolean isRadioOn(String callingPackage) {
1624 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001625 }
1626
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001627 @Override
1628 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001630 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001631 return false;
1632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001633
1634 final long identity = Binder.clearCallingIdentity();
1635 try {
1636 return isRadioOnForSubscriber(subId);
1637 } finally {
1638 Binder.restoreCallingIdentity(identity);
1639 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001640 }
1641
1642 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001643 final long identity = Binder.clearCallingIdentity();
1644 try {
1645 final Phone phone = getPhone(subId);
1646 if (phone != null) {
1647 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1648 } else {
1649 return false;
1650 }
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 }
1655
1656 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001657 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
Wink Saville36469e72014-06-11 15:17:00 -07001659
Wink Savilleb564aae2014-10-23 10:18:09 -07001660 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001662
1663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 final Phone phone = getPhone(subId);
1666 if (phone != null) {
1667 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1668 }
1669 } finally {
1670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 }
Wink Saville36469e72014-06-11 15:17:00 -07001672 }
1673
1674 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001675 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001676 }
1677
Wink Savilleb564aae2014-10-23 10:18:09 -07001678 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001679 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001680
1681 final long identity = Binder.clearCallingIdentity();
1682 try {
1683 final Phone phone = getPhone(subId);
1684 if (phone == null) {
1685 return false;
1686 }
1687 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1688 toggleRadioOnOffForSubscriber(subId);
1689 }
1690 return true;
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 }
Wink Saville36469e72014-06-11 15:17:00 -07001695
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001696 public boolean needMobileRadioShutdown() {
1697 /*
1698 * If any of the Radios are available, it will need to be
1699 * shutdown. So return true if any Radio is available.
1700 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001701 final long identity = Binder.clearCallingIdentity();
1702 try {
1703 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1704 Phone phone = PhoneFactory.getPhone(i);
1705 if (phone != null && phone.isRadioAvailable()) return true;
1706 }
1707 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1708 return false;
1709 } finally {
1710 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001711 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001712 }
1713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001714 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001715 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716 enforceModifyPermission();
1717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1721 logv("Shutting down Phone " + i);
1722 shutdownRadioUsingPhoneId(i);
1723 }
1724 } finally {
1725 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001726 }
1727 }
1728
1729 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001730 Phone phone = PhoneFactory.getPhone(phoneId);
1731 if (phone != null && phone.isRadioAvailable()) {
1732 phone.shutdownRadio();
1733 }
1734 }
1735
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001738
1739 final long identity = Binder.clearCallingIdentity();
1740 try {
1741 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1742 if (defaultPhone != null) {
1743 defaultPhone.setRadioPower(turnOn);
1744 return true;
1745 } else {
1746 loge("There's no default phone.");
1747 return false;
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001751 }
Wink Saville36469e72014-06-11 15:17:00 -07001752 }
1753
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
1761 phone.setRadioPower(turnOn);
1762 return true;
1763 } else {
1764 return false;
1765 }
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
Wink Saville36469e72014-06-11 15:17:00 -07001771 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 public boolean enableDataConnectivity() {
1774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001775
1776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 int subId = mSubscriptionController.getDefaultDataSubId();
1779 final Phone phone = getPhone(subId);
1780 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001781 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782 return true;
1783 } else {
1784 return false;
1785 }
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
Wink Saville36469e72014-06-11 15:17:00 -07001791 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 public boolean disableDataConnectivity() {
1794 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795
1796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 int subId = mSubscriptionController.getDefaultDataSubId();
1799 final Phone phone = getPhone(subId);
1800 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001801 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001802 return true;
1803 } else {
1804 return false;
1805 }
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001812 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 final Phone phone = getPhone(subId);
1816 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001817 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001818 } else {
1819 return false;
1820 }
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
1826 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001827 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001828 }
1829
pkanwarae03a6b2016-11-06 20:37:09 -08001830 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001831 enforceCallPermission();
1832
1833 final long identity = Binder.clearCallingIdentity();
1834 try {
1835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1836 return;
1837 }
1838 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1839 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
1842 }
pkanwar32d516d2016-10-14 19:37:38 -07001843 };
1844
Wink Savilleb564aae2014-10-23 10:18:09 -07001845 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847
1848 final long identity = Binder.clearCallingIdentity();
1849 try {
1850 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1851 return false;
1852 }
1853 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1854 } finally {
1855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 }
1858
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001860 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001861 }
1862
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001863 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001864 final long identity = Binder.clearCallingIdentity();
1865 try {
1866 Phone phone = PhoneFactory.getPhone(slotIndex);
1867 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1868 PhoneConstantConversions.convertCallState(phone.getState());
1869 } finally {
1870 Binder.restoreCallingIdentity(identity);
1871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873
Sanket Padawe356d7632015-06-22 14:03:32 -07001874 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001876 final long identity = Binder.clearCallingIdentity();
1877 try {
1878 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1879 if (phone != null) {
1880 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1881 } else {
1882 return PhoneConstantConversions.convertDataState(
1883 PhoneConstants.DataState.DISCONNECTED);
1884 }
1885 } finally {
1886 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001887 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 }
1889
Sanket Padawe356d7632015-06-22 14:03:32 -07001890 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001892 final long identity = Binder.clearCallingIdentity();
1893 try {
1894 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1895 if (phone != null) {
1896 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1897 } else {
1898 return TelephonyManager.DATA_ACTIVITY_NONE;
1899 }
1900 } finally {
1901 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
1905 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001906 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001907 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001908 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001909
1910 LocationAccessPolicy.LocationPermissionResult locationResult =
1911 LocationAccessPolicy.checkLocationPermission(mApp,
1912 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1913 .setCallingPackage(callingPackage)
1914 .setCallingPid(Binder.getCallingPid())
1915 .setCallingUid(Binder.getCallingUid())
1916 .setMethod("getCellLocation")
1917 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1918 .build());
1919 switch (locationResult) {
1920 case DENIED_HARD:
1921 throw new SecurityException("Not allowed to access cell location");
1922 case DENIED_SOFT:
1923 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 }
1925
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001926 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 if (DBG_LOC) log("getCellLocation: is active user");
1930 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001931 int subId = mSubscriptionController.getDefaultDataSubId();
1932 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1933 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001934 return data;
1935 } finally {
1936 Binder.restoreCallingIdentity(identity);
1937 }
Svetoslav64fad262015-04-14 14:35:21 -07001938 }
1939
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001941 public String getNetworkCountryIsoForPhone(int phoneId) {
1942 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1943 // registered cell info, so return a NULL country instead.
1944 final long identity = Binder.clearCallingIdentity();
1945 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001946 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1947 // Get default phone in this case.
1948 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1949 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001950 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001951 // Todo: fix this when we can get the actual cellular network info when the device
1952 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001953 if (TelephonyManager.NETWORK_TYPE_IWLAN
1954 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1955 return "";
1956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001957 Phone phone = PhoneFactory.getPhone(phoneId);
1958 if (phone != null) {
1959 ServiceStateTracker sst = phone.getServiceStateTracker();
1960 if (sst != null) {
1961 LocaleTracker lt = sst.getLocaleTracker();
1962 if (lt != null) {
1963 return lt.getCurrentCountry();
1964 }
1965 }
1966 }
1967 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001968 } finally {
1969 Binder.restoreCallingIdentity(identity);
1970 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001971 }
1972
1973 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001975 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001976 }
1977
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001979 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980 mApp.enforceCallingOrSelfPermission(
1981 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001982
1983 final long identity = Binder.clearCallingIdentity();
1984 try {
1985 final Phone phone = getPhone(subId);
1986 if (phone != null) {
1987 phone.enableLocationUpdates();
1988 }
1989 } finally {
1990 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992 }
1993
1994 @Override
1995 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001996 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001997 }
1998
Sanket Padawe356d7632015-06-22 14:03:32 -07001999 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002000 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 mApp.enforceCallingOrSelfPermission(
2002 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002003
2004 final long identity = Binder.clearCallingIdentity();
2005 try {
2006 final Phone phone = getPhone(subId);
2007 if (phone != null) {
2008 phone.disableLocationUpdates();
2009 }
2010 } finally {
2011 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
2014
Nathan Harold31d7ff32018-10-15 20:20:30 -07002015 /**
2016 * Returns the target SDK version number for a given package name.
2017 *
2018 * @return target SDK if the package is found or INT_MAX.
2019 */
2020 private int getTargetSdk(String packageName) {
2021 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002022 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2023 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002024 if (ai != null) return ai.targetSdkVersion;
2025 } catch (PackageManager.NameNotFoundException unexpected) {
2026 }
2027 return Integer.MAX_VALUE;
2028 }
2029
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 @Override
2031 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002032 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2033 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002034 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2035 throw new SecurityException(
2036 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2037 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002038
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2040 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2041 return null;
2042 }
Svetoslav64fad262015-04-14 14:35:21 -07002043
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002044 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045
Nathan Haroldf180aac2018-06-01 18:43:55 -07002046 List<CellInfo> info = getAllCellInfo(callingPackage);
2047 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048
Nathan Haroldf180aac2018-06-01 18:43:55 -07002049 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2050 for (CellInfo ci : info) {
2051 if (ci instanceof CellInfoGsm) {
2052 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2053 } else if (ci instanceof CellInfoWcdma) {
2054 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2055 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002057 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 }
2059
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002060 private List<CellInfo> getCachedCellInfo() {
2061 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2062 for (Phone phone : PhoneFactory.getPhones()) {
2063 List<CellInfo> info = phone.getAllCellInfo();
2064 if (info != null) cellInfos.addAll(info);
2065 }
2066 return cellInfos;
2067 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068
2069 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002070 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002071 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002072 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002073
2074 LocationAccessPolicy.LocationPermissionResult locationResult =
2075 LocationAccessPolicy.checkLocationPermission(mApp,
2076 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2077 .setCallingPackage(callingPackage)
2078 .setCallingPid(Binder.getCallingPid())
2079 .setCallingUid(Binder.getCallingUid())
2080 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002081 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002082 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2083 .build());
2084 switch (locationResult) {
2085 case DENIED_HARD:
2086 throw new SecurityException("Not allowed to access cell info");
2087 case DENIED_SOFT:
2088 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 }
2090
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002091 final int targetSdk = getTargetSdk(callingPackage);
2092 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2093 return getCachedCellInfo();
2094 }
2095
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002096 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002097 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002098 final long identity = Binder.clearCallingIdentity();
2099 try {
2100 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2101 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002102 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002103 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002104 if (info != null) cellInfos.addAll(info);
2105 }
2106 return cellInfos;
2107 } finally {
2108 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 }
2110 }
2111
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002112 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002113 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2114 requestCellInfoUpdateInternal(
2115 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2116 }
2117
2118 @Override
2119 public void requestCellInfoUpdateWithWorkSource(
2120 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2121 enforceModifyPermission();
2122 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2123 }
2124
2125 private void requestCellInfoUpdateInternal(
2126 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002127 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002128 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002129
2130 LocationAccessPolicy.LocationPermissionResult locationResult =
2131 LocationAccessPolicy.checkLocationPermission(mApp,
2132 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2133 .setCallingPackage(callingPackage)
2134 .setCallingPid(Binder.getCallingPid())
2135 .setCallingUid(Binder.getCallingUid())
2136 .setMethod("requestCellInfoUpdate")
2137 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2138 .build());
2139 switch (locationResult) {
2140 case DENIED_HARD:
2141 throw new SecurityException("Not allowed to access cell info");
2142 case DENIED_SOFT:
Nathan Haroldb3c5da42019-05-09 10:26:08 -07002143 try {
2144 cb.onCellInfo(new ArrayList<CellInfo>());
2145 } catch (RemoteException re) {
2146 // Drop without consequences
2147 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002148 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002149 }
2150
Nathan Harold32e84c42019-05-09 10:13:47 -07002151
2152 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002153 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2154
2155 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2156 }
2157
2158 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002160 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002161 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002162
2163 final long identity = Binder.clearCallingIdentity();
2164 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002165 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002166 } finally {
2167 Binder.restoreCallingIdentity(identity);
2168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 }
2170
Shishir Agrawala9f32182016-04-12 12:00:16 -07002171 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002172 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002173 Phone phone = PhoneFactory.getPhone(slotIndex);
2174 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002175 return null;
2176 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002177 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002178 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2179 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002180 return null;
2181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002182
2183 final long identity = Binder.clearCallingIdentity();
2184 try {
2185 return phone.getImei();
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
2188 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002189 }
2190
2191 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002192 public String getTypeAllocationCodeForSlot(int slotIndex) {
2193 Phone phone = PhoneFactory.getPhone(slotIndex);
2194 String tac = null;
2195 if (phone != null) {
2196 String imei = phone.getImei();
2197 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2198 }
2199 return tac;
2200 }
2201
2202 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002203 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002204 Phone phone = PhoneFactory.getPhone(slotIndex);
2205 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002206 return null;
2207 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002208
Jeff Davidson913390f2018-02-23 17:11:49 -08002209 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002210 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2211 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002212 return null;
2213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214
2215 final long identity = Binder.clearCallingIdentity();
2216 try {
2217 return phone.getMeid();
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
2220 }
Jack Yu2af8d712017-03-15 17:14:14 -07002221 }
2222
2223 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002224 public String getManufacturerCodeForSlot(int slotIndex) {
2225 Phone phone = PhoneFactory.getPhone(slotIndex);
2226 String manufacturerCode = null;
2227 if (phone != null) {
2228 String meid = phone.getMeid();
2229 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2230 }
2231 return manufacturerCode;
2232 }
2233
2234 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002235 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002236 Phone phone = PhoneFactory.getPhone(slotIndex);
2237 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002238 return null;
2239 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002240 int subId = phone.getSubId();
2241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2242 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2243 return null;
2244 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245
2246 final long identity = Binder.clearCallingIdentity();
2247 try {
2248 return phone.getDeviceSvn();
2249 } finally {
2250 Binder.restoreCallingIdentity(identity);
2251 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002252 }
2253
fionaxu43304da2017-11-27 22:51:16 -08002254 @Override
2255 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002256 final long identity = Binder.clearCallingIdentity();
2257 try {
2258 final Phone phone = getPhone(subId);
2259 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2260 } finally {
2261 Binder.restoreCallingIdentity(identity);
2262 }
fionaxu43304da2017-11-27 22:51:16 -08002263 }
2264
2265 @Override
2266 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002267 final long identity = Binder.clearCallingIdentity();
2268 try {
2269 final Phone phone = getPhone(subId);
2270 return phone == null ? null : phone.getCarrierName();
2271 } finally {
2272 Binder.restoreCallingIdentity(identity);
2273 }
fionaxu43304da2017-11-27 22:51:16 -08002274 }
2275
calvinpanffe225e2018-11-01 19:43:06 +08002276 @Override
chen xu0026ca62019-03-06 15:28:50 -08002277 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002278 final long identity = Binder.clearCallingIdentity();
2279 try {
2280 final Phone phone = getPhone(subId);
2281 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002282 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002283 } finally {
2284 Binder.restoreCallingIdentity(identity);
2285 }
2286 }
2287
2288 @Override
chen xu0026ca62019-03-06 15:28:50 -08002289 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002293 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002294 } finally {
2295 Binder.restoreCallingIdentity(identity);
2296 }
2297 }
2298
chen xu651eec72018-11-11 19:03:44 -08002299 @Override
chen xu864e11c2018-12-06 22:10:03 -08002300 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2301 if (!isSubscriptionMccMnc) {
2302 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2303 }
chen xu651eec72018-11-11 19:03:44 -08002304 final Phone phone = PhoneFactory.getPhone(slotIndex);
2305 if (phone == null) {
2306 return TelephonyManager.UNKNOWN_CARRIER_ID;
2307 }
2308 final long identity = Binder.clearCallingIdentity();
2309 try {
2310 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
2313 }
2314 }
2315
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 //
2317 // Internal helper methods.
2318 //
2319
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002320 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2322 *
2323 * @throws SecurityException if the caller does not have the required permission
2324 */
2325 private void enforceModifyPermission() {
2326 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2327 }
2328
2329 /**
2330 * Make sure the caller has the CALL_PHONE permission.
2331 *
2332 * @throws SecurityException if the caller does not have the required permission
2333 */
2334 private void enforceCallPermission() {
2335 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2336 }
2337
Stuart Scott8eef64f2015-04-08 15:13:54 -07002338 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002339 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002340 "ConnectivityService");
2341 }
2342
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 private String createTelUrl(String number) {
2344 if (TextUtils.isEmpty(number)) {
2345 return null;
2346 }
2347
Jake Hambye994d462014-02-03 13:10:13 -08002348 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 }
2350
Ihab Awadf9e92732013-12-05 18:02:52 -08002351 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2353 }
2354
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002355 private static void logv(String msg) {
2356 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2357 }
2358
Ihab Awadf9e92732013-12-05 18:02:52 -08002359 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2361 }
2362
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002363 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002365 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002366 }
2367
Sanket Padawe356d7632015-06-22 14:03:32 -07002368 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002369 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370 final long identity = Binder.clearCallingIdentity();
2371 try {
2372 final Phone phone = PhoneFactory.getPhone(slotIndex);
2373 if (phone == null) {
2374 return PhoneConstants.PHONE_TYPE_NONE;
2375 } else {
2376 return phone.getPhoneType();
2377 }
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 }
2382
2383 /**
2384 * Returns the CDMA ERI icon index to display
2385 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002386 @Override
2387 public int getCdmaEriIconIndex(String callingPackage) {
2388 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002389 }
2390
Sanket Padawe356d7632015-06-22 14:03:32 -07002391 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002392 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002394 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002395 return -1;
2396 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397
2398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 final Phone phone = getPhone(subId);
2401 if (phone != null) {
2402 return phone.getCdmaEriIconIndex();
2403 } else {
2404 return -1;
2405 }
2406 } finally {
2407 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 }
2410
2411 /**
2412 * Returns the CDMA ERI icon mode,
2413 * 0 - ON
2414 * 1 - FLASHING
2415 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002416 @Override
2417 public int getCdmaEriIconMode(String callingPackage) {
2418 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002419 }
2420
Sanket Padawe356d7632015-06-22 14:03:32 -07002421 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002422 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002423 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002424 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002425 return -1;
2426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427
2428 final long identity = Binder.clearCallingIdentity();
2429 try {
2430 final Phone phone = getPhone(subId);
2431 if (phone != null) {
2432 return phone.getCdmaEriIconMode();
2433 } else {
2434 return -1;
2435 }
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439 }
2440
2441 /**
2442 * Returns the CDMA ERI text,
2443 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002444 @Override
2445 public String getCdmaEriText(String callingPackage) {
2446 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002447 }
2448
Sanket Padawe356d7632015-06-22 14:03:32 -07002449 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002450 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002452 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002453 return null;
2454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002455
2456 final long identity = Binder.clearCallingIdentity();
2457 try {
2458 final Phone phone = getPhone(subId);
2459 if (phone != null) {
2460 return phone.getCdmaEriText();
2461 } else {
2462 return null;
2463 }
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 }
2468
2469 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002470 * Returns the CDMA MDN.
2471 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002472 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002473 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2475 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476
2477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002480 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481 return phone.getLine1Number();
2482 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002483 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 return null;
2485 }
2486 } finally {
2487 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002488 }
2489 }
2490
2491 /**
2492 * Returns the CDMA MIN.
2493 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002494 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002495 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2497 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498
2499 final long identity = Binder.clearCallingIdentity();
2500 try {
2501 final Phone phone = getPhone(subId);
2502 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2503 return phone.getCdmaMin();
2504 } else {
2505 return null;
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002509 }
2510 }
2511
Hall Liud892bec2018-11-30 14:51:45 -08002512 @Override
2513 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2514 INumberVerificationCallback callback, String callingPackage) {
2515 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2516 != PERMISSION_GRANTED) {
2517 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2518 }
2519 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2520
2521 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2522 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2523 throw new SecurityException("Calling package must be configured in the device config");
2524 }
2525
2526 if (range == null) {
2527 throw new NullPointerException("Range must be non-null");
2528 }
2529
2530 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002531 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002532
2533 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2534 }
2535
Junda Liuca05d5d2014-08-14 22:36:34 -07002536 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 * Returns true if CDMA provisioning needs to run.
2538 */
2539 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540 final long identity = Binder.clearCallingIdentity();
2541 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002542 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 }
2547
2548 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002549 * Sets the voice mail number of a given subId.
2550 */
2551 @Override
2552 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002553 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554
2555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2558 new Pair<String, String>(alphaTag, number), new Integer(subId));
2559 return success;
2560 } finally {
2561 Binder.restoreCallingIdentity(identity);
2562 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002563 }
2564
Ta-wei Yen87c49842016-05-13 21:19:52 -07002565 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002566 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2567 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002568 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002569 if (!TextUtils.equals(callingPackage, systemDialer)) {
2570 throw new SecurityException("caller must be system dialer");
2571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572
2573 final long identity = Binder.clearCallingIdentity();
2574 try {
2575 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2576 if (phoneAccountHandle == null) {
2577 return null;
2578 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002579 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580 } finally {
2581 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002582 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002583 }
2584
2585 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002586 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002589 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002590 return null;
2591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002593 final long identity = Binder.clearCallingIdentity();
2594 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002595 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002596 } finally {
2597 Binder.restoreCallingIdentity(identity);
2598 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002599 }
2600
2601 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002602 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2603 VisualVoicemailSmsFilterSettings settings) {
2604 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605
2606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002609 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 } finally {
2611 Binder.restoreCallingIdentity(identity);
2612 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002613 }
2614
2615 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002616 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2617 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618
2619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002622 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 } finally {
2624 Binder.restoreCallingIdentity(identity);
2625 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002626 }
2627
2628 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002629 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2630 String callingPackage, int subId) {
2631 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002636 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637 } finally {
2638 Binder.restoreCallingIdentity(identity);
2639 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002640 }
2641
2642 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002643 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002644 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645
2646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002649 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 } finally {
2651 Binder.restoreCallingIdentity(identity);
2652 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002653 }
2654
2655 @Override
2656 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2657 String number, int port, String text, PendingIntent sentIntent) {
2658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002659 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002660 enforceSendSmsPermission();
2661 // Make the calls as the phone process.
2662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2665 if (port == 0) {
2666 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2667 sentIntent, null, false);
2668 } else {
2669 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2670 smsManager.sendDataMessageWithSelfPermissions(number, null,
2671 (short) port, data, sentIntent, null);
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
2675 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002676 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002677 /**
fionaxu0152e512016-11-14 13:36:14 -08002678 * Sets the voice activation state of a given subId.
2679 */
2680 @Override
2681 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2683 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 final Phone phone = getPhone(subId);
2688 if (phone != null) {
2689 phone.setVoiceActivationState(activationState);
2690 } else {
2691 loge("setVoiceActivationState fails with invalid subId: " + subId);
2692 }
2693 } finally {
2694 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002695 }
2696 }
2697
2698 /**
2699 * Sets the data activation state of a given subId.
2700 */
2701 @Override
2702 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2704 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705
2706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 final Phone phone = getPhone(subId);
2709 if (phone != null) {
2710 phone.setDataActivationState(activationState);
2711 } else {
2712 loge("setVoiceActivationState fails with invalid subId: " + subId);
2713 }
2714 } finally {
2715 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002716 }
2717 }
2718
2719 /**
2720 * Returns the voice activation state of a given subId.
2721 */
2722 @Override
2723 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002724 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725
fionaxu0152e512016-11-14 13:36:14 -08002726 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 if (phone != null) {
2730 return phone.getVoiceActivationState();
2731 } else {
2732 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2733 }
2734 } finally {
2735 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002736 }
2737 }
2738
2739 /**
2740 * Returns the data activation state of a given subId.
2741 */
2742 @Override
2743 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002744 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745
fionaxu0152e512016-11-14 13:36:14 -08002746 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747 final long identity = Binder.clearCallingIdentity();
2748 try {
2749 if (phone != null) {
2750 return phone.getDataActivationState();
2751 } else {
2752 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2753 }
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002756 }
2757 }
2758
2759 /**
Wink Saville36469e72014-06-11 15:17:00 -07002760 * Returns the unread count of voicemails for a subId
2761 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002762 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002763 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2765 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2766 return 0;
2767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 final Phone phone = getPhone(subId);
2771 if (phone != null) {
2772 return phone.getVoiceMessageCount();
2773 } else {
2774 return 0;
2775 }
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780
2781 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002782 * returns true, if the device is in a state where both voice and data
2783 * are supported simultaneously. This can change based on location or network condition.
2784 */
2785 @Override
2786 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 final Phone phone = getPhone(subId);
2790 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
2793 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002794 }
2795
2796 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002797 * Send the dialer code if called from the current default dialer or the caller has
2798 * carrier privilege.
2799 * @param inputCode The dialer code to send
2800 */
2801 @Override
2802 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002803 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002804 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002805 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2806 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002807 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002808 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2809 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002810 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811
2812 final long identity = Binder.clearCallingIdentity();
2813 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002814 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815 } finally {
2816 Binder.restoreCallingIdentity(identity);
2817 }
fionaxu235cc5e2017-03-06 22:25:57 -08002818 }
2819
2820 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002821 * Returns the data network type.
2822 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002823 *
2824 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2825 */
2826 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002827 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 final Phone phone = getPhone(getDefaultSubscription());
2831 if (phone != null) {
2832 return phone.getServiceState().getDataNetworkType();
2833 } else {
2834 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2835 }
2836 } finally {
2837 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002838 }
Wink Saville36469e72014-06-11 15:17:00 -07002839 }
2840
Pengquan Menga1bb6272018-09-06 09:59:22 -07002841 @Override
2842 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002843 if (!isActiveSubscription(subId)) {
2844 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2845 }
2846
Pengquan Menga1bb6272018-09-06 09:59:22 -07002847 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2848 }
2849
Brad Ebinger35c841c2018-10-01 10:40:55 -07002850 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002851 public boolean isInEmergencySmsMode() {
2852 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 for (Phone phone : PhoneFactory.getPhones()) {
2856 if (phone.isInEmergencySmsMode()) {
2857 return true;
2858 }
2859 }
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
2862 }
2863 return false;
2864 }
2865
2866 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002867 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2868 throws RemoteException {
2869 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002870 final long token = Binder.clearCallingIdentity();
2871 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002873 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002874 .addRegistrationCallbackForSubscription(c, subId);
2875 } finally {
2876 Binder.restoreCallingIdentity(token);
2877 }
2878 }
2879
2880 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002881 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2882 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002883 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2884 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2885 }
2886 Binder.withCleanCallingIdentity(() -> {
2887 try {
2888 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002889 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002890 .removeRegistrationCallbackForSubscription(c, subId);
2891 } catch (IllegalArgumentException e) {
2892 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2893 + "is inactive, ignoring unregister.");
2894 // If the subscription is no longer active, just return, since the callback
2895 // will already have been removed internally.
2896 }
2897 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002898 }
2899
2900 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002901 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2902 throws RemoteException {
2903 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002904 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2905 final long token = Binder.clearCallingIdentity();
2906 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002907 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002908 .addCapabilitiesCallbackForSubscription(c, subId);
2909 } finally {
2910 Binder.restoreCallingIdentity(token);
2911 }
2912 }
2913
2914 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002915 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2916 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002917
2918 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2919 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2920 }
2921 Binder.withCleanCallingIdentity(() -> {
2922 try {
2923 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002924 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002925 .removeCapabilitiesCallbackForSubscription(c, subId);
2926 } catch (IllegalArgumentException e) {
2927 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2928 + "is inactive, ignoring unregister.");
2929 // If the subscription is no longer active, just return, since the callback
2930 // will already have been removed internally.
2931 }
2932 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002933 }
2934
2935 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002936 public boolean isCapable(int subId, int capability, int regTech) {
2937 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002938 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2939 final long token = Binder.clearCallingIdentity();
2940 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002941 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002942 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2943 } catch (ImsException e) {
2944 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2945 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002946 } catch (IllegalArgumentException e) {
2947 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2948 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002949 } finally {
2950 Binder.restoreCallingIdentity(token);
2951 }
2952 }
2953
2954 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002955 public boolean isAvailable(int subId, int capability, int regTech) {
2956 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002957 final long token = Binder.clearCallingIdentity();
2958 try {
2959 Phone phone = getPhone(subId);
2960 if (phone == null) return false;
2961 return phone.isImsCapabilityAvailable(capability, regTech);
2962 } finally {
2963 Binder.restoreCallingIdentity(token);
2964 }
2965 }
2966
2967 @Override
2968 public boolean isAdvancedCallingSettingEnabled(int subId) {
2969 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2971 final long token = Binder.clearCallingIdentity();
2972 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002973 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002974 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2975 } finally {
2976 Binder.restoreCallingIdentity(token);
2977 }
2978 }
2979
2980 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002981 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002983 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
2992 }
2993
2994 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002995 public boolean isVtSettingEnabled(int subId) {
2996 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003000 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003001 getSlotIndexOrException(subId)).isVtEnabledByUser();
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
3005 }
3006
3007 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003008 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003010 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003014 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
3018 }
3019
3020 @Override
3021 public boolean isVoWiFiSettingEnabled(int subId) {
3022 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003026 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003027 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
3031 }
3032
3033 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003034 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003036 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003037 final long identity = Binder.clearCallingIdentity();
3038 try {
3039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003040 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
3044 }
3045
3046 @Override
3047 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3048 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003052 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003053 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
3057 }
3058
3059 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003060 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003062 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003066 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003067 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
3071 }
3072
3073 @Override
3074 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3076 "setVoWiFiNonPersistent");
3077 final long identity = Binder.clearCallingIdentity();
3078 try {
3079 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003080 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003081 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003082 } finally {
3083 Binder.restoreCallingIdentity(identity);
3084 }
3085 }
3086
3087 @Override
3088 public int getVoWiFiModeSetting(int subId) {
3089 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003093 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003094 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3095 } finally {
3096 Binder.restoreCallingIdentity(identity);
3097 }
3098 }
3099
3100 @Override
3101 public void setVoWiFiModeSetting(int subId, int mode) {
3102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3103 "setVoWiFiModeSetting");
3104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003107 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
3112 }
3113
3114 @Override
3115 public int getVoWiFiRoamingModeSetting(int subId) {
3116 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3117 final long identity = Binder.clearCallingIdentity();
3118 try {
3119 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003120 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003121 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
3125 }
3126
3127 @Override
3128 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3130 "setVoWiFiRoamingModeSetting");
3131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003134 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003135 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
3139 }
3140
3141 @Override
3142 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3144 "setRttCapabilityEnabled");
3145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003148 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003149 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
3153 }
3154
3155 @Override
3156 public boolean isTtyOverVolteEnabled(int subId) {
3157 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003161 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003162 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
3166 }
3167
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003168 @Override
3169 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3170 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003174 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003175 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003176 } finally {
3177 Binder.restoreCallingIdentity(identity);
3178 }
3179 }
3180
3181 @Override
3182 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3183 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3184 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003185 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3186 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3187 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003188 try {
3189 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003190 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003191 .removeProvisioningCallbackForSubscription(callback, subId);
3192 } catch (IllegalArgumentException e) {
3193 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3194 + "is inactive, ignoring unregister.");
3195 // If the subscription is no longer active, just return, since the callback will already
3196 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003197 } finally {
3198 Binder.restoreCallingIdentity(identity);
3199 }
3200 }
3201
3202 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003203 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3204 boolean isProvisioned) {
3205 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3206 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3207 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3208 }
3209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3210 "setProvisioningStatusForCapability");
3211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3214 Phone phone = getPhone(subId);
3215 if (phone == null) {
3216 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3217 + subId);
3218 return;
3219 }
3220 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3221 return;
3222 }
3223
3224 // this capability requires provisioning, route to the correct API.
3225 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3226 switch (capability) {
3227 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3228 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3229 ims.setVolteProvisioned(isProvisioned);
3230 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3231 ims.setWfcProvisioned(isProvisioned);
3232 }
3233 break;
3234 }
3235 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3236 // There is currently no difference in VT provisioning type.
3237 ims.setVtProvisioned(isProvisioned);
3238 break;
3239 }
3240 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3241 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3242 // change the capability of the feature instead if needed.
3243 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3244 == isProvisioned) {
3245 // No change in provisioning.
3246 return;
3247 }
3248 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3249 try {
3250 ims.changeMmTelCapability(capability, tech, isProvisioned);
3251 } catch (ImsException e) {
3252 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3253 + ", Exception" + e.getMessage());
3254 }
3255 break;
3256 }
3257 default: {
3258 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3259 + capability + "', which does not require provisioning.");
3260 }
3261 }
3262
3263 } finally {
3264 Binder.restoreCallingIdentity(identity);
3265 }
3266 }
3267
3268 @Override
3269 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3270 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3271 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3272 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3273 }
3274 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3275 final long identity = Binder.clearCallingIdentity();
3276 try {
3277 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3278 Phone phone = getPhone(subId);
3279 if (phone == null) {
3280 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3281 + subId);
3282 // We will fail with "true" as the provisioning status because this is the default
3283 // if we do not require provisioning.
3284 return true;
3285 }
3286
3287 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3288 return true;
3289 }
3290
3291 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3292 switch (capability) {
3293 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3294 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3295 return ims.isVolteProvisionedOnDevice();
3296 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3297 return ims.isWfcProvisionedOnDevice();
3298 }
3299 // This should never happen, since we are checking tech above to make sure it
3300 // is either LTE or IWLAN.
3301 throw new IllegalArgumentException("Invalid radio technology for voice "
3302 + "capability.");
3303 }
3304 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3305 // There is currently no difference in VT provisioning type.
3306 return ims.isVtProvisionedOnDevice();
3307 }
3308 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3309 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3310 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3311 }
3312 default: {
3313 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3314 + capability + "', which does not require provisioning.");
3315 }
3316 }
3317
3318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
3321 }
3322
3323 @Override
3324 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3325 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3326 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3327 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3328 }
3329 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3330 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3331 return (provisionedBits & capability) > 0;
3332 }
3333
3334 @Override
3335 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3336 boolean isProvisioned) {
3337 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3338 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3339 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3340 }
3341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3342 "setProvisioningStatusForCapability");
3343 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3344 // If the current provisioning status for capability already matches isProvisioned,
3345 // do nothing.
3346 if (((provisionedBits & capability) > 0) == isProvisioned) {
3347 return;
3348 }
3349 if (isProvisioned) {
3350 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3351 } else {
3352 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3353 }
3354 }
3355
3356 /**
3357 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3358 * technology. The bitfield should mirror the bitfield defined by
3359 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3360 */
3361 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3362 String key = getMmTelProvisioningKey(subId, tech);
3363 // Default is no capabilities are provisioned.
3364 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3365 }
3366
3367 /**
3368 * Sets the MmTel capability provisioning bitfield (defined by
3369 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3370 * technology specified.
3371 *
3372 * Note: This is a synchronous command and should not be called on UI thread.
3373 */
3374 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3375 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3376 String key = getMmTelProvisioningKey(subId, tech);
3377 editor.putInt(key, newField);
3378 editor.commit();
3379 }
3380
3381 private static String getMmTelProvisioningKey(int subId, int tech) {
3382 // resulting key is provision_ims_mmtel_{subId}_{tech}
3383 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3384 }
3385
3386 /**
3387 * Query CarrierConfig to see if the specified capability requires provisioning for the
3388 * carrier associated with the subscription id.
3389 */
3390 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3391 int capability) {
3392 CarrierConfigManager configManager = new CarrierConfigManager(context);
3393 PersistableBundle c = configManager.getConfigForSubId(subId);
3394 boolean requireUtProvisioning = c.getBoolean(
3395 // By default, this config is true (even if there is no SIM). We also check to make
3396 // sure the subscription needs provisioning here, so we do not need to check for
3397 // the no-SIM case, where we would normally shortcut this to false.
3398 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3399 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3400 false);
3401 boolean requireVoiceVtProvisioning = c.getBoolean(
3402 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3403
3404 // First check to make sure that the capability requires provisioning.
3405 switch (capability) {
3406 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3407 // intentional fallthrough
3408 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3409 if (requireVoiceVtProvisioning) {
3410 // Voice and Video requires provisioning
3411 return true;
3412 }
3413 break;
3414 }
3415 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3416 if (requireUtProvisioning) {
3417 // UT requires provisioning
3418 return true;
3419 }
3420 break;
3421 }
3422 }
3423 return false;
3424 }
3425
3426 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003427 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003428 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3429 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3430 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003431 enforceReadPrivilegedPermission("getImsProvisioningInt");
3432 final long identity = Binder.clearCallingIdentity();
3433 try {
3434 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003435 int slotId = getSlotIndex(subId);
3436 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3437 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3438 + subId + "' for key:" + key);
3439 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3440 }
3441 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003442 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003443 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3444 + subId + "' for key:" + key);
3445 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003446 } finally {
3447 Binder.restoreCallingIdentity(identity);
3448 }
3449 }
3450
3451 @Override
3452 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003453 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3454 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3455 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003456 enforceReadPrivilegedPermission("getImsProvisioningString");
3457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003460 int slotId = getSlotIndex(subId);
3461 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3462 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3463 + subId + "' for key:" + key);
3464 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3465 }
3466 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003467 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003468 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3469 + subId + "' for key:" + key);
3470 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003471 } finally {
3472 Binder.restoreCallingIdentity(identity);
3473 }
3474 }
3475
3476 @Override
3477 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003478 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3479 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3480 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3482 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003486 int slotId = getSlotIndex(subId);
3487 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3488 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3489 + subId + "' for key:" + key);
3490 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3491 }
3492 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003493 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003494 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3495 + "' for key:" + key);
3496 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
3500 }
3501
3502 @Override
3503 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003504 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3505 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3506 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3508 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003512 int slotId = getSlotIndex(subId);
3513 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3514 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3515 + subId + "' for key:" + key);
3516 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3517 }
3518 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003519 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003520 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3521 + "' for key:" + key);
3522 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
3526 }
3527
Brad Ebinger35c841c2018-10-01 10:40:55 -07003528 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3529 int slotId = SubscriptionManager.getSlotIndex(subId);
3530 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003531 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003532 }
3533 return slotId;
3534 }
3535
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003536 private int getSlotIndex(int subId) {
3537 int slotId = SubscriptionManager.getSlotIndex(subId);
3538 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3539 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3540 }
3541 return slotId;
3542 }
3543
Wink Saville36469e72014-06-11 15:17:00 -07003544 /**
3545 * Returns the network type for a subId
3546 */
3547 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003548 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003550 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003551 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3552 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554 final long identity = Binder.clearCallingIdentity();
3555 try {
3556 final Phone phone = getPhone(subId);
3557 if (phone != null) {
3558 return phone.getServiceState().getDataNetworkType();
3559 } else {
3560 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3561 }
3562 } finally {
3563 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003565 }
3566
3567 /**
3568 * Returns the data network type
3569 */
3570 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003571 public int getDataNetworkType(String callingPackage) {
3572 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003573 }
3574
3575 /**
3576 * Returns the data network type for a subId
3577 */
3578 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003579 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003581 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003582 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3583 }
3584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003585 final long identity = Binder.clearCallingIdentity();
3586 try {
3587 final Phone phone = getPhone(subId);
3588 if (phone != null) {
3589 return phone.getServiceState().getDataNetworkType();
3590 } else {
3591 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3592 }
3593 } finally {
3594 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003595 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003596 }
3597
3598 /**
Wink Saville36469e72014-06-11 15:17:00 -07003599 * Returns the Voice network type for a subId
3600 */
3601 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003602 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003604 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003605 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3606 }
3607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003608 final long identity = Binder.clearCallingIdentity();
3609 try {
3610 final Phone phone = getPhone(subId);
3611 if (phone != null) {
3612 return phone.getServiceState().getVoiceNetworkType();
3613 } else {
3614 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3615 }
3616 } finally {
3617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003619 }
3620
3621 /**
3622 * @return true if a ICC card is present
3623 */
3624 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003625 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003626 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3627 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003628 }
3629
3630 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003631 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003632 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003633 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003634 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 final Phone phone = PhoneFactory.getPhone(slotIndex);
3638 if (phone != null) {
3639 return phone.getIccCard().hasIccCard();
3640 } else {
3641 return false;
3642 }
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003645 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003646 }
3647
3648 /**
3649 * Return if the current radio is LTE on CDMA. This
3650 * is a tri-state return value as for a period of time
3651 * the mode may be unknown.
3652 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003653 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003654 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003655 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003656 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003657 @Override
3658 public int getLteOnCdmaMode(String callingPackage) {
3659 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003660 }
3661
Sanket Padawe356d7632015-06-22 14:03:32 -07003662 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003663 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003665 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003666 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3667 }
3668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 final Phone phone = getPhone(subId);
3672 if (phone == null) {
3673 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3674 } else {
3675 return phone.getLteOnCdmaMode();
3676 }
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003679 }
Wink Saville36469e72014-06-11 15:17:00 -07003680 }
3681
Wink Saville36469e72014-06-11 15:17:00 -07003682 /**
3683 * {@hide}
3684 * Returns Default subId, 0 in the case of single standby.
3685 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003686 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003687 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003688 }
3689
Shishir Agrawala9f32182016-04-12 12:00:16 -07003690 private int getSlotForDefaultSubscription() {
3691 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3692 }
3693
Wink Savilleb564aae2014-10-23 10:18:09 -07003694 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003695 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003696 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003697
Pengquan Menge92a50d2018-09-21 15:54:48 -07003698 private boolean isActiveSubscription(int subId) {
3699 return mSubscriptionController.isActiveSubId(subId);
3700 }
3701
Ihab Awadf2177b72013-11-25 13:33:23 -08003702 /**
3703 * @see android.telephony.TelephonyManager.WifiCallingChoices
3704 */
3705 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706 final long identity = Binder.clearCallingIdentity();
3707 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003708 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003709 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3710 getWhenToMakeWifiCallsDefaultPreference());
3711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003714 }
3715
3716 /**
3717 * @see android.telephony.TelephonyManager.WifiCallingChoices
3718 */
3719 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003728 }
3729
Sailesh Nepald1e68152013-12-12 19:08:02 -08003730 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003731 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003732 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003733 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003734
Jordan Liu4c733742019-02-28 12:03:40 -08003735 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3736 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3737 if (phoneId == -1) {
3738 throw new IllegalArgumentException("Given slot index: " + slotIndex
3739 + " does not correspond to an active phone");
3740 }
3741 return PhoneFactory.getPhone(phoneId);
3742 }
3743
Shishir Agrawal566b7612013-10-28 14:41:00 -07003744 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003745 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3746 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3748 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003750 if (DBG) {
3751 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3752 }
3753 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3754 p2);
3755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003756
Jordan Liu4c733742019-02-28 12:03:40 -08003757
3758 @Override
3759 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3760 int slotIndex, String callingPackage, String aid, int p2) {
3761 enforceModifyPermission();
3762 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3763 if (DBG) {
3764 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3765 }
3766 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3767 callingPackage, aid, p2);
3768 }
3769
3770 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3771 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772 final long identity = Binder.clearCallingIdentity();
3773 try {
3774 if (TextUtils.equals(ISDR_AID, aid)) {
3775 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003776 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3777 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003778 if (bestComponent == null
3779 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3780 loge("The calling package is not allowed to access ISD-R.");
3781 throw new SecurityException(
3782 "The calling package is not allowed to access ISD-R.");
3783 }
Derek Tan740e1672017-06-27 14:56:27 -07003784 }
Derek Tan740e1672017-06-27 14:56:27 -07003785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003787 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3788 null /* workSource */);
3789 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790 return response;
3791 } finally {
3792 Binder.restoreCallingIdentity(identity);
3793 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003794 }
3795
3796 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003797 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3799 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003800 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3801 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3802 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003803
Jordan Liu4c733742019-02-28 12:03:40 -08003804 @Override
3805 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3806 enforceModifyPermission();
3807 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3808 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3809 channel);
3810 }
3811
3812 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 final long identity = Binder.clearCallingIdentity();
3814 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003815 if (channel < 0) {
3816 return false;
3817 }
Jordan Liu4c733742019-02-28 12:03:40 -08003818 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3819 null /* workSource */);
3820 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821 return success;
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003824 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003825 }
3826
3827 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003828 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003829 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3831 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003832 if (DBG) {
3833 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3834 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3835 + p3 + " data=" + data);
3836 }
3837 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3838 command, p1, p2, p3, data);
3839 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003840
Jordan Liu4c733742019-02-28 12:03:40 -08003841 @Override
3842 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3843 int command, int p1, int p2, int p3, String data) {
3844 enforceModifyPermission();
3845 if (DBG) {
3846 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3847 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3848 + p3 + " data=" + data);
3849 }
3850 return iccTransmitApduLogicalChannelWithPermission(
3851 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3852 data);
3853 }
3854
3855 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3856 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003859 if (channel < 0) {
3860 return "";
3861 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003864 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3865 null /* workSource */);
3866 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003868 // Append the returned status code to the end of the response payload.
3869 String s = Integer.toHexString(
3870 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3871 if (response.payload != null) {
3872 s = IccUtils.bytesToHexString(response.payload) + s;
3873 }
3874 return s;
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003877 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003878 }
Jake Hambye994d462014-02-03 13:10:13 -08003879
Evan Charltonc66da362014-05-16 14:06:40 -07003880 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003881 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3882 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3884 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003885 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003886 if (DBG) {
3887 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3888 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3889 }
3890 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3891 cla, command, p1, p2, p3, data);
3892 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003893
Jordan Liu4c733742019-02-28 12:03:40 -08003894 @Override
3895 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3896 int command, int p1, int p2, int p3, String data) {
3897 enforceModifyPermission();
3898 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3899 if (DBG) {
3900 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3901 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3902 + " data=" + data);
3903 }
3904
3905 return iccTransmitApduBasicChannelWithPermission(
3906 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3907 p2, p3, data);
3908 }
3909
3910 // open APDU basic channel assuming the caller has sufficient permissions
3911 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3912 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3916 && TextUtils.equals(ISDR_AID, data)) {
3917 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003918 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3919 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920 if (bestComponent == null
3921 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3922 loge("The calling package is not allowed to select ISD-R.");
3923 throw new SecurityException(
3924 "The calling package is not allowed to select ISD-R.");
3925 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003926 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003929 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3930 null /* workSource */);
3931 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933 // Append the returned status code to the end of the response payload.
3934 String s = Integer.toHexString(
3935 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3936 if (response.payload != null) {
3937 s = IccUtils.bytesToHexString(response.payload) + s;
3938 }
3939 return s;
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003942 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003943 }
3944
3945 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003946 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003947 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3949 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003951 final long identity = Binder.clearCallingIdentity();
3952 try {
3953 if (DBG) {
3954 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3955 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3956 }
3957
3958 IccIoResult response =
3959 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3960 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3961 subId);
3962
3963 if (DBG) {
3964 log("Exchange SIM_IO [R]" + response);
3965 }
3966
3967 byte[] result = null;
3968 int length = 2;
3969 if (response.payload != null) {
3970 length = 2 + response.payload.length;
3971 result = new byte[length];
3972 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3973 } else {
3974 result = new byte[length];
3975 }
3976
3977 result[length - 1] = (byte) response.sw2;
3978 result[length - 2] = (byte) response.sw1;
3979 return result;
3980 } finally {
3981 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003982 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003983 }
3984
Nathan Haroldb3014052017-01-25 15:57:32 -08003985 /**
3986 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3987 * on a particular subscription
3988 */
sqianb6e41952018-03-12 14:54:01 -07003989 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3991 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3992 return null;
3993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994
3995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 if (appType != TelephonyManager.APPTYPE_USIM
3998 && appType != TelephonyManager.APPTYPE_SIM) {
3999 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4000 return null;
4001 }
4002 Object response = sendRequest(
4003 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4004 if (response instanceof String[]) {
4005 return (String[]) response;
4006 }
4007 // Response is an Exception of some kind,
4008 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004009 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010 } finally {
4011 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004012 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004013 }
4014
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004015 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004016 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4018 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4023 if (response.payload == null) {
4024 return "";
4025 }
Evan Charltonc66da362014-05-16 14:06:40 -07004026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027 // Append the returned status code to the end of the response payload.
4028 String s = Integer.toHexString(
4029 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4030 s = IccUtils.bytesToHexString(response.payload) + s;
4031 return s;
4032 } finally {
4033 Binder.restoreCallingIdentity(identity);
4034 }
Evan Charltonc66da362014-05-16 14:06:40 -07004035 }
4036
Jake Hambye994d462014-02-03 13:10:13 -08004037 /**
4038 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4039 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4040 *
4041 * @param itemID the ID of the item to read
4042 * @return the NV item as a String, or null on error.
4043 */
4044 @Override
4045 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004046 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4048 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049
4050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004053 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4055 return value;
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
Jake Hambye994d462014-02-03 13:10:13 -08004059 }
4060
4061 /**
4062 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4063 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4064 *
4065 * @param itemID the ID of the item to read
4066 * @param itemValue the value to write, as a String
4067 * @return true on success; false on any failure
4068 */
4069 @Override
4070 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004071 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4073 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004074
4075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4078 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004079 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4081 return success;
4082 } finally {
4083 Binder.restoreCallingIdentity(identity);
4084 }
Jake Hambye994d462014-02-03 13:10:13 -08004085 }
4086
4087 /**
4088 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4089 * Used for device configuration by some CDMA operators.
4090 *
4091 * @param preferredRoamingList byte array containing the new PRL
4092 * @return true on success; false on any failure
4093 */
4094 @Override
4095 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4097 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098
4099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4102 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4103 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4104 return success;
4105 } finally {
4106 Binder.restoreCallingIdentity(identity);
4107 }
Jake Hambye994d462014-02-03 13:10:13 -08004108 }
4109
4110 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004111 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004112 * Used for device configuration by some CDMA operators.
4113 *
chen xu6dac5ab2018-10-26 17:39:23 -07004114 * @param slotIndex - device slot.
4115 *
Jake Hambye994d462014-02-03 13:10:13 -08004116 * @return true on success; false on any failure
4117 */
4118 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004119 public boolean resetModemConfig(int slotIndex) {
4120 Phone phone = PhoneFactory.getPhone(slotIndex);
4121 if (phone != null) {
4122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4123 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124
chen xu6dac5ab2018-10-26 17:39:23 -07004125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4128 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4129 return success;
4130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004133 }
chen xu6dac5ab2018-10-26 17:39:23 -07004134 return false;
4135 }
4136
4137 /**
4138 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4139 *
4140 * @param slotIndex - device slot.
4141 *
4142 * @return true on success; false on any failure
4143 */
4144 @Override
4145 public boolean rebootModem(int slotIndex) {
4146 Phone phone = PhoneFactory.getPhone(slotIndex);
4147 if (phone != null) {
4148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4149 mApp, phone.getSubId(), "rebootModem");
4150
4151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4154 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4155 return success;
4156 } finally {
4157 Binder.restoreCallingIdentity(identity);
4158 }
4159 }
4160 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004161 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004162
Svet Ganovb320e182015-04-16 12:30:10 -07004163 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004164 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004166 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004167 return new String[0];
4168 }
4169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004170 final long identity = Binder.clearCallingIdentity();
4171 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004172 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004173 } finally {
4174 Binder.restoreCallingIdentity(identity);
4175 }
Wink Saville36469e72014-06-11 15:17:00 -07004176 }
4177
Brad Ebinger51f743a2017-01-23 13:50:20 -08004178 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004179 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4180 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004181 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004182 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004183 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184
4185 final long identity = Binder.clearCallingIdentity();
4186 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004187 ImsResolver resolver = PhoneFactory.getImsResolver();
4188 if (resolver == null) {
4189 // may happen if the device does not support IMS.
4190 return;
4191 }
4192 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193 } finally {
4194 Binder.restoreCallingIdentity(identity);
4195 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004196 }
4197
4198 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004199 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4200 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004201 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004202 public void disableIms(int slotId) {
4203 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004204
4205 final long identity = Binder.clearCallingIdentity();
4206 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004207 ImsResolver resolver = PhoneFactory.getImsResolver();
4208 if (resolver == null) {
4209 // may happen if the device does not support IMS.
4210 return;
4211 }
4212 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 } finally {
4214 Binder.restoreCallingIdentity(identity);
4215 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004216 }
4217
4218 /**
4219 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4220 * feature or {@link null} if the service is not available. If the feature is available, the
4221 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4222 */
4223 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004224 IImsServiceFeatureCallback callback) {
4225 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226
4227 final long identity = Binder.clearCallingIdentity();
4228 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004229 ImsResolver resolver = PhoneFactory.getImsResolver();
4230 if (resolver == null) {
4231 // may happen if the device does not support IMS.
4232 return null;
4233 }
4234 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004238 }
4239
4240 /**
4241 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4242 * feature during emergency calling or {@link null} if the service is not available. If the
4243 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4244 * listener for feature updates.
4245 */
4246 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4247 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248
4249 final long identity = Binder.clearCallingIdentity();
4250 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004251 ImsResolver resolver = PhoneFactory.getImsResolver();
4252 if (resolver == null) {
4253 // may happen if the device does not support IMS.
4254 return null;
4255 }
4256 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 } finally {
4258 Binder.restoreCallingIdentity(identity);
4259 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004260 }
4261
Brad Ebinger5f64b052017-12-14 14:26:15 -08004262 /**
4263 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004264 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004265 */
4266 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4267 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268
4269 final long identity = Binder.clearCallingIdentity();
4270 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004271 ImsResolver resolver = PhoneFactory.getImsResolver();
4272 if (resolver == null) {
4273 // may happen if the device does not support IMS.
4274 return null;
4275 }
4276 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277 } finally {
4278 Binder.restoreCallingIdentity(identity);
4279 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004280 }
4281
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004282 /**
4283 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004284 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004285 */
4286 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4287 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288
4289 final long identity = Binder.clearCallingIdentity();
4290 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004291 ImsResolver resolver = PhoneFactory.getImsResolver();
4292 if (resolver == null) {
4293 // may happen if the device does not support IMS.
4294 return null;
4295 }
4296 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297 } finally {
4298 Binder.restoreCallingIdentity(identity);
4299 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004300 }
4301
Brad Ebinger884c07b2018-02-15 16:17:40 -08004302 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004303 * Sets the ImsService Package Name that Telephony will bind to.
4304 *
4305 * @param slotId the slot ID that the ImsService should bind for.
4306 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4307 * ImsService is the device default ImsService.
4308 * @param packageName The package name of the application that contains the ImsService to bind
4309 * to.
4310 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4311 * @hide
4312 */
4313 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004314 int[] subIds = SubscriptionManager.getSubId(slotId);
4315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4316 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4317 "setImsService");
4318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004319 final long identity = Binder.clearCallingIdentity();
4320 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004321 ImsResolver resolver = PhoneFactory.getImsResolver();
4322 if (resolver == null) {
4323 // may happen if the device does not support IMS.
4324 return false;
4325 }
4326 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4327 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004331 }
4332
4333 /**
4334 * Return the ImsService configuration.
4335 *
4336 * @param slotId The slot that the ImsService is associated with.
4337 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4338 * the device default.
4339 * @return the package name of the ImsService configuration.
4340 */
4341 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004342 int[] subIds = SubscriptionManager.getSubId(slotId);
4343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4344 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4345 "getImsService");
4346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347 final long identity = Binder.clearCallingIdentity();
4348 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004349 ImsResolver resolver = PhoneFactory.getImsResolver();
4350 if (resolver == null) {
4351 // may happen if the device does not support IMS.
4352 return "";
4353 }
4354 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004358 }
4359
Wink Saville36469e72014-06-11 15:17:00 -07004360 public void setImsRegistrationState(boolean registered) {
4361 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004362
4363 final long identity = Binder.clearCallingIdentity();
4364 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004365 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 } finally {
4367 Binder.restoreCallingIdentity(identity);
4368 }
Wink Saville36469e72014-06-11 15:17:00 -07004369 }
4370
4371 /**
Stuart Scott54788802015-03-30 13:18:01 -07004372 * Set the network selection mode to automatic.
4373 *
4374 */
4375 @Override
4376 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4378 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004379
Pengquan Menge92a50d2018-09-21 15:54:48 -07004380 if (!isActiveSubscription(subId)) {
4381 return;
4382 }
4383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384 final long identity = Binder.clearCallingIdentity();
4385 try {
4386 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4387 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4388 } finally {
4389 Binder.restoreCallingIdentity(identity);
4390 }
Stuart Scott54788802015-03-30 13:18:01 -07004391 }
4392
Pengquan Mengea84e042018-09-20 14:57:26 -07004393 /**
4394 * Ask the radio to connect to the input network and change selection mode to manual.
4395 *
4396 * @param subId the id of the subscription.
4397 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4398 * the operator to attach to.
4399 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4400 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4401 * normal network selection next time.
4402 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004403 */
4404 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004405 public boolean setNetworkSelectionModeManual(
4406 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4408 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004409
4410 if (!isActiveSubscription(subId)) {
4411 return false;
4412 }
4413
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414 final long identity = Binder.clearCallingIdentity();
4415 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004416 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004417 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004418 if (DBG) {
4419 log("setNetworkSelectionModeManual: subId: " + subId
4420 + " operator: " + operatorInfo);
4421 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4423 } finally {
4424 Binder.restoreCallingIdentity(identity);
4425 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004426 }
4427
4428 /**
4429 * Scans for available networks.
4430 */
4431 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004432 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4434 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004435 LocationAccessPolicy.LocationPermissionResult locationResult =
4436 LocationAccessPolicy.checkLocationPermission(mApp,
4437 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4438 .setCallingPackage(callingPackage)
4439 .setCallingPid(Binder.getCallingPid())
4440 .setCallingUid(Binder.getCallingUid())
4441 .setMethod("getCellNetworkScanResults")
4442 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4443 .build());
4444 switch (locationResult) {
4445 case DENIED_HARD:
4446 throw new SecurityException("Not allowed to access scan results -- location");
4447 case DENIED_SOFT:
4448 return null;
4449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450
Pengquan Menga1bb6272018-09-06 09:59:22 -07004451 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 try {
4453 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004454 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004459 }
4460
4461 /**
yinxub1bed742017-04-17 11:45:04 -07004462 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004463 *
yinxub1bed742017-04-17 11:45:04 -07004464 * @param subId id of the subscription
4465 * @param request contains the radio access networks with bands/channels to scan
4466 * @param messenger callback messenger for scan results or errors
4467 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004468 * @return the id of the requested scan which can be used to stop the scan.
4469 */
4470 @Override
4471 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004472 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4474 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004475 LocationAccessPolicy.LocationPermissionResult locationResult =
4476 LocationAccessPolicy.checkLocationPermission(mApp,
4477 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4478 .setCallingPackage(callingPackage)
4479 .setCallingPid(Binder.getCallingPid())
4480 .setCallingUid(Binder.getCallingUid())
4481 .setMethod("requestNetworkScan")
4482 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4483 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004484 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4485 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4486 if (e != null) {
4487 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4488 throw e;
4489 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004490 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004491 return TelephonyScanManager.INVALID_SCAN_ID;
4492 }
4493 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494 }
Hall Liu912dfd32019-04-25 14:02:26 -07004495 int callingUid = Binder.getCallingUid();
4496 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004497 final long identity = Binder.clearCallingIdentity();
4498 try {
4499 return mNetworkScanRequestTracker.startNetworkScan(
4500 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004501 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004502 } finally {
4503 Binder.restoreCallingIdentity(identity);
4504 }
yinxu504e1392017-04-12 16:03:22 -07004505 }
4506
Hall Liub2ac8ef2019-02-28 15:56:23 -08004507 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4508 NetworkScanRequest request) {
4509 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4510 != PERMISSION_GRANTED) {
4511 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4512 + " without location access.");
4513 }
4514
4515 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4516 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004517 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4518 return new SecurityException("Specific channels must not be"
4519 + " scanned without location access.");
4520 }
4521 }
4522 }
4523
Hall Liub2ac8ef2019-02-28 15:56:23 -08004524 return null;
4525 }
4526
yinxu504e1392017-04-12 16:03:22 -07004527 /**
4528 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004529 *
4530 * @param subId id of the subscription
4531 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004532 */
4533 @Override
4534 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4536 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537
Hall Liu912dfd32019-04-25 14:02:26 -07004538 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539 final long identity = Binder.clearCallingIdentity();
4540 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004541 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004542 } finally {
4543 Binder.restoreCallingIdentity(identity);
4544 }
yinxu504e1392017-04-12 16:03:22 -07004545 }
4546
4547 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004548 * Get the calculated preferred network type.
4549 * Used for debugging incorrect network type.
4550 *
4551 * @return the preferred network type, defined in RILConstants.java.
4552 */
4553 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004554 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004555 final Phone defaultPhone = getDefaultPhone();
4556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4557 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004558 return RILConstants.PREFERRED_NETWORK_MODE;
4559 }
4560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 final long identity = Binder.clearCallingIdentity();
4562 try {
4563 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004564 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
Junda Liu84d15a22014-07-02 11:21:04 -07004568 }
4569
4570 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004571 * Get the preferred network type.
4572 * Used for device configuration by some CDMA operators.
4573 *
4574 * @return the preferred network type, defined in RILConstants.java.
4575 */
4576 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004577 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004578 TelephonyPermissions
4579 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4580 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581
4582 final long identity = Binder.clearCallingIdentity();
4583 try {
4584 if (DBG) log("getPreferredNetworkType");
4585 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4586 int networkType = (result != null ? result[0] : -1);
4587 if (DBG) log("getPreferredNetworkType: " + networkType);
4588 return networkType;
4589 } finally {
4590 Binder.restoreCallingIdentity(identity);
4591 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004592 }
4593
4594 /**
4595 * Set the preferred network type.
4596 * Used for device configuration by some CDMA operators.
4597 *
4598 * @param networkType the preferred network type, defined in RILConstants.java.
4599 * @return true on success; false on any failure.
4600 */
4601 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004602 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4604 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605
4606 final long identity = Binder.clearCallingIdentity();
4607 try {
4608 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4609 Boolean success = (Boolean) sendRequest(
4610 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4611 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4612 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004613 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4615 }
4616 return success;
4617 } finally {
4618 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004619 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004620 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004621
4622 /**
Miaoa84611c2019-03-15 09:21:10 +08004623 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004624 *
Miaoa84611c2019-03-15 09:21:10 +08004625 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004626 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004627 * @hide
4628 */
4629 @Override
Miaoa84611c2019-03-15 09:21:10 +08004630 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004631 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004633 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004634 try {
Miaoa84611c2019-03-15 09:21:10 +08004635 if (phone != null) {
4636 return phone.hasMatchedTetherApnSetting();
4637 } else {
4638 return false;
4639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 } finally {
4641 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004642 }
Junda Liu475951f2014-11-07 16:45:03 -08004643 }
4644
4645 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004646 * Set mobile data enabled
4647 * Used by the user through settings etc to turn on/off mobile data
4648 *
4649 * @param enable {@code true} turn turn data on, else {@code false}
4650 */
4651 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004652 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4654 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655
4656 final long identity = Binder.clearCallingIdentity();
4657 try {
4658 int phoneId = mSubscriptionController.getPhoneId(subId);
4659 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4660 Phone phone = PhoneFactory.getPhone(phoneId);
4661 if (phone != null) {
4662 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004663 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004665 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666 }
4667 } finally {
4668 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004669 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004670 }
4671
4672 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004673 * Get the user enabled state of Mobile Data.
4674 *
4675 * TODO: remove and use isUserDataEnabled.
4676 * This can't be removed now because some vendor codes
4677 * calls through ITelephony directly while they should
4678 * use TelephonyManager.
4679 *
4680 * @return true on enabled
4681 */
4682 @Override
4683 public boolean getDataEnabled(int subId) {
4684 return isUserDataEnabled(subId);
4685 }
4686
4687 /**
4688 * Get whether mobile data is enabled per user setting.
4689 *
4690 * There are other factors deciding whether mobile data is actually enabled, but they are
4691 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004692 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004693 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004694 *
4695 * @return {@code true} if data is enabled else {@code false}
4696 */
4697 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004698 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004699 try {
4700 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4701 null);
4702 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4704 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706
4707 final long identity = Binder.clearCallingIdentity();
4708 try {
4709 int phoneId = mSubscriptionController.getPhoneId(subId);
4710 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4711 Phone phone = PhoneFactory.getPhone(phoneId);
4712 if (phone != null) {
4713 boolean retVal = phone.isUserDataEnabled();
4714 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4715 return retVal;
4716 } else {
4717 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4718 return false;
4719 }
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004722 }
4723 }
4724
4725 /**
4726 * Get whether mobile data is enabled.
4727 *
4728 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4729 * whether mobile data is actually enabled.
4730 *
4731 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4732 *
4733 * @return {@code true} if data is enabled else {@code false}
4734 */
4735 @Override
4736 public boolean isDataEnabled(int subId) {
4737 try {
4738 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4739 null);
4740 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4742 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004743 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744
4745 final long identity = Binder.clearCallingIdentity();
4746 try {
4747 int phoneId = mSubscriptionController.getPhoneId(subId);
4748 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4749 Phone phone = PhoneFactory.getPhone(phoneId);
4750 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004751 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4753 return retVal;
4754 } else {
4755 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4756 return false;
4757 }
4758 } finally {
4759 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004760 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004761 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004762
4763 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004764 public int getCarrierPrivilegeStatus(int subId) {
4765 final Phone phone = getPhone(subId);
4766 if (phone == null) {
4767 loge("getCarrierPrivilegeStatus: Invalid subId");
4768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4769 }
4770 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004771 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004772 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004773 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4774 }
4775 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004776 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004777 }
Junda Liu29340342014-07-10 15:23:27 -07004778
4779 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004780 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4781 final Phone phone = getPhone(subId);
4782 if (phone == null) {
4783 loge("getCarrierPrivilegeStatus: Invalid subId");
4784 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4785 }
4786 UiccProfile profile =
4787 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4788 if (profile == null) {
4789 loge("getCarrierPrivilegeStatus: No UICC");
4790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4791 }
4792 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4793 }
4794
4795 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004796 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004797 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004798 if (TextUtils.isEmpty(pkgName))
4799 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004800 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004801 if (card == null) {
4802 loge("checkCarrierPrivilegesForPackage: No UICC");
4803 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4804 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004805 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4806 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004807 }
4808
4809 @Override
4810 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004811 if (TextUtils.isEmpty(pkgName))
4812 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004813 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4814 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4815 UiccCard card = UiccController.getInstance().getUiccCard(i);
4816 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004817 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004818 continue;
4819 }
4820
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004821 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004822 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4823 break;
4824 }
4825 }
4826
4827 return result;
Junda Liu29340342014-07-10 15:23:27 -07004828 }
Derek Tan89e89d42014-07-08 17:00:10 -07004829
4830 @Override
Junda Liue64de782015-04-16 17:19:16 -07004831 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4832 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4833 loge("phoneId " + phoneId + " is not valid.");
4834 return null;
4835 }
4836 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004837 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004838 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004839 return null ;
4840 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004841 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004842 }
4843
Amith Yamasani6e118872016-02-19 12:53:51 -08004844 @Override
4845 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004846 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004847 List<String> privilegedPackages = new ArrayList<>();
4848 List<PackageInfo> packages = null;
4849 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4850 UiccCard card = UiccController.getInstance().getUiccCard(i);
4851 if (card == null) {
4852 // No UICC in that slot.
4853 continue;
4854 }
4855 if (card.hasCarrierPrivilegeRules()) {
4856 if (packages == null) {
4857 // Only check packages in user 0 for now
4858 packages = pm.getInstalledPackagesAsUser(
4859 PackageManager.MATCH_DISABLED_COMPONENTS
4860 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4861 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4862 }
4863 for (int p = packages.size() - 1; p >= 0; p--) {
4864 PackageInfo pkgInfo = packages.get(p);
4865 if (pkgInfo != null && pkgInfo.packageName != null
4866 && card.getCarrierPrivilegeStatus(pkgInfo)
4867 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4868 privilegedPackages.add(pkgInfo.packageName);
4869 }
4870 }
4871 }
4872 }
4873 return privilegedPackages;
4874 }
4875
Wink Savilleb564aae2014-10-23 10:18:09 -07004876 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004877 final Phone phone = getPhone(subId);
4878 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004879 if (card == null) {
4880 loge("getIccId: No UICC");
4881 return null;
4882 }
4883 String iccId = card.getIccId();
4884 if (TextUtils.isEmpty(iccId)) {
4885 loge("getIccId: ICC ID is null or empty.");
4886 return null;
4887 }
4888 return iccId;
4889 }
4890
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004891 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004892 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4893 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004894 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4895 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 final long identity = Binder.clearCallingIdentity();
4898 try {
4899 final String iccId = getIccId(subId);
4900 final Phone phone = getPhone(subId);
4901 if (phone == null) {
4902 return false;
4903 }
4904 final String subscriberId = phone.getSubscriberId();
4905
4906 if (DBG_MERGE) {
4907 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4908 + subscriberId + " to " + number);
4909 }
4910
4911 if (TextUtils.isEmpty(iccId)) {
4912 return false;
4913 }
4914
4915 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4916
4917 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4918 if (alphaTag == null) {
4919 editor.remove(alphaTagPrefKey);
4920 } else {
4921 editor.putString(alphaTagPrefKey, alphaTag);
4922 }
4923
4924 // Record both the line number and IMSI for this ICCID, since we need to
4925 // track all merged IMSIs based on line number
4926 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4927 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4928 if (number == null) {
4929 editor.remove(numberPrefKey);
4930 editor.remove(subscriberPrefKey);
4931 } else {
4932 editor.putString(numberPrefKey, number);
4933 editor.putString(subscriberPrefKey, subscriberId);
4934 }
4935
4936 editor.commit();
4937 return true;
4938 } finally {
4939 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004940 }
Derek Tan7226c842014-07-02 17:42:23 -07004941 }
4942
4943 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004944 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004945 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004947 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004948 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004949 return null;
4950 }
Derek Tan97ebb422014-09-05 16:55:38 -07004951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 final long identity = Binder.clearCallingIdentity();
4953 try {
4954 String iccId = getIccId(subId);
4955 if (iccId != null) {
4956 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4957 if (DBG_MERGE) {
4958 log("getLine1NumberForDisplay returning "
4959 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4960 }
4961 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4964 return null;
4965 } finally {
4966 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004967 }
Derek Tan7226c842014-07-02 17:42:23 -07004968 }
4969
4970 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004971 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004973 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004974 return null;
4975 }
Derek Tan97ebb422014-09-05 16:55:38 -07004976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977 final long identity = Binder.clearCallingIdentity();
4978 try {
4979 String iccId = getIccId(subId);
4980 if (iccId != null) {
4981 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4982 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4983 }
4984 return null;
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004987 }
Derek Tan7226c842014-07-02 17:42:23 -07004988 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004989
4990 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07004991 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004992 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4993 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004995 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4996 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004997 return null;
4998 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004999
Jordan Liub49b04b2019-05-06 14:45:15 -07005000 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5001 // the process, where TelephonyManager was instantiated.
5002 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005003 final long identity = Binder.clearCallingIdentity();
5004 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005005 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 final TelephonyManager tele = TelephonyManager.from(context);
5007 final SubscriptionManager sub = SubscriptionManager.from(context);
5008
5009 // Figure out what subscribers are currently active
5010 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011
Jordan Liub49b04b2019-05-06 14:45:15 -07005012 // Only consider subs which match the current subId
5013 // This logic can be simplified. See b/131189269 for progress.
5014 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005015 activeSubscriberIds.add(tele.getSubscriberId(subId));
5016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017
5018 // First pass, find a number override for an active subscriber
5019 String mergeNumber = null;
5020 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5021 for (String key : prefs.keySet()) {
5022 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5023 final String subscriberId = (String) prefs.get(key);
5024 if (activeSubscriberIds.contains(subscriberId)) {
5025 final String iccId = key.substring(
5026 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5027 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5028 mergeNumber = (String) prefs.get(numberKey);
5029 if (DBG_MERGE) {
5030 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5031 + " for active subscriber " + subscriberId);
5032 }
5033 if (!TextUtils.isEmpty(mergeNumber)) {
5034 break;
5035 }
5036 }
5037 }
5038 }
5039
5040 // Shortcut when no active merged subscribers
5041 if (TextUtils.isEmpty(mergeNumber)) {
5042 return null;
5043 }
5044
5045 // Second pass, find all subscribers under that line override
5046 final ArraySet<String> result = new ArraySet<>();
5047 for (String key : prefs.keySet()) {
5048 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5049 final String number = (String) prefs.get(key);
5050 if (mergeNumber.equals(number)) {
5051 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5052 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5053 final String subscriberId = (String) prefs.get(subscriberKey);
5054 if (!TextUtils.isEmpty(subscriberId)) {
5055 result.add(subscriberId);
5056 }
5057 }
5058 }
5059 }
5060
5061 final String[] resultArray = result.toArray(new String[result.size()]);
5062 Arrays.sort(resultArray);
5063 if (DBG_MERGE) {
5064 Slog.d(LOG_TAG,
5065 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5066 }
5067 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005068 } finally {
5069 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005070 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005071 }
5072
5073 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005074 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005075 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5076 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077
5078 final long identity = Binder.clearCallingIdentity();
5079 try {
5080 final Phone phone = getPhone(subId);
5081 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5082 } finally {
5083 Binder.restoreCallingIdentity(identity);
5084 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005085 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005086
5087 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005088 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005089 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5090 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005091 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092
5093 final long identity = Binder.clearCallingIdentity();
5094 try {
5095 final Phone phone = getPhone(subId);
5096 if (phone == null) {
5097 return false;
5098 }
5099 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5100 cdmaNonRoamingList);
5101 } finally {
5102 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005103 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005104 }
5105
5106 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005107 @Deprecated
5108 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5109 enforceModifyPermission();
5110
5111 int returnValue = 0;
5112 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005113 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005114 if(result.exception == null) {
5115 if (result.result != null) {
5116 byte[] responseData = (byte[])(result.result);
5117 if(responseData.length > oemResp.length) {
5118 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5119 responseData.length + "bytes. Buffer Size is " +
5120 oemResp.length + "bytes.");
5121 }
5122 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5123 returnValue = responseData.length;
5124 }
5125 } else {
5126 CommandException ex = (CommandException) result.exception;
5127 returnValue = ex.getCommandError().ordinal();
5128 if(returnValue > 0) returnValue *= -1;
5129 }
5130 } catch (RuntimeException e) {
5131 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5132 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5133 if(returnValue > 0) returnValue *= -1;
5134 }
5135
5136 return returnValue;
5137 }
5138
5139 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005140 public void setRadioCapability(RadioAccessFamily[] rafs) {
5141 try {
5142 ProxyController.getInstance().setRadioCapability(rafs);
5143 } catch (RuntimeException e) {
5144 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5145 }
5146 }
5147
5148 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005149 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005150 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005151 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005152 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005153 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155 final long identity = Binder.clearCallingIdentity();
5156 try {
chen xub97461a2018-10-26 14:17:57 -07005157 TelephonyPermissions
5158 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5159 mApp, phone.getSubId(), "getRadioAccessFamily");
5160 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 } finally {
5162 Binder.restoreCallingIdentity(identity);
5163 }
chen xub97461a2018-10-26 14:17:57 -07005164 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005165 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005166
5167 @Override
5168 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005169 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171
5172 final long identity = Binder.clearCallingIdentity();
5173 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005174 ImsManager.getInstance(defaultPhone.getContext(),
5175 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005179 }
5180
5181 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005182 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005183 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005185 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005186 return false;
5187 }
Svet Ganovb320e182015-04-16 12:30:10 -07005188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 final long identity = Binder.clearCallingIdentity();
5190 try {
5191 // Check the user preference and the system-level IMS setting. Even if the user has
5192 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5193 // In the long run, we may instead need to check if there exists a connection service
5194 // which can support video calling.
5195 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005196 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 return imsManager.isVtEnabledByPlatform()
5198 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5199 && imsManager.isVtEnabledByUser();
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005203 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005204
Andrew Leea1239f22015-03-02 17:44:07 -08005205 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5208 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5209 return false;
5210 }
5211
5212 final long identity = Binder.clearCallingIdentity();
5213 try {
5214 CarrierConfigManager configManager =
5215 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005216 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Andrew Leea1239f22015-03-02 17:44:07 -08005221 }
5222
5223 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 public boolean isWorldPhone(int subId, String callingPackage) {
5225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5226 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5227 return false;
5228 }
5229
5230 final long identity = Binder.clearCallingIdentity();
5231 try {
5232 CarrierConfigManager configManager =
5233 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005234 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
Andrew Leea1239f22015-03-02 17:44:07 -08005239 }
5240
Andrew Lee9431b832015-03-09 18:46:45 -07005241 @Override
5242 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005243 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005244 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005245 }
5246
5247 @Override
5248 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 final long identity = Binder.clearCallingIdentity();
5250 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005251 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
Andrew Lee9431b832015-03-09 18:46:45 -07005255 }
5256
Hall Liuf6668912018-10-31 17:05:23 -07005257 /**
5258 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5259 * support for the feature and device firmware support.
5260 *
5261 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5262 */
5263 @Override
5264 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005266 final Phone phone = getPhone(subscriptionId);
5267 if (phone == null) {
5268 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5269 return false;
5270 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005272 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5274 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005275 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 return isCarrierSupported && isDeviceSupported;
5277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
Hall Liu98187582018-01-22 19:15:32 -08005280 }
5281
Hall Liuf6668912018-10-31 17:05:23 -07005282 /**
5283 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5284 * both also support RTT.
5285 */
5286 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 final long identity = Binder.clearCallingIdentity();
5288 try {
Hall Liuf6668912018-10-31 17:05:23 -07005289 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005290 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005294 }
5295
Sanket Padawe7310cc72015-01-14 09:53:20 -08005296 /**
5297 * Returns the unique device ID of phone, for example, the IMEI for
5298 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5299 *
5300 * <p>Requires Permission:
5301 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5302 */
5303 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005304 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005305 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005306 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005307 return null;
5308 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005309 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005310 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5311 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005312 return null;
5313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005314
5315 final long identity = Binder.clearCallingIdentity();
5316 try {
5317 return phone.getDeviceId();
5318 } finally {
5319 Binder.restoreCallingIdentity(identity);
5320 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005321 }
5322
Ping Sunc67b7c22016-03-02 19:16:45 +08005323 /**
5324 * {@hide}
5325 * Returns the IMS Registration Status on a particular subid
5326 *
5327 * @param subId
5328 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005329 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005330 Phone phone = getPhone(subId);
5331 if (phone != null) {
5332 return phone.isImsRegistered();
5333 } else {
5334 return false;
5335 }
5336 }
5337
Santos Cordon7a1885b2015-02-03 11:15:19 -08005338 @Override
5339 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5343 } finally {
5344 Binder.restoreCallingIdentity(identity);
5345 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005346 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005347
Tyler Gunnf70ed162019-04-03 15:28:53 -07005348 @Override
5349 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5350 final long identity = Binder.clearCallingIdentity();
5351 try {
5352 Phone phone = getPhone(subscriptionId);
5353 if (phone == null) {
5354 return null;
5355 }
5356 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5357 } finally {
5358 Binder.restoreCallingIdentity(identity);
5359 }
5360 }
5361
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005362 /**
5363 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005364 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005365 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 final long identity = Binder.clearCallingIdentity();
5367 try {
5368 Phone phone = getPhone(subId);
5369 if (phone != null) {
5370 return phone.isWifiCallingEnabled();
5371 } else {
5372 return false;
5373 }
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005376 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005377 }
5378
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005379 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005380 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005381 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005382 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 final long identity = Binder.clearCallingIdentity();
5384 try {
5385 Phone phone = getPhone(subId);
5386 if (phone != null) {
5387 return phone.isVideoEnabled();
5388 } else {
5389 return false;
5390 }
5391 } finally {
5392 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005393 }
5394 }
5395
5396 /**
5397 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5398 * defined in {@link ImsRegistrationImplBase}.
5399 */
5400 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 final long identity = Binder.clearCallingIdentity();
5402 try {
5403 Phone phone = getPhone(subId);
5404 if (phone != null) {
5405 return phone.getImsRegistrationTech();
5406 } else {
5407 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5408 }
5409 } finally {
5410 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005411 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005412 }
5413
Stuart Scott8eef64f2015-04-08 15:13:54 -07005414 @Override
5415 public void factoryReset(int subId) {
5416 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005417 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5418 return;
5419 }
5420
Svet Ganovcc087f82015-05-12 20:35:54 -07005421 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005422
Svet Ganovcc087f82015-05-12 20:35:54 -07005423 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005424 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5425 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005426 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005427 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005428 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005429 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5430 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005431 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005432 // There has been issues when Sms raw table somehow stores orphan
5433 // fragments. They lead to garbled message when new fragments come
5434 // in and combined with those stale ones. In case this happens again,
5435 // user can reset all network settings which will clean up this table.
5436 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005437 } finally {
5438 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005439 }
5440 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005441
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005442 private void cleanUpSmsRawTable(Context context) {
5443 ContentResolver resolver = context.getContentResolver();
5444 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5445 resolver.delete(uri, null, null);
5446 }
5447
Narayan Kamath1c496c22015-04-16 14:40:19 +01005448 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005449 public String getSimLocaleForSubscriber(int subId) {
5450 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5451 final Phone phone = getPhone(subId);
5452 if (phone == null) {
5453 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005454 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456 final long identity = Binder.clearCallingIdentity();
5457 try {
chen xu5d3637b2019-01-21 23:31:38 -08005458 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5459 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005460 if (info == null) {
5461 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5462 return null;
5463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 // Try and fetch the locale from the carrier properties or from the SIM language
5465 // preferences (EF-PL and EF-LI)...
5466 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005468 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5469 if (localeFromDefaultSim != null) {
5470 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5471 if (DBG) log("Using locale from subId: " + subId + " locale: "
5472 + localeFromDefaultSim);
5473 return localeFromDefaultSim.toLanguageTag();
5474 } else {
5475 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 }
5477 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 // The SIM language preferences only store a language (e.g. fr = French), not an
5480 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5481 // the SIM and carrier preferences does not include a country we add the country
5482 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005483 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005485 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 return mccLocale.toLanguageTag();
5487 }
5488
5489 if (DBG) log("No locale found - returning null");
5490 return null;
5491 } finally {
5492 Binder.restoreCallingIdentity(identity);
5493 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005494 }
5495
5496 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005497 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005498 }
5499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 /**
5501 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5502 */
5503 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005504 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005505 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005506
Chenjie Yu1ba97252018-01-11 18:16:20 -08005507 private final ModemActivityInfo mLastModemActivityInfo =
5508 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5509
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005510 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005511 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5512 * representing the state of the modem.
5513 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005514 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5515 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005516 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005517 */
5518 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005519 public void requestModemActivityInfo(ResultReceiver result) {
5520 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005521 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522
5523 final long identity = Binder.clearCallingIdentity();
5524 try {
5525 ModemActivityInfo ret = null;
5526 synchronized (mLastModemActivityInfo) {
5527 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5528 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005529 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005530 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5532 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005533 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5534 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005535 }
5536 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005537 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5538 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 mLastModemActivityInfo.setIdleTimeMillis(
5540 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5541 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5542 mLastModemActivityInfo.setRxTimeMillis(
5543 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5544 mLastModemActivityInfo.setEnergyUsed(
5545 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5548 mLastModemActivityInfo.getSleepTimeMillis(),
5549 mLastModemActivityInfo.getIdleTimeMillis(),
5550 mLastModemActivityInfo.getTxTimeMillis(),
5551 mLastModemActivityInfo.getRxTimeMillis(),
5552 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 Bundle bundle = new Bundle();
5555 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5556 result.send(0, bundle);
5557 } finally {
5558 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005559 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005560 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005561
Siddharth Rayb8114062018-06-17 15:02:38 -07005562 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5563 // less than total activity duration.
5564 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5565 if (info == null) {
5566 return false;
5567 }
5568 int activityDurationMs =
5569 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5570 int totalTxTimeMs = 0;
5571 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5572 totalTxTimeMs += info.getTxTimeMillis()[i];
5573 }
5574 return (info.isValid()
5575 && (info.getSleepTimeMillis() <= activityDurationMs)
5576 && (info.getIdleTimeMillis() <= activityDurationMs)
5577 && (info.getRxTimeMillis() <= activityDurationMs)
5578 && (totalTxTimeMs <= activityDurationMs));
5579 }
5580
Jack Yu85bd38a2015-11-09 11:34:32 -08005581 /**
5582 * {@hide}
5583 * Returns the service state information on specified subscription.
5584 */
5585 @Override
5586 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005588 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005589 return null;
5590 }
5591
Hall Liuf19c44f2018-11-27 14:38:17 -08005592 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5593 LocationAccessPolicy.checkLocationPermission(mApp,
5594 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5595 .setCallingPackage(callingPackage)
5596 .setCallingPid(Binder.getCallingPid())
5597 .setCallingUid(Binder.getCallingUid())
5598 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005599 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005600 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5601 .build());
5602
5603 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5604 LocationAccessPolicy.checkLocationPermission(mApp,
5605 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5606 .setCallingPackage(callingPackage)
5607 .setCallingPid(Binder.getCallingPid())
5608 .setCallingUid(Binder.getCallingUid())
5609 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005610 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005611 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5612 .build());
5613 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5614 boolean hasFinePermission =
5615 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5616 boolean hasCoarsePermission =
5617 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 final Phone phone = getPhone(subId);
5622 if (phone == null) {
5623 return null;
5624 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005625
Hall Liuf19c44f2018-11-27 14:38:17 -08005626 ServiceState ss = phone.getServiceState();
5627
5628 // Scrub out the location info in ServiceState depending on what level of access
5629 // the caller has.
5630 if (hasFinePermission) return ss;
5631 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5632 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 } finally {
5634 Binder.restoreCallingIdentity(identity);
5635 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005636 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005637
5638 /**
5639 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5640 *
5641 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5642 * voicemail ringtone.
5643 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5644 * PhoneAccount.
5645 */
5646 @Override
5647 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 final long identity = Binder.clearCallingIdentity();
5649 try {
5650 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5651 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005652 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5656 } finally {
5657 Binder.restoreCallingIdentity(identity);
5658 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005659 }
5660
5661 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005662 * Sets the per-account voicemail ringtone.
5663 *
5664 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5665 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5666 *
5667 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5668 * voicemail ringtone.
5669 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5670 * PhoneAccount.
5671 */
5672 @Override
5673 public void setVoicemailRingtoneUri(String callingPackage,
5674 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005675 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5677 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005678 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5680 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5681 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683
5684 final long identity = Binder.clearCallingIdentity();
5685 try {
5686 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5687 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005688 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689 }
5690 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005693 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005694 }
5695
5696 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005697 * Returns whether vibration is set for voicemail notification in Phone settings.
5698 *
5699 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5700 * voicemail vibration setting.
5701 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5702 */
5703 @Override
5704 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 final long identity = Binder.clearCallingIdentity();
5706 try {
5707 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5708 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005709 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5713 } finally {
5714 Binder.restoreCallingIdentity(identity);
5715 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005716 }
5717
Youhan Wange64578a2016-05-02 15:32:42 -07005718 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005719 * Sets the per-account voicemail vibration.
5720 *
5721 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5722 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5723 *
5724 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5725 * voicemail vibration setting.
5726 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5727 * specific PhoneAccount.
5728 */
5729 @Override
5730 public void setVoicemailVibrationEnabled(String callingPackage,
5731 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005732 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5734 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005735 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5737 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5738 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005739 }
5740
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 final long identity = Binder.clearCallingIdentity();
5742 try {
5743 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5744 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005745 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 }
5747 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005750 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005751 }
5752
5753 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005754 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5755 *
5756 * @throws SecurityException if the caller does not have the required permission
5757 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005758 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005759 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005760 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005761 }
5762
5763 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005764 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5765 * permission.
5766 *
5767 * @throws SecurityException if the caller does not have the required permission
5768 */
5769 private void enforceSendSmsPermission() {
5770 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5771 }
5772
5773 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005774 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005775 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005776 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005777 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005778 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779 final long identity = Binder.clearCallingIdentity();
5780 try {
5781 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005782 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783 if (componentName == null) {
5784 throw new SecurityException(
5785 "Caller not current active visual voicemail package[null]");
5786 }
5787 String vvmPackage = componentName.getPackageName();
5788 if (!callingPackage.equals(vvmPackage)) {
5789 throw new SecurityException("Caller not current active visual voicemail package["
5790 + vvmPackage + "]");
5791 }
5792 } finally {
5793 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005794 }
5795 }
5796
5797 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005798 * Return the application ID for the app type.
5799 *
5800 * @param subId the subscription ID that this request applies to.
5801 * @param appType the uicc app type.
5802 * @return Application ID for specificied app type, or null if no uicc.
5803 */
5804 @Override
5805 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005806 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005807 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808
5809 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005810 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005811 if (phone == null) {
5812 return null;
5813 }
5814 String aid = null;
5815 try {
5816 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5817 .getApplicationByType(appType).getAid();
5818 } catch (Exception e) {
5819 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5820 }
5821 return aid;
5822 } finally {
5823 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005824 }
Youhan Wange64578a2016-05-02 15:32:42 -07005825 }
5826
Youhan Wang4001d252016-05-11 10:29:41 -07005827 /**
5828 * Return the Electronic Serial Number.
5829 *
5830 * @param subId the subscription ID that this request applies to.
5831 * @return ESN or null if error.
5832 */
5833 @Override
5834 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005835 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005836 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837
5838 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005839 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840 if (phone == null) {
5841 return null;
5842 }
5843 String esn = null;
5844 try {
5845 esn = phone.getEsn();
5846 } catch (Exception e) {
5847 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5848 }
5849 return esn;
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005852 }
Youhan Wang4001d252016-05-11 10:29:41 -07005853 }
5854
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005855 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005856 * Return the Preferred Roaming List Version.
5857 *
5858 * @param subId the subscription ID that this request applies to.
5859 * @return PRLVersion or null if error.
5860 */
5861 @Override
5862 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005863 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005864 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865
5866 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005867 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 if (phone == null) {
5869 return null;
5870 }
5871 String cdmaPrlVersion = null;
5872 try {
5873 cdmaPrlVersion = phone.getCdmaPrlVersion();
5874 } catch (Exception e) {
5875 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5876 }
5877 return cdmaPrlVersion;
5878 } finally {
5879 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005880 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005881 }
5882
5883 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005884 * Get snapshot of Telephony histograms
5885 * @return List of Telephony histograms
5886 * @hide
5887 */
5888 @Override
5889 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5891 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892
5893 final long identity = Binder.clearCallingIdentity();
5894 try {
5895 return RIL.getTelephonyRILTimingHistograms();
5896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005899 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005900
5901 /**
5902 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005903 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5904 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005905 * Require system privileges. In the future we may add this to carrier APIs.
5906 *
Michele Berionne482f8202018-11-27 18:57:59 -08005907 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005908 */
5909 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005910 @TelephonyManager.SetCarrierRestrictionResult
5911 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005912 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005913 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005914
Michele Berionne482f8202018-11-27 18:57:59 -08005915 if (carrierRestrictionRules == null) {
5916 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005917 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005918
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 final long identity = Binder.clearCallingIdentity();
5920 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005921 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005922 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923 } finally {
5924 Binder.restoreCallingIdentity(identity);
5925 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005926 }
5927
5928 /**
5929 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005930 * Get the allowed carrier list and the excluded carrier list, including the priority between
5931 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005932 * Require system privileges. In the future we may add this to carrier APIs.
5933 *
Michele Berionne482f8202018-11-27 18:57:59 -08005934 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005935 */
5936 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005937 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005938 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005939 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940
5941 final long identity = Binder.clearCallingIdentity();
5942 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005943 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5944 if (response instanceof CarrierRestrictionRules) {
5945 return (CarrierRestrictionRules) response;
5946 }
5947 // Response is an Exception of some kind,
5948 // which is signalled to the user as a NULL retval
5949 return null;
5950 } catch (Exception e) {
5951 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5952 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 } finally {
5954 Binder.restoreCallingIdentity(identity);
5955 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005956 }
5957
fionaxu59545b42016-05-25 15:53:37 -07005958 /**
5959 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5960 * @param subId the subscription ID that this action applies to.
5961 * @param enabled control enable or disable metered apns.
5962 * {@hide}
5963 */
5964 @Override
5965 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5966 enforceModifyPermission();
5967 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968
5969 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005970 if (phone == null) {
5971 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5972 return;
5973 }
5974 try {
5975 phone.carrierActionSetMeteredApnsEnabled(enabled);
5976 } catch (Exception e) {
5977 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 } finally {
5979 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005980 }
5981 }
5982
5983 /**
5984 * Action set from carrier signalling broadcast receivers to enable/disable radio
5985 * @param subId the subscription ID that this action applies to.
5986 * @param enabled control enable or disable radio.
5987 * {@hide}
5988 */
5989 @Override
5990 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5991 enforceModifyPermission();
5992 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993
5994 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005995 if (phone == null) {
5996 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5997 return;
5998 }
5999 try {
6000 phone.carrierActionSetRadioEnabled(enabled);
6001 } catch (Exception e) {
6002 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 } finally {
6004 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006005 }
6006 }
6007
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006008 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006009 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6010 * network status based on which carrier apps could apply actions accordingly,
6011 * enable/disable default url handler for example.
6012 *
6013 * @param subId the subscription ID that this action applies to.
6014 * @param report control start/stop reporting the default network status.
6015 * {@hide}
6016 */
6017 @Override
6018 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6019 enforceModifyPermission();
6020 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021
6022 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006023 if (phone == null) {
6024 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6025 return;
6026 }
6027 try {
6028 phone.carrierActionReportDefaultNetworkStatus(report);
6029 } catch (Exception e) {
6030 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 } finally {
6032 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006033 }
6034 }
6035
6036 /**
fionaxud9622282017-07-17 17:51:30 -07006037 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6038 * @param subId the subscription ID that this action applies to.
6039 * {@hide}
6040 */
6041 @Override
6042 public void carrierActionResetAll(int subId) {
6043 enforceModifyPermission();
6044 final Phone phone = getPhone(subId);
6045 if (phone == null) {
6046 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6047 return;
6048 }
6049 try {
6050 phone.carrierActionResetAll();
6051 } catch (Exception e) {
6052 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6053 }
6054 }
6055
6056 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006057 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6058 * bug report is being generated.
6059 */
6060 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006061 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006062 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6063 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006064 writer.println("Permission Denial: can't dump Phone from pid="
6065 + Binder.getCallingPid()
6066 + ", uid=" + Binder.getCallingUid()
6067 + "without permission "
6068 + android.Manifest.permission.DUMP);
6069 return;
6070 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006071 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006072 }
Jack Yueb89b242016-06-22 13:27:47 -07006073
Brad Ebingerdac2f002018-04-03 15:17:52 -07006074 @Override
6075 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6076 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6077 throws RemoteException {
6078 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6079 }
6080
Jack Yueb89b242016-06-22 13:27:47 -07006081 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006082 * Get aggregated video call data usage since boot.
6083 *
6084 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6085 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006086 * {@hide}
6087 */
6088 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006089 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006090 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6091 null);
6092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 final long identity = Binder.clearCallingIdentity();
6094 try {
6095 // NetworkStatsService keeps tracking the active network interface and identity. It
6096 // records the delta with the corresponding network identity.
6097 // We just return the total video call data usage snapshot since boot.
6098 Phone phone = getPhone(subId);
6099 if (phone != null) {
6100 return phone.getVtDataUsage(perUidStats);
6101 }
6102 return null;
6103 } finally {
6104 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006105 }
Jack Yueb89b242016-06-22 13:27:47 -07006106 }
Jack Yu75ab2952016-07-08 14:29:33 -07006107
6108 /**
6109 * Policy control of data connection. Usually used when data limit is passed.
6110 * @param enabled True if enabling the data, otherwise disabling.
6111 * @param subId Subscription index
6112 * {@hide}
6113 */
6114 @Override
6115 public void setPolicyDataEnabled(boolean enabled, int subId) {
6116 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117
6118 final long identity = Binder.clearCallingIdentity();
6119 try {
6120 Phone phone = getPhone(subId);
6121 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006122 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 }
6124 } finally {
6125 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006126 }
6127 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006128
6129 /**
6130 * Get Client request stats
6131 * @return List of Client Request Stats
6132 * @hide
6133 */
6134 @Override
6135 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006137 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006138 return null;
6139 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006140 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 final long identity = Binder.clearCallingIdentity();
6143 try {
6144 if (phone != null) {
6145 return phone.getClientRequestStats();
6146 }
6147
6148 return null;
6149 } finally {
6150 Binder.restoreCallingIdentity(identity);
6151 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006152 }
6153
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006154 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006155 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006156 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006157 }
Jack Yueb4124c2017-02-16 15:32:43 -08006158
6159 /**
Grace Chen70990072017-03-24 17:21:30 -07006160 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006161 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006162 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006163 * @param state State of SIM (power down, power up, pass through)
6164 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6165 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6166 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006167 *
6168 **/
6169 @Override
Grace Chen70990072017-03-24 17:21:30 -07006170 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006171 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006172 Phone phone = PhoneFactory.getPhone(slotIndex);
6173
vagdeviaf9a5b92018-08-15 16:01:53 -07006174 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 final long identity = Binder.clearCallingIdentity();
6177 try {
6178 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006179 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180 }
6181 } finally {
6182 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006183 }
6184 }
Shuo Qiandd210312017-04-12 22:11:33 +00006185
Tyler Gunn65d45c22017-06-05 11:22:26 -07006186 private boolean isUssdApiAllowed(int subId) {
6187 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006188 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006189 if (configManager == null) {
6190 return false;
6191 }
6192 PersistableBundle pb = configManager.getConfigForSubId(subId);
6193 if (pb == null) {
6194 return false;
6195 }
6196 return pb.getBoolean(
6197 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6198 }
6199
Shuo Qiandd210312017-04-12 22:11:33 +00006200 /**
6201 * Check if phone is in emergency callback mode
6202 * @return true if phone is in emergency callback mode
6203 * @param subId sub id
6204 */
goneil9c5f4872017-12-05 14:07:56 -08006205 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006206 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006207 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006208 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209
6210 final long identity = Binder.clearCallingIdentity();
6211 try {
6212 if (phone != null) {
6213 return phone.isInEcm();
6214 } else {
6215 return false;
6216 }
6217 } finally {
6218 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006219 }
6220 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006221
6222 /**
6223 * Get the current signal strength information for the given subscription.
6224 * Because this information is not updated when the device is in a low power state
6225 * it should not be relied-upon to be current.
6226 * @param subId Subscription index
6227 * @return the most recent cached signal strength info from the modem
6228 */
6229 @Override
6230 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231 final long identity = Binder.clearCallingIdentity();
6232 try {
6233 Phone p = getPhone(subId);
6234 if (p == null) {
6235 return null;
6236 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 return p.getSignalStrength();
6239 } finally {
6240 Binder.restoreCallingIdentity(identity);
6241 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006242 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006243
Pengquan Meng77b7f132018-08-22 14:49:57 -07006244 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006245 * Get the current modem radio state for the given slot.
6246 * @param slotIndex slot index.
6247 * @param callingPackage the name of the package making the call.
6248 * @return the current radio power state from the modem
6249 */
6250 @Override
6251 public int getRadioPowerState(int slotIndex, String callingPackage) {
6252 Phone phone = PhoneFactory.getPhone(slotIndex);
6253 if (phone != null) {
6254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6255 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6256 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6257 }
6258
6259 final long identity = Binder.clearCallingIdentity();
6260 try {
6261 return phone.getRadioPowerState();
6262 } finally {
6263 Binder.restoreCallingIdentity(identity);
6264 }
6265 }
6266 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6267 }
6268
6269 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006270 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6271 *
6272 * <p>Requires one of the following permissions:
6273 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6274 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6275 * privileges.
6276 *
6277 * @param subId subscription id
6278 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6279 * {@code false}.
6280 */
6281 @Override
6282 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006283 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6284 null /* message */);
6285
Pengquan Menga1bb6272018-09-06 09:59:22 -07006286 boolean isEnabled = false;
6287 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006288 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006289 Phone phone = getPhone(subId);
6290 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006291 } catch (Exception e) {
6292 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6293 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006294 } finally {
6295 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006296 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006297 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006298 }
6299
6300
6301 /**
6302 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6303 *
6304 * <p> Requires permission:
6305 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6306 * privileges.
6307 *
6308 * @param subId subscription id
6309 * @param isEnabled {@code true} means enable, {@code false} means disable.
6310 */
6311 @Override
6312 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6314 mApp, subId, "setDataRoamingEnabled");
6315
Pengquan Menga1bb6272018-09-06 09:59:22 -07006316 final long identity = Binder.clearCallingIdentity();
6317 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006318 Phone phone = getPhone(subId);
6319 if (phone != null) {
6320 phone.setDataRoamingEnabled(isEnabled);
6321 }
6322 } finally {
6323 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006324 }
6325 }
6326
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006327 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006328 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006329 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6330 mApp, subId, "isManualNetworkSelectionAllowed");
6331
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006332 boolean isAllowed = true;
6333 final long identity = Binder.clearCallingIdentity();
6334 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006335 Phone phone = getPhone(subId);
6336 if (phone != null) {
6337 isAllowed = phone.isCspPlmnEnabled();
6338 }
6339 } finally {
6340 Binder.restoreCallingIdentity(identity);
6341 }
6342 return isAllowed;
6343 }
6344
6345 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006346 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006347 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006348 try {
6349 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006350 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006351 } catch (SecurityException e) {
6352 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6353 // has carrier privileges on an active UICC
6354 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6355 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006356 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006357 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006358 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006359
6360 final long identity = Binder.clearCallingIdentity();
6361 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006362 UiccController uiccController = UiccController.getInstance();
6363 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006364 if (hasReadPermission) {
6365 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006366 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006367
6368 // Remove private info if the caller doesn't have access
6369 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6370 for (UiccCardInfo cardInfo : cardInfos) {
6371 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6372 // is available
6373 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6374 if (card == null || card.getUiccProfile() == null) {
6375 // assume no access if the card or profile is unavailable
6376 filteredInfos.add(cardInfo.getUnprivileged());
6377 continue;
6378 }
6379 UiccProfile profile = card.getUiccProfile();
6380 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6381 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6382 filteredInfos.add(cardInfo);
6383 } else {
6384 filteredInfos.add(cardInfo.getUnprivileged());
6385 }
6386 }
6387 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
6391 }
6392
6393 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006394 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006395 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 final long identity = Binder.clearCallingIdentity();
6398 try {
6399 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6400 if (slots == null) {
6401 Rlog.i(LOG_TAG, "slots is null.");
6402 return null;
6403 }
6404
6405 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6406 for (int i = 0; i < slots.length; i++) {
6407 UiccSlot slot = slots[i];
6408 if (slot == null) {
6409 continue;
6410 }
6411
Jordan Liu7be7e652019-05-06 18:55:02 +00006412 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 UiccCard card = slot.getUiccCard();
6414 if (card != null) {
6415 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006416 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 cardId = slot.getIccId();
6418 }
6419
6420 int cardState = 0;
6421 switch (slot.getCardState()) {
6422 case CARDSTATE_ABSENT:
6423 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6424 break;
6425 case CARDSTATE_PRESENT:
6426 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6427 break;
6428 case CARDSTATE_ERROR:
6429 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6430 break;
6431 case CARDSTATE_RESTRICTED:
6432 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6433 break;
6434 default:
6435 break;
6436
6437 }
6438
6439 infos[i] = new UiccSlotInfo(
6440 slot.isActive(),
6441 slot.isEuicc(),
6442 cardId,
6443 cardState,
6444 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006445 slot.isExtendedApduSupported(),
6446 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447 }
6448 return infos;
6449 } finally {
6450 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006451 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006452 }
6453
6454 @Override
6455 public boolean switchSlots(int[] physicalSlots) {
6456 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457
6458 final long identity = Binder.clearCallingIdentity();
6459 try {
6460 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
6463 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006464 }
Jack Yu4c988042018-02-27 15:30:01 -08006465
6466 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006467 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006468 final long identity = Binder.clearCallingIdentity();
6469 try {
6470 return UiccController.getInstance().getCardIdForDefaultEuicc();
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
6474 }
6475
6476 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006477 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6478 enforceModifyPermission();
6479 final Phone phone = getPhone(subId);
6480 if (phone == null) {
6481 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6482 return;
6483 }
6484
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006485 final long identity = Binder.clearCallingIdentity();
6486 try {
6487 phone.setRadioIndicationUpdateMode(filters, mode);
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
Jack Yu4c988042018-02-27 15:30:01 -08006491 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006492
6493 /**
goneil47ffb6e2018-04-06 15:40:58 -07006494 * A test API to reload the UICC profile.
6495 *
6496 * <p>Requires that the calling app has permission
6497 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6498 * @hide
6499 */
6500 @Override
6501 public void refreshUiccProfile(int subId) {
6502 enforceModifyPermission();
6503
6504 final long identity = Binder.clearCallingIdentity();
6505 try {
6506 Phone phone = getPhone(subId);
6507 if (phone == null) {
6508 return;
6509 }
6510 UiccCard uiccCard = phone.getUiccCard();
6511 if (uiccCard == null) {
6512 return;
6513 }
6514 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6515 if (uiccProfile == null) {
6516 return;
6517 }
6518 uiccProfile.refresh();
6519 } finally {
6520 Binder.restoreCallingIdentity(identity);
6521 }
6522 }
6523
6524 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006525 * Returns false if the mobile data is disabled by default, otherwise return true.
6526 */
6527 private boolean getDefaultDataEnabled() {
6528 return "true".equalsIgnoreCase(
6529 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6530 }
6531
6532 /**
6533 * Returns true if the data roaming is enabled by default, i.e the system property
6534 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6535 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6536 */
6537 private boolean getDefaultDataRoamingEnabled(int subId) {
6538 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006539 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006540 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6541 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6542 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6543 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6544 return isDataRoamingEnabled;
6545 }
6546
6547 /**
6548 * Returns the default network type for the given {@code subId}, if the default network type is
6549 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6550 */
6551 private int getDefaultNetworkType(int subId) {
6552 return Integer.parseInt(
6553 TelephonyManager.getTelephonyProperty(
6554 mSubscriptionController.getPhoneId(subId),
6555 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6556 String.valueOf(Phone.PREFERRED_NT_MODE)));
6557 }
fionaxua13278b2018-03-21 00:08:13 -07006558
6559 @Override
6560 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006561 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006562 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
6566 final Phone phone = getPhone(subId);
6567 if (phone == null) {
6568 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6569 return;
6570 }
chen xueaba88a2019-03-15 13:15:10 -07006571 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6572 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 } finally {
6574 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006575 }
fionaxua13278b2018-03-21 00:08:13 -07006576 }
6577
6578 @Override
6579 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006580 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581
6582 final long identity = Binder.clearCallingIdentity();
6583 try {
6584 final Phone phone = getPhone(subId);
6585 if (phone == null) {
6586 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6587 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6588 }
6589 return phone.getCarrierIdListVersion();
6590 } finally {
6591 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006592 }
fionaxua13278b2018-03-21 00:08:13 -07006593 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006594
6595 @Override
6596 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6598 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6599 return -1;
6600 }
6601
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6605 } finally {
6606 Binder.restoreCallingIdentity(identity);
6607 }
6608 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006609
6610 @Override
6611 public int getCdmaRoamingMode(int subId) {
6612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6613 mApp, subId, "getCdmaRoamingMode");
6614
6615 final long identity = Binder.clearCallingIdentity();
6616 try {
6617 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6618 } finally {
6619 Binder.restoreCallingIdentity(identity);
6620 }
6621 }
6622
6623 @Override
6624 public boolean setCdmaRoamingMode(int subId, int mode) {
6625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6626 mApp, subId, "setCdmaRoamingMode");
6627
6628 final long identity = Binder.clearCallingIdentity();
6629 try {
6630 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6631 } finally {
6632 Binder.restoreCallingIdentity(identity);
6633 }
6634 }
6635
6636 @Override
6637 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6639 mApp, subId, "setCdmaSubscriptionMode");
6640
6641 final long identity = Binder.clearCallingIdentity();
6642 try {
6643 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6644 } finally {
6645 Binder.restoreCallingIdentity(identity);
6646 }
6647 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006648
6649 private void ensureUserRunning(int userId) {
6650 if (!mUserManager.isUserRunning(userId)) {
6651 throw new IllegalStateException("User " + userId + " does not exist or not running");
6652 }
6653 }
6654
6655 /**
6656 * Returns a list of SMS apps on a given user.
6657 *
6658 * Only the shell user (UID 2000 or 0) can call it.
6659 * Target user must be running.
6660 */
6661 @Override
6662 public String[] getSmsApps(int userId) {
6663 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6664 ensureUserRunning(userId);
6665
6666 final Collection<SmsApplicationData> apps =
6667 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6668
6669 String[] ret = new String[apps.size()];
6670 int i = 0;
6671 for (SmsApplicationData app : apps) {
6672 ret[i++] = app.mPackageName;
6673 }
6674 return ret;
6675 }
6676
6677 /**
6678 * Returns the default SMS app package name on a given user.
6679 *
6680 * Only the shell user (UID 2000 or 0) can call it.
6681 * Target user must be running.
6682 */
6683 @Override
6684 public String getDefaultSmsApp(int userId) {
6685 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6686 ensureUserRunning(userId);
6687
6688 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6689 /* updateIfNeeded= */ true, userId);
6690 return cn == null ? null : cn.getPackageName();
6691 }
6692
6693 /**
6694 * Set a package as the default SMS app on a given user.
6695 *
6696 * Only the shell user (UID 2000 or 0) can call it.
6697 * Target user must be running.
6698 */
6699 @Override
6700 public void setDefaultSmsApp(int userId, String packageName) {
6701 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6702 ensureUserRunning(userId);
6703
6704 boolean found = false;
6705 for (String pkg : getSmsApps(userId)) {
6706 if (TextUtils.equals(packageName, pkg)) {
6707 found = true;
6708 break;
6709 }
6710 }
6711 if (!found) {
6712 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6713 }
6714
6715 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6716 }
sqianc5eccab2018-10-19 18:46:41 -07006717
6718 @Override
sqian8c685422019-02-22 15:55:18 -08006719 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006720 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006721 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006722 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006723 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6724 }
6725 final long identity = Binder.clearCallingIdentity();
6726 try {
sqian854d44b2018-12-12 16:48:18 -08006727 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6728 for (Phone phone: PhoneFactory.getPhones()) {
6729 if (phone.getEmergencyNumberTracker() != null
6730 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6731 emergencyNumberListInternal.put(
6732 phone.getSubId(),
6733 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6734 }
sqian11b7a0e2018-12-05 18:48:28 -08006735 }
sqian854d44b2018-12-12 16:48:18 -08006736 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006737 } finally {
6738 Binder.restoreCallingIdentity(identity);
6739 }
sqianc5eccab2018-10-19 18:46:41 -07006740 }
6741
6742 @Override
sqian8c685422019-02-22 15:55:18 -08006743 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006744 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006745 if (!exactMatch) {
6746 TelephonyPermissions
6747 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006748 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006749 }
6750 final long identity = Binder.clearCallingIdentity();
6751 try {
sqian854d44b2018-12-12 16:48:18 -08006752 for (Phone phone: PhoneFactory.getPhones()) {
6753 if (phone.getEmergencyNumberTracker() != null
6754 && phone.getEmergencyNumberTracker() != null) {
6755 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6756 number, exactMatch)) {
6757 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006758 }
6759 }
sqian11b7a0e2018-12-05 18:48:28 -08006760 }
6761 return false;
6762 } finally {
6763 Binder.restoreCallingIdentity(identity);
6764 }
6765 }
6766
sqianf4ca7ed2019-01-15 18:32:07 -08006767 /**
6768 * Update emergency number list for test mode.
6769 */
6770 @Override
6771 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6772 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6773 "updateEmergencyNumberListTestMode");
6774
6775 final long identity = Binder.clearCallingIdentity();
6776 try {
6777 for (Phone phone: PhoneFactory.getPhones()) {
6778 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6779 if (tracker != null) {
6780 tracker.executeEmergencyNumberTestModeCommand(action, num);
6781 }
6782 }
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
6786 }
6787
6788 /**
6789 * Get the full emergency number list for test mode.
6790 */
6791 @Override
6792 public List<String> getEmergencyNumberListTestMode() {
6793 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6794 "getEmergencyNumberListTestMode");
6795
6796 final long identity = Binder.clearCallingIdentity();
6797 try {
6798 Set<String> emergencyNumbers = new HashSet<>();
6799 for (Phone phone: PhoneFactory.getPhones()) {
6800 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6801 if (tracker != null) {
6802 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6803 emergencyNumbers.add(num.getNumber());
6804 }
6805 }
6806 }
6807 return new ArrayList<>(emergencyNumbers);
6808 } finally {
6809 Binder.restoreCallingIdentity(identity);
6810 }
6811 }
6812
chen xud6b45bd2018-10-30 22:27:10 -07006813 @Override
6814 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6815 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6816 Phone phone = getPhone(subId);
6817 if (phone == null) {
6818 return null;
6819 }
6820 final long identity = Binder.clearCallingIdentity();
6821 try {
6822 UiccProfile profile = UiccController.getInstance()
6823 .getUiccProfileForPhone(phone.getPhoneId());
6824 if (profile != null) {
6825 return profile.getCertsFromCarrierPrivilegeAccessRules();
6826 }
6827 } finally {
6828 Binder.restoreCallingIdentity(identity);
6829 }
6830 return null;
6831 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006832
6833 /**
6834 * Enable or disable a modem stack.
6835 */
6836 @Override
6837 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6838 enforceModifyPermission();
6839
6840 final long identity = Binder.clearCallingIdentity();
6841 try {
6842 Phone phone = PhoneFactory.getPhone(slotIndex);
6843 if (phone == null) {
6844 return false;
6845 } else {
6846 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6847 }
6848 } finally {
6849 Binder.restoreCallingIdentity(identity);
6850 }
6851 }
Michelecea4cf22018-12-21 15:00:11 -08006852
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006853 /**
6854 * Whether a modem stack is enabled or not.
6855 */
6856 @Override
6857 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6858 Phone phone = PhoneFactory.getPhone(slotIndex);
6859 if (phone == null) return false;
6860
6861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6862 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6863 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6864 }
6865
6866 final long identity = Binder.clearCallingIdentity();
6867 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006868 try {
6869 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6870 } catch (NoSuchElementException ex) {
6871 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6872 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006873 } finally {
6874 Binder.restoreCallingIdentity(identity);
6875 }
6876 }
6877
Michelecea4cf22018-12-21 15:00:11 -08006878 @Override
Michele0ea7d782019-03-19 14:58:42 -07006879 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006880 enforceModifyPermission();
6881
6882 final long identity = Binder.clearCallingIdentity();
6883 try {
6884 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006885 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006886 .commit();
6887 } finally {
6888 Binder.restoreCallingIdentity(identity);
6889 }
6890 }
6891
6892 @Override
Michele0ea7d782019-03-19 14:58:42 -07006893 @TelephonyManager.IsMultiSimSupportedResult
6894 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006896 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6897 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006898 }
Michelecea4cf22018-12-21 15:00:11 -08006899
6900 final long identity = Binder.clearCallingIdentity();
6901 try {
Michele0ea7d782019-03-19 14:58:42 -07006902 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006903 } finally {
6904 Binder.restoreCallingIdentity(identity);
6905 }
6906 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006907
Michele0ea7d782019-03-19 14:58:42 -07006908 @TelephonyManager.IsMultiSimSupportedResult
6909 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006910 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6911 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6912 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006913 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6914 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006915 }
6916 // Check if the hardware supports multisim functionality. If usage of multisim is not
6917 // supported by the modem, indicate that it is restricted.
6918 PhoneCapability staticCapability =
6919 mPhoneConfigurationManager.getStaticPhoneCapability();
6920 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006921 loge("isMultiSimSupportedInternal: no static configuration available");
6922 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006923 }
6924 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006925 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6926 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006927 }
6928 // Check if support of multiple SIMs is restricted by carrier
6929 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006930 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006931 }
6932
Michele0ea7d782019-03-19 14:58:42 -07006933 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006934 }
6935
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006936 /**
6937 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006938 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6939 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6940 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006941 * @param numOfSims number of active sims we want to switch to
6942 */
6943 @Override
6944 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006945 if (numOfSims == 1) {
6946 enforceModifyPermission();
6947 } else {
6948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6949 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6950 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006951 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006952
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006953 try {
Michele30b57b22019-03-01 12:01:14 -08006954 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006955 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006956 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6957 return;
6958 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006959 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
6962 }
6963 }
6964
6965 /**
chen xub4baa772019-04-03 10:23:41 -07006966 * Get whether making changes to modem configurations will trigger reboot.
6967 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006968 */
6969 @Override
chen xub4baa772019-04-03 10:23:41 -07006970 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6972 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6973 return false;
6974 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006975 final long identity = Binder.clearCallingIdentity();
6976 try {
6977 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6978 } finally {
6979 Binder.restoreCallingIdentity(identity);
6980 }
6981 }
6982
Nathan Harold29f5f052019-02-15 13:41:57 -08006983 private void updateModemStateMetrics() {
6984 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6985 // TODO: check the state for each modem if the api is ready.
6986 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6987 }
6988
Pengquan Meng3889a572019-01-23 11:16:29 -08006989 @Override
6990 public int[] getSlotsMapping() {
6991 enforceReadPrivilegedPermission("getSlotsMapping");
6992
6993 final long identity = Binder.clearCallingIdentity();
6994 try {
6995 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6996 // All logical slots should have a mapping to a physical slot.
6997 int[] logicalSlotsMapping = new int[phoneCount];
6998 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6999 for (int i = 0; i < slotInfos.length; i++) {
7000 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7001 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7002 }
7003 }
7004 return logicalSlotsMapping;
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
7008 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007009
7010 /**
7011 * Get the IRadio HAL Version
7012 */
7013 @Override
7014 public int getRadioHalVersion() {
7015 Phone phone = getDefaultPhone();
7016 if (phone == null) return -1;
7017 HalVersion hv = phone.getHalVersion();
7018 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7019 return hv.major * 100 + hv.minor;
7020 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007021
7022 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007023 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7024 * corresponding network requests on a subId.
7025 *
7026 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007027 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007028 * 2) APN is un-metered for this subscription, or
7029 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7030 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7031 *
7032 * @return whether data is allowed for a apn type.
7033 *
7034 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007035 */
7036 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007037 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007039 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7040 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007041 }
7042
7043 // Now that all security checks passes, perform the operation as ourselves.
7044 final long identity = Binder.clearCallingIdentity();
7045 try {
7046 Phone phone = getPhone(subId);
7047 if (phone == null) return false;
7048
Jack Yu41407ee2019-05-13 16:54:09 -07007049 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007050 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7051 } finally {
7052 Binder.restoreCallingIdentity(identity);
7053 }
7054 }
7055
7056 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007057 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007058 enforceReadPrivilegedPermission("isApnMetered");
7059
7060 // Now that all security checks passes, perform the operation as ourselves.
7061 final long identity = Binder.clearCallingIdentity();
7062 try {
7063 Phone phone = getPhone(subId);
7064 if (phone == null) return true; // By default return true.
7065
Jack Yu41407ee2019-05-13 16:54:09 -07007066 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007067 } finally {
7068 Binder.restoreCallingIdentity(identity);
7069 }
7070 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007071
7072 @Override
7073 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7074 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7075 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7076 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7077 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7078 }
7079 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7080 Intent intent = new Intent();
7081 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7082 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7083 // Bring up choose default SMS subscription dialog right now
7084 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7085 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7086 mApp.startActivity(intent);
7087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007088}