blob: 2061796e7933baad242716b4fe0dd4af8a75459a [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;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080082import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070084import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070085import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080087import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000088import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070089import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070091import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080092import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070093import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080094import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080096import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070097import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080098import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070099import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800100import android.telephony.ims.aidl.IImsMmTelFeature;
101import android.telephony.ims.aidl.IImsRcsFeature;
102import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800104import android.telephony.ims.feature.MmTelFeature;
105import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800106import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800110import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800112
Brad Ebinger35c841c2018-10-01 10:40:55 -0700113import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700114import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800115import com.android.ims.internal.IImsServiceFeatureCallback;
Jordan Liua39e6c12020-03-04 13:59:23 -0800116import com.android.internal.annotations.VisibleForTesting;
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;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700144import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700145import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800146import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800147import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700148import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800149import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700150import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800151import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800152import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.uicc.IccIoResult;
154import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800155import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700156import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800157import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800159import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000160import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700161import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800162import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700164import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800165import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700166import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700167import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800168
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700169import java.io.FileDescriptor;
170import java.io.PrintWriter;
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() */
Jordan Liua39e6c12020-03-04 13:59:23 -08001323 @VisibleForTesting
1324 /* package */ PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001327 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1329 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001330 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001331 mTelephonySharedPreferences =
1332 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001333 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001334 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001335
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 publish();
1337 }
1338
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001339 private Phone getDefaultPhone() {
1340 Phone thePhone = getPhone(getDefaultSubscription());
1341 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1342 }
1343
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344 private void publish() {
1345 if (DBG) log("publish: " + this);
1346
1347 ServiceManager.addService("phone", this);
1348 }
1349
Stuart Scott584921c2015-01-15 17:10:34 -08001350 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001351 if (request.phone != null) {
1352 return request.phone;
1353 } else {
1354 return getPhoneFromSubId(request.subId);
1355 }
1356 }
1357
1358 private Phone getPhoneFromSubId(int subId) {
1359 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1360 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001361 }
1362
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001363 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1364 Phone phone = getPhoneFromRequest(request);
1365 return phone == null ? null :
1366 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1367 }
1368
Wink Saville36469e72014-06-11 15:17:00 -07001369 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001370 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001371 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373
1374 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 if (DBG) log("dial: " + number);
1380 // No permission check needed here: This is just a wrapper around the
1381 // ACTION_DIAL intent, which is available to any app since it puts up
1382 // the UI before it does anything.
1383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001384 final long identity = Binder.clearCallingIdentity();
1385 try {
1386 String url = createTelUrl(number);
1387 if (url == null) {
1388 return;
1389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001391 // PENDING: should we just silently fail if phone is offhook or ringing?
1392 PhoneConstants.State state = mCM.getState(subId);
1393 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1394 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1395 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1396 mApp.startActivity(intent);
1397 }
1398 } finally {
1399 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 }
1401 }
1402
1403 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001404 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001405 }
1406
Wink Savilleb564aae2014-10-23 10:18:09 -07001407 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 if (DBG) log("call: " + number);
1409
1410 // This is just a wrapper around the ACTION_CALL intent, but we still
1411 // need to do a permission check since we're calling startActivity()
1412 // from the context of the phone app.
1413 enforceCallPermission();
1414
1415 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1416 != AppOpsManager.MODE_ALLOWED) {
1417 return;
1418 }
1419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001420 final long identity = Binder.clearCallingIdentity();
1421 try {
1422 String url = createTelUrl(number);
1423 if (url == null) {
1424 return;
1425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001427 boolean isValid = false;
1428 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1429 if (slist != null) {
1430 for (SubscriptionInfo subInfoRecord : slist) {
1431 if (subInfoRecord.getSubscriptionId() == subId) {
1432 isValid = true;
1433 break;
1434 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001435 }
Wink Saville08874612014-08-31 19:19:58 -07001436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001437 if (!isValid) {
1438 return;
1439 }
Wink Saville08874612014-08-31 19:19:58 -07001440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001441 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1442 intent.putExtra(SUBSCRIPTION_KEY, subId);
1443 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1444 mApp.startActivity(intent);
1445 } finally {
1446 Binder.restoreCallingIdentity(identity);
1447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 }
1449
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001451 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001452 }
1453
Wink Savilleb564aae2014-10-23 10:18:09 -07001454 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001456 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1457 }
1458
1459 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001460 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001461 }
1462
Wink Savilleb564aae2014-10-23 10:18:09 -07001463 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001464 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001465 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1466 }
1467
1468 /** {@hide} */
1469 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001470 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001471 }
1472
Wink Savilleb564aae2014-10-23 10:18:09 -07001473 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001475
1476 final long identity = Binder.clearCallingIdentity();
1477 try {
1478 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1479 checkSimPin.start();
1480 return checkSimPin.unlockSim(null, pin);
1481 } finally {
1482 Binder.restoreCallingIdentity(identity);
1483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484 }
1485
Wink Saville9de0f752013-10-22 19:04:03 -07001486 /** {@hide} */
1487 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001488 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001489 }
1490
Wink Savilleb564aae2014-10-23 10:18:09 -07001491 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001493
1494 final long identity = Binder.clearCallingIdentity();
1495 try {
1496 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1497 checkSimPuk.start();
1498 return checkSimPuk.unlockSim(puk, pin);
1499 } finally {
1500 Binder.restoreCallingIdentity(identity);
1501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 }
1503
1504 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001505 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 * a synchronous one.
1507 */
1508 private static class UnlockSim extends Thread {
1509
1510 private final IccCard mSimCard;
1511
1512 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001513 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1514 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515
1516 // For replies from SimCard interface
1517 private Handler mHandler;
1518
1519 // For async handler to identify request type
1520 private static final int SUPPLY_PIN_COMPLETE = 100;
1521
1522 public UnlockSim(IccCard simCard) {
1523 mSimCard = simCard;
1524 }
1525
1526 @Override
1527 public void run() {
1528 Looper.prepare();
1529 synchronized (UnlockSim.this) {
1530 mHandler = new Handler() {
1531 @Override
1532 public void handleMessage(Message msg) {
1533 AsyncResult ar = (AsyncResult) msg.obj;
1534 switch (msg.what) {
1535 case SUPPLY_PIN_COMPLETE:
1536 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1537 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001538 mRetryCount = msg.arg1;
1539 if (ar.exception != null) {
1540 if (ar.exception instanceof CommandException &&
1541 ((CommandException)(ar.exception)).getCommandError()
1542 == CommandException.Error.PASSWORD_INCORRECT) {
1543 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1544 } else {
1545 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1546 }
1547 } else {
1548 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 mDone = true;
1551 UnlockSim.this.notifyAll();
1552 }
1553 break;
1554 }
1555 }
1556 };
1557 UnlockSim.this.notifyAll();
1558 }
1559 Looper.loop();
1560 }
1561
1562 /*
1563 * Use PIN or PUK to unlock SIM card
1564 *
1565 * If PUK is null, unlock SIM card with PIN
1566 *
1567 * If PUK is not null, unlock SIM card with PUK and set PIN code
1568 */
Wink Saville9de0f752013-10-22 19:04:03 -07001569 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570
1571 while (mHandler == null) {
1572 try {
1573 wait();
1574 } catch (InterruptedException e) {
1575 Thread.currentThread().interrupt();
1576 }
1577 }
1578 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1579
1580 if (puk == null) {
1581 mSimCard.supplyPin(pin, callback);
1582 } else {
1583 mSimCard.supplyPuk(puk, pin, callback);
1584 }
1585
1586 while (!mDone) {
1587 try {
1588 Log.d(LOG_TAG, "wait for done");
1589 wait();
1590 } catch (InterruptedException e) {
1591 // Restore the interrupted status
1592 Thread.currentThread().interrupt();
1593 }
1594 }
1595 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001596 int[] resultArray = new int[2];
1597 resultArray[0] = mResult;
1598 resultArray[1] = mRetryCount;
1599 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
1601 }
1602
1603 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001604 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001605
1606 }
1607
Wink Savilleb564aae2014-10-23 10:18:09 -07001608 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 // No permission check needed here: this call is harmless, and it's
1610 // needed for the ServiceState.requestStateUpdate() call (which is
1611 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001612 final long identity = Binder.clearCallingIdentity();
1613 try {
1614 final Phone phone = getPhone(subId);
1615 if (phone != null) {
1616 phone.updateServiceLocation();
1617 }
1618 } finally {
1619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001623 @Override
1624 public boolean isRadioOn(String callingPackage) {
1625 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001626 }
1627
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001628 @Override
1629 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001631 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001632 return false;
1633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001634
1635 final long identity = Binder.clearCallingIdentity();
1636 try {
1637 return isRadioOnForSubscriber(subId);
1638 } finally {
1639 Binder.restoreCallingIdentity(identity);
1640 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001641 }
1642
1643 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001644 final long identity = Binder.clearCallingIdentity();
1645 try {
1646 final Phone phone = getPhone(subId);
1647 if (phone != null) {
1648 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1649 } else {
1650 return false;
1651 }
1652 } finally {
1653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 }
1656
1657 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001658 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
Wink Saville36469e72014-06-11 15:17:00 -07001660
Wink Savilleb564aae2014-10-23 10:18:09 -07001661 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001663
1664 final long identity = Binder.clearCallingIdentity();
1665 try {
1666 final Phone phone = getPhone(subId);
1667 if (phone != null) {
1668 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1669 }
1670 } finally {
1671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 }
Wink Saville36469e72014-06-11 15:17:00 -07001673 }
1674
1675 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001676 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001677 }
1678
Wink Savilleb564aae2014-10-23 10:18:09 -07001679 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001681
1682 final long identity = Binder.clearCallingIdentity();
1683 try {
1684 final Phone phone = getPhone(subId);
1685 if (phone == null) {
1686 return false;
1687 }
1688 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1689 toggleRadioOnOffForSubscriber(subId);
1690 }
1691 return true;
1692 } finally {
1693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 }
Wink Saville36469e72014-06-11 15:17:00 -07001696
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001697 public boolean needMobileRadioShutdown() {
1698 /*
1699 * If any of the Radios are available, it will need to be
1700 * shutdown. So return true if any Radio is available.
1701 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001702 final long identity = Binder.clearCallingIdentity();
1703 try {
1704 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1705 Phone phone = PhoneFactory.getPhone(i);
1706 if (phone != null && phone.isRadioAvailable()) return true;
1707 }
1708 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1709 return false;
1710 } finally {
1711 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001712 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001713 }
1714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001716 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717 enforceModifyPermission();
1718
1719 final long identity = Binder.clearCallingIdentity();
1720 try {
1721 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1722 logv("Shutting down Phone " + i);
1723 shutdownRadioUsingPhoneId(i);
1724 }
1725 } finally {
1726 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001727 }
1728 }
1729
1730 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001731 Phone phone = PhoneFactory.getPhone(phoneId);
1732 if (phone != null && phone.isRadioAvailable()) {
1733 phone.shutdownRadio();
1734 }
1735 }
1736
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001738 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001739
1740 final long identity = Binder.clearCallingIdentity();
1741 try {
1742 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1743 if (defaultPhone != null) {
1744 defaultPhone.setRadioPower(turnOn);
1745 return true;
1746 } else {
1747 loge("There's no default phone.");
1748 return false;
1749 }
1750 } finally {
1751 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001752 }
Wink Saville36469e72014-06-11 15:17:00 -07001753 }
1754
Wink Savilleb564aae2014-10-23 10:18:09 -07001755 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
1762 phone.setRadioPower(turnOn);
1763 return true;
1764 } else {
1765 return false;
1766 }
1767 } finally {
1768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
Wink Saville36469e72014-06-11 15:17:00 -07001772 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public boolean enableDataConnectivity() {
1775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001776
1777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 int subId = mSubscriptionController.getDefaultDataSubId();
1780 final Phone phone = getPhone(subId);
1781 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001782 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001783 return true;
1784 } else {
1785 return false;
1786 }
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
Wink Saville36469e72014-06-11 15:17:00 -07001792 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 public boolean disableDataConnectivity() {
1795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796
1797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 int subId = mSubscriptionController.getDefaultDataSubId();
1800 final Phone phone = getPhone(subId);
1801 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001802 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001803 return true;
1804 } else {
1805 return false;
1806 }
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 }
1811
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001813 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001814 final long identity = Binder.clearCallingIdentity();
1815 try {
1816 final Phone phone = getPhone(subId);
1817 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001818 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819 } else {
1820 return false;
1821 }
1822 } finally {
1823 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 }
1826
1827 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001828 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001829 }
1830
pkanwarae03a6b2016-11-06 20:37:09 -08001831 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001832 enforceCallPermission();
1833
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1837 return;
1838 }
1839 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1840 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
1843 }
pkanwar32d516d2016-10-14 19:37:38 -07001844 };
1845
Wink Savilleb564aae2014-10-23 10:18:09 -07001846 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001848
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1852 return false;
1853 }
1854 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1855 } finally {
1856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001861 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001862 }
1863
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001864 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001865 final long identity = Binder.clearCallingIdentity();
1866 try {
1867 Phone phone = PhoneFactory.getPhone(slotIndex);
1868 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1869 PhoneConstantConversions.convertCallState(phone.getState());
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
1872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001877 final long identity = Binder.clearCallingIdentity();
1878 try {
1879 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1880 if (phone != null) {
1881 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1882 } else {
1883 return PhoneConstantConversions.convertDataState(
1884 PhoneConstants.DataState.DISCONNECTED);
1885 }
1886 } finally {
1887 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 }
1890
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001893 final long identity = Binder.clearCallingIdentity();
1894 try {
1895 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1896 if (phone != null) {
1897 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1898 } else {
1899 return TelephonyManager.DATA_ACTIVITY_NONE;
1900 }
1901 } finally {
1902 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 }
1905
1906 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001907 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001908 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001909 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001910
1911 LocationAccessPolicy.LocationPermissionResult locationResult =
1912 LocationAccessPolicy.checkLocationPermission(mApp,
1913 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1914 .setCallingPackage(callingPackage)
1915 .setCallingPid(Binder.getCallingPid())
1916 .setCallingUid(Binder.getCallingUid())
1917 .setMethod("getCellLocation")
1918 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1919 .build());
1920 switch (locationResult) {
1921 case DENIED_HARD:
1922 throw new SecurityException("Not allowed to access cell location");
1923 case DENIED_SOFT:
1924 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001927 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001928 final long identity = Binder.clearCallingIdentity();
1929 try {
1930 if (DBG_LOC) log("getCellLocation: is active user");
1931 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001932 int subId = mSubscriptionController.getDefaultDataSubId();
1933 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1934 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001935 return data;
1936 } finally {
1937 Binder.restoreCallingIdentity(identity);
1938 }
Svetoslav64fad262015-04-14 14:35:21 -07001939 }
1940
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001942 public String getNetworkCountryIsoForPhone(int phoneId) {
1943 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1944 // registered cell info, so return a NULL country instead.
1945 final long identity = Binder.clearCallingIdentity();
1946 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001947 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1948 // Get default phone in this case.
1949 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1950 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001951 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001952 // Todo: fix this when we can get the actual cellular network info when the device
1953 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001954 if (TelephonyManager.NETWORK_TYPE_IWLAN
1955 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1956 return "";
1957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958 Phone phone = PhoneFactory.getPhone(phoneId);
1959 if (phone != null) {
1960 ServiceStateTracker sst = phone.getServiceStateTracker();
1961 if (sst != null) {
1962 LocaleTracker lt = sst.getLocaleTracker();
1963 if (lt != null) {
1964 return lt.getCurrentCountry();
1965 }
1966 }
1967 }
1968 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001969 } finally {
1970 Binder.restoreCallingIdentity(identity);
1971 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001972 }
1973
1974 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001976 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001977 }
1978
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001980 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 mApp.enforceCallingOrSelfPermission(
1982 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983
1984 final long identity = Binder.clearCallingIdentity();
1985 try {
1986 final Phone phone = getPhone(subId);
1987 if (phone != null) {
1988 phone.enableLocationUpdates();
1989 }
1990 } finally {
1991 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 }
1994
1995 @Override
1996 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001997 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001998 }
1999
Sanket Padawe356d7632015-06-22 14:03:32 -07002000 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002001 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 mApp.enforceCallingOrSelfPermission(
2003 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002004
2005 final long identity = Binder.clearCallingIdentity();
2006 try {
2007 final Phone phone = getPhone(subId);
2008 if (phone != null) {
2009 phone.disableLocationUpdates();
2010 }
2011 } finally {
2012 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002014 }
2015
Nathan Harold31d7ff32018-10-15 20:20:30 -07002016 /**
2017 * Returns the target SDK version number for a given package name.
2018 *
2019 * @return target SDK if the package is found or INT_MAX.
2020 */
2021 private int getTargetSdk(String packageName) {
2022 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002023 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2024 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002025 if (ai != null) return ai.targetSdkVersion;
2026 } catch (PackageManager.NameNotFoundException unexpected) {
2027 }
2028 return Integer.MAX_VALUE;
2029 }
2030
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 @Override
2032 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002033 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2034 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002035 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2036 throw new SecurityException(
2037 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2038 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002039
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2041 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2042 return null;
2043 }
Svetoslav64fad262015-04-14 14:35:21 -07002044
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002045 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046
Nathan Haroldf180aac2018-06-01 18:43:55 -07002047 List<CellInfo> info = getAllCellInfo(callingPackage);
2048 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049
Nathan Haroldf180aac2018-06-01 18:43:55 -07002050 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2051 for (CellInfo ci : info) {
2052 if (ci instanceof CellInfoGsm) {
2053 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2054 } else if (ci instanceof CellInfoWcdma) {
2055 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002058 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 }
2060
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002061 private List<CellInfo> getCachedCellInfo() {
2062 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2063 for (Phone phone : PhoneFactory.getPhones()) {
2064 List<CellInfo> info = phone.getAllCellInfo();
2065 if (info != null) cellInfos.addAll(info);
2066 }
2067 return cellInfos;
2068 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069
2070 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002071 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002072 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002073 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002074
2075 LocationAccessPolicy.LocationPermissionResult locationResult =
2076 LocationAccessPolicy.checkLocationPermission(mApp,
2077 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2078 .setCallingPackage(callingPackage)
2079 .setCallingPid(Binder.getCallingPid())
2080 .setCallingUid(Binder.getCallingUid())
2081 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002082 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002083 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2084 .build());
2085 switch (locationResult) {
2086 case DENIED_HARD:
2087 throw new SecurityException("Not allowed to access cell info");
2088 case DENIED_SOFT:
2089 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 }
2091
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002092 final int targetSdk = getTargetSdk(callingPackage);
2093 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2094 return getCachedCellInfo();
2095 }
2096
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002097 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002098 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099 final long identity = Binder.clearCallingIdentity();
2100 try {
2101 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2102 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002103 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002104 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002105 if (info != null) cellInfos.addAll(info);
2106 }
2107 return cellInfos;
2108 } finally {
2109 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111 }
2112
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002113 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002114 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2115 requestCellInfoUpdateInternal(
2116 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2117 }
2118
2119 @Override
2120 public void requestCellInfoUpdateWithWorkSource(
2121 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2122 enforceModifyPermission();
2123 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2124 }
2125
2126 private void requestCellInfoUpdateInternal(
2127 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002128 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002129 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002130
2131 LocationAccessPolicy.LocationPermissionResult locationResult =
2132 LocationAccessPolicy.checkLocationPermission(mApp,
2133 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2134 .setCallingPackage(callingPackage)
2135 .setCallingPid(Binder.getCallingPid())
2136 .setCallingUid(Binder.getCallingUid())
2137 .setMethod("requestCellInfoUpdate")
2138 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2139 .build());
2140 switch (locationResult) {
2141 case DENIED_HARD:
2142 throw new SecurityException("Not allowed to access cell info");
2143 case DENIED_SOFT:
Nathan Haroldb3c5da42019-05-09 10:26:08 -07002144 try {
2145 cb.onCellInfo(new ArrayList<CellInfo>());
2146 } catch (RemoteException re) {
2147 // Drop without consequences
2148 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002149 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002150 }
2151
Nathan Harold32e84c42019-05-09 10:13:47 -07002152
2153 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002154 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2155
2156 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2157 }
2158
2159 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002161 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002162 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002163
2164 final long identity = Binder.clearCallingIdentity();
2165 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002166 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002167 } finally {
2168 Binder.restoreCallingIdentity(identity);
2169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 }
2171
Shishir Agrawala9f32182016-04-12 12:00:16 -07002172 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002173 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002174 Phone phone = PhoneFactory.getPhone(slotIndex);
2175 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002176 return null;
2177 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002178 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002179 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2180 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002181 return null;
2182 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002183
2184 final long identity = Binder.clearCallingIdentity();
2185 try {
2186 return phone.getImei();
2187 } finally {
2188 Binder.restoreCallingIdentity(identity);
2189 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002190 }
2191
2192 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002193 public String getTypeAllocationCodeForSlot(int slotIndex) {
2194 Phone phone = PhoneFactory.getPhone(slotIndex);
2195 String tac = null;
2196 if (phone != null) {
2197 String imei = phone.getImei();
2198 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2199 }
2200 return tac;
2201 }
2202
2203 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002204 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002205 Phone phone = PhoneFactory.getPhone(slotIndex);
2206 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002207 return null;
2208 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002209
Jeff Davidson913390f2018-02-23 17:11:49 -08002210 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002211 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2212 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002213 return null;
2214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002215
2216 final long identity = Binder.clearCallingIdentity();
2217 try {
2218 return phone.getMeid();
2219 } finally {
2220 Binder.restoreCallingIdentity(identity);
2221 }
Jack Yu2af8d712017-03-15 17:14:14 -07002222 }
2223
2224 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002225 public String getManufacturerCodeForSlot(int slotIndex) {
2226 Phone phone = PhoneFactory.getPhone(slotIndex);
2227 String manufacturerCode = null;
2228 if (phone != null) {
2229 String meid = phone.getMeid();
2230 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2231 }
2232 return manufacturerCode;
2233 }
2234
2235 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002236 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002237 Phone phone = PhoneFactory.getPhone(slotIndex);
2238 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002239 return null;
2240 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002241 int subId = phone.getSubId();
2242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2243 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2244 return null;
2245 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002246
2247 final long identity = Binder.clearCallingIdentity();
2248 try {
2249 return phone.getDeviceSvn();
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
2252 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002253 }
2254
fionaxu43304da2017-11-27 22:51:16 -08002255 @Override
2256 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 final Phone phone = getPhone(subId);
2260 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2261 } finally {
2262 Binder.restoreCallingIdentity(identity);
2263 }
fionaxu43304da2017-11-27 22:51:16 -08002264 }
2265
2266 @Override
2267 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268 final long identity = Binder.clearCallingIdentity();
2269 try {
2270 final Phone phone = getPhone(subId);
2271 return phone == null ? null : phone.getCarrierName();
2272 } finally {
2273 Binder.restoreCallingIdentity(identity);
2274 }
fionaxu43304da2017-11-27 22:51:16 -08002275 }
2276
calvinpanffe225e2018-11-01 19:43:06 +08002277 @Override
chen xu0026ca62019-03-06 15:28:50 -08002278 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002279 final long identity = Binder.clearCallingIdentity();
2280 try {
2281 final Phone phone = getPhone(subId);
2282 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002283 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002284 } finally {
2285 Binder.restoreCallingIdentity(identity);
2286 }
2287 }
2288
2289 @Override
chen xu0026ca62019-03-06 15:28:50 -08002290 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002291 final long identity = Binder.clearCallingIdentity();
2292 try {
2293 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002294 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002295 } finally {
2296 Binder.restoreCallingIdentity(identity);
2297 }
2298 }
2299
chen xu651eec72018-11-11 19:03:44 -08002300 @Override
chen xu864e11c2018-12-06 22:10:03 -08002301 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2302 if (!isSubscriptionMccMnc) {
2303 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2304 }
chen xu651eec72018-11-11 19:03:44 -08002305 final Phone phone = PhoneFactory.getPhone(slotIndex);
2306 if (phone == null) {
2307 return TelephonyManager.UNKNOWN_CARRIER_ID;
2308 }
2309 final long identity = Binder.clearCallingIdentity();
2310 try {
2311 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2312 } finally {
2313 Binder.restoreCallingIdentity(identity);
2314 }
2315 }
2316
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 //
2318 // Internal helper methods.
2319 //
2320
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002321 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2323 *
2324 * @throws SecurityException if the caller does not have the required permission
2325 */
2326 private void enforceModifyPermission() {
2327 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2328 }
2329
2330 /**
2331 * Make sure the caller has the CALL_PHONE permission.
2332 *
2333 * @throws SecurityException if the caller does not have the required permission
2334 */
2335 private void enforceCallPermission() {
2336 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2337 }
2338
Stuart Scott8eef64f2015-04-08 15:13:54 -07002339 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002340 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002341 "ConnectivityService");
2342 }
2343
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 private String createTelUrl(String number) {
2345 if (TextUtils.isEmpty(number)) {
2346 return null;
2347 }
2348
Jake Hambye994d462014-02-03 13:10:13 -08002349 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 }
2351
Ihab Awadf9e92732013-12-05 18:02:52 -08002352 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2354 }
2355
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002356 private static void logv(String msg) {
2357 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2358 }
2359
Ihab Awadf9e92732013-12-05 18:02:52 -08002360 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2362 }
2363
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002364 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002366 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002367 }
2368
Sanket Padawe356d7632015-06-22 14:03:32 -07002369 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002370 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = PhoneFactory.getPhone(slotIndex);
2374 if (phone == null) {
2375 return PhoneConstants.PHONE_TYPE_NONE;
2376 } else {
2377 return phone.getPhoneType();
2378 }
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 }
2383
2384 /**
2385 * Returns the CDMA ERI icon index to display
2386 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002387 @Override
2388 public int getCdmaEriIconIndex(String callingPackage) {
2389 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002390 }
2391
Sanket Padawe356d7632015-06-22 14:03:32 -07002392 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002393 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002395 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002396 return -1;
2397 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398
2399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 final Phone phone = getPhone(subId);
2402 if (phone != null) {
2403 return phone.getCdmaEriIconIndex();
2404 } else {
2405 return -1;
2406 }
2407 } finally {
2408 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 }
2411
2412 /**
2413 * Returns the CDMA ERI icon mode,
2414 * 0 - ON
2415 * 1 - FLASHING
2416 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002417 @Override
2418 public int getCdmaEriIconMode(String callingPackage) {
2419 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002420 }
2421
Sanket Padawe356d7632015-06-22 14:03:32 -07002422 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002423 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002424 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002425 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002426 return -1;
2427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002428
2429 final long identity = Binder.clearCallingIdentity();
2430 try {
2431 final Phone phone = getPhone(subId);
2432 if (phone != null) {
2433 return phone.getCdmaEriIconMode();
2434 } else {
2435 return -1;
2436 }
2437 } finally {
2438 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 }
2441
2442 /**
2443 * Returns the CDMA ERI text,
2444 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002445 @Override
2446 public String getCdmaEriText(String callingPackage) {
2447 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002448 }
2449
Sanket Padawe356d7632015-06-22 14:03:32 -07002450 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002451 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002453 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002454 return null;
2455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456
2457 final long identity = Binder.clearCallingIdentity();
2458 try {
2459 final Phone phone = getPhone(subId);
2460 if (phone != null) {
2461 return phone.getCdmaEriText();
2462 } else {
2463 return null;
2464 }
2465 } finally {
2466 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
2469
2470 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002471 * Returns the CDMA MDN.
2472 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002473 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002474 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2476 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477
2478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002481 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 return phone.getLine1Number();
2483 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002484 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002485 return null;
2486 }
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002489 }
2490 }
2491
2492 /**
2493 * Returns the CDMA MIN.
2494 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002495 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002496 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2498 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 final Phone phone = getPhone(subId);
2503 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2504 return phone.getCdmaMin();
2505 } else {
2506 return null;
2507 }
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002510 }
2511 }
2512
Hall Liud892bec2018-11-30 14:51:45 -08002513 @Override
2514 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2515 INumberVerificationCallback callback, String callingPackage) {
2516 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2517 != PERMISSION_GRANTED) {
2518 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2519 }
2520 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2521
2522 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2523 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2524 throw new SecurityException("Calling package must be configured in the device config");
2525 }
2526
2527 if (range == null) {
2528 throw new NullPointerException("Range must be non-null");
2529 }
2530
2531 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002532 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002533
2534 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2535 }
2536
Junda Liuca05d5d2014-08-14 22:36:34 -07002537 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 * Returns true if CDMA provisioning needs to run.
2539 */
2540 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541 final long identity = Binder.clearCallingIdentity();
2542 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002543 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544 } finally {
2545 Binder.restoreCallingIdentity(identity);
2546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 }
2548
2549 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002550 * Sets the voice mail number of a given subId.
2551 */
2552 @Override
2553 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002554 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555
2556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2559 new Pair<String, String>(alphaTag, number), new Integer(subId));
2560 return success;
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
2563 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002564 }
2565
Ta-wei Yen87c49842016-05-13 21:19:52 -07002566 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002567 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2568 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002569 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002570 if (!TextUtils.equals(callingPackage, systemDialer)) {
2571 throw new SecurityException("caller must be system dialer");
2572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2577 if (phoneAccountHandle == null) {
2578 return null;
2579 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002580 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002581 } finally {
2582 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002583 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002584 }
2585
2586 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002587 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002588 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002590 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002591 return null;
2592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002594 final long identity = Binder.clearCallingIdentity();
2595 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002596 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002597 } finally {
2598 Binder.restoreCallingIdentity(identity);
2599 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002600 }
2601
2602 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002603 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2604 VisualVoicemailSmsFilterSettings settings) {
2605 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606
2607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002610 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611 } finally {
2612 Binder.restoreCallingIdentity(identity);
2613 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002614 }
2615
2616 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002617 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2618 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619
2620 final long identity = Binder.clearCallingIdentity();
2621 try {
2622 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002623 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 } finally {
2625 Binder.restoreCallingIdentity(identity);
2626 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002627 }
2628
2629 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002630 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2631 String callingPackage, int subId) {
2632 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633
2634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002637 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638 } finally {
2639 Binder.restoreCallingIdentity(identity);
2640 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002641 }
2642
2643 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002644 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002645 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646
2647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002650 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 } finally {
2652 Binder.restoreCallingIdentity(identity);
2653 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002654 }
2655
2656 @Override
2657 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2658 String number, int port, String text, PendingIntent sentIntent) {
2659 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002660 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002661 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002662 SmsController smsController = PhoneFactory.getSmsController();
2663 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2664 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002665 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002666
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002667 /**
fionaxu0152e512016-11-14 13:36:14 -08002668 * Sets the voice activation state of a given subId.
2669 */
2670 @Override
2671 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2673 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674
2675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 final Phone phone = getPhone(subId);
2678 if (phone != null) {
2679 phone.setVoiceActivationState(activationState);
2680 } else {
2681 loge("setVoiceActivationState fails with invalid subId: " + subId);
2682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002685 }
2686 }
2687
2688 /**
2689 * Sets the data activation state of a given subId.
2690 */
2691 @Override
2692 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2694 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695
2696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 final Phone phone = getPhone(subId);
2699 if (phone != null) {
2700 phone.setDataActivationState(activationState);
2701 } else {
2702 loge("setVoiceActivationState fails with invalid subId: " + subId);
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002706 }
2707 }
2708
2709 /**
2710 * Returns the voice activation state of a given subId.
2711 */
2712 @Override
2713 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002714 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715
fionaxu0152e512016-11-14 13:36:14 -08002716 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 if (phone != null) {
2720 return phone.getVoiceActivationState();
2721 } else {
2722 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002726 }
2727 }
2728
2729 /**
2730 * Returns the data activation state of a given subId.
2731 */
2732 @Override
2733 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002734 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735
fionaxu0152e512016-11-14 13:36:14 -08002736 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 final long identity = Binder.clearCallingIdentity();
2738 try {
2739 if (phone != null) {
2740 return phone.getDataActivationState();
2741 } else {
2742 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002746 }
2747 }
2748
2749 /**
Wink Saville36469e72014-06-11 15:17:00 -07002750 * Returns the unread count of voicemails for a subId
2751 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002752 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002753 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2755 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2756 return 0;
2757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 final Phone phone = getPhone(subId);
2761 if (phone != null) {
2762 return phone.getVoiceMessageCount();
2763 } else {
2764 return 0;
2765 }
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
2771 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002772 * returns true, if the device is in a state where both voice and data
2773 * are supported simultaneously. This can change based on location or network condition.
2774 */
2775 @Override
2776 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 final Phone phone = getPhone(subId);
2780 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2781 } finally {
2782 Binder.restoreCallingIdentity(identity);
2783 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002784 }
2785
2786 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002787 * Send the dialer code if called from the current default dialer or the caller has
2788 * carrier privilege.
2789 * @param inputCode The dialer code to send
2790 */
2791 @Override
2792 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002793 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002795 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2796 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002797 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002798 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2799 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002804 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805 } finally {
2806 Binder.restoreCallingIdentity(identity);
2807 }
fionaxu235cc5e2017-03-06 22:25:57 -08002808 }
2809
Pengquan Menga1bb6272018-09-06 09:59:22 -07002810 @Override
2811 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002812 if (!isActiveSubscription(subId)) {
2813 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2814 }
2815
Pengquan Menga1bb6272018-09-06 09:59:22 -07002816 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2817 }
2818
Brad Ebinger35c841c2018-10-01 10:40:55 -07002819 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002820 public boolean isInEmergencySmsMode() {
2821 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 for (Phone phone : PhoneFactory.getPhones()) {
2825 if (phone.isInEmergencySmsMode()) {
2826 return true;
2827 }
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
2831 }
2832 return false;
2833 }
2834
2835 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002836 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2837 throws RemoteException {
2838 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002839 final long token = Binder.clearCallingIdentity();
2840 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002842 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002843 .addRegistrationCallbackForSubscription(c, subId);
2844 } finally {
2845 Binder.restoreCallingIdentity(token);
2846 }
2847 }
2848
2849 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002850 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2851 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002852 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2853 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2854 }
2855 Binder.withCleanCallingIdentity(() -> {
2856 try {
2857 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002858 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002859 .removeRegistrationCallbackForSubscription(c, subId);
2860 } catch (IllegalArgumentException e) {
2861 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2862 + "is inactive, ignoring unregister.");
2863 // If the subscription is no longer active, just return, since the callback
2864 // will already have been removed internally.
2865 }
2866 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002867 }
2868
2869 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002870 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2871 throws RemoteException {
2872 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002873 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2874 final long token = Binder.clearCallingIdentity();
2875 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002876 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002877 .addCapabilitiesCallbackForSubscription(c, subId);
2878 } finally {
2879 Binder.restoreCallingIdentity(token);
2880 }
2881 }
2882
2883 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002884 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2885 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002886
2887 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2888 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2889 }
2890 Binder.withCleanCallingIdentity(() -> {
2891 try {
2892 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002893 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002894 .removeCapabilitiesCallbackForSubscription(c, subId);
2895 } catch (IllegalArgumentException e) {
2896 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2897 + "is inactive, ignoring unregister.");
2898 // If the subscription is no longer active, just return, since the callback
2899 // will already have been removed internally.
2900 }
2901 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002902 }
2903
2904 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002905 public boolean isCapable(int subId, int capability, int regTech) {
2906 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2908 final long token = Binder.clearCallingIdentity();
2909 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002910 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002911 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2912 } catch (ImsException e) {
2913 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2914 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002915 } catch (IllegalArgumentException e) {
2916 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2917 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002918 } finally {
2919 Binder.restoreCallingIdentity(token);
2920 }
2921 }
2922
2923 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002924 public boolean isAvailable(int subId, int capability, int regTech) {
2925 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002926 final long token = Binder.clearCallingIdentity();
2927 try {
2928 Phone phone = getPhone(subId);
2929 if (phone == null) return false;
2930 return phone.isImsCapabilityAvailable(capability, regTech);
2931 } finally {
2932 Binder.restoreCallingIdentity(token);
2933 }
2934 }
2935
2936 @Override
2937 public boolean isAdvancedCallingSettingEnabled(int subId) {
2938 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2939 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2940 final long token = Binder.clearCallingIdentity();
2941 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002942 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002943 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2944 } finally {
2945 Binder.restoreCallingIdentity(token);
2946 }
2947 }
2948
2949 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002950 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002952 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002956 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002957 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
2960 }
2961 }
2962
2963 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002964 public boolean isVtSettingEnabled(int subId) {
2965 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002966 final long identity = Binder.clearCallingIdentity();
2967 try {
2968 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002969 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002970 getSlotIndexOrException(subId)).isVtEnabledByUser();
2971 } finally {
2972 Binder.restoreCallingIdentity(identity);
2973 }
2974 }
2975
2976 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002977 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002979 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002983 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
2987 }
2988
2989 @Override
2990 public boolean isVoWiFiSettingEnabled(int subId) {
2991 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002995 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
3000 }
3001
3002 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003003 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003005 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003009 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003010 } finally {
3011 Binder.restoreCallingIdentity(identity);
3012 }
3013 }
3014
3015 @Override
3016 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3017 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003021 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003022 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
3026 }
3027
3028 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003029 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003031 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003035 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003036 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
3040 }
3041
3042 @Override
3043 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3045 "setVoWiFiNonPersistent");
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003049 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003050 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
3054 }
3055
3056 @Override
3057 public int getVoWiFiModeSetting(int subId) {
3058 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003062 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003063 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3064 } finally {
3065 Binder.restoreCallingIdentity(identity);
3066 }
3067 }
3068
3069 @Override
3070 public void setVoWiFiModeSetting(int subId, int mode) {
3071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3072 "setVoWiFiModeSetting");
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003076 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
3081 }
3082
3083 @Override
3084 public int getVoWiFiRoamingModeSetting(int subId) {
3085 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003089 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003090 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
3094 }
3095
3096 @Override
3097 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3099 "setVoWiFiRoamingModeSetting");
3100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003103 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003104 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
3108 }
3109
3110 @Override
3111 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3113 "setRttCapabilityEnabled");
3114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003117 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003118 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
3124 @Override
3125 public boolean isTtyOverVolteEnabled(int subId) {
3126 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3127 final long identity = Binder.clearCallingIdentity();
3128 try {
3129 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003130 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003131 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003137 @Override
3138 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3139 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3140 final long identity = Binder.clearCallingIdentity();
3141 try {
3142 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003143 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003144 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003145 } finally {
3146 Binder.restoreCallingIdentity(identity);
3147 }
3148 }
3149
3150 @Override
3151 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3152 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3153 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003154 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3155 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3156 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003157 try {
3158 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003159 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003160 .removeProvisioningCallbackForSubscription(callback, subId);
3161 } catch (IllegalArgumentException e) {
3162 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3163 + "is inactive, ignoring unregister.");
3164 // If the subscription is no longer active, just return, since the callback will already
3165 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003166 } finally {
3167 Binder.restoreCallingIdentity(identity);
3168 }
3169 }
3170
3171 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003172 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3173 boolean isProvisioned) {
3174 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3175 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3176 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3177 }
3178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3179 "setProvisioningStatusForCapability");
3180 final long identity = Binder.clearCallingIdentity();
3181 try {
3182 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3183 Phone phone = getPhone(subId);
3184 if (phone == null) {
3185 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3186 + subId);
3187 return;
3188 }
3189 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3190 return;
3191 }
3192
3193 // this capability requires provisioning, route to the correct API.
3194 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3195 switch (capability) {
3196 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3197 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3198 ims.setVolteProvisioned(isProvisioned);
3199 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3200 ims.setWfcProvisioned(isProvisioned);
3201 }
3202 break;
3203 }
3204 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3205 // There is currently no difference in VT provisioning type.
3206 ims.setVtProvisioned(isProvisioned);
3207 break;
3208 }
3209 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3210 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3211 // change the capability of the feature instead if needed.
3212 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3213 == isProvisioned) {
3214 // No change in provisioning.
3215 return;
3216 }
3217 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3218 try {
3219 ims.changeMmTelCapability(capability, tech, isProvisioned);
3220 } catch (ImsException e) {
3221 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3222 + ", Exception" + e.getMessage());
3223 }
3224 break;
3225 }
3226 default: {
3227 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3228 + capability + "', which does not require provisioning.");
3229 }
3230 }
3231
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
3235 }
3236
3237 @Override
3238 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3239 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3240 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3241 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3242 }
3243 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3247 Phone phone = getPhone(subId);
3248 if (phone == null) {
3249 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3250 + subId);
3251 // We will fail with "true" as the provisioning status because this is the default
3252 // if we do not require provisioning.
3253 return true;
3254 }
3255
3256 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3257 return true;
3258 }
3259
3260 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3261 switch (capability) {
3262 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3263 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3264 return ims.isVolteProvisionedOnDevice();
3265 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3266 return ims.isWfcProvisionedOnDevice();
3267 }
3268 // This should never happen, since we are checking tech above to make sure it
3269 // is either LTE or IWLAN.
3270 throw new IllegalArgumentException("Invalid radio technology for voice "
3271 + "capability.");
3272 }
3273 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3274 // There is currently no difference in VT provisioning type.
3275 return ims.isVtProvisionedOnDevice();
3276 }
3277 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3278 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3279 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3280 }
3281 default: {
3282 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3283 + capability + "', which does not require provisioning.");
3284 }
3285 }
3286
3287 } finally {
3288 Binder.restoreCallingIdentity(identity);
3289 }
3290 }
3291
3292 @Override
3293 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3294 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3295 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3296 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3297 }
3298 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3299 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3300 return (provisionedBits & capability) > 0;
3301 }
3302
3303 @Override
3304 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3305 boolean isProvisioned) {
3306 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3307 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3308 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3309 }
3310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3311 "setProvisioningStatusForCapability");
3312 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3313 // If the current provisioning status for capability already matches isProvisioned,
3314 // do nothing.
3315 if (((provisionedBits & capability) > 0) == isProvisioned) {
3316 return;
3317 }
3318 if (isProvisioned) {
3319 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3320 } else {
3321 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3322 }
3323 }
3324
3325 /**
3326 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3327 * technology. The bitfield should mirror the bitfield defined by
3328 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3329 */
3330 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3331 String key = getMmTelProvisioningKey(subId, tech);
3332 // Default is no capabilities are provisioned.
3333 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3334 }
3335
3336 /**
3337 * Sets the MmTel capability provisioning bitfield (defined by
3338 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3339 * technology specified.
3340 *
3341 * Note: This is a synchronous command and should not be called on UI thread.
3342 */
3343 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3344 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3345 String key = getMmTelProvisioningKey(subId, tech);
3346 editor.putInt(key, newField);
3347 editor.commit();
3348 }
3349
3350 private static String getMmTelProvisioningKey(int subId, int tech) {
3351 // resulting key is provision_ims_mmtel_{subId}_{tech}
3352 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3353 }
3354
3355 /**
3356 * Query CarrierConfig to see if the specified capability requires provisioning for the
3357 * carrier associated with the subscription id.
3358 */
3359 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3360 int capability) {
3361 CarrierConfigManager configManager = new CarrierConfigManager(context);
3362 PersistableBundle c = configManager.getConfigForSubId(subId);
3363 boolean requireUtProvisioning = c.getBoolean(
3364 // By default, this config is true (even if there is no SIM). We also check to make
3365 // sure the subscription needs provisioning here, so we do not need to check for
3366 // the no-SIM case, where we would normally shortcut this to false.
3367 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3368 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3369 false);
3370 boolean requireVoiceVtProvisioning = c.getBoolean(
3371 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3372
3373 // First check to make sure that the capability requires provisioning.
3374 switch (capability) {
3375 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3376 // intentional fallthrough
3377 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3378 if (requireVoiceVtProvisioning) {
3379 // Voice and Video requires provisioning
3380 return true;
3381 }
3382 break;
3383 }
3384 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3385 if (requireUtProvisioning) {
3386 // UT requires provisioning
3387 return true;
3388 }
3389 break;
3390 }
3391 }
3392 return false;
3393 }
3394
3395 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003396 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003397 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3398 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3399 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003400 enforceReadPrivilegedPermission("getImsProvisioningInt");
3401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003404 int slotId = getSlotIndex(subId);
3405 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3406 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3407 + subId + "' for key:" + key);
3408 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3409 }
3410 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003411 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003412 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3413 + subId + "' for key:" + key);
3414 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
3418 }
3419
3420 @Override
3421 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003422 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3423 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3424 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003425 enforceReadPrivilegedPermission("getImsProvisioningString");
3426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003429 int slotId = getSlotIndex(subId);
3430 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3431 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3432 + subId + "' for key:" + key);
3433 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3434 }
3435 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003436 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003437 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3438 + subId + "' for key:" + key);
3439 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003440 } finally {
3441 Binder.restoreCallingIdentity(identity);
3442 }
3443 }
3444
3445 @Override
3446 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003447 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3448 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3449 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3451 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003452 final long identity = Binder.clearCallingIdentity();
3453 try {
3454 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003455 int slotId = getSlotIndex(subId);
3456 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3457 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3458 + subId + "' for key:" + key);
3459 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3460 }
3461 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003462 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003463 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3464 + "' for key:" + key);
3465 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
3469 }
3470
3471 @Override
3472 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003473 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3474 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3475 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3477 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003478 final long identity = Binder.clearCallingIdentity();
3479 try {
3480 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003481 int slotId = getSlotIndex(subId);
3482 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3483 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3484 + subId + "' for key:" + key);
3485 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3486 }
3487 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003488 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003489 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3490 + "' for key:" + key);
3491 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003492 } finally {
3493 Binder.restoreCallingIdentity(identity);
3494 }
3495 }
3496
Brad Ebinger35c841c2018-10-01 10:40:55 -07003497 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3498 int slotId = SubscriptionManager.getSlotIndex(subId);
3499 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003500 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003501 }
3502 return slotId;
3503 }
3504
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003505 private int getSlotIndex(int subId) {
3506 int slotId = SubscriptionManager.getSlotIndex(subId);
3507 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3508 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3509 }
3510 return slotId;
3511 }
3512
Wink Saville36469e72014-06-11 15:17:00 -07003513 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003514 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003515 */
3516 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003517 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Harold9042f0b2019-05-21 15:51:27 -07003518 if (getTargetSdk(callingPackage) >= android.os.Build.VERSION_CODES.Q
3519 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3520 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003521 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3522 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003524 final long identity = Binder.clearCallingIdentity();
3525 try {
3526 final Phone phone = getPhone(subId);
3527 if (phone != null) {
3528 return phone.getServiceState().getDataNetworkType();
3529 } else {
3530 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3531 }
3532 } finally {
3533 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003535 }
3536
3537 /**
3538 * Returns the data network type
3539 */
3540 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003541 public int getDataNetworkType(String callingPackage) {
3542 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003543 }
3544
3545 /**
3546 * Returns the data network type for a subId
3547 */
3548 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003549 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003551 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003552 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3553 }
3554
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 final Phone phone = getPhone(subId);
3558 if (phone != null) {
3559 return phone.getServiceState().getDataNetworkType();
3560 } else {
3561 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3562 }
3563 } finally {
3564 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003566 }
3567
3568 /**
Wink Saville36469e72014-06-11 15:17:00 -07003569 * Returns the Voice network type for a subId
3570 */
3571 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003572 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003574 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003575 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3576 }
3577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578 final long identity = Binder.clearCallingIdentity();
3579 try {
3580 final Phone phone = getPhone(subId);
3581 if (phone != null) {
3582 return phone.getServiceState().getVoiceNetworkType();
3583 } else {
3584 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3585 }
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003589 }
3590
3591 /**
3592 * @return true if a ICC card is present
3593 */
3594 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003595 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003596 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3597 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003598 }
3599
3600 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003601 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003602 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003603 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003604 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605 final long identity = Binder.clearCallingIdentity();
3606 try {
3607 final Phone phone = PhoneFactory.getPhone(slotIndex);
3608 if (phone != null) {
3609 return phone.getIccCard().hasIccCard();
3610 } else {
3611 return false;
3612 }
3613 } finally {
3614 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003616 }
3617
3618 /**
3619 * Return if the current radio is LTE on CDMA. This
3620 * is a tri-state return value as for a period of time
3621 * the mode may be unknown.
3622 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003623 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003624 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003625 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003626 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003627 @Override
3628 public int getLteOnCdmaMode(String callingPackage) {
3629 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003630 }
3631
Sanket Padawe356d7632015-06-22 14:03:32 -07003632 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003633 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003635 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003636 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3637 }
3638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 final Phone phone = getPhone(subId);
3642 if (phone == null) {
3643 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3644 } else {
3645 return phone.getLteOnCdmaMode();
3646 }
3647 } finally {
3648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003649 }
Wink Saville36469e72014-06-11 15:17:00 -07003650 }
3651
Wink Saville36469e72014-06-11 15:17:00 -07003652 /**
3653 * {@hide}
3654 * Returns Default subId, 0 in the case of single standby.
3655 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003656 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003657 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003658 }
3659
Shishir Agrawala9f32182016-04-12 12:00:16 -07003660 private int getSlotForDefaultSubscription() {
3661 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3662 }
3663
Wink Savilleb564aae2014-10-23 10:18:09 -07003664 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003665 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003666 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003667
Pengquan Menge92a50d2018-09-21 15:54:48 -07003668 private boolean isActiveSubscription(int subId) {
3669 return mSubscriptionController.isActiveSubId(subId);
3670 }
3671
Ihab Awadf2177b72013-11-25 13:33:23 -08003672 /**
3673 * @see android.telephony.TelephonyManager.WifiCallingChoices
3674 */
3675 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676 final long identity = Binder.clearCallingIdentity();
3677 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003678 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003679 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3680 getWhenToMakeWifiCallsDefaultPreference());
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003684 }
3685
3686 /**
3687 * @see android.telephony.TelephonyManager.WifiCallingChoices
3688 */
3689 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690 final long identity = Binder.clearCallingIdentity();
3691 try {
3692 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003693 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003694 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3695 } finally {
3696 Binder.restoreCallingIdentity(identity);
3697 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003698 }
3699
Sailesh Nepald1e68152013-12-12 19:08:02 -08003700 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003701 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003702 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003703 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003704
Jordan Liu4c733742019-02-28 12:03:40 -08003705 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3706 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3707 if (phoneId == -1) {
3708 throw new IllegalArgumentException("Given slot index: " + slotIndex
3709 + " does not correspond to an active phone");
3710 }
3711 return PhoneFactory.getPhone(phoneId);
3712 }
3713
Shishir Agrawal566b7612013-10-28 14:41:00 -07003714 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003715 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3716 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3718 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003720 if (DBG) {
3721 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3722 }
3723 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3724 p2);
3725 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003726
Jordan Liu4c733742019-02-28 12:03:40 -08003727
3728 @Override
3729 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3730 int slotIndex, String callingPackage, String aid, int p2) {
3731 enforceModifyPermission();
3732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3733 if (DBG) {
3734 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3735 }
3736 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3737 callingPackage, aid, p2);
3738 }
3739
3740 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3741 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 if (TextUtils.equals(ISDR_AID, aid)) {
3745 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003746 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3747 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748 if (bestComponent == null
3749 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3750 loge("The calling package is not allowed to access ISD-R.");
3751 throw new SecurityException(
3752 "The calling package is not allowed to access ISD-R.");
3753 }
Derek Tan740e1672017-06-27 14:56:27 -07003754 }
Derek Tan740e1672017-06-27 14:56:27 -07003755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003757 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3758 null /* workSource */);
3759 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003760 return response;
3761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003764 }
3765
3766 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003767 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3769 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003770 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3771 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3772 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003773
Jordan Liu4c733742019-02-28 12:03:40 -08003774 @Override
3775 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3776 enforceModifyPermission();
3777 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3778 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3779 channel);
3780 }
3781
3782 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783 final long identity = Binder.clearCallingIdentity();
3784 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785 if (channel < 0) {
3786 return false;
3787 }
Jordan Liu4c733742019-02-28 12:03:40 -08003788 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3789 null /* workSource */);
3790 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791 return success;
3792 } finally {
3793 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003794 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003795 }
3796
3797 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003798 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003799 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3801 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003802 if (DBG) {
3803 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3804 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3805 + p3 + " data=" + data);
3806 }
3807 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3808 command, p1, p2, p3, data);
3809 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003810
Jordan Liu4c733742019-02-28 12:03:40 -08003811 @Override
3812 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3813 int command, int p1, int p2, int p3, String data) {
3814 enforceModifyPermission();
3815 if (DBG) {
3816 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3817 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3818 + p3 + " data=" + data);
3819 }
3820 return iccTransmitApduLogicalChannelWithPermission(
3821 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3822 data);
3823 }
3824
3825 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3826 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003829 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830 return "";
3831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003834 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3835 null /* workSource */);
3836 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003838 // Append the returned status code to the end of the response payload.
3839 String s = Integer.toHexString(
3840 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3841 if (response.payload != null) {
3842 s = IccUtils.bytesToHexString(response.payload) + s;
3843 }
3844 return s;
3845 } finally {
3846 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003847 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003848 }
Jake Hambye994d462014-02-03 13:10:13 -08003849
Evan Charltonc66da362014-05-16 14:06:40 -07003850 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003851 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3852 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3854 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003855 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003856 if (DBG) {
3857 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3858 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3859 }
3860 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3861 cla, command, p1, p2, p3, data);
3862 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003863
Jordan Liu4c733742019-02-28 12:03:40 -08003864 @Override
3865 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3866 int command, int p1, int p2, int p3, String data) {
3867 enforceModifyPermission();
3868 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3869 if (DBG) {
3870 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3871 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3872 + " data=" + data);
3873 }
3874
3875 return iccTransmitApduBasicChannelWithPermission(
3876 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3877 p2, p3, data);
3878 }
3879
3880 // open APDU basic channel assuming the caller has sufficient permissions
3881 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3882 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3886 && TextUtils.equals(ISDR_AID, data)) {
3887 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003888 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3889 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890 if (bestComponent == null
3891 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3892 loge("The calling package is not allowed to select ISD-R.");
3893 throw new SecurityException(
3894 "The calling package is not allowed to select ISD-R.");
3895 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003896 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003899 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3900 null /* workSource */);
3901 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903 // Append the returned status code to the end of the response payload.
3904 String s = Integer.toHexString(
3905 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3906 if (response.payload != null) {
3907 s = IccUtils.bytesToHexString(response.payload) + s;
3908 }
3909 return s;
3910 } finally {
3911 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003912 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003913 }
3914
3915 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003916 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003917 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3919 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921 final long identity = Binder.clearCallingIdentity();
3922 try {
3923 if (DBG) {
3924 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3925 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3926 }
3927
3928 IccIoResult response =
3929 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3930 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3931 subId);
3932
3933 if (DBG) {
3934 log("Exchange SIM_IO [R]" + response);
3935 }
3936
3937 byte[] result = null;
3938 int length = 2;
3939 if (response.payload != null) {
3940 length = 2 + response.payload.length;
3941 result = new byte[length];
3942 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3943 } else {
3944 result = new byte[length];
3945 }
3946
3947 result[length - 1] = (byte) response.sw2;
3948 result[length - 2] = (byte) response.sw1;
3949 return result;
3950 } finally {
3951 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003952 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003953 }
3954
Nathan Haroldb3014052017-01-25 15:57:32 -08003955 /**
3956 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3957 * on a particular subscription
3958 */
sqianb6e41952018-03-12 14:54:01 -07003959 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3961 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3962 return null;
3963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003964
3965 final long identity = Binder.clearCallingIdentity();
3966 try {
3967 if (appType != TelephonyManager.APPTYPE_USIM
3968 && appType != TelephonyManager.APPTYPE_SIM) {
3969 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3970 return null;
3971 }
3972 Object response = sendRequest(
3973 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3974 if (response instanceof String[]) {
3975 return (String[]) response;
3976 }
3977 // Response is an Exception of some kind,
3978 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003979 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980 } finally {
3981 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003982 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003983 }
3984
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003985 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003986 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3988 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3993 if (response.payload == null) {
3994 return "";
3995 }
Evan Charltonc66da362014-05-16 14:06:40 -07003996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003997 // Append the returned status code to the end of the response payload.
3998 String s = Integer.toHexString(
3999 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4000 s = IccUtils.bytesToHexString(response.payload) + s;
4001 return s;
4002 } finally {
4003 Binder.restoreCallingIdentity(identity);
4004 }
Evan Charltonc66da362014-05-16 14:06:40 -07004005 }
4006
Jake Hambye994d462014-02-03 13:10:13 -08004007 /**
4008 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4009 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4010 *
4011 * @param itemID the ID of the item to read
4012 * @return the NV item as a String, or null on error.
4013 */
4014 @Override
4015 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004016 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4018 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004019
4020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004023 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004024 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4025 return value;
4026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
Jake Hambye994d462014-02-03 13:10:13 -08004029 }
4030
4031 /**
4032 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4033 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4034 *
4035 * @param itemID the ID of the item to read
4036 * @param itemValue the value to write, as a String
4037 * @return true on success; false on any failure
4038 */
4039 @Override
4040 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004041 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4043 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044
4045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4048 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004049 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4051 return success;
4052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
Jake Hambye994d462014-02-03 13:10:13 -08004055 }
4056
4057 /**
4058 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4059 * Used for device configuration by some CDMA operators.
4060 *
4061 * @param preferredRoamingList byte array containing the new PRL
4062 * @return true on success; false on any failure
4063 */
4064 @Override
4065 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4067 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068
4069 final long identity = Binder.clearCallingIdentity();
4070 try {
4071 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4072 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4073 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4074 return success;
4075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
Jake Hambye994d462014-02-03 13:10:13 -08004078 }
4079
4080 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004081 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004082 * Used for device configuration by some CDMA operators.
4083 *
chen xu6dac5ab2018-10-26 17:39:23 -07004084 * @param slotIndex - device slot.
4085 *
Jake Hambye994d462014-02-03 13:10:13 -08004086 * @return true on success; false on any failure
4087 */
4088 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004089 public boolean resetModemConfig(int slotIndex) {
4090 Phone phone = PhoneFactory.getPhone(slotIndex);
4091 if (phone != null) {
4092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4093 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094
chen xu6dac5ab2018-10-26 17:39:23 -07004095 final long identity = Binder.clearCallingIdentity();
4096 try {
4097 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4098 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4099 return success;
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103 }
chen xu6dac5ab2018-10-26 17:39:23 -07004104 return false;
4105 }
4106
4107 /**
4108 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4109 *
4110 * @param slotIndex - device slot.
4111 *
4112 * @return true on success; false on any failure
4113 */
4114 @Override
4115 public boolean rebootModem(int slotIndex) {
4116 Phone phone = PhoneFactory.getPhone(slotIndex);
4117 if (phone != null) {
4118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4119 mApp, phone.getSubId(), "rebootModem");
4120
4121 final long identity = Binder.clearCallingIdentity();
4122 try {
4123 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4124 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4125 return success;
4126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
4129 }
4130 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004131 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004132
Svet Ganovb320e182015-04-16 12:30:10 -07004133 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004134 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004136 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004137 return new String[0];
4138 }
4139
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140 final long identity = Binder.clearCallingIdentity();
4141 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004142 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 } finally {
4144 Binder.restoreCallingIdentity(identity);
4145 }
Wink Saville36469e72014-06-11 15:17:00 -07004146 }
4147
Brad Ebinger51f743a2017-01-23 13:50:20 -08004148 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004149 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4150 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004151 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004152 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004153 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004154
4155 final long identity = Binder.clearCallingIdentity();
4156 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004157 ImsResolver resolver = PhoneFactory.getImsResolver();
4158 if (resolver == null) {
4159 // may happen if the device does not support IMS.
4160 return;
4161 }
4162 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004166 }
4167
4168 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004169 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4170 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004171 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004172 public void disableIms(int slotId) {
4173 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004174
4175 final long identity = Binder.clearCallingIdentity();
4176 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004177 ImsResolver resolver = PhoneFactory.getImsResolver();
4178 if (resolver == null) {
4179 // may happen if the device does not support IMS.
4180 return;
4181 }
4182 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004186 }
4187
4188 /**
4189 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4190 * feature or {@link null} if the service is not available. If the feature is available, the
4191 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4192 */
4193 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004194 IImsServiceFeatureCallback callback) {
4195 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196
4197 final long identity = Binder.clearCallingIdentity();
4198 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004199 ImsResolver resolver = PhoneFactory.getImsResolver();
4200 if (resolver == null) {
4201 // may happen if the device does not support IMS.
4202 return null;
4203 }
4204 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004208 }
4209
4210 /**
4211 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4212 * feature during emergency calling or {@link null} if the service is not available. If the
4213 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4214 * listener for feature updates.
4215 */
4216 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4217 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004221 ImsResolver resolver = PhoneFactory.getImsResolver();
4222 if (resolver == null) {
4223 // may happen if the device does not support IMS.
4224 return null;
4225 }
4226 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004230 }
4231
Brad Ebinger5f64b052017-12-14 14:26:15 -08004232 /**
4233 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004234 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004235 */
4236 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4237 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238
4239 final long identity = Binder.clearCallingIdentity();
4240 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004241 ImsResolver resolver = PhoneFactory.getImsResolver();
4242 if (resolver == null) {
4243 // may happen if the device does not support IMS.
4244 return null;
4245 }
4246 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247 } finally {
4248 Binder.restoreCallingIdentity(identity);
4249 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004250 }
4251
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004252 /**
4253 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004254 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004255 */
4256 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4257 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258
4259 final long identity = Binder.clearCallingIdentity();
4260 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004261 ImsResolver resolver = PhoneFactory.getImsResolver();
4262 if (resolver == null) {
4263 // may happen if the device does not support IMS.
4264 return null;
4265 }
4266 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004270 }
4271
Brad Ebinger884c07b2018-02-15 16:17:40 -08004272 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004273 * Sets the ImsService Package Name that Telephony will bind to.
4274 *
4275 * @param slotId the slot ID that the ImsService should bind for.
4276 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4277 * ImsService is the device default ImsService.
4278 * @param packageName The package name of the application that contains the ImsService to bind
4279 * to.
4280 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4281 * @hide
4282 */
4283 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004284 int[] subIds = SubscriptionManager.getSubId(slotId);
4285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4286 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4287 "setImsService");
4288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 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 false;
4295 }
4296 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4297 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004301 }
4302
4303 /**
4304 * Return the ImsService configuration.
4305 *
4306 * @param slotId The slot that the ImsService is associated with.
4307 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4308 * the device default.
4309 * @return the package name of the ImsService configuration.
4310 */
4311 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004312 int[] subIds = SubscriptionManager.getSubId(slotId);
4313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4314 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4315 "getImsService");
4316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317 final long identity = Binder.clearCallingIdentity();
4318 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004319 ImsResolver resolver = PhoneFactory.getImsResolver();
4320 if (resolver == null) {
4321 // may happen if the device does not support IMS.
4322 return "";
4323 }
4324 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004328 }
4329
Wink Saville36469e72014-06-11 15:17:00 -07004330 public void setImsRegistrationState(boolean registered) {
4331 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332
4333 final long identity = Binder.clearCallingIdentity();
4334 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004335 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
Wink Saville36469e72014-06-11 15:17:00 -07004339 }
4340
4341 /**
Stuart Scott54788802015-03-30 13:18:01 -07004342 * Set the network selection mode to automatic.
4343 *
4344 */
4345 @Override
4346 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4348 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349
Pengquan Menge92a50d2018-09-21 15:54:48 -07004350 if (!isActiveSubscription(subId)) {
4351 return;
4352 }
4353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004354 final long identity = Binder.clearCallingIdentity();
4355 try {
4356 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4357 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
Stuart Scott54788802015-03-30 13:18:01 -07004361 }
4362
Pengquan Mengea84e042018-09-20 14:57:26 -07004363 /**
4364 * Ask the radio to connect to the input network and change selection mode to manual.
4365 *
4366 * @param subId the id of the subscription.
4367 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4368 * the operator to attach to.
4369 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4370 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4371 * normal network selection next time.
4372 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004373 */
4374 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004375 public boolean setNetworkSelectionModeManual(
4376 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4378 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004379
4380 if (!isActiveSubscription(subId)) {
4381 return false;
4382 }
4383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384 final long identity = Binder.clearCallingIdentity();
4385 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004386 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004388 if (DBG) {
4389 log("setNetworkSelectionModeManual: subId: " + subId
4390 + " operator: " + operatorInfo);
4391 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4393 } finally {
4394 Binder.restoreCallingIdentity(identity);
4395 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004396 }
4397
4398 /**
4399 * Scans for available networks.
4400 */
4401 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004402 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4404 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004405 LocationAccessPolicy.LocationPermissionResult locationResult =
4406 LocationAccessPolicy.checkLocationPermission(mApp,
4407 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4408 .setCallingPackage(callingPackage)
4409 .setCallingPid(Binder.getCallingPid())
4410 .setCallingUid(Binder.getCallingUid())
4411 .setMethod("getCellNetworkScanResults")
4412 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4413 .build());
4414 switch (locationResult) {
4415 case DENIED_HARD:
4416 throw new SecurityException("Not allowed to access scan results -- location");
4417 case DENIED_SOFT:
4418 return null;
4419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420
Pengquan Menga1bb6272018-09-06 09:59:22 -07004421 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 try {
4423 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004424 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004425 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 } finally {
4427 Binder.restoreCallingIdentity(identity);
4428 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004429 }
4430
4431 /**
yinxub1bed742017-04-17 11:45:04 -07004432 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004433 *
yinxub1bed742017-04-17 11:45:04 -07004434 * @param subId id of the subscription
4435 * @param request contains the radio access networks with bands/channels to scan
4436 * @param messenger callback messenger for scan results or errors
4437 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004438 * @return the id of the requested scan which can be used to stop the scan.
4439 */
4440 @Override
4441 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004442 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4444 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004445 LocationAccessPolicy.LocationPermissionResult locationResult =
4446 LocationAccessPolicy.checkLocationPermission(mApp,
4447 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4448 .setCallingPackage(callingPackage)
4449 .setCallingPid(Binder.getCallingPid())
4450 .setCallingUid(Binder.getCallingUid())
4451 .setMethod("requestNetworkScan")
4452 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4453 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004454 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004455 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004456 if (e != null) {
4457 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4458 throw e;
4459 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004460 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004461 return TelephonyScanManager.INVALID_SCAN_ID;
4462 }
4463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004464 }
Hall Liu912dfd32019-04-25 14:02:26 -07004465 int callingUid = Binder.getCallingUid();
4466 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004467 final long identity = Binder.clearCallingIdentity();
4468 try {
4469 return mNetworkScanRequestTracker.startNetworkScan(
4470 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004471 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
yinxu504e1392017-04-12 16:03:22 -07004475 }
4476
Hall Liub2ac8ef2019-02-28 15:56:23 -08004477 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004478 NetworkScanRequest request, int subId) {
4479 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4480 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4481 boolean hasNetworkScanPermission =
4482 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4483 == PERMISSION_GRANTED;
4484
4485 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4486 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4487 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004488 }
4489
4490 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4491 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004492 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4493 return new SecurityException("Specific channels must not be"
4494 + " scanned without location access.");
4495 }
4496 }
4497 }
4498
Hall Liub2ac8ef2019-02-28 15:56:23 -08004499 return null;
4500 }
4501
yinxu504e1392017-04-12 16:03:22 -07004502 /**
4503 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004504 *
4505 * @param subId id of the subscription
4506 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004507 */
4508 @Override
4509 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4511 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512
Hall Liu912dfd32019-04-25 14:02:26 -07004513 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 final long identity = Binder.clearCallingIdentity();
4515 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004516 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
yinxu504e1392017-04-12 16:03:22 -07004520 }
4521
4522 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004523 * Get the calculated preferred network type.
4524 * Used for debugging incorrect network type.
4525 *
4526 * @return the preferred network type, defined in RILConstants.java.
4527 */
4528 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004529 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004530 final Phone defaultPhone = getDefaultPhone();
4531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4532 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004533 return RILConstants.PREFERRED_NETWORK_MODE;
4534 }
4535
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004536 final long identity = Binder.clearCallingIdentity();
4537 try {
4538 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004539 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
Junda Liu84d15a22014-07-02 11:21:04 -07004543 }
4544
4545 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004546 * Get the preferred network type.
4547 * Used for device configuration by some CDMA operators.
4548 *
4549 * @return the preferred network type, defined in RILConstants.java.
4550 */
4551 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004552 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004553 TelephonyPermissions
4554 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4555 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556
4557 final long identity = Binder.clearCallingIdentity();
4558 try {
4559 if (DBG) log("getPreferredNetworkType");
4560 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4561 int networkType = (result != null ? result[0] : -1);
4562 if (DBG) log("getPreferredNetworkType: " + networkType);
4563 return networkType;
4564 } finally {
4565 Binder.restoreCallingIdentity(identity);
4566 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004567 }
4568
4569 /**
4570 * Set the preferred network type.
4571 * Used for device configuration by some CDMA operators.
4572 *
4573 * @param networkType the preferred network type, defined in RILConstants.java.
4574 * @return true on success; false on any failure.
4575 */
4576 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004577 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4579 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004580
4581 final long identity = Binder.clearCallingIdentity();
4582 try {
4583 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4584 Boolean success = (Boolean) sendRequest(
4585 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4586 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4587 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004588 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4590 }
4591 return success;
4592 } finally {
4593 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004594 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004595 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004596
4597 /**
Miaoa84611c2019-03-15 09:21:10 +08004598 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004599 *
Miaoa84611c2019-03-15 09:21:10 +08004600 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004601 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004602 * @hide
4603 */
4604 @Override
Miaoa84611c2019-03-15 09:21:10 +08004605 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004606 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004608 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004609 try {
Miaoa84611c2019-03-15 09:21:10 +08004610 if (phone != null) {
4611 return phone.hasMatchedTetherApnSetting();
4612 } else {
4613 return false;
4614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 } finally {
4616 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004617 }
Junda Liu475951f2014-11-07 16:45:03 -08004618 }
4619
4620 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004621 * Set mobile data enabled
4622 * Used by the user through settings etc to turn on/off mobile data
4623 *
4624 * @param enable {@code true} turn turn data on, else {@code false}
4625 */
4626 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004627 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4629 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630
4631 final long identity = Binder.clearCallingIdentity();
4632 try {
4633 int phoneId = mSubscriptionController.getPhoneId(subId);
4634 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4635 Phone phone = PhoneFactory.getPhone(phoneId);
4636 if (phone != null) {
4637 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004638 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004639 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004640 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 }
4642 } finally {
4643 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004644 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004645 }
4646
4647 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004648 * Get the user enabled state of Mobile Data.
4649 *
4650 * TODO: remove and use isUserDataEnabled.
4651 * This can't be removed now because some vendor codes
4652 * calls through ITelephony directly while they should
4653 * use TelephonyManager.
4654 *
4655 * @return true on enabled
4656 */
4657 @Override
4658 public boolean getDataEnabled(int subId) {
4659 return isUserDataEnabled(subId);
4660 }
4661
4662 /**
4663 * Get whether mobile data is enabled per user setting.
4664 *
4665 * There are other factors deciding whether mobile data is actually enabled, but they are
4666 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004667 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004668 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004669 *
4670 * @return {@code true} if data is enabled else {@code false}
4671 */
4672 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004673 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004674 try {
4675 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4676 null);
4677 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4679 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681
4682 final long identity = Binder.clearCallingIdentity();
4683 try {
4684 int phoneId = mSubscriptionController.getPhoneId(subId);
4685 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4686 Phone phone = PhoneFactory.getPhone(phoneId);
4687 if (phone != null) {
4688 boolean retVal = phone.isUserDataEnabled();
4689 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4690 return retVal;
4691 } else {
4692 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4693 return false;
4694 }
4695 } finally {
4696 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004697 }
4698 }
4699
4700 /**
4701 * Get whether mobile data is enabled.
4702 *
4703 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4704 * whether mobile data is actually enabled.
4705 *
4706 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4707 *
4708 * @return {@code true} if data is enabled else {@code false}
4709 */
4710 @Override
4711 public boolean isDataEnabled(int subId) {
4712 try {
4713 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4714 null);
4715 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4717 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719
4720 final long identity = Binder.clearCallingIdentity();
4721 try {
4722 int phoneId = mSubscriptionController.getPhoneId(subId);
4723 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4724 Phone phone = PhoneFactory.getPhone(phoneId);
4725 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004726 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4728 return retVal;
4729 } else {
4730 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4731 return false;
4732 }
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004735 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004736 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004737
4738 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004739 public int getCarrierPrivilegeStatus(int subId) {
4740 final Phone phone = getPhone(subId);
4741 if (phone == null) {
4742 loge("getCarrierPrivilegeStatus: Invalid subId");
4743 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4744 }
4745 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004746 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004747 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004748 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4749 }
4750 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004751 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004752 }
Junda Liu29340342014-07-10 15:23:27 -07004753
4754 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004755 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4756 final Phone phone = getPhone(subId);
4757 if (phone == null) {
4758 loge("getCarrierPrivilegeStatus: Invalid subId");
4759 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4760 }
4761 UiccProfile profile =
4762 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4763 if (profile == null) {
4764 loge("getCarrierPrivilegeStatus: No UICC");
4765 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4766 }
4767 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4768 }
4769
4770 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004771 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4772 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004773 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004774 }
4775
4776 int phoneId = SubscriptionManager.getPhoneId(subId);
4777 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004778 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004779 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004780 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4781 }
chen xuf7e9fe82019-05-09 19:31:02 -07004782
4783 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004784 }
4785
4786 @Override
4787 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004788 if (TextUtils.isEmpty(pkgName))
4789 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004790 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4791 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4792 UiccCard card = UiccController.getInstance().getUiccCard(i);
4793 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004794 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004795 continue;
4796 }
4797
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004798 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004799 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4800 break;
4801 }
4802 }
4803
4804 return result;
Junda Liu29340342014-07-10 15:23:27 -07004805 }
Derek Tan89e89d42014-07-08 17:00:10 -07004806
4807 @Override
Junda Liue64de782015-04-16 17:19:16 -07004808 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4809 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4810 loge("phoneId " + phoneId + " is not valid.");
4811 return null;
4812 }
4813 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004814 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004815 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004816 return null ;
4817 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004818 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004819 }
4820
Amith Yamasani6e118872016-02-19 12:53:51 -08004821 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004822 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004823 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004824 List<String> privilegedPackages = new ArrayList<>();
4825 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004826 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4827 // has UICC in that slot.
4828 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004829 if (card.hasCarrierPrivilegeRules()) {
4830 if (packages == null) {
4831 // Only check packages in user 0 for now
4832 packages = pm.getInstalledPackagesAsUser(
4833 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07004834 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4835 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004836 }
4837 for (int p = packages.size() - 1; p >= 0; p--) {
4838 PackageInfo pkgInfo = packages.get(p);
4839 if (pkgInfo != null && pkgInfo.packageName != null
4840 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004841 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004842 privilegedPackages.add(pkgInfo.packageName);
4843 }
4844 }
4845 }
4846 }
4847 return privilegedPackages;
4848 }
4849
chen xuf7e9fe82019-05-09 19:31:02 -07004850 @Override
4851 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4852 List<String> privilegedPackages = new ArrayList<>();
4853 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4854 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4855 }
4856 return privilegedPackages;
4857 }
4858
Wink Savilleb564aae2014-10-23 10:18:09 -07004859 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004860 final Phone phone = getPhone(subId);
4861 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004862 if (card == null) {
4863 loge("getIccId: No UICC");
4864 return null;
4865 }
4866 String iccId = card.getIccId();
4867 if (TextUtils.isEmpty(iccId)) {
4868 loge("getIccId: ICC ID is null or empty.");
4869 return null;
4870 }
4871 return iccId;
4872 }
4873
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004874 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004875 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4876 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004877 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4878 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 final long identity = Binder.clearCallingIdentity();
4881 try {
4882 final String iccId = getIccId(subId);
4883 final Phone phone = getPhone(subId);
4884 if (phone == null) {
4885 return false;
4886 }
4887 final String subscriberId = phone.getSubscriberId();
4888
4889 if (DBG_MERGE) {
4890 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4891 + subscriberId + " to " + number);
4892 }
4893
4894 if (TextUtils.isEmpty(iccId)) {
4895 return false;
4896 }
4897
4898 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4899
4900 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4901 if (alphaTag == null) {
4902 editor.remove(alphaTagPrefKey);
4903 } else {
4904 editor.putString(alphaTagPrefKey, alphaTag);
4905 }
4906
4907 // Record both the line number and IMSI for this ICCID, since we need to
4908 // track all merged IMSIs based on line number
4909 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4910 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4911 if (number == null) {
4912 editor.remove(numberPrefKey);
4913 editor.remove(subscriberPrefKey);
4914 } else {
4915 editor.putString(numberPrefKey, number);
4916 editor.putString(subscriberPrefKey, subscriberId);
4917 }
4918
4919 editor.commit();
4920 return true;
4921 } finally {
4922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004923 }
Derek Tan7226c842014-07-02 17:42:23 -07004924 }
4925
4926 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004927 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004928 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004930 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004931 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004932 return null;
4933 }
Derek Tan97ebb422014-09-05 16:55:38 -07004934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 final long identity = Binder.clearCallingIdentity();
4936 try {
4937 String iccId = getIccId(subId);
4938 if (iccId != null) {
4939 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4940 if (DBG_MERGE) {
4941 log("getLine1NumberForDisplay returning "
4942 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4943 }
4944 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4947 return null;
4948 } finally {
4949 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004950 }
Derek Tan7226c842014-07-02 17:42:23 -07004951 }
4952
4953 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004954 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004956 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004957 return null;
4958 }
Derek Tan97ebb422014-09-05 16:55:38 -07004959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 final long identity = Binder.clearCallingIdentity();
4961 try {
4962 String iccId = getIccId(subId);
4963 if (iccId != null) {
4964 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4965 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4966 }
4967 return null;
4968 } finally {
4969 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004970 }
Derek Tan7226c842014-07-02 17:42:23 -07004971 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004972
4973 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07004974 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004975 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4976 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004978 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4979 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004980 return null;
4981 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004982
Jordan Liub49b04b2019-05-06 14:45:15 -07004983 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4984 // the process, where TelephonyManager was instantiated.
4985 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004986 final long identity = Binder.clearCallingIdentity();
4987 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004988 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 final TelephonyManager tele = TelephonyManager.from(context);
4990 final SubscriptionManager sub = SubscriptionManager.from(context);
4991
4992 // Figure out what subscribers are currently active
4993 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994
Jordan Liub49b04b2019-05-06 14:45:15 -07004995 // Only consider subs which match the current subId
4996 // This logic can be simplified. See b/131189269 for progress.
4997 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004998 activeSubscriberIds.add(tele.getSubscriberId(subId));
4999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000
5001 // First pass, find a number override for an active subscriber
5002 String mergeNumber = null;
5003 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5004 for (String key : prefs.keySet()) {
5005 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5006 final String subscriberId = (String) prefs.get(key);
5007 if (activeSubscriberIds.contains(subscriberId)) {
5008 final String iccId = key.substring(
5009 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5010 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5011 mergeNumber = (String) prefs.get(numberKey);
5012 if (DBG_MERGE) {
5013 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5014 + " for active subscriber " + subscriberId);
5015 }
5016 if (!TextUtils.isEmpty(mergeNumber)) {
5017 break;
5018 }
5019 }
5020 }
5021 }
5022
5023 // Shortcut when no active merged subscribers
5024 if (TextUtils.isEmpty(mergeNumber)) {
5025 return null;
5026 }
5027
5028 // Second pass, find all subscribers under that line override
5029 final ArraySet<String> result = new ArraySet<>();
5030 for (String key : prefs.keySet()) {
5031 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5032 final String number = (String) prefs.get(key);
5033 if (mergeNumber.equals(number)) {
5034 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5035 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5036 final String subscriberId = (String) prefs.get(subscriberKey);
5037 if (!TextUtils.isEmpty(subscriberId)) {
5038 result.add(subscriberId);
5039 }
5040 }
5041 }
5042 }
5043
5044 final String[] resultArray = result.toArray(new String[result.size()]);
5045 Arrays.sort(resultArray);
5046 if (DBG_MERGE) {
5047 Slog.d(LOG_TAG,
5048 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5049 }
5050 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005051 } finally {
5052 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005053 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005054 }
5055
5056 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005057 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005058 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5059 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005060
5061 final long identity = Binder.clearCallingIdentity();
5062 try {
5063 final Phone phone = getPhone(subId);
5064 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5065 } finally {
5066 Binder.restoreCallingIdentity(identity);
5067 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005068 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005069
5070 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005071 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005072 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5073 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005074 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005075
5076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 final Phone phone = getPhone(subId);
5079 if (phone == null) {
5080 return false;
5081 }
5082 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5083 cdmaNonRoamingList);
5084 } finally {
5085 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005086 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005087 }
5088
5089 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005090 @Deprecated
5091 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5092 enforceModifyPermission();
5093
5094 int returnValue = 0;
5095 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005096 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005097 if(result.exception == null) {
5098 if (result.result != null) {
5099 byte[] responseData = (byte[])(result.result);
5100 if(responseData.length > oemResp.length) {
5101 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5102 responseData.length + "bytes. Buffer Size is " +
5103 oemResp.length + "bytes.");
5104 }
5105 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5106 returnValue = responseData.length;
5107 }
5108 } else {
5109 CommandException ex = (CommandException) result.exception;
5110 returnValue = ex.getCommandError().ordinal();
5111 if(returnValue > 0) returnValue *= -1;
5112 }
5113 } catch (RuntimeException e) {
5114 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5115 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5116 if(returnValue > 0) returnValue *= -1;
5117 }
5118
5119 return returnValue;
5120 }
5121
5122 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005123 public void setRadioCapability(RadioAccessFamily[] rafs) {
5124 try {
5125 ProxyController.getInstance().setRadioCapability(rafs);
5126 } catch (RuntimeException e) {
5127 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5128 }
5129 }
5130
5131 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005132 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005133 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005134 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005135 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005136 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 final long identity = Binder.clearCallingIdentity();
5139 try {
chen xub97461a2018-10-26 14:17:57 -07005140 TelephonyPermissions
5141 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5142 mApp, phone.getSubId(), "getRadioAccessFamily");
5143 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
chen xub97461a2018-10-26 14:17:57 -07005147 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005148 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005149
5150 @Override
5151 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005152 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005153 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154
5155 final long identity = Binder.clearCallingIdentity();
5156 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005157 ImsManager.getInstance(defaultPhone.getContext(),
5158 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005162 }
5163
5164 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005165 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005166 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005168 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005169 return false;
5170 }
Svet Ganovb320e182015-04-16 12:30:10 -07005171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 final long identity = Binder.clearCallingIdentity();
5173 try {
5174 // Check the user preference and the system-level IMS setting. Even if the user has
5175 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5176 // In the long run, we may instead need to check if there exists a connection service
5177 // which can support video calling.
5178 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005179 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 return imsManager.isVtEnabledByPlatform()
5181 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5182 && imsManager.isVtEnabledByUser();
5183 } finally {
5184 Binder.restoreCallingIdentity(identity);
5185 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005186 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005187
Andrew Leea1239f22015-03-02 17:44:07 -08005188 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5191 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5192 return false;
5193 }
5194
5195 final long identity = Binder.clearCallingIdentity();
5196 try {
5197 CarrierConfigManager configManager =
5198 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005199 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
Andrew Leea1239f22015-03-02 17:44:07 -08005204 }
5205
5206 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 public boolean isWorldPhone(int subId, String callingPackage) {
5208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5209 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5210 return false;
5211 }
5212
5213 final long identity = Binder.clearCallingIdentity();
5214 try {
5215 CarrierConfigManager configManager =
5216 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005217 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5219 } finally {
5220 Binder.restoreCallingIdentity(identity);
5221 }
Andrew Leea1239f22015-03-02 17:44:07 -08005222 }
5223
Andrew Lee9431b832015-03-09 18:46:45 -07005224 @Override
5225 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005226 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005227 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005228 }
5229
5230 @Override
5231 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 final long identity = Binder.clearCallingIdentity();
5233 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005234 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
Andrew Lee9431b832015-03-09 18:46:45 -07005238 }
5239
Hall Liuf6668912018-10-31 17:05:23 -07005240 /**
5241 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5242 * support for the feature and device firmware support.
5243 *
5244 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5245 */
5246 @Override
5247 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005249 final Phone phone = getPhone(subscriptionId);
5250 if (phone == null) {
5251 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5252 return false;
5253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005255 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5257 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005258 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 return isCarrierSupported && isDeviceSupported;
5260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
Hall Liu98187582018-01-22 19:15:32 -08005263 }
5264
Hall Liuf6668912018-10-31 17:05:23 -07005265 /**
5266 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5267 * both also support RTT.
5268 */
5269 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 final long identity = Binder.clearCallingIdentity();
5271 try {
Hall Liuf6668912018-10-31 17:05:23 -07005272 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005273 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005277 }
5278
Sanket Padawe7310cc72015-01-14 09:53:20 -08005279 /**
5280 * Returns the unique device ID of phone, for example, the IMEI for
5281 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5282 *
5283 * <p>Requires Permission:
5284 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5285 */
5286 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005287 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005288 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005289 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005290 return null;
5291 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005292 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005293 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5294 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005295 return null;
5296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297
5298 final long identity = Binder.clearCallingIdentity();
5299 try {
5300 return phone.getDeviceId();
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
5303 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005304 }
5305
Ping Sunc67b7c22016-03-02 19:16:45 +08005306 /**
5307 * {@hide}
5308 * Returns the IMS Registration Status on a particular subid
5309 *
5310 * @param subId
5311 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005312 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005313 Phone phone = getPhone(subId);
5314 if (phone != null) {
5315 return phone.isImsRegistered();
5316 } else {
5317 return false;
5318 }
5319 }
5320
Santos Cordon7a1885b2015-02-03 11:15:19 -08005321 @Override
5322 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 final long identity = Binder.clearCallingIdentity();
5324 try {
5325 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005329 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005330
Tyler Gunnf70ed162019-04-03 15:28:53 -07005331 @Override
5332 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5333 final long identity = Binder.clearCallingIdentity();
5334 try {
5335 Phone phone = getPhone(subscriptionId);
5336 if (phone == null) {
5337 return null;
5338 }
5339 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
5342 }
5343 }
5344
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005345 /**
5346 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005347 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005348 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349 final long identity = Binder.clearCallingIdentity();
5350 try {
5351 Phone phone = getPhone(subId);
5352 if (phone != null) {
5353 return phone.isWifiCallingEnabled();
5354 } else {
5355 return false;
5356 }
5357 } finally {
5358 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005359 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005360 }
5361
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005362 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005363 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005364 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005365 public boolean isVideoTelephonyAvailable(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.isVideoEnabled();
5371 } else {
5372 return false;
5373 }
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005376 }
5377 }
5378
5379 /**
5380 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5381 * defined in {@link ImsRegistrationImplBase}.
5382 */
5383 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 final long identity = Binder.clearCallingIdentity();
5385 try {
5386 Phone phone = getPhone(subId);
5387 if (phone != null) {
5388 return phone.getImsRegistrationTech();
5389 } else {
5390 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5391 }
5392 } finally {
5393 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005394 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005395 }
5396
Stuart Scott8eef64f2015-04-08 15:13:54 -07005397 @Override
5398 public void factoryReset(int subId) {
5399 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005400 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5401 return;
5402 }
5403
Svet Ganovcc087f82015-05-12 20:35:54 -07005404 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005405
Svet Ganovcc087f82015-05-12 20:35:54 -07005406 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005407 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5408 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005409 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005410 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005411 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005412 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5413 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005414 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005415 // There has been issues when Sms raw table somehow stores orphan
5416 // fragments. They lead to garbled message when new fragments come
5417 // in and combined with those stale ones. In case this happens again,
5418 // user can reset all network settings which will clean up this table.
5419 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005420 } finally {
5421 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005422 }
5423 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005424
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005425 private void cleanUpSmsRawTable(Context context) {
5426 ContentResolver resolver = context.getContentResolver();
5427 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5428 resolver.delete(uri, null, null);
5429 }
5430
Narayan Kamath1c496c22015-04-16 14:40:19 +01005431 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005432 public String getSimLocaleForSubscriber(int subId) {
5433 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5434 final Phone phone = getPhone(subId);
5435 if (phone == null) {
5436 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005437 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 final long identity = Binder.clearCallingIdentity();
5440 try {
chen xu5d3637b2019-01-21 23:31:38 -08005441 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5442 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005443 if (info == null) {
5444 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5445 return null;
5446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 // Try and fetch the locale from the carrier properties or from the SIM language
5448 // preferences (EF-PL and EF-LI)...
5449 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005451 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5452 if (localeFromDefaultSim != null) {
5453 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5454 if (DBG) log("Using locale from subId: " + subId + " locale: "
5455 + localeFromDefaultSim);
5456 return localeFromDefaultSim.toLanguageTag();
5457 } else {
5458 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 }
5460 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462 // The SIM language preferences only store a language (e.g. fr = French), not an
5463 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5464 // the SIM and carrier preferences does not include a country we add the country
5465 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005466 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005468 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 return mccLocale.toLanguageTag();
5470 }
5471
5472 if (DBG) log("No locale found - returning null");
5473 return null;
5474 } finally {
5475 Binder.restoreCallingIdentity(identity);
5476 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005477 }
5478
5479 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005480 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005481 }
5482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 /**
5484 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5485 */
5486 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005487 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005488 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005489
Chenjie Yu1ba97252018-01-11 18:16:20 -08005490 private final ModemActivityInfo mLastModemActivityInfo =
5491 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5492
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005493 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005494 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5495 * representing the state of the modem.
5496 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005497 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5498 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005499 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005500 */
5501 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005502 public void requestModemActivityInfo(ResultReceiver result) {
5503 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005504 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505
5506 final long identity = Binder.clearCallingIdentity();
5507 try {
5508 ModemActivityInfo ret = null;
5509 synchronized (mLastModemActivityInfo) {
5510 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5511 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005512 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005513 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5515 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005516 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5517 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 }
5519 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005520 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5521 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 mLastModemActivityInfo.setIdleTimeMillis(
5523 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5524 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5525 mLastModemActivityInfo.setRxTimeMillis(
5526 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5527 mLastModemActivityInfo.setEnergyUsed(
5528 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5531 mLastModemActivityInfo.getSleepTimeMillis(),
5532 mLastModemActivityInfo.getIdleTimeMillis(),
5533 mLastModemActivityInfo.getTxTimeMillis(),
5534 mLastModemActivityInfo.getRxTimeMillis(),
5535 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005537 Bundle bundle = new Bundle();
5538 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5539 result.send(0, bundle);
5540 } finally {
5541 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005542 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005543 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005544
Siddharth Rayb8114062018-06-17 15:02:38 -07005545 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5546 // less than total activity duration.
5547 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5548 if (info == null) {
5549 return false;
5550 }
5551 int activityDurationMs =
5552 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5553 int totalTxTimeMs = 0;
5554 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5555 totalTxTimeMs += info.getTxTimeMillis()[i];
5556 }
5557 return (info.isValid()
5558 && (info.getSleepTimeMillis() <= activityDurationMs)
5559 && (info.getIdleTimeMillis() <= activityDurationMs)
5560 && (info.getRxTimeMillis() <= activityDurationMs)
5561 && (totalTxTimeMs <= activityDurationMs));
5562 }
5563
Jack Yu85bd38a2015-11-09 11:34:32 -08005564 /**
5565 * {@hide}
5566 * Returns the service state information on specified subscription.
5567 */
5568 @Override
5569 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005571 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005572 return null;
5573 }
5574
Hall Liuf19c44f2018-11-27 14:38:17 -08005575 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5576 LocationAccessPolicy.checkLocationPermission(mApp,
5577 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5578 .setCallingPackage(callingPackage)
5579 .setCallingPid(Binder.getCallingPid())
5580 .setCallingUid(Binder.getCallingUid())
5581 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005582 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005583 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5584 .build());
5585
5586 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5587 LocationAccessPolicy.checkLocationPermission(mApp,
5588 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5589 .setCallingPackage(callingPackage)
5590 .setCallingPid(Binder.getCallingPid())
5591 .setCallingUid(Binder.getCallingUid())
5592 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005593 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005594 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5595 .build());
5596 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5597 boolean hasFinePermission =
5598 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5599 boolean hasCoarsePermission =
5600 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602 final long identity = Binder.clearCallingIdentity();
5603 try {
5604 final Phone phone = getPhone(subId);
5605 if (phone == null) {
5606 return null;
5607 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005608
Hall Liuf19c44f2018-11-27 14:38:17 -08005609 ServiceState ss = phone.getServiceState();
5610
5611 // Scrub out the location info in ServiceState depending on what level of access
5612 // the caller has.
5613 if (hasFinePermission) return ss;
5614 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5615 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616 } finally {
5617 Binder.restoreCallingIdentity(identity);
5618 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005619 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005620
5621 /**
5622 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5623 *
5624 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5625 * voicemail ringtone.
5626 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5627 * PhoneAccount.
5628 */
5629 @Override
5630 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005631 final long identity = Binder.clearCallingIdentity();
5632 try {
5633 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5634 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005635 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5639 } finally {
5640 Binder.restoreCallingIdentity(identity);
5641 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005642 }
5643
5644 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005645 * Sets the per-account voicemail ringtone.
5646 *
5647 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5648 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5649 *
5650 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5651 * voicemail ringtone.
5652 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5653 * PhoneAccount.
5654 */
5655 @Override
5656 public void setVoicemailRingtoneUri(String callingPackage,
5657 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005658 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005659 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5660 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005661 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5663 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5664 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
5669 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5670 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005671 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 }
5673 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5674 } finally {
5675 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005676 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005677 }
5678
5679 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005680 * Returns whether vibration is set for voicemail notification in Phone settings.
5681 *
5682 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5683 * voicemail vibration setting.
5684 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5685 */
5686 @Override
5687 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 final long identity = Binder.clearCallingIdentity();
5689 try {
5690 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5691 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005692 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005699 }
5700
Youhan Wange64578a2016-05-02 15:32:42 -07005701 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005702 * Sets the per-account voicemail vibration.
5703 *
5704 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5705 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5706 *
5707 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5708 * voicemail vibration setting.
5709 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5710 * specific PhoneAccount.
5711 */
5712 @Override
5713 public void setVoicemailVibrationEnabled(String callingPackage,
5714 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005715 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005716 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5717 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005718 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5720 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5721 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005722 }
5723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 final long identity = Binder.clearCallingIdentity();
5725 try {
5726 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5727 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005728 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 }
5730 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5731 } finally {
5732 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005733 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005734 }
5735
5736 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005737 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5738 *
5739 * @throws SecurityException if the caller does not have the required permission
5740 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005741 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005742 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005743 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005744 }
5745
5746 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005747 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5748 * permission.
5749 *
5750 * @throws SecurityException if the caller does not have the required permission
5751 */
5752 private void enforceSendSmsPermission() {
5753 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5754 }
5755
5756 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005757 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005758 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005759 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005760 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005761 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 final long identity = Binder.clearCallingIdentity();
5763 try {
5764 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005765 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 if (componentName == null) {
5767 throw new SecurityException(
5768 "Caller not current active visual voicemail package[null]");
5769 }
5770 String vvmPackage = componentName.getPackageName();
5771 if (!callingPackage.equals(vvmPackage)) {
5772 throw new SecurityException("Caller not current active visual voicemail package["
5773 + vvmPackage + "]");
5774 }
5775 } finally {
5776 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005777 }
5778 }
5779
5780 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005781 * Return the application ID for the app type.
5782 *
5783 * @param subId the subscription ID that this request applies to.
5784 * @param appType the uicc app type.
5785 * @return Application ID for specificied app type, or null if no uicc.
5786 */
5787 @Override
5788 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005789 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005790 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791
5792 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005793 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 if (phone == null) {
5795 return null;
5796 }
5797 String aid = null;
5798 try {
5799 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5800 .getApplicationByType(appType).getAid();
5801 } catch (Exception e) {
5802 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5803 }
5804 return aid;
5805 } finally {
5806 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005807 }
Youhan Wange64578a2016-05-02 15:32:42 -07005808 }
5809
Youhan Wang4001d252016-05-11 10:29:41 -07005810 /**
5811 * Return the Electronic Serial Number.
5812 *
5813 * @param subId the subscription ID that this request applies to.
5814 * @return ESN or null if error.
5815 */
5816 @Override
5817 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005818 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005819 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820
5821 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005822 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 if (phone == null) {
5824 return null;
5825 }
5826 String esn = null;
5827 try {
5828 esn = phone.getEsn();
5829 } catch (Exception e) {
5830 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5831 }
5832 return esn;
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005835 }
Youhan Wang4001d252016-05-11 10:29:41 -07005836 }
5837
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005838 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005839 * Return the Preferred Roaming List Version.
5840 *
5841 * @param subId the subscription ID that this request applies to.
5842 * @return PRLVersion or null if error.
5843 */
5844 @Override
5845 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005846 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005847 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848
5849 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005850 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 if (phone == null) {
5852 return null;
5853 }
5854 String cdmaPrlVersion = null;
5855 try {
5856 cdmaPrlVersion = phone.getCdmaPrlVersion();
5857 } catch (Exception e) {
5858 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5859 }
5860 return cdmaPrlVersion;
5861 } finally {
5862 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005863 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005864 }
5865
5866 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005867 * Get snapshot of Telephony histograms
5868 * @return List of Telephony histograms
5869 * @hide
5870 */
5871 @Override
5872 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5874 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875
5876 final long identity = Binder.clearCallingIdentity();
5877 try {
5878 return RIL.getTelephonyRILTimingHistograms();
5879 } finally {
5880 Binder.restoreCallingIdentity(identity);
5881 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005882 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005883
5884 /**
5885 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005886 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5887 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005888 * Require system privileges. In the future we may add this to carrier APIs.
5889 *
Michele Berionne482f8202018-11-27 18:57:59 -08005890 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005891 */
5892 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005893 @TelephonyManager.SetCarrierRestrictionResult
5894 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005895 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005896 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005897
Michele Berionne482f8202018-11-27 18:57:59 -08005898 if (carrierRestrictionRules == null) {
5899 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005900 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 final long identity = Binder.clearCallingIdentity();
5903 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005904 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005905 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 } finally {
5907 Binder.restoreCallingIdentity(identity);
5908 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005909 }
5910
5911 /**
5912 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005913 * Get the allowed carrier list and the excluded carrier list, including the priority between
5914 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005915 * Require system privileges. In the future we may add this to carrier APIs.
5916 *
Michele Berionne482f8202018-11-27 18:57:59 -08005917 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005918 */
5919 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005920 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005921 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005922 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923
5924 final long identity = Binder.clearCallingIdentity();
5925 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005926 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5927 if (response instanceof CarrierRestrictionRules) {
5928 return (CarrierRestrictionRules) response;
5929 }
5930 // Response is an Exception of some kind,
5931 // which is signalled to the user as a NULL retval
5932 return null;
5933 } catch (Exception e) {
5934 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5935 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 } finally {
5937 Binder.restoreCallingIdentity(identity);
5938 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005939 }
5940
fionaxu59545b42016-05-25 15:53:37 -07005941 /**
5942 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5943 * @param subId the subscription ID that this action applies to.
5944 * @param enabled control enable or disable metered apns.
5945 * {@hide}
5946 */
5947 @Override
5948 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5949 enforceModifyPermission();
5950 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951
5952 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005953 if (phone == null) {
5954 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5955 return;
5956 }
5957 try {
5958 phone.carrierActionSetMeteredApnsEnabled(enabled);
5959 } catch (Exception e) {
5960 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961 } finally {
5962 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005963 }
5964 }
5965
5966 /**
5967 * Action set from carrier signalling broadcast receivers to enable/disable radio
5968 * @param subId the subscription ID that this action applies to.
5969 * @param enabled control enable or disable radio.
5970 * {@hide}
5971 */
5972 @Override
5973 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5974 enforceModifyPermission();
5975 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976
5977 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005978 if (phone == null) {
5979 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5980 return;
5981 }
5982 try {
5983 phone.carrierActionSetRadioEnabled(enabled);
5984 } catch (Exception e) {
5985 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 } finally {
5987 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005988 }
5989 }
5990
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005991 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005992 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5993 * network status based on which carrier apps could apply actions accordingly,
5994 * enable/disable default url handler for example.
5995 *
5996 * @param subId the subscription ID that this action applies to.
5997 * @param report control start/stop reporting the default network status.
5998 * {@hide}
5999 */
6000 @Override
6001 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6002 enforceModifyPermission();
6003 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004
6005 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006006 if (phone == null) {
6007 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6008 return;
6009 }
6010 try {
6011 phone.carrierActionReportDefaultNetworkStatus(report);
6012 } catch (Exception e) {
6013 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 } finally {
6015 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006016 }
6017 }
6018
6019 /**
fionaxud9622282017-07-17 17:51:30 -07006020 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6021 * @param subId the subscription ID that this action applies to.
6022 * {@hide}
6023 */
6024 @Override
6025 public void carrierActionResetAll(int subId) {
6026 enforceModifyPermission();
6027 final Phone phone = getPhone(subId);
6028 if (phone == null) {
6029 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6030 return;
6031 }
6032 try {
6033 phone.carrierActionResetAll();
6034 } catch (Exception e) {
6035 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6036 }
6037 }
6038
6039 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006040 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6041 * bug report is being generated.
6042 */
6043 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006044 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006045 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6046 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006047 writer.println("Permission Denial: can't dump Phone from pid="
6048 + Binder.getCallingPid()
6049 + ", uid=" + Binder.getCallingUid()
6050 + "without permission "
6051 + android.Manifest.permission.DUMP);
6052 return;
6053 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006054 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006055 }
Jack Yueb89b242016-06-22 13:27:47 -07006056
Brad Ebingerdac2f002018-04-03 15:17:52 -07006057 @Override
6058 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6059 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6060 throws RemoteException {
6061 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6062 }
6063
Jack Yueb89b242016-06-22 13:27:47 -07006064 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006065 * Get aggregated video call data usage since boot.
6066 *
6067 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6068 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006069 * {@hide}
6070 */
6071 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006072 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006073 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6074 null);
6075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 final long identity = Binder.clearCallingIdentity();
6077 try {
6078 // NetworkStatsService keeps tracking the active network interface and identity. It
6079 // records the delta with the corresponding network identity.
6080 // We just return the total video call data usage snapshot since boot.
6081 Phone phone = getPhone(subId);
6082 if (phone != null) {
6083 return phone.getVtDataUsage(perUidStats);
6084 }
6085 return null;
6086 } finally {
6087 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006088 }
Jack Yueb89b242016-06-22 13:27:47 -07006089 }
Jack Yu75ab2952016-07-08 14:29:33 -07006090
6091 /**
6092 * Policy control of data connection. Usually used when data limit is passed.
6093 * @param enabled True if enabling the data, otherwise disabling.
6094 * @param subId Subscription index
6095 * {@hide}
6096 */
6097 @Override
6098 public void setPolicyDataEnabled(boolean enabled, int subId) {
6099 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
6103 Phone phone = getPhone(subId);
6104 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006105 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106 }
6107 } finally {
6108 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006109 }
6110 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006111
6112 /**
6113 * Get Client request stats
6114 * @return List of Client Request Stats
6115 * @hide
6116 */
6117 @Override
6118 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006120 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006121 return null;
6122 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006123 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006124
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125 final long identity = Binder.clearCallingIdentity();
6126 try {
6127 if (phone != null) {
6128 return phone.getClientRequestStats();
6129 }
6130
6131 return null;
6132 } finally {
6133 Binder.restoreCallingIdentity(identity);
6134 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006135 }
6136
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006137 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006138 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006139 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006140 }
Jack Yueb4124c2017-02-16 15:32:43 -08006141
6142 /**
Grace Chen70990072017-03-24 17:21:30 -07006143 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006144 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006145 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006146 * @param state State of SIM (power down, power up, pass through)
6147 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6148 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6149 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006150 *
6151 **/
6152 @Override
Grace Chen70990072017-03-24 17:21:30 -07006153 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006154 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006155 Phone phone = PhoneFactory.getPhone(slotIndex);
6156
vagdeviaf9a5b92018-08-15 16:01:53 -07006157 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 final long identity = Binder.clearCallingIdentity();
6160 try {
6161 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006162 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 }
6164 } finally {
6165 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006166 }
6167 }
Shuo Qiandd210312017-04-12 22:11:33 +00006168
Tyler Gunn65d45c22017-06-05 11:22:26 -07006169 private boolean isUssdApiAllowed(int subId) {
6170 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006171 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006172 if (configManager == null) {
6173 return false;
6174 }
6175 PersistableBundle pb = configManager.getConfigForSubId(subId);
6176 if (pb == null) {
6177 return false;
6178 }
6179 return pb.getBoolean(
6180 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6181 }
6182
Shuo Qiandd210312017-04-12 22:11:33 +00006183 /**
6184 * Check if phone is in emergency callback mode
6185 * @return true if phone is in emergency callback mode
6186 * @param subId sub id
6187 */
goneil9c5f4872017-12-05 14:07:56 -08006188 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006189 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006190 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006191 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192
6193 final long identity = Binder.clearCallingIdentity();
6194 try {
6195 if (phone != null) {
6196 return phone.isInEcm();
6197 } else {
6198 return false;
6199 }
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006202 }
6203 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006204
6205 /**
6206 * Get the current signal strength information for the given subscription.
6207 * Because this information is not updated when the device is in a low power state
6208 * it should not be relied-upon to be current.
6209 * @param subId Subscription index
6210 * @return the most recent cached signal strength info from the modem
6211 */
6212 @Override
6213 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 final long identity = Binder.clearCallingIdentity();
6215 try {
6216 Phone p = getPhone(subId);
6217 if (p == null) {
6218 return null;
6219 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006221 return p.getSignalStrength();
6222 } finally {
6223 Binder.restoreCallingIdentity(identity);
6224 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006225 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006226
Pengquan Meng77b7f132018-08-22 14:49:57 -07006227 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006228 * Get the current modem radio state for the given slot.
6229 * @param slotIndex slot index.
6230 * @param callingPackage the name of the package making the call.
6231 * @return the current radio power state from the modem
6232 */
6233 @Override
6234 public int getRadioPowerState(int slotIndex, String callingPackage) {
6235 Phone phone = PhoneFactory.getPhone(slotIndex);
6236 if (phone != null) {
6237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6238 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6239 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6240 }
6241
6242 final long identity = Binder.clearCallingIdentity();
6243 try {
6244 return phone.getRadioPowerState();
6245 } finally {
6246 Binder.restoreCallingIdentity(identity);
6247 }
6248 }
6249 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6250 }
6251
6252 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006253 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6254 *
6255 * <p>Requires one of the following permissions:
6256 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6257 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6258 * privileges.
6259 *
6260 * @param subId subscription id
6261 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6262 * {@code false}.
6263 */
6264 @Override
6265 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006266 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6267 null /* message */);
6268
Pengquan Menga1bb6272018-09-06 09:59:22 -07006269 boolean isEnabled = false;
6270 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006271 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006272 Phone phone = getPhone(subId);
6273 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006274 } catch (Exception e) {
6275 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6276 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006277 } finally {
6278 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006279 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006280 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006281 }
6282
6283
6284 /**
6285 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6286 *
6287 * <p> Requires permission:
6288 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6289 * privileges.
6290 *
6291 * @param subId subscription id
6292 * @param isEnabled {@code true} means enable, {@code false} means disable.
6293 */
6294 @Override
6295 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6297 mApp, subId, "setDataRoamingEnabled");
6298
Pengquan Menga1bb6272018-09-06 09:59:22 -07006299 final long identity = Binder.clearCallingIdentity();
6300 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006301 Phone phone = getPhone(subId);
6302 if (phone != null) {
6303 phone.setDataRoamingEnabled(isEnabled);
6304 }
6305 } finally {
6306 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006307 }
6308 }
6309
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006310 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006311 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006312 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6313 mApp, subId, "isManualNetworkSelectionAllowed");
6314
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006315 boolean isAllowed = true;
6316 final long identity = Binder.clearCallingIdentity();
6317 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006318 Phone phone = getPhone(subId);
6319 if (phone != null) {
6320 isAllowed = phone.isCspPlmnEnabled();
6321 }
6322 } finally {
6323 Binder.restoreCallingIdentity(identity);
6324 }
6325 return isAllowed;
6326 }
6327
6328 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006329 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liua39e6c12020-03-04 13:59:23 -08006330 try {
6331 PackageManager pm = mApp.getPackageManager();
6332 if (Binder.getCallingUid() != pm.getPackageUid(callingPackage, 0)) {
6333 throw new SecurityException("Calling package " + callingPackage + " does not match "
6334 + "calling UID");
6335 }
6336 } catch (PackageManager.NameNotFoundException e) {
6337 throw new SecurityException("Invalid calling package. e=" + e);
6338 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006339 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006340 try {
6341 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006342 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006343 } catch (SecurityException e) {
6344 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6345 // has carrier privileges on an active UICC
6346 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6347 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006348 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006349 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006350 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006351
6352 final long identity = Binder.clearCallingIdentity();
6353 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006354 UiccController uiccController = UiccController.getInstance();
6355 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006356 if (hasReadPermission) {
6357 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006358 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006359
6360 // Remove private info if the caller doesn't have access
6361 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6362 for (UiccCardInfo cardInfo : cardInfos) {
6363 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6364 // is available
6365 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6366 if (card == null || card.getUiccProfile() == null) {
6367 // assume no access if the card or profile is unavailable
6368 filteredInfos.add(cardInfo.getUnprivileged());
6369 continue;
6370 }
6371 UiccProfile profile = card.getUiccProfile();
6372 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6373 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6374 filteredInfos.add(cardInfo);
6375 } else {
6376 filteredInfos.add(cardInfo.getUnprivileged());
6377 }
6378 }
6379 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
6383 }
6384
6385 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006386 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006387 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 final long identity = Binder.clearCallingIdentity();
6390 try {
6391 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6392 if (slots == null) {
6393 Rlog.i(LOG_TAG, "slots is null.");
6394 return null;
6395 }
6396
6397 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6398 for (int i = 0; i < slots.length; i++) {
6399 UiccSlot slot = slots[i];
6400 if (slot == null) {
6401 continue;
6402 }
6403
Jordan Liu7be7e652019-05-06 18:55:02 +00006404 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 UiccCard card = slot.getUiccCard();
6406 if (card != null) {
6407 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006408 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409 cardId = slot.getIccId();
6410 }
6411
6412 int cardState = 0;
6413 switch (slot.getCardState()) {
6414 case CARDSTATE_ABSENT:
6415 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6416 break;
6417 case CARDSTATE_PRESENT:
6418 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6419 break;
6420 case CARDSTATE_ERROR:
6421 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6422 break;
6423 case CARDSTATE_RESTRICTED:
6424 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6425 break;
6426 default:
6427 break;
6428
6429 }
6430
6431 infos[i] = new UiccSlotInfo(
6432 slot.isActive(),
6433 slot.isEuicc(),
6434 cardId,
6435 cardState,
6436 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006437 slot.isExtendedApduSupported(),
6438 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 }
6440 return infos;
6441 } finally {
6442 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006443 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006444 }
6445
6446 @Override
6447 public boolean switchSlots(int[] physicalSlots) {
6448 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449
6450 final long identity = Binder.clearCallingIdentity();
6451 try {
6452 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
6455 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006456 }
Jack Yu4c988042018-02-27 15:30:01 -08006457
6458 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006459 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006460 final long identity = Binder.clearCallingIdentity();
6461 try {
6462 return UiccController.getInstance().getCardIdForDefaultEuicc();
6463 } finally {
6464 Binder.restoreCallingIdentity(identity);
6465 }
6466 }
6467
6468 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006469 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6470 enforceModifyPermission();
6471 final Phone phone = getPhone(subId);
6472 if (phone == null) {
6473 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6474 return;
6475 }
6476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477 final long identity = Binder.clearCallingIdentity();
6478 try {
6479 phone.setRadioIndicationUpdateMode(filters, mode);
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
Jack Yu4c988042018-02-27 15:30:01 -08006483 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006484
6485 /**
goneil47ffb6e2018-04-06 15:40:58 -07006486 * A test API to reload the UICC profile.
6487 *
6488 * <p>Requires that the calling app has permission
6489 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6490 * @hide
6491 */
6492 @Override
6493 public void refreshUiccProfile(int subId) {
6494 enforceModifyPermission();
6495
6496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 Phone phone = getPhone(subId);
6499 if (phone == null) {
6500 return;
6501 }
6502 UiccCard uiccCard = phone.getUiccCard();
6503 if (uiccCard == null) {
6504 return;
6505 }
6506 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6507 if (uiccProfile == null) {
6508 return;
6509 }
6510 uiccProfile.refresh();
6511 } finally {
6512 Binder.restoreCallingIdentity(identity);
6513 }
6514 }
6515
6516 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006517 * Returns false if the mobile data is disabled by default, otherwise return true.
6518 */
6519 private boolean getDefaultDataEnabled() {
6520 return "true".equalsIgnoreCase(
6521 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6522 }
6523
6524 /**
6525 * Returns true if the data roaming is enabled by default, i.e the system property
6526 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6527 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6528 */
6529 private boolean getDefaultDataRoamingEnabled(int subId) {
6530 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006531 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006532 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6533 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6534 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6535 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6536 return isDataRoamingEnabled;
6537 }
6538
6539 /**
6540 * Returns the default network type for the given {@code subId}, if the default network type is
6541 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6542 */
6543 private int getDefaultNetworkType(int subId) {
6544 return Integer.parseInt(
6545 TelephonyManager.getTelephonyProperty(
6546 mSubscriptionController.getPhoneId(subId),
6547 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6548 String.valueOf(Phone.PREFERRED_NT_MODE)));
6549 }
fionaxua13278b2018-03-21 00:08:13 -07006550
6551 @Override
6552 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006553 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555
6556 final long identity = Binder.clearCallingIdentity();
6557 try {
6558 final Phone phone = getPhone(subId);
6559 if (phone == null) {
6560 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6561 return;
6562 }
chen xueaba88a2019-03-15 13:15:10 -07006563 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6564 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 } finally {
6566 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006567 }
fionaxua13278b2018-03-21 00:08:13 -07006568 }
6569
6570 @Override
6571 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006572 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573
6574 final long identity = Binder.clearCallingIdentity();
6575 try {
6576 final Phone phone = getPhone(subId);
6577 if (phone == null) {
6578 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6579 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6580 }
6581 return phone.getCarrierIdListVersion();
6582 } finally {
6583 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006584 }
fionaxua13278b2018-03-21 00:08:13 -07006585 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006586
6587 @Override
6588 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6590 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6591 return -1;
6592 }
6593
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
6596 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6597 } finally {
6598 Binder.restoreCallingIdentity(identity);
6599 }
6600 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006601
6602 @Override
6603 public int getCdmaRoamingMode(int subId) {
6604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6605 mApp, subId, "getCdmaRoamingMode");
6606
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
6609 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
6613 }
6614
6615 @Override
6616 public boolean setCdmaRoamingMode(int subId, int mode) {
6617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6618 mApp, subId, "setCdmaRoamingMode");
6619
6620 final long identity = Binder.clearCallingIdentity();
6621 try {
6622 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
6625 }
6626 }
6627
6628 @Override
6629 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6631 mApp, subId, "setCdmaSubscriptionMode");
6632
6633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
6638 }
6639 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006640
6641 private void ensureUserRunning(int userId) {
6642 if (!mUserManager.isUserRunning(userId)) {
6643 throw new IllegalStateException("User " + userId + " does not exist or not running");
6644 }
6645 }
6646
6647 /**
6648 * Returns a list of SMS apps on a given user.
6649 *
6650 * Only the shell user (UID 2000 or 0) can call it.
6651 * Target user must be running.
6652 */
6653 @Override
6654 public String[] getSmsApps(int userId) {
6655 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6656 ensureUserRunning(userId);
6657
6658 final Collection<SmsApplicationData> apps =
6659 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6660
6661 String[] ret = new String[apps.size()];
6662 int i = 0;
6663 for (SmsApplicationData app : apps) {
6664 ret[i++] = app.mPackageName;
6665 }
6666 return ret;
6667 }
6668
6669 /**
6670 * Returns the default SMS app package name on a given user.
6671 *
6672 * Only the shell user (UID 2000 or 0) can call it.
6673 * Target user must be running.
6674 */
6675 @Override
6676 public String getDefaultSmsApp(int userId) {
6677 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6678 ensureUserRunning(userId);
6679
6680 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6681 /* updateIfNeeded= */ true, userId);
6682 return cn == null ? null : cn.getPackageName();
6683 }
6684
6685 /**
6686 * Set a package as the default SMS app on a given user.
6687 *
6688 * Only the shell user (UID 2000 or 0) can call it.
6689 * Target user must be running.
6690 */
6691 @Override
6692 public void setDefaultSmsApp(int userId, String packageName) {
6693 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6694 ensureUserRunning(userId);
6695
6696 boolean found = false;
6697 for (String pkg : getSmsApps(userId)) {
6698 if (TextUtils.equals(packageName, pkg)) {
6699 found = true;
6700 break;
6701 }
6702 }
6703 if (!found) {
6704 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6705 }
6706
6707 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6708 }
sqianc5eccab2018-10-19 18:46:41 -07006709
6710 @Override
sqian8c685422019-02-22 15:55:18 -08006711 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006712 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006714 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006715 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6716 }
6717 final long identity = Binder.clearCallingIdentity();
6718 try {
sqian854d44b2018-12-12 16:48:18 -08006719 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6720 for (Phone phone: PhoneFactory.getPhones()) {
6721 if (phone.getEmergencyNumberTracker() != null
6722 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6723 emergencyNumberListInternal.put(
6724 phone.getSubId(),
6725 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6726 }
sqian11b7a0e2018-12-05 18:48:28 -08006727 }
sqian854d44b2018-12-12 16:48:18 -08006728 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006729 } finally {
6730 Binder.restoreCallingIdentity(identity);
6731 }
sqianc5eccab2018-10-19 18:46:41 -07006732 }
6733
6734 @Override
sqian8c685422019-02-22 15:55:18 -08006735 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006736 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006737 if (!exactMatch) {
6738 TelephonyPermissions
6739 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006740 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006741 }
6742 final long identity = Binder.clearCallingIdentity();
6743 try {
sqian854d44b2018-12-12 16:48:18 -08006744 for (Phone phone: PhoneFactory.getPhones()) {
6745 if (phone.getEmergencyNumberTracker() != null
6746 && phone.getEmergencyNumberTracker() != null) {
6747 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6748 number, exactMatch)) {
6749 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006750 }
6751 }
sqian11b7a0e2018-12-05 18:48:28 -08006752 }
6753 return false;
6754 } finally {
6755 Binder.restoreCallingIdentity(identity);
6756 }
6757 }
6758
sqianf4ca7ed2019-01-15 18:32:07 -08006759 /**
6760 * Update emergency number list for test mode.
6761 */
6762 @Override
6763 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6764 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6765 "updateEmergencyNumberListTestMode");
6766
6767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 for (Phone phone: PhoneFactory.getPhones()) {
6770 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6771 if (tracker != null) {
6772 tracker.executeEmergencyNumberTestModeCommand(action, num);
6773 }
6774 }
6775 } finally {
6776 Binder.restoreCallingIdentity(identity);
6777 }
6778 }
6779
6780 /**
6781 * Get the full emergency number list for test mode.
6782 */
6783 @Override
6784 public List<String> getEmergencyNumberListTestMode() {
6785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6786 "getEmergencyNumberListTestMode");
6787
6788 final long identity = Binder.clearCallingIdentity();
6789 try {
6790 Set<String> emergencyNumbers = new HashSet<>();
6791 for (Phone phone: PhoneFactory.getPhones()) {
6792 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6793 if (tracker != null) {
6794 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6795 emergencyNumbers.add(num.getNumber());
6796 }
6797 }
6798 }
6799 return new ArrayList<>(emergencyNumbers);
6800 } finally {
6801 Binder.restoreCallingIdentity(identity);
6802 }
6803 }
6804
chen xud6b45bd2018-10-30 22:27:10 -07006805 @Override
6806 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6807 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6808 Phone phone = getPhone(subId);
6809 if (phone == null) {
6810 return null;
6811 }
6812 final long identity = Binder.clearCallingIdentity();
6813 try {
6814 UiccProfile profile = UiccController.getInstance()
6815 .getUiccProfileForPhone(phone.getPhoneId());
6816 if (profile != null) {
6817 return profile.getCertsFromCarrierPrivilegeAccessRules();
6818 }
6819 } finally {
6820 Binder.restoreCallingIdentity(identity);
6821 }
6822 return null;
6823 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006824
6825 /**
6826 * Enable or disable a modem stack.
6827 */
6828 @Override
6829 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6830 enforceModifyPermission();
6831
6832 final long identity = Binder.clearCallingIdentity();
6833 try {
6834 Phone phone = PhoneFactory.getPhone(slotIndex);
6835 if (phone == null) {
6836 return false;
6837 } else {
6838 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6839 }
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
6842 }
6843 }
Michelecea4cf22018-12-21 15:00:11 -08006844
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006845 /**
6846 * Whether a modem stack is enabled or not.
6847 */
6848 @Override
6849 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6850 Phone phone = PhoneFactory.getPhone(slotIndex);
6851 if (phone == null) return false;
6852
6853 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6854 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6855 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6856 }
6857
6858 final long identity = Binder.clearCallingIdentity();
6859 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006860 try {
6861 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6862 } catch (NoSuchElementException ex) {
6863 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6864 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006865 } finally {
6866 Binder.restoreCallingIdentity(identity);
6867 }
6868 }
6869
Michelecea4cf22018-12-21 15:00:11 -08006870 @Override
Michele0ea7d782019-03-19 14:58:42 -07006871 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006872 enforceModifyPermission();
6873
6874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006877 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006878 .commit();
6879 } finally {
6880 Binder.restoreCallingIdentity(identity);
6881 }
6882 }
6883
6884 @Override
Michele0ea7d782019-03-19 14:58:42 -07006885 @TelephonyManager.IsMultiSimSupportedResult
6886 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006888 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6889 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006890 }
Michelecea4cf22018-12-21 15:00:11 -08006891
6892 final long identity = Binder.clearCallingIdentity();
6893 try {
Michele0ea7d782019-03-19 14:58:42 -07006894 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006895 } finally {
6896 Binder.restoreCallingIdentity(identity);
6897 }
6898 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006899
Michele0ea7d782019-03-19 14:58:42 -07006900 @TelephonyManager.IsMultiSimSupportedResult
6901 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006902 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6903 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6904 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006905 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6906 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006907 }
6908 // Check if the hardware supports multisim functionality. If usage of multisim is not
6909 // supported by the modem, indicate that it is restricted.
6910 PhoneCapability staticCapability =
6911 mPhoneConfigurationManager.getStaticPhoneCapability();
6912 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006913 loge("isMultiSimSupportedInternal: no static configuration available");
6914 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006915 }
6916 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006917 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6918 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006919 }
6920 // Check if support of multiple SIMs is restricted by carrier
6921 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006922 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006923 }
6924
Michele0ea7d782019-03-19 14:58:42 -07006925 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006926 }
6927
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006928 /**
6929 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006930 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6931 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6932 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006933 * @param numOfSims number of active sims we want to switch to
6934 */
6935 @Override
6936 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006937 if (numOfSims == 1) {
6938 enforceModifyPermission();
6939 } else {
6940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6941 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6942 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006943 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006944
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006945 try {
Michele30b57b22019-03-01 12:01:14 -08006946 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006947 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006948 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6949 return;
6950 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006951 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6952 } finally {
6953 Binder.restoreCallingIdentity(identity);
6954 }
6955 }
6956
6957 /**
chen xub4baa772019-04-03 10:23:41 -07006958 * Get whether making changes to modem configurations will trigger reboot.
6959 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006960 */
6961 @Override
chen xub4baa772019-04-03 10:23:41 -07006962 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
6963 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6964 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
6965 return false;
6966 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6970 } finally {
6971 Binder.restoreCallingIdentity(identity);
6972 }
6973 }
6974
Nathan Harold29f5f052019-02-15 13:41:57 -08006975 private void updateModemStateMetrics() {
6976 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6977 // TODO: check the state for each modem if the api is ready.
6978 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6979 }
6980
Pengquan Meng3889a572019-01-23 11:16:29 -08006981 @Override
6982 public int[] getSlotsMapping() {
6983 enforceReadPrivilegedPermission("getSlotsMapping");
6984
6985 final long identity = Binder.clearCallingIdentity();
6986 try {
6987 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6988 // All logical slots should have a mapping to a physical slot.
6989 int[] logicalSlotsMapping = new int[phoneCount];
6990 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6991 for (int i = 0; i < slotInfos.length; i++) {
6992 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6993 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6994 }
6995 }
6996 return logicalSlotsMapping;
6997 } finally {
6998 Binder.restoreCallingIdentity(identity);
6999 }
7000 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007001
7002 /**
7003 * Get the IRadio HAL Version
7004 */
7005 @Override
7006 public int getRadioHalVersion() {
7007 Phone phone = getDefaultPhone();
7008 if (phone == null) return -1;
7009 HalVersion hv = phone.getHalVersion();
7010 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7011 return hv.major * 100 + hv.minor;
7012 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007013
7014 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007015 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7016 * corresponding network requests on a subId.
7017 *
7018 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007019 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007020 * 2) APN is un-metered for this subscription, or
7021 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7022 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7023 *
7024 * @return whether data is allowed for a apn type.
7025 *
7026 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007027 */
7028 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007029 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007031 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7032 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007033 }
7034
7035 // Now that all security checks passes, perform the operation as ourselves.
7036 final long identity = Binder.clearCallingIdentity();
7037 try {
7038 Phone phone = getPhone(subId);
7039 if (phone == null) return false;
7040
Jack Yu41407ee2019-05-13 16:54:09 -07007041 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007042 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7043 } finally {
7044 Binder.restoreCallingIdentity(identity);
7045 }
7046 }
7047
7048 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007049 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007050 enforceReadPrivilegedPermission("isApnMetered");
7051
7052 // Now that all security checks passes, perform the operation as ourselves.
7053 final long identity = Binder.clearCallingIdentity();
7054 try {
7055 Phone phone = getPhone(subId);
7056 if (phone == null) return true; // By default return true.
7057
Jack Yu41407ee2019-05-13 16:54:09 -07007058 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007059 } finally {
7060 Binder.restoreCallingIdentity(identity);
7061 }
7062 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007063
7064 @Override
7065 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7066 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7067 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7068 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7069 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7070 }
7071 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7072 Intent intent = new Intent();
7073 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7074 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7075 // Bring up choose default SMS subscription dialog right now
7076 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7077 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7078 mApp.startActivity(intent);
7079 }
chen xud5ca2d52019-05-28 15:20:57 -07007080
7081 @Override
7082 public String getMmsUAProfUrl(int subId) {
7083 //TODO investigate if this API should require proper permission check in R b/133791609
7084 final long identity = Binder.clearCallingIdentity();
7085 try {
7086 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7087 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7088 } finally {
7089 Binder.restoreCallingIdentity(identity);
7090 }
7091 }
7092
7093 @Override
7094 public String getMmsUserAgent(int subId) {
7095 //TODO investigate if this API should require proper permission check in R b/133791609
7096 final long identity = Binder.clearCallingIdentity();
7097 try {
7098 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7099 .getString(com.android.internal.R.string.config_mms_user_agent);
7100 } finally {
7101 Binder.restoreCallingIdentity(identity);
7102 }
7103 }
Jack Yub07d4972019-05-28 16:12:25 -07007104
7105 @Override
7106 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7107 enforceModifyPermission();
7108
7109 // Now that all security checks passes, perform the operation as ourselves.
7110 final long identity = Binder.clearCallingIdentity();
7111 try {
7112 Phone phone = getPhone(subId);
7113 if (phone == null) return false;
7114
7115 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7116 } finally {
7117 Binder.restoreCallingIdentity(identity);
7118 }
7119 }
7120
7121 @Override
7122 public boolean isDataAllowedInVoiceCall(int subId) {
7123 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7124
7125 // Now that all security checks passes, perform the operation as ourselves.
7126 final long identity = Binder.clearCallingIdentity();
7127 try {
7128 Phone phone = getPhone(subId);
7129 if (phone == null) return false;
7130
7131 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7132 } finally {
7133 Binder.restoreCallingIdentity(identity);
7134 }
7135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007136}